10 Replies Latest reply on Aug 25, 2005 6:06 PM by Thomas Diesler

    Mapping between SOAP faults and service exceptions

    Ole Matzura Novice

      Hi!

      we solved this by adding our own typemapping to ws4ee-deployment.xml, in your case it would be something like;

       <typeMapping
       deserializer="org.apache.axis.encoding.ser.BeanDeserializerFactory"
       encodingStyle="" qname="wsdlNS:Fault1"
       serializer="org.apache.axis.encoding.ser.BeanSerializerFactory"
       type="java:sample.Exception1"
      xmlns:wsdlNS=".. your namespace.. "/>
      


      you may have to change the qname to the actual element name (not its type)...

      hope this helps..

      /Ole

        • 1. Re: Mapping between SOAP faults and service exceptions
          Thomas Diesler Master

          Exception mapping is supposed to work. Here are the SOAP envelops exchanged by

          ant -Dtest=org.jboss.test.webservice.exception.ExceptionTestCase one-test

          <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
           <soapenv:Header>
           <jbws:username soapenv:actor="http://webservice.jboss.com/ws4ee/login" xmlns:jbws="http://webservice.jboss.com/ws4ee">jduke</jbws:username>
           <jbws:password soapenv:actor="http://webservice.jboss.com/ws4ee/login" xmlns:jbws="http://webservice.jboss.com/ws4ee">dGhlZHVrZQ==</jbws:password>
           </soapenv:Header>
           <soapenv:Body>
           <ns1:throwException xmlns:ns1="http://org.jboss.webservice/exception"/>
           </soapenv:Body>
          </soapenv:Envelope>
          
          <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
           <soapenv:Body>
           <soapenv:Fault>
           <faultcode>soapenv:Client</faultcode>
           <faultstring>org.jboss.test.webservice.exception.UserException</faultstring>
           <detail>
           <ns1:UserException xmlns:ns1="http://org.jboss.webservice/exception/types">
           <message xsi:nil="1"/>
           </ns1:UserException>
           </detail>
           </soapenv:Fault>
           </soapenv:Body>
          </soapenv:Envelope>
          
          <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
           <soapenv:Header>
           <jbws:username soapenv:actor="http://webservice.jboss.com/ws4ee/login" xmlns:jbws="http://webservice.jboss.com/ws4ee">jduke</jbws:username>
           <jbws:password soapenv:actor="http://webservice.jboss.com/ws4ee/login" xmlns:jbws="http://webservice.jboss.com/ws4ee">dGhlZHVrZQ==</jbws:password>
           </soapenv:Header>
           <soapenv:Body>
           <ns1:throwExceptionWithMessage xmlns:ns1="http://org.jboss.webservice/exception">
           <String_1>Don't worry it's just a test</String_1>
           </ns1:throwExceptionWithMessage>
           </soapenv:Body>
          </soapenv:Envelope>
          
          <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
           <soapenv:Body>
           <soapenv:Fault>
           <faultcode>soapenv:Client</faultcode>
           <faultstring>Don't worry it's just a test</faultstring>
           <detail>
           <ns1:UserMessageException xmlns:ns1="http://org.jboss.webservice/exception/types">
           <message>Don't worry it's just a test</message>
           </ns1:UserMessageException>
           </detail>
           </soapenv:Fault>
           </soapenv:Body>
          </soapenv:Envelope>
          
          <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
           <soapenv:Header>
           <jbws:username soapenv:actor="http://webservice.jboss.com/ws4ee/login" xmlns:jbws="http://webservice.jboss.com/ws4ee">jduke</jbws:username>
           <jbws:password soapenv:actor="http://webservice.jboss.com/ws4ee/login" xmlns:jbws="http://webservice.jboss.com/ws4ee">dGhlZHVrZQ==</jbws:password>
           </soapenv:Header>
           <soapenv:Body>
           <ns1:throwComplexUserException xmlns:ns1="http://org.jboss.webservice/exception">
           <String_1>Don't worry it's just a test</String_1>
           <int_2>200</int_2>
           </ns1:throwComplexUserException>
           </soapenv:Body>
          </soapenv:Envelope>
          
          <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
           <soapenv:Body>
           <soapenv:Fault>
           <faultcode>soapenv:Client</faultcode>
           <faultstring>Don't worry it's just a test</faultstring>
           <detail>
           <ns1:ComplexUserException xmlns:ns1="http://org.jboss.webservice/exception/types">
           <message>Don't worry it's just a test</message>
           <errorCode>200</errorCode>
           </ns1:ComplexUserException>
           </detail>
           </soapenv:Fault>
           </soapenv:Body>
          </soapenv:Envelope>
          


          • 2. Re: Mapping between SOAP faults and service exceptions
            Thomas Diesler Master

            There should be no extra typeMapping necessary

            • 3. Re: Mapping between SOAP faults and service exceptions
              Ole Matzura Novice

              Hi!

              The type-mapping was required to get this working..

              Maybe because our ws was created from an existing wsdl using wscompile -import?

              /Ole

              • 4. Re: Mapping between SOAP faults and service exceptions
                Vladimir Kravchenko Newbie

                Hi everybody,

                the problem is solved.

                "exception-mapping" element in jaxrpc-mapping.xml was not enough. After I've added "java-xml-type-mapping" element for my exceptions, everything works fine.

                It works without ws4ee-deployment.xml. Proper jaxrpc-mapping.xml is enough.

                Thank everybody.

                /Vlad

                • 5. Re: Mapping between SOAP faults and service exceptions
                  Thomas Diesler Master

                  I told you ;-)

                  wscompile would probably have generated valid jaxrpc-mapping.xml

                  • 6. Re: Mapping between SOAP faults and service exceptions
                    Ole Matzura Novice

                    Great!

                    Thanks for digging this up.. wscompile -import only generates an exception-mapping so it seems to be a wscompile bug..

                    on the other hand, isn't the information conveyed from an exception-mapping enough for "understanding" how to map
                    exceptions to wsdl-messages/xml-types?

                    ie the generated wscompile exception-mapping is

                    <exception-mapping>
                    <exception-type>my.package.MyFaultMessage</exception-type>
                    <wsdl-message xmlns:exMsgNS="my/fault/namespace">exMsgNS:MyFaultMessage</wsdl-message>
                    </exception-mapping>
                    


                    why is the java-xml-type-mapping (or an equivilant typeMapping in ws4ee-deployment.xml) also required by jbossws?

                    (just wondering :-)

                    regards!

                    /Ole

                    • 7. Re: Mapping between SOAP faults and service exceptions
                      Jason Greene Master

                       

                      "omatzura" wrote:

                      why is the java-xml-type-mapping (or an equivilant typeMapping in ws4ee-deployment.xml) also required by jbossws?


                      This is required by jsr109. Otherwise, there would be no way to map the member variables in the exception.

                      For more information, take a look at jsr109 http://www.jcp.org/en/jsr/detail?id=109.

                      -Jason

                      • 8. Re: Mapping between SOAP faults and service exceptions
                        Andrei Iltchenko Newbie

                         

                        "thomas.diesler@jboss.com" wrote:
                        Exception mapping is supposed to work. Here are the SOAP envelops exchanged by

                        ant -Dtest=org.jboss.test.webservice.exception.ExceptionTestCase one-test

                        
                        ...skipped
                        ...
                        <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
                         <soapenv:Header>
                         <jbws:username soapenv:actor="http://webservice.jboss.com/ws4ee/login" xmlns:jbws="http://webservice.jboss.com/ws4ee">jduke</jbws:username>
                         <jbws:password soapenv:actor="http://webservice.jboss.com/ws4ee/login" xmlns:jbws="http://webservice.jboss.com/ws4ee">dGhlZHVrZQ==</jbws:password>
                         </soapenv:Header>
                         <soapenv:Body>
                         <ns1:throwComplexUserException xmlns:ns1="http://org.jboss.webservice/exception">
                         <String_1>Don't worry it's just a test</String_1>
                         <int_2>200</int_2>
                         </ns1:throwComplexUserException>
                         </soapenv:Body>
                        </soapenv:Envelope>
                        
                        <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
                         <soapenv:Body>
                         <soapenv:Fault>
                         <faultcode>soapenv:Client</faultcode>
                         <faultstring>Don't worry it's just a test</faultstring>
                         <detail>
                         <ns1:ComplexUserException xmlns:ns1="http://org.jboss.webservice/exception/types">
                         <message>Don't worry it's just a test</message>
                         <errorCode>200</errorCode>
                         </ns1:ComplexUserException>
                         </detail>
                         </soapenv:Fault>
                         </soapenv:Body>
                        </soapenv:Envelope>
                        


                        Thomas, I think there's a bug in the behaviour of JBoss with regard to the faults exchanged above. Specifically I am calling into question the 'message' element of the 'ns1:ComplexUserException' as the 'ComplexUserException' Java class doesn't declare such a property.

                        The problem is more generic as JBoss 4.0.x always generates this gratuitous element regardless of the corresponding exception- and java-xml-type- mapping.

                        I've been wrestling with this problem in JBoss 4.0.2 for about two hours before I devided to consult the relevant source code. I've found the following (org/jboss/axis/utils/BeanInfo.java, Line 155):

                        // Include the message property
                         if (isThrowable)
                         {
                         List bpList = new ArrayList();
                         bpList.add(new PropertyDescriptor("message", Throwable.class, "getMessage", null));
                         bpList.addAll(Arrays.asList(result));
                         result = new PropertyDescriptor[bpList.size()];
                         bpList.toArray(result);
                         }


                        this explains why JBoss always disregards exception- and java-xml-type- mapping information and serializes this element. As a matter of fact this non-conformant behaviour is discontinued as of Axis 1.2. It would really be great if you guys got rid of this code too.

                        Hope this helps.

                        Regards,
                        Andrei.



                        • 9. Re: Mapping between SOAP faults and service exceptions
                          Thomas Diesler Master

                          You need to look at the abstract contract in wsdl. It sais

                           <complexType name="ComplexUserException">
                           <sequence>
                           <element name="message" type="string" nillable="true"/>
                           <element name="errorCode" type="int"/>
                           </sequence>
                           </complexType>
                          


                          So the 'message' element is supposed to be there.

                          With UserException, as defined by

                           <complexType name="UserException">
                           <sequence/>
                           </complexType>
                          


                          you are indeed right, and a message element should not appear on the wire.

                           <soapenv:Fault>
                           <faultcode>soapenv:Client</faultcode>
                           <faultstring>org.jboss.test.webservice.exception.UserException</faultstring>
                           <detail>
                           <ns1:UserException xmlns:ns1="http://org.jboss.webservice/exception/types">
                           <message xsi:nil="1"/>
                           </ns1:UserException>
                           </detail>
                           </soapenv:Fault>