3/4/08


Web services exceptions handling


There are two web methods in previous topic. Each of them throws exception:
RuntimeException and checked exception com.MyException

In second case wsdl description has fault description part:

<s0:operation name="meth2Checked">
<s3:operation soapAction="" style="document"/>
<s0:input>
<s3:body parts="parameters" use="literal"/>
</s0:input>
<s0:output>
<s3:body use="literal"/>
</s0:output>
<s0:fault name="MyException">
<s3:fault name="MyException" use="literal"/>
</s0:fault>


So JAX-RPC stubs has exception description in signature of the correspondent methods.
If involkes such methods:

Exception in thread "main" com.MyException
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)....


In case of throwing RuntimeException we just have in runtime:

Exception in thread "main" java.rmi.RemoteException: SOAPFaultException - FaultCode [{http://schemas.xmlsoap.org/soap/envelope/}Server] FaultString [Failed to invoke end componentFailed to invoke method >> RUN TIME EXCEPTION << ] FaultActor [null] Detail [<detail><bea_fault:stacktrace xmlns:bea_fault=http://www.bea.com/servers/wls70/webservice/fault/1.0.0>java.lang.RuntimeException: >> RUN TIME EXCEPTION <<
at com.ErrWs.meth1RunTime(ErrWs.java:10)
at jrockit.reflect.VirtualNativeMethodInvoker.invoke(Ljava.lang.Object;[Ljava.lang.Object;)Ljava.lang.Object;(Unknown Source)
at java.lang.reflect.Method.invoke(Ljava.lang.Object;[Ljava.lang.Object;I)Ljava.lang.Object;(Unknown Source)
....


In case of some transport problem (e.g. absent WS in the defined location) is gotten:

Exception in thread "main" java.rmi.RemoteException: SOAPFaultException - FaultCode [{http://schemas.xmlsoap.org/soap/envelope/}Server] FaultString [Failed to receive message java.io.IOException: The server at http://localhost:7001/WebService_ws/ErrWs returned a 404 error code (Not Found). Please ensure that your URL is correct, and the web service has deployed without error.The server at http://localhost:7001/WebService_ws/ErrWs returned a 404 error code (Not Found). Please ensure that your URL is correct, and the web service has deployed without error.] FaultActor [null] Detail [java.io.IOException: The server at http://localhost:7001/WebService_ws/ErrWs returned a 404 error code (Not Found). Please ensure that your URL is correct, and the web service has deployed without error....

No comments: