openjpa-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ppod...@apache.org
Subject svn commit: r1042274 - in /openjpa/sandboxes/jest/openjpa-persistence/src/main: java/org/apache/openjpa/persistence/jest/ resources/org/apache/openjpa/persistence/jest/
Date Sun, 05 Dec 2010 02:03:10 GMT
Author: ppoddar
Date: Sun Dec  5 02:03:09 2010
New Revision: 1042274

URL: http://svn.apache.org/viewvc?rev=1042274&view=rev
Log:
OPENJPA-1851: Render error in client

Modified:
    openjpa/sandboxes/jest/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/jest/Constants.java
    openjpa/sandboxes/jest/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/jest/ExceptionFormatter.java
    openjpa/sandboxes/jest/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/jest/ProcessingException.java
    openjpa/sandboxes/jest/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/jest/QueryCommand.java
    openjpa/sandboxes/jest/openjpa-persistence/src/main/resources/org/apache/openjpa/persistence/jest/jest.js

Modified: openjpa/sandboxes/jest/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/jest/Constants.java
URL: http://svn.apache.org/viewvc/openjpa/sandboxes/jest/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/jest/Constants.java?rev=1042274&r1=1042273&r2=1042274&view=diff
==============================================================================
--- openjpa/sandboxes/jest/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/jest/Constants.java
(original)
+++ openjpa/sandboxes/jest/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/jest/Constants.java
Sun Dec  5 02:03:09 2010
@@ -99,7 +99,7 @@ public interface Constants {
     
     
     public static final String ROOT_ELEMENT_ERROR      = "error";
-    public static final String ELEMENT_ERROR_HEADER    = "error-code";
+    public static final String ELEMENT_ERROR_HEADER    = "error-header";
     public static final String ELEMENT_ERROR_MESSAGE   = "error-message";
     public static final String ELEMENT_ERROR_TRACE     = "stacktrace";
     

Modified: openjpa/sandboxes/jest/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/jest/ExceptionFormatter.java
URL: http://svn.apache.org/viewvc/openjpa/sandboxes/jest/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/jest/ExceptionFormatter.java?rev=1042274&r1=1042273&r2=1042274&view=diff
==============================================================================
--- openjpa/sandboxes/jest/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/jest/ExceptionFormatter.java
(original)
+++ openjpa/sandboxes/jest/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/jest/ExceptionFormatter.java
Sun Dec  5 02:03:09 2010
@@ -38,21 +38,21 @@ class ExceptionFormatter extends XMLForm
      * @param header
      * @param e
      */
-    public Document createXML(String code, String message, Throwable e) {
+    public Document createXML(String header, Throwable e) {
         Element root = newDocument(Constants.ROOT_ELEMENT_ERROR);
         Document doc = root.getOwnerDocument();
-        Element errorCode    = doc.createElement(Constants.ELEMENT_ERROR_HEADER);
+        Element errorHeader  = doc.createElement(Constants.ELEMENT_ERROR_HEADER);
         Element errorMessage = doc.createElement(Constants.ELEMENT_ERROR_MESSAGE);
         Element stackTrace   = doc.createElement(Constants.ELEMENT_ERROR_TRACE);
 
-        errorCode.setTextContent(code);
+        errorHeader.setTextContent(header);
         errorMessage.appendChild(doc.createCDATASection(e.getMessage()));
         
         StringWriter buf = new StringWriter();
         e.printStackTrace(new PrintWriter(buf, true));
         stackTrace.appendChild(doc.createCDATASection(buf.toString()));
         
-        root.appendChild(errorCode);
+        root.appendChild(errorHeader);
         root.appendChild(errorMessage);
         root.appendChild(stackTrace);
         

Modified: openjpa/sandboxes/jest/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/jest/ProcessingException.java
URL: http://svn.apache.org/viewvc/openjpa/sandboxes/jest/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/jest/ProcessingException.java?rev=1042274&r1=1042273&r2=1042274&view=diff
==============================================================================
--- openjpa/sandboxes/jest/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/jest/ProcessingException.java
(original)
+++ openjpa/sandboxes/jest/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/jest/ProcessingException.java
Sun Dec  5 02:03:09 2010
@@ -75,19 +75,23 @@ public class ProcessingException extends
      * @throws IOException
      */
     public void printStackTrace() {
+        HttpServletResponse response = ctx.getResponse();
+        response.setContentType(MIME_TYPE_XML);
+        response.setStatus(_errorCode);
+
+        String uri = ctx.getRequestURI().toString();
         try {
-            HttpServletResponse response = ctx.getResponse();
-            response.setContentType(MIME_TYPE_XML);
-            response.setStatus(_errorCode);
-            Throwable t = this.getCause() == null ? this : getCause();
-            String uri = "URI: " + URLDecoder.decode(ctx.getRequestURI().toString(), "UTF-8");
-            ExceptionFormatter formatter = new ExceptionFormatter();
-            Document xml = formatter.createXML("HTTP Error: " + _errorCode, uri, t);
-            formatter.write(xml, response.getOutputStream(), false);
+            uri = URLDecoder.decode(uri, "UTF-8");
         } catch (Exception e) {
-            throw new RuntimeException(e);
+        }
+        Throwable t = this.getCause() == null ? this : getCause();
+        ExceptionFormatter formatter = new ExceptionFormatter();
+        Document xml = formatter.createXML("Request URI: " + uri, t);
+        try {
+            formatter.write(xml, response.getOutputStream(), false);
+        } catch (IOException e) {
+            e.printStackTrace();
+            throw new RuntimeException("Request URI: " + uri, e);
         }
     }
-    
-
 }

Modified: openjpa/sandboxes/jest/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/jest/QueryCommand.java
URL: http://svn.apache.org/viewvc/openjpa/sandboxes/jest/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/jest/QueryCommand.java?rev=1042274&r1=1042273&r2=1042274&view=diff
==============================================================================
--- openjpa/sandboxes/jest/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/jest/QueryCommand.java
(original)
+++ openjpa/sandboxes/jest/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/jest/QueryCommand.java
Sun Dec  5 02:03:09 2010
@@ -29,6 +29,9 @@ import static org.apache.openjpa.persist
 import javax.persistence.EntityManager;
 import javax.persistence.Query;
 
+import org.apache.openjpa.persistence.ArgumentException;
+import static java.net.HttpURLConnection.HTTP_BAD_REQUEST;;
+
 /**
  * Executes query.
  * 
@@ -80,6 +83,8 @@ class QueryCommand extends AbstractComma
                  em.getMetamodel(), 
                  _loc.get("query-title").toString(), _loc.get("query-desc").toString(), ctx.getRequestURI(),

                  ctx.getResponse().getOutputStream());
+        } catch (ArgumentException e1) {
+            throw new ProcessingException(ctx, e1, _loc.get("query-execution-error", spec),
HTTP_BAD_REQUEST);
         } catch (Exception e) {
             throw new ProcessingException(ctx, e, _loc.get("query-execution-error", spec));
         }

Modified: openjpa/sandboxes/jest/openjpa-persistence/src/main/resources/org/apache/openjpa/persistence/jest/jest.js
URL: http://svn.apache.org/viewvc/openjpa/sandboxes/jest/openjpa-persistence/src/main/resources/org/apache/openjpa/persistence/jest/jest.js?rev=1042274&r1=1042273&r2=1042274&view=diff
==============================================================================
--- openjpa/sandboxes/jest/openjpa-persistence/src/main/resources/org/apache/openjpa/persistence/jest/jest.js
(original)
+++ openjpa/sandboxes/jest/openjpa-persistence/src/main/resources/org/apache/openjpa/persistence/jest/jest.js
Sun Dec  5 02:03:09 2010
@@ -152,10 +152,6 @@ function toURI(commandName) {
 function addVarArgRow(rowIdPrefix, index, message) {
 	var rowId = rowIdPrefix + '.' + index;
 	var row = document.getElementById(rowId);
-	if (row == null) {
-		console.log("*ERROR: Variable argument row id [" + rowId + "] not found in the document");
-		return;
-    }
 	clearElement(rowId);
 	
 	// New input column for parameter name. Element id is rowId + '.key'
@@ -250,7 +246,6 @@ function Command(name, qualifiers, argum
  * @returns a string form of URI
  * ---------------------------------------------------------------------------------------
*/
 function Command_toURI() {
-	console.log("Rewriting URI for " + this.name + " command");
 	var uri = this.name; // command name is same as URI name -- need not be
 	var iformat = 'xml';  // default response format
 	for (var i = 0; i < this.qualifiers.length; i++) {
@@ -615,21 +610,25 @@ function render(/* string */ uri, /* id 
         preventCache: contentType == 'instances',
         timeout : 1000,
         load: function(data, ioargs) {
-    		var newDivs = null;
-        	if (iformat == 'json') {
-        		newDivs = renderJSONResponse(data, contentType);
+        	if (ioargs.xhr.status == 200) { // HTTP OK
+	    		var newDivs = null;
+	        	if (iformat == 'json') {
+	        		newDivs = renderJSONResponse(data, contentType);
+	        	} else {
+	        		newDivs = renderXMLResponse(data, contentType);
+	        	} 
+	    		var displayModes = getSupportedDisplayModes(iformat, contentType);
+	        	targetNode.appendChild(createDisplayModeControl(displayModes));
+	        	for (var i = 0; i < newDivs.length; i++) {
+	        		targetNode.appendChild(newDivs[i]);
+	        	}
         	} else {
-        		newDivs = renderXMLResponse(data, contentType);
-        	} 
-    		var displayModes = getSupportedDisplayModes(iformat, contentType);
-        	targetNode.appendChild(createDisplayModeControl(displayModes));
-        	for (var i = 0; i < newDivs.length; i++) {
-        		targetNode.appendChild(newDivs[i]);
+            	var errorDiv = renderErrorFromXMLAsHTML(data, ioargs);
+            	targetNode.appendChild(errorDiv);
         	}
         },
         error: function(error, ioargs) {
-        	console.log("error : " + error + " ioargs:" + ioargs);
-        	var errorDiv = renderErrorFromXMLAsHTML(error, ioargs);
+        	var errorDiv = renderErrorFromXMLAsHTML(ioargs.xhr.responseXML, ioargs);
         	targetNode.appendChild(errorDiv);
         }
     };
@@ -848,21 +847,26 @@ function renderPropertiesFromXMLAsHTML(/
  * 
  * @returns a div element with error details
  */
-function renderErrorFromXMLAsHTML(/*XML DOM*/data, ioargs) {
-	console.log("renderErrorFromXMLAsHTML " + data);
-	var div = document.createElement("div");
-//	var errorCode = document.createElement("p");
-//	var msg = document.createElement("p");
-//	var trace = document.createElement("pre");
-//	errorCode.setAttribute("class", "error-code");
-//	msg.setAttribute("class", "error-message");
-//	errorCode.innerHTML = getNodeValue(data.getElementsByTagName("error-code")[0]);
-//	msg.innerHTML       = getNodeValue(data.getElementsByTagName("error-message")[0]);
-//	trace.innerHTML     = getNodeValue(data.getElementsByTagName("stacktrace")[0]);
-//	div.appendChild(errorCode);
-//	div.appendChild(msg);
-//	div.appendChild(trace);
-	div.innerHTML = ioargs.xhr.status + ' ' + data;
+function renderErrorFromXMLAsHTML(/*response as XML DOM*/responseXML, ioargs) {
+	var div    = document.createElement("div");
+	var ecode  = document.createElement("h3");
+	var header = document.createElement("p");
+	var msg    = document.createElement("p");
+	var trace  = document.createElement("pre");
+	ecode.setAttribute("class", "error-header");
+	header.setAttribute("class", "error-message");
+	msg.setAttribute("class", "error-message");
+	
+	var serverError = responseXML.documentElement;
+	ecode.innerHTML  = "HTTP Error " + ioargs.xhr.status;
+	header.innerHTML = dojox.xml.parser.textContent(serverError.getElementsByTagName("error-header").item(0));
+	msg.innerHTML    = dojox.xml.parser.textContent(serverError.getElementsByTagName("error-message").item(0));
+	trace.innerHTML  = dojox.xml.parser.textContent(serverError.getElementsByTagName("stacktrace").item(0));
+	div.appendChild(ecode);
+	div.appendChild(header);
+	div.appendChild(msg);
+	div.appendChild(trace);
+
 	return div;
 }
 
@@ -880,7 +884,6 @@ function createInstanceDojoWidget(/*XML 
 	var instanceTable = document.createElement("table");
 	dojo.query('id, basic, enum, version', instanceNode)
 	    .forEach(function(item) { 
-	    	console.log("createInstanceDojoWidget " + instanceNode.getAttribute("id") + "." + item.getAttribute("name"));
 			var attrRow     = document.createElement("tr");
 			var nameColumn  = document.createElement("td");
 			var valueColumn = document.createElement("td");
@@ -983,12 +986,6 @@ function createEntityTypeDojoWidget(node
  */
 function renderXMLasXML(/*XML DOM*/dom) {
 	var newDiv = document.createElement('div');
-//	var pre    = document.createElement('pre');
-//	newDiv.appendChild(pre);
-//	// replace all < character to &lt; so that they display properly
-//	var replaced = dojox.xml.parser.innerXML(dom).replace(/</g, '&lt;');
-//	pre.innerHTML = replaced;
-	
 	print(dom.documentElement, newDiv, 0);
 	return newDiv;
 }



Mime
View raw message