Author: manaRH
Date: 2009-08-03 09:45:14 -0400 (Mon, 03 Aug 2009)
New Revision: 11335
Modified:
branches/enterprise/JBPAPP_4_3_FP01/src/remoting/org/jboss/seam/remoting/Call.java
branches/enterprise/JBPAPP_4_3_FP01/src/remoting/org/jboss/seam/remoting/ExecutionHandler.java
branches/enterprise/JBPAPP_4_3_FP01/src/remoting/org/jboss/seam/remoting/InterfaceGenerator.java
branches/enterprise/JBPAPP_4_3_FP01/src/remoting/org/jboss/seam/remoting/MarshalUtils.java
branches/enterprise/JBPAPP_4_3_FP01/src/remoting/org/jboss/seam/remoting/remote.js
branches/enterprise/JBPAPP_4_3_FP01/src/test/unit/org/jboss/seam/test/unit/RemotingTest.java
Log:
JBPAPP-2272
Modified:
branches/enterprise/JBPAPP_4_3_FP01/src/remoting/org/jboss/seam/remoting/Call.java
===================================================================
---
branches/enterprise/JBPAPP_4_3_FP01/src/remoting/org/jboss/seam/remoting/Call.java 2009-08-01
18:51:04 UTC (rev 11334)
+++
branches/enterprise/JBPAPP_4_3_FP01/src/remoting/org/jboss/seam/remoting/Call.java 2009-08-03
13:45:14 UTC (rev 11335)
@@ -10,7 +10,6 @@
import org.jboss.seam.Component;
import org.jboss.seam.annotations.remoting.WebRemote;
-import org.jboss.seam.core.Expressions;
import org.jboss.seam.remoting.wrapper.ConversionException;
import org.jboss.seam.remoting.wrapper.ConversionScore;
import org.jboss.seam.remoting.wrapper.Wrapper;
@@ -25,8 +24,10 @@
private String id;
private String componentName;
private String methodName;
- private String expression;
+ //private String expression;
+ private Throwable exception;
+
private List<Wrapper> params = new ArrayList<Wrapper> ();
private Object result;
@@ -50,18 +51,6 @@
}
/**
- *
- * @param id
- * @param expression
- */
- public Call(String id, String expression)
- {
- this.id = id;
- this.expression = expression;
- this.context = new CallContext();
- }
-
- /**
* Return the call context.
*
* @return CallContext
@@ -70,6 +59,19 @@
{
return context;
}
+
+
+ /**
+ * Returns the exception thrown by the invoked method. If no exception was thrown,
+ * will return null
+ *
+ * @return Throwable
+ */
+ public Throwable getException()
+ {
+ return exception;
+ }
+
/**
* Add a parameter to this call.
@@ -91,7 +93,18 @@
return result;
}
+
/**
+ * Required for unit tests
+ *
+ * @param result
+ */
+ public void setResult(Object result)
+ {
+ this.result = result;
+ }
+
+ /**
* Returns the id of this call.
*
* @return String
@@ -110,6 +123,16 @@
{
return constraints;
}
+
+ /**
+ * Required for unit tests
+ *
+ * @param constraints
+ */
+ public void setConstraints(List<String> constraints)
+ {
+ this.constraints = constraints;
+ }
/**
* Execute this call
@@ -123,10 +146,6 @@
{
processInvocation();
}
- else if (expression != null)
- {
- processExpression();
- }
}
private void processInvocation()
@@ -178,14 +197,16 @@
constraints = Arrays.asList(m.getAnnotation(WebRemote.class).exclude());
// Invoke!
- result = m.invoke(instance, convertParams(m.getGenericParameterTypes()));
+ try
+ {
+ result = m.invoke(instance, convertParams(m.getGenericParameterTypes()));
+ }
+ catch (Exception e)
+ {
+ this.exception = e.getCause();
+ }
}
- private void processExpression()
- {
- result = Expressions.instance().createValueExpression(expression).getValue();
- }
-
/**
* Convert our parameter values to an Object array of the specified target
* types.
Modified:
branches/enterprise/JBPAPP_4_3_FP01/src/remoting/org/jboss/seam/remoting/ExecutionHandler.java
===================================================================
---
branches/enterprise/JBPAPP_4_3_FP01/src/remoting/org/jboss/seam/remoting/ExecutionHandler.java 2009-08-01
18:51:04 UTC (rev 11334)
+++
branches/enterprise/JBPAPP_4_3_FP01/src/remoting/org/jboss/seam/remoting/ExecutionHandler.java 2009-08-03
13:45:14 UTC (rev 11335)
@@ -186,13 +186,6 @@
calls.add(call);
}
-
- List<Element> exprElements =
env.element("body").elements("eval");
- for (Element e : exprElements)
- {
- Call call = new Call(e.attributeValue("id"),
e.attributeValue("expr"));
- calls.add(call);
- }
return calls;
}
@@ -230,8 +223,7 @@
for (Call call : calls)
{
- MarshalUtils.marshalResult(call.getId(), call.getContext(), out,
- call.getResult(), call.getConstraints());
+ MarshalUtils.marshalResult(call, out);
}
out.write(BODY_TAG_CLOSE);
Modified:
branches/enterprise/JBPAPP_4_3_FP01/src/remoting/org/jboss/seam/remoting/InterfaceGenerator.java
===================================================================
---
branches/enterprise/JBPAPP_4_3_FP01/src/remoting/org/jboss/seam/remoting/InterfaceGenerator.java 2009-08-01
18:51:04 UTC (rev 11334)
+++
branches/enterprise/JBPAPP_4_3_FP01/src/remoting/org/jboss/seam/remoting/InterfaceGenerator.java 2009-08-03
13:45:14 UTC (rev 11335)
@@ -364,7 +364,7 @@
componentSrc.append(i);
}
- componentSrc.append("], callback);\n");
+ componentSrc.append("], callback, exceptionHandler);\n");
componentSrc.append(" }\n");
}
Modified:
branches/enterprise/JBPAPP_4_3_FP01/src/remoting/org/jboss/seam/remoting/MarshalUtils.java
===================================================================
---
branches/enterprise/JBPAPP_4_3_FP01/src/remoting/org/jboss/seam/remoting/MarshalUtils.java 2009-08-01
18:51:04 UTC (rev 11334)
+++
branches/enterprise/JBPAPP_4_3_FP01/src/remoting/org/jboss/seam/remoting/MarshalUtils.java 2009-08-03
13:45:14 UTC (rev 11335)
@@ -20,46 +20,63 @@
private static final byte[] VALUE_TAG_OPEN = "<value>".getBytes();
private static final byte[] VALUE_TAG_CLOSE = "</value>".getBytes();
+
+ private static final byte[] EXCEPTION_TAG_OPEN =
"<exception>".getBytes();
+ private static final byte[] EXCEPTION_TAG_CLOSE =
"</exception>".getBytes();
+
+ private static final byte[] MESSAGE_TAG_OPEN = "<message>".getBytes();
+ private static final byte[] MESSAGE_TAG_CLOSE =
"</message>".getBytes();
- public static void marshalResult(String callId, CallContext ctx, OutputStream out,
- Object result, List<String> constraints)
+ public static void marshalResult(Call call, OutputStream out)
throws IOException
{
- if (callId != null)
+ if (call.getId() != null)
{
out.write(RESULT_TAG_OPEN_START);
- out.write(callId.getBytes());
+ out.write(call.getId().getBytes());
out.write(RESULT_TAG_OPEN_END);
}
else
out.write(RESULT_TAG_OPEN);
- out.write(VALUE_TAG_OPEN);
-
- ctx.createWrapperFromObject(result, "").marshal(out);
-
- out.write(VALUE_TAG_CLOSE);
-
- out.write(RequestHandler.REFS_TAG_OPEN);
-
- // Using a for-loop, because stuff can get added to outRefs as we recurse the object
graph
- for (int i = 0; i < ctx.getOutRefs().size(); i++)
+ if (call.getException() != null)
{
- Wrapper wrapper = ctx.getOutRefs().get(i);
-
- out.write(RequestHandler.REF_TAG_OPEN_START);
- out.write(Integer.toString(i).getBytes());
- out.write(RequestHandler.REF_TAG_OPEN_END);
-
- if (wrapper instanceof BeanWrapper && constraints != null)
- ((BeanWrapper) wrapper).serialize(out, constraints);
- else
- wrapper.serialize(out);
-
- out.write(RequestHandler.REF_TAG_CLOSE);
+ out.write(EXCEPTION_TAG_OPEN);
+ out.write(MESSAGE_TAG_OPEN);
+ call.getContext().createWrapperFromObject(call.getException().getMessage(),
"").marshal(out);
+ out.write(MESSAGE_TAG_CLOSE);
+ out.write(EXCEPTION_TAG_CLOSE);
}
-
- out.write(RequestHandler.REFS_TAG_CLOSE);
+ else
+ {
+ out.write(VALUE_TAG_OPEN);
+
+ call.getContext().createWrapperFromObject(call.getResult(),
"").marshal(out);
+
+ out.write(VALUE_TAG_CLOSE);
+
+ out.write(RequestHandler.REFS_TAG_OPEN);
+
+ // Using a for-loop, because stuff can get added to outRefs as we recurse the
object graph
+ for (int i = 0; i < call.getContext().getOutRefs().size(); i++)
+ {
+ Wrapper wrapper = call.getContext().getOutRefs().get(i);
+
+ out.write(RequestHandler.REF_TAG_OPEN_START);
+ out.write(Integer.toString(i).getBytes());
+ out.write(RequestHandler.REF_TAG_OPEN_END);
+
+ if (wrapper instanceof BeanWrapper && call.getConstraints() != null)
+ ((BeanWrapper) wrapper).serialize(out, call.getConstraints());
+ else
+ wrapper.serialize(out);
+
+ out.write(RequestHandler.REF_TAG_CLOSE);
+ }
+
+ out.write(RequestHandler.REFS_TAG_CLOSE);
+ }
+
out.write(RESULT_TAG_CLOSE);
}
}
Modified:
branches/enterprise/JBPAPP_4_3_FP01/src/remoting/org/jboss/seam/remoting/remote.js
===================================================================
---
branches/enterprise/JBPAPP_4_3_FP01/src/remoting/org/jboss/seam/remoting/remote.js 2009-08-01
18:51:04 UTC (rev 11334)
+++
branches/enterprise/JBPAPP_4_3_FP01/src/remoting/org/jboss/seam/remoting/remote.js 2009-08-03
13:45:14 UTC (rev 11335)
@@ -152,7 +152,8 @@
}
}
-Seam.Remoting.__Context = function() {
+Seam.Remoting.__Context = function()
+{
this.conversationId = null;
Seam.Remoting.__Context.prototype.setConversationId = function(conversationId)
@@ -166,6 +167,16 @@
}
}
+Seam.Remoting.Exception = function(msg)
+{
+ this.message = msg;
+
+ Seam.Remoting.Exception.prototype.getMessage = function()
+ {
+ return this.message;
+ }
+}
+
Seam.Remoting.context = new Seam.Remoting.__Context();
Seam.Remoting.getContext = function()
@@ -464,7 +475,7 @@
call.asyncReq = Seam.Remoting.sendAjaxRequest(envelope, Seam.Remoting.PATH_EXECUTE,
Seam.Remoting.processResponse, false);
}
-Seam.Remoting.createCall = function(component, methodName, params, callback)
+Seam.Remoting.createCall = function(component, methodName, params, callback,
exceptionHandler)
{
var callId = "" + Seam.Remoting.__callId++;
if (!callback)
@@ -504,7 +515,7 @@
data += "</call>";
- return {data: data, id: callId, callback: callback};
+ return {data: data, id: callId, callback: callback, exceptionHandler:
exceptionHandler};
}
Seam.Remoting.createHeader = function()
@@ -593,9 +604,9 @@
}
}
-Seam.Remoting.execute = function(component, methodName, params, callback)
+Seam.Remoting.execute = function(component, methodName, params, callback,
exceptionHandler)
{
- var call = Seam.Remoting.createCall(component, methodName, params, callback);
+ var call = Seam.Remoting.createCall(component, methodName, params, callback,
exceptionHandler);
if (Seam.Remoting.inBatch)
{
@@ -731,10 +742,11 @@
var call = Seam.Remoting.pendingCalls.get(callId);
Seam.Remoting.pendingCalls.remove(callId);
- if (call && call.callback)
+ if (call && (call.callback || call.exceptionHandler))
{
var valueNode = null;
var refsNode = null;
+ var exceptionNode = null;
var children = result.childNodes;
for (var i = 0; i < children.length; i++)
@@ -744,15 +756,35 @@
valueNode = children.item(i);
else if (tag == "refs")
refsNode = children.item(i);
+ else if (tag == "exception")
+ exceptionNode = children.item(i);
}
- var refs = new Array();
- if (refsNode)
- Seam.Remoting.unmarshalRefs(refsNode, refs);
-
- var value = Seam.Remoting.unmarshalValue(valueNode.firstChild, refs);
-
- call.callback(value, context);
+ if (exceptionNode != null)
+ {
+ var msgNode = null;
+ var children = exceptionNode.childNodes;
+ for (var i = 0; i < children.length; i++)
+ {
+ var tag = children.item(i).tagName;
+ if (tag == "message")
+ msgNode = children.item(i);
+ }
+
+ var msg = Seam.Remoting.unmarshalValue(msgNode.firstChild);
+ var ex = new Seam.Remoting.Exception(msg);
+ call.exceptionHandler(ex);
+ }
+ else
+ {
+ var refs = new Array();
+ if (refsNode)
+ Seam.Remoting.unmarshalRefs(refsNode, refs);
+
+ var value = Seam.Remoting.unmarshalValue(valueNode.firstChild, refs);
+
+ call.callback(value, context, callId);
+ }
}
}
Modified:
branches/enterprise/JBPAPP_4_3_FP01/src/test/unit/org/jboss/seam/test/unit/RemotingTest.java
===================================================================
---
branches/enterprise/JBPAPP_4_3_FP01/src/test/unit/org/jboss/seam/test/unit/RemotingTest.java 2009-08-01
18:51:04 UTC (rev 11334)
+++
branches/enterprise/JBPAPP_4_3_FP01/src/test/unit/org/jboss/seam/test/unit/RemotingTest.java 2009-08-03
13:45:14 UTC (rev 11335)
@@ -34,6 +34,7 @@
import org.jboss.seam.contexts.ServletLifecycle;
import org.jboss.seam.init.Initialization;
import org.jboss.seam.mock.MockServletContext;
+import org.jboss.seam.remoting.Call;
import org.jboss.seam.remoting.CallContext;
import org.jboss.seam.remoting.MarshalUtils;
import org.jboss.seam.remoting.client.ParserUtils;
@@ -740,9 +741,10 @@
ByteArrayOutputStream out = new ByteArrayOutputStream();
// Constrain a single field of the result
- List<String> constraints = Arrays.asList(new String[] { "secret"
});
- MarshalUtils.marshalResult(null, new CallContext(), out, result,
- constraints);
+ Call c = new Call(null, null, null);
+ c.setConstraints(Arrays.asList(new String[] { "secret" }));
+ c.setResult(result);
+ MarshalUtils.marshalResult(c, out);
SAXReader xmlReader = new SAXReader();
Document doc = xmlReader.read(new StringReader(new String(out
@@ -766,10 +768,9 @@
out.reset();
// Now we're going to constrain result.child's secret field
- constraints = Arrays.asList(new String[] { "child.secret" });
- MarshalUtils.marshalResult(null, new CallContext(), out, result,
- constraints);
-
+ c.setConstraints(Arrays.asList(new String[] { "child.secret" }));
+ MarshalUtils.marshalResult(c, out);
+
doc = xmlReader.read(new StringReader(new String(out.toByteArray())));
widget = (Widget) ParserUtils.unmarshalResult(doc.getRootElement());
assert "foo".equals(widget.getValue());
@@ -789,10 +790,8 @@
// Constrain the "secret" field of the widgetMap map's values
(sounds
// confusing, I know...)
- constraints = Arrays
- .asList(new String[] { "widgetMap[value].secret" });
- MarshalUtils.marshalResult(null, new CallContext(), out, result,
- constraints);
+ c.setConstraints(Arrays.asList(new String[] {
"widgetMap[value].secret" }));
+ MarshalUtils.marshalResult(c, out);
doc = xmlReader.read(new StringReader(new String(out.toByteArray())));
widget = (Widget) ParserUtils.unmarshalResult(doc.getRootElement());
@@ -812,9 +811,8 @@
result.getWidgetList().add(item);
// Constraint the "secret" field of widgetList
- constraints = Arrays.asList(new String[] { "widgetList.secret" });
- MarshalUtils.marshalResult(null, new CallContext(), out, result,
- constraints);
+ c.setConstraints(Arrays.asList(new String[] { "widgetList.secret"
}));
+ MarshalUtils.marshalResult(c, out);
doc = xmlReader.read(new StringReader(new String(out.toByteArray())));
widget = (Widget) ParserUtils.unmarshalResult(doc.getRootElement());
@@ -827,10 +825,8 @@
out.reset();
// Now constrain all secrets
- constraints = Arrays
- .asList(new String[] { "[" + Widget.class.getName() +
"].secret" });
- MarshalUtils.marshalResult(null, new CallContext(), out, result,
- constraints);
+ c.setConstraints(Arrays.asList(new String[] { "[" +
Widget.class.getName() + "].secret" }));
+ MarshalUtils.marshalResult(c, out);
doc = xmlReader.read(new StringReader(new String(out.toByteArray())));
widget = (Widget) ParserUtils.unmarshalResult(doc.getRootElement());