Uploaded image for project: 'CXF'
  1. CXF
  2. CXF-6050

NullPointerException while creating custom exception in CXF client

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Open
    • Major
    • Resolution: Unresolved
    • 2.7.6
    • None
    • JAX-WS Runtime
    • Windows OS with Tomcat servlet container; CXF 2.7.6

    • Unknown

    Description

      As stated in CXF-3763, when server throws an exception which looks like

      <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
        <soapenv:Body>
          <soapenv:Fault>
            <faultcode>soapenv:Server</faultcode>
            <faultstring>Remote part returned an error while getting bonuses</faultstring>
            <detail>
              <fault>
                <faultcode>:214</faultcode>
                <faultstring>Remote part returned an error while getting bonuses</faultstring>
                <faultactor>http://www.somhost.ru/appmod#2.0?module</faultactor>
                <detail>
                  <common-detail>
                    <code>214</code>
                    <message>Remote part returned an error while getting bonuses</message>
                  </common-detail>
                </detail>
              </fault>
            </detail>
          </soapenv:Fault>
        </soapenv:Body>
      </soapenv:Envelope>
      

      , CXF tries to deserialize it into custom Fault object (generated by wsdl2java in my case) but fails with another internal exception:

      INFO       org.apache.cxf.interceptor.ClientFaultConverter - Exception occurred while creating exception: null
      java.lang.NullPointerException
      	at org.apache.cxf.interceptor.ClientFaultConverter.getConstructor(ClientFaultConverter.java:203)
      	at org.apache.cxf.interceptor.ClientFaultConverter.processFaultDetail(ClientFaultConverter.java:175)
      	at org.apache.cxf.interceptor.ClientFaultConverter.handleMessage(ClientFaultConverter.java:79)
      	at org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:271)
      	at org.apache.cxf.interceptor.AbstractFaultChainInitiatorObserver.onMessage(AbstractFaultChainInitiatorObserver.java:113)
      	at org.apache.cxf.binding.soap.interceptor.CheckFaultInterceptor.handleMessage(CheckFaultInterceptor.java:69)
      	at org.apache.cxf.binding.soap.interceptor.CheckFaultInterceptor.handleMessage(CheckFaultInterceptor.java:34)
      	at org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:271)
      	at org.apache.cxf.endpoint.ClientImpl.onMessage(ClientImpl.java:811)
      	at org.apache.cxf.transport.http.HTTPConduit$WrappedOutputStream.handleResponseInternal(HTTPConduit.java:1590)
      	at org.apache.cxf.transport.http.HTTPConduit$WrappedOutputStream.handleResponse(HTTPConduit.java:1486)
      	at org.apache.cxf.transport.http.HTTPConduit$WrappedOutputStream.close(HTTPConduit.java:1305)
      	at org.apache.cxf.io.CacheAndWriteOutputStream.postClose(CacheAndWriteOutputStream.java:50)
      	at org.apache.cxf.io.CachedOutputStream.close(CachedOutputStream.java:223)
      	at org.apache.cxf.transport.AbstractConduit.close(AbstractConduit.java:56)
      	at org.apache.cxf.transport.http.HTTPConduit.close(HTTPConduit.java:623)
      	at org.apache.cxf.interceptor.MessageSenderInterceptor$MessageSenderEndingInterceptor.handleMessage(MessageSenderInterceptor.java:62)
      	at org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:271)
      	at org.apache.cxf.endpoint.ClientImpl.doInvoke(ClientImpl.java:541)
      	at org.apache.cxf.endpoint.ClientImpl.invoke(ClientImpl.java:474)
      	at org.apache.cxf.endpoint.ClientImpl.invoke(ClientImpl.java:377)
      	at org.apache.cxf.endpoint.ClientImpl.invoke(ClientImpl.java:330)
      	at org.apache.cxf.frontend.ClientProxy.invokeSync(ClientProxy.java:96)
      	at org.apache.cxf.jaxws.JaxWsClientProxy.invoke(JaxWsClientProxy.java:134)
              ... (some application code)
      

      Source code of generated Fault.java and Fault_Exception.java classes is attached to the issue.

      I use JAXB mapping so the patch offered in CXF-3763 doesn't help in my case because it's applied to TypeClassInitializer while my client runs on another ServiceModelVisitor descendant - JAXBContextInitializer class.
      During debugging of JAXBContextInitializer I've found out that every time when begin() method triggers for a MessagePartInfo describing a fault, it immediately returns because getTypeClass() on the part returns null (see org.apache.cxf.jaxb.JAXBContextInitializer:77).
      AFAIU the method should continue execution to line 82 where the part would be marked as custom exception.

      Some WSDL excerpts
      WSDL Fault message:

        <wsdl:message name="Fault">
          <wsdl:part name="fault" element="fault"/>
        </wsdl:message>
      

      XSD Fault element:

      <xs:element name="fault">
      <xs:annotation>
        <xs:documentation>Comment describing your root element</xs:documentation>
      </xs:annotation>
      <xs:complexType>
        <xs:sequence>
      	<xs:element name="faultcode">...</xs:element>
      	<xs:element name="faultstring">...</xs:element>
      	<xs:element name="faultactor">...</xs:element>
      	<xs:element minOccurs="0" name="detail">...</xs:element>
        </xs:sequence>
      </xs:complexType>
      </xs:element>
      

      Example of WSDL operation description:

          <wsdl:operation name="BonusConversionState">
            <wsdl:input name="BonusConversionStateRequest" message="tns:BonusConversionStateRequest"/>
            <wsdl:output name="BonusConversionStateResponse" message="tns:BonusConversionStateResponse"/>
            <wsdl:fault name="Fault" message="tns:Fault"/>
          </wsdl:operation>
      

      Additional info can be provided if needed.
      Any suggestion on how to workaround the problem would be also appreciated.

      Attachments

        1. cxf-test.zip
          7.00 MB
          Vladimir Plizga
        2. Fault_Exception.java
          1 kB
          Vladimir Plizga
        3. Fault.java
          16 kB
          Vladimir Plizga

        Issue Links

          Activity

            People

              Unassigned Unassigned
              Toparvion Vladimir Plizga
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

                Created:
                Updated: