uCosminexus Application Server, Web Service Development Guide

[Contents][Glossary][Index][Back][Next]

10.4.3 Propagation of the Java exception

When both the Web Service and Web Service client are deployed on the Cosminexus JAX-WS engine, the Java exception occurring in the Web Service can be propagated to the Web Service client. This is applicable to both, POJO and EJB Web Services. This subsection describes the Java exception propagation method and the operations.

Note
The propagation of the Java exception is not a functionality given in the SOAP 1.1 specifications and JAX-WS 2.2 specifications; therefore, when you connect with the basic Web Service products other than the Cosminexus JAX-WS functionality, unintended operations might occur and communication might fail. The stack trace might also include internal information about Web Service implementation (if system settings information and individual information is handled, that information). Therefore, assuming that this functionality is used in real operations, we recommend that you do not implement the Web Service. Use this functionality as required during development.
Organization of this subsection
(1) Java exception propagation method
(2) Operations for propagating the Java exception (in the Web Service)
(3) Operations for propagating the Java exception (In the Web Service client)

(1) Java exception propagation method

To propagate the Java exception that occurred in the Web Service, specify true for the com.cosminexus.jaxws.fault.SOAPFaultBuilder.captureStackTrace property in the action definition file.

For the com.cosminexus.jaxws.fault.SOAPFaultBuilder.captureStackTrace property, see the section 10.1.2 Settings for the common definition file.

(2) Operations for propagating the Java exception (in the Web Service)

When the Java exception is propagated in the Web Service, the {http://jax-ws.dev.java.net/}exception element specific to the Cosminexus JAX-WS functionality is added as the child element of the detail element or soapenv12:Detail element, and the information about the occurred Java exception is marshalled.

The following is an example of a runtime exception:

//runtime exception is thrown
catch( NullPointerException ){
 throw new IllegalArgumentException( "Something illegal.", e );
}

When the exception is thrown in this manner, an example of the SOAP fault message of SOAP 1.1 specifications that will be sent is as follows (actually, there is no linefeed and indent):

<?xml version="1.0" ?>
<S:Envelope xmlns:S= "http://schemas.xmlsoap.org/soap/envelope/">
 <S:Body>
 <ns2:Fault xmlns:ns2="http://schemas.xmlsoap.org/soap/envelope/"
              xmlns:ns3="http://www.w3.org/2003/05/soap-envelope">
 <faultcode>ns2:Server</faultcode>
 <faultstring>Something illegal.</faultstring>
 <detail>
 <ns2:exception xmlns:ns2="http://jax-ws.dev.java.net/"
 class="java.lang.IllegalArgumentException"
 note="To disable this feature, set com.cosminexus.jaxws.fault.SOAPFaultBuilder.captureStackTrace property to false">
 <message>Something illegal</message>
 <ns2:stackTrace>
 <ns2:frame class="com.example.sample.TestJaxWsImpl" file="TestJaxWsImpl.java" line="32" method="jaxWsTest1"/>
 <ns2:frame class="sun.reflect.NativeMethodAccessorImpl" file="NativeMethodAccessorImpl.java" line="native" method="invoke0"/>
 <ns2:frame class="sun.reflect.NativeMethodAccessorImpl" file="NativeMethodAccessorImpl.java" line="39" method="invoke"/>
 ...
 <ns2:frame class="java.lang.Thread" file="Thread.java" line="595" method="run"/>
 </ns2:stackTrace>
 <ns2:cause class="java.lang.NullPointerException"
 note="To disable this feature, set com.cosminexus.jaxws.fault.SOAPFaultBuilder.captureStackTrace property to false">
 <message>Something null.</message>
 <ns2:stackTrace>
 <ns2:frame class="com.example.sample.TestJaxWsImpl" file="TestJaxWsImpl.java" line="32" method="jaxWsTest1"/>
 <ns2:frame class="sun.reflect.NativeMethodAccessorImpl" file="NativeMethodAccessorImpl.java" line="native" method="invoke0"/>
 ...
 <ns2:frame class="sun.reflect.DelegatingMethodAccessorImpl" file="DelegatingMethodAccessorImpl.java" line="25" method="invoke"/><ns2:frame class="java.lang.reflect.Method" file="Method.java" line="585" method="invoke"/>
 <ns2:frame class="org.apache.tomcat.util.threads.ThreadPool$ControlRunnable" file="ThreadPool.java" line="1510" method="run"/>
 <ns2:frame class="java.lang.Thread" file="Thread.java" line="595" method="run"/>
 </ns2:stackTrace>
 </ns2:cause>
 </ns2:exception>
 </detail>
 </ns2:Fault>
 </S:Body>
</S:Envelope>

The following is an example of a SOAP fault message of the SOAP 1.2 specifications that will be sent (actually, there is no linefeed and indent):

<?xml version="1.0" ?>
<S:Envelope xmlns:S="http://www.w3.org/2003/05/soap-envelope">
  <S:Body>
    <ns3:Fault xmlns:ns2="http://schemas.xmlsoap.org/soap/envelope/"
               xmlns:ns3="http://www.w3.org/2003/05/soap-envelope">
      <ns3:Code>
        <ns3:Value>ns3:Receiver</ns3:Value>
      </ns3:Code>
      <ns3:Reason>
        <ns3:Text xml:lang="ja">Something illegal.</ns3:Text>
      </ns3:Reason>
      <ns3:Detail>
        <env:Detail xmlns:env="http://www.w3.org/2003/05/soap-envelope">
          <detailTest>TEST.</detailTest>
        </env:Detail>
        <ns2:exception xmlns:ns2="http://jax-ws.dev.java.net/"
            class="javax.xml.ws.soap.SOAPFaultException"
            note="To disable this feature, set com.cosminexus.jaxws.fault.SOAPFaultBuilder.captureStackTrace property to false">
          ...
          (Same as the SOAP fault of SOAP 1.1 specifications)
          ...
        </ns2:exception>
      </ns3:Detail>
    </ns3:Fault>
  </S:Body>
</S:Envelope>

(3) Operations for propagating the Java exception (In the Web Service client)

When the Java exception is propagated in the Web Service client, the exception (exception that occurred in the Web Service) un-marshalled from the information about the {http://jax-ws.dev.java.net/}exception element is set up in the cause of the wrapper exception class or javax.xml.ws.soap.SOAPFaultException thrown in the Web Service client.

The Web Service client can acquire the exception occurring in the Web Service by executing the getCause method.