What steps will reproduce the problem?
- Make a GWT call from the client that throws a checked exception on the server.
What is the expected output? What do you see instead?
The client should be able to classify the thrown exception in its "onFailure" method of the callback. But the problem is that the Throwable parameter of onFailure() is really an instance of java.lang.reflect.InvocationTargetException, which GWT doesn't emulate.
What version of the product are you using? On what operating system?
Struts 2, latest struts2gwtplugin, Java 6
Please provide any additional information below.
You have some comments in the code near the problem, and I think the solution will just be a one-line fix. In fact, I've modified my local copy of your code and it works as expected. Here's what you have in GWTServlet around lines 124-139:
// now make the call
Object callResult = null;
try {
callResult = method.invoke(actionInvocation.getAction(),
rpcRequest.getParameters());
} catch (IllegalAccessException iie) {
// This may need to change this to package up up the cause
// instead of the thrown exception, not sure if the
// chaining will translate
result = RPC.encodeResponseForFailure(method, iie);
} catch (InvocationTargetException ite) {
// This may need to change this to package up up the cause
// instead of the thrown exception, not sure if the
// chaining will translate
result = RPC.encodeResponseForFailure(method, ite);
}
and here's what I'd use instead
// now make the call
Object callResult = null;
try {
callResult = method.invoke(actionInvocation.getAction(),
rpcRequest.getParameters());
} catch (IllegalAccessException iie) {
// This may need to change this to package up up the cause
// instead of the thrown exception, not sure if the
// chaining will translate
result = RPC.encodeResponseForFailure(method, iie);
} catch (InvocationTargetException ite) {
// This may need to change this to package up up the cause
// instead of the thrown exception, not sure if the
// chaining will translate
result = RPC.encodeResponseForFailure(method,
ite.getTargetExcpeption()); }
Comment #1
Posted on Jan 16, 2008 by Helpful PandaFor me its not enough
The line "result = RPC.encodeResponseForSuccess(method, callResult);" must be moved from after the catch to after "result = RPC.encodeResponseForSuccess(method, callResult);". If the encoding is done after the catch, the result is overridden in case of a exception is thrown.
Modified code:
// now make the call
Object callResult = null;
try {
callResult = method.invoke(actionInvocation.getAction(),
rpcRequest.getParameters()); // package up response for GWT result = RPC.encodeResponseForSuccess(method, callResult); // Moved to here } catch (IllegalAccessException iie) { // This may need to change this to package up up the cause // instead of the thrown exception, not sure if the // chaining will translate result = RPC.encodeResponseForFailure(method, iie, rpcRequest.getSerializationPolicy()); } catch (InvocationTargetException ite) { // This may need to change this to package up up the cause // instead of the thrown exception, not sure if the // chaining will translate result = RPC.encodeResponseForFailure(method, ite.getTargetException(), rpcRequest.getSerializationPolicy()); }
// return our response
return result;
Best regards Beat Keller http://crane.dnsalias.com/
Comment #2
Posted on Feb 2, 2009 by Swift OxI just patched this and other problems in our usage. Is there no one available to accept patches? or is there a more actively maintained fork somewhere???
Status: New
Labels:
Type-Defect
Priority-Medium