开发者

How do I get a Java WebService to actually show me exceptions from the proxy object?

开发者 https://www.devze.com 2023-01-22 17:37 出处:网络
I\'m chasing what should be a simple NullPointerException but a webservice proxy keeps swallowing the error.

I'm chasing what should be a simple NullPointerException but a webservice proxy keeps swallowing the error.

The WS is exposed through a simple client library, that client then calls the WS. Somewhere in the WS theres an NPE and I can't find it because the stack trace only shows "$Proxy.someMethod" instead of the cause of the issue.

How can I get the stack trace from the p开发者_如何学Croxy object? Is there a good strategy to log or handle these exceptions?

...
Caused by: javax.xml.ws.soap.SOAPFaultException: java.lang.NullPointerException
    at com.sun.xml.ws.fault.SOAP11Fault.getProtocolException(SOAP11Fault.java:187)
    at com.sun.xml.ws.fault.SOAPFaultBuilder.createException(SOAPFaultBuilder.java:116)
    at com.sun.xml.ws.client.sei.SyncMethodHandler.invoke(SyncMethodHandler.java:254)
    at com.sun.xml.ws.client.sei.SyncMethodHandler.invoke(SyncMethodHandler.java:224)
    at com.sun.xml.ws.client.sei.SEIStub.invoke(SEIStub.java:117)
******** I need the trace from this line *********
    at $Proxy43.myMethod(Unknown Source) 
*****************
    at com.mypackage.client.MyClient.aMethod(MyClient.java:70)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at org.mozilla.javascript.MemberBox.invoke(MemberBox.java:161)
    ... 17 more

I've done some reading and it seems like this has to do with checked vs. unchecked exceptions. So if I were throwing an IOException I'd get the stack trace, but since there is a NullPointerException bubbling up its not giving me the trace.


Wrap your service in a try/catch block and throw the exception that's defined as the fault element of the called service in your WSDL. That way the client will get a useable stacktrace.

0

精彩评论

暂无评论...
验证码 换一张
取 消