kamalasv / struts2gwtplugin

Automatically exported from code.google.com/p/struts2gwtplugin
Apache License 2.0
0 stars 0 forks source link

InvocationTargetException chaining problem #6

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?

1. 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());
        }

Original issue reported on code.google.com by eho...@gmail.com on 24 Oct 2007 at 10:39

GoogleCodeExporter commented 9 years ago
For 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/

Original comment by beat.kel...@btxtech.com on 16 Jan 2008 at 2:54

GoogleCodeExporter commented 9 years ago
I 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???

Original comment by karajdaar@gmail.com on 2 Feb 2009 at 5:46