0 Replies Latest reply on Nov 15, 2012 6:29 AM by morten.nyhaug

    JAX-WS fails to unmarshal payload due to strict namespaces

    morten.nyhaug

      I have a web service that receives the following payload

      <soap-env:Envelope xmlns:soap-env="http://schemas.xmlsoap.org/soap/envelope/">
          <soap-env:Header/>
          <soap-env:Body>
              <mm7:DeliverReq xmlns:mm7="http://www.3gpp.org/ftp/Specs/archive/23_series/23.140/schema/REL-5-MM7-1-0">
                  <MM7Version>5.3.0</MM7Version>
              </mm7:DeliverReq>
          </soap-env:Body>
      </soap-env:Envelope>
      

      I have generated classes for the schema using xjc, and created a webservice with an endpoint interface to receive it

      @WebService(name = "deliver")
      @SOAPBinding(parameterStyle = SOAPBinding.ParameterStyle.BARE)
      @XmlSeeAlso({
          org._3gpp.ftp.specs.archive._23_series._23_140.schema.rel_5_mm7_1_0.ObjectFactory.class
      })
      public interface Rel5Mm710ReceiverApi {
          @WebMethod(action = "deliverRequest")
          @WebResult(name = "DeliverRsp", targetNamespace = "http://www.3gpp.org/ftp/Specs/archive/23_series/23.140/schema/REL-5-MM7-1-0")
          public DeliverRspType deliverRequest(
                  @WebParam(name = "DeliverReq", targetNamespace = "http://www.3gpp.org/ftp/Specs/archive/23_series/23.140/schema/REL-5-MM7-1-0")
                  DeliverReqType request);
      }
      

       

      @WebService(serviceName = "soap")
      @HandlerChain(file = "handler.xml")
      public class InboundApi implements Rel5Mm710ReceiverApi {
          @Override
          @WebMethod
          public DeliverRspType deliverRequest(DeliverReqType request) {
              ...
          }
      }
      

      When I deploy this service on jboss as 7.1 and test it with soap ui by sending in the payload shown above, I get the following error:

      10:52:56,107 WARNING [org.apache.cxf.phase.PhaseInterceptorChain] (http--127.0.0.1-8080-1) Interceptor for {http://mms.tele2.returia.nrk.no/}soap#{http://api.mm7.returia.nrk.no/}deliverRequest has thrown exception, unwinding now: org.apache.cxf.interceptor.Fault: Unmarshalling Error: unexpected element (uri:"", local:"MM7Version"). Expected elements are <{http://www.3gpp.org/ftp/Specs/archive/23_series/23.140/schema/REL-5-MM7-1-0}MMSRelayServerID>,<{http://www.3gpp.org/ftp/Specs/archive/23_series/23.140/schema/REL-5-MM7-1-0}Content>,<{http://www.3gpp.org/ftp/Specs/archive/23_series/23.140/schema/REL-5-MM7-1-0}ReplyChargingID>,<{http://www.3gpp.org/ftp/Specs/archive/23_series/23.140/schema/REL-5-MM7-1-0}Priority>,<{http://www.3gpp.org/ftp/Specs/archive/23_series/23.140/schema/REL-5-MM7-1-0}Recipients>,<{http://www.3gpp.org/ftp/Specs/archive/23_series/23.140/schema/REL-5-MM7-1-0}TimeStamp>,<{http://www.3gpp.org/ftp/Specs/archive/23_series/23.140/schema/REL-5-MM7-1-0}Sender>,<{http://www.3gpp.org/ftp/Specs/archive/23_series/23.140/schema/REL-5-MM7-1-0}MM7Version>,<{http://www.3gpp.org/ftp/Specs/archive/23_series/23.140/schema/REL-5-MM7-1-0}LinkedID>,<{http://www.3gpp.org/ftp/Specs/archive/23_series/23.140/schema/REL-5-MM7-1-0}Subject>
          at org.apache.cxf.jaxb.JAXBEncoderDecoder.unmarshall(JAXBEncoderDecoder.java:801)
          at org.apache.cxf.jaxb.JAXBEncoderDecoder.unmarshall(JAXBEncoderDecoder.java:642)
          at org.apache.cxf.jaxb.io.DataReaderImpl.read(DataReaderImpl.java:156)
          at org.apache.cxf.interceptor.DocLiteralInInterceptor.handleMessage(DocLiteralInInterceptor.java:201)
          at org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:263)
          at org.apache.cxf.transport.ChainInitiationObserver.onMessage(ChainInitiationObserver.java:121)
          at org.apache.cxf.transport.http.AbstractHTTPDestination.invoke(AbstractHTTPDestination.java:207)
          ...
      Caused by: javax.xml.bind.UnmarshalException
      - with linked exception:
      [javax.xml.bind.UnmarshalException: unexpected element (uri:"", local:"MM7Version"). Expected elements are <{http://www.3gpp.org/ftp/Specs/archive/23_series/23.140/schema/REL-5-MM7-1-0}MMSRelayServerID>,<{http://www.3gpp.org/ftp/Specs/archive/23_series/23.140/schema/REL-5-MM7-1-0}Content>,<{http://www.3gpp.org/ftp/Specs/archive/23_series/23.140/schema/REL-5-MM7-1-0}ReplyChargingID>,<{http://www.3gpp.org/ftp/Specs/archive/23_series/23.140/schema/REL-5-MM7-1-0}Priority>,<{http://www.3gpp.org/ftp/Specs/archive/23_series/23.140/schema/REL-5-MM7-1-0}Recipients>,<{http://www.3gpp.org/ftp/Specs/archive/23_series/23.140/schema/REL-5-MM7-1-0}TimeStamp>,<{http://www.3gpp.org/ftp/Specs/archive/23_series/23.140/schema/REL-5-MM7-1-0}Sender>,<{http://www.3gpp.org/ftp/Specs/archive/23_series/23.140/schema/REL-5-MM7-1-0}MM7Version>,<{http://www.3gpp.org/ftp/Specs/archive/23_series/23.140/schema/REL-5-MM7-1-0}LinkedID>,<{http://www.3gpp.org/ftp/Specs/archive/23_series/23.140/schema/REL-5-MM7-1-0}Subject>]
          at com.sun.xml.bind.v2.runtime.unmarshaller.UnmarshallerImpl.handleStreamException(UnmarshallerImpl.java:434)
          at com.sun.xml.bind.v2.runtime.unmarshaller.UnmarshallerImpl.unmarshal0(UnmarshallerImpl.java:371)
          at com.sun.xml.bind.v2.runtime.unmarshaller.UnmarshallerImpl.unmarshal(UnmarshallerImpl.java:348)
          at org.apache.cxf.jaxb.JAXBEncoderDecoder.unmarshall(JAXBEncoderDecoder.java:778)
          ... 31 more
      

       

      The funny thing is, if I try to unmarshal this using JAXB, I get no errors at all. If I try to modify the payload so that it is like this:

      <mm7:DeliverReq xmlns:mm7="http://www.3gpp.org/ftp/Specs/archive/23_series/23.140/schema/REL-5-MM7-1-0">
          <mm7:MM7Version>5.3.0</mm7:MM7Version>
      </mm7:DeliverReq>
      

      I also get no errors. Obviously changing the payload is not an option since I cant control what 3rd parties are sending me.

       

      How can I get rid of this error? How can I tell JAX-WS to not be so strict regarding namespaces?

       

      I have tried using a SOAPHandler to set some properties or other, but no amount of googling has led me to the correct solution. Since JAXB is able to unmarshal this, then surly it must be possible to make JAX-WS do this as well?