title: org.apache.cxf.binding.soap.SoapFault: Unmarshalling Error: cvc-elt.1.a: Cannot find the declaration of element 'ns1:RequestMetaData'
body: <p>We have a couple of SOAP based web services, some are exposed via Apache CXF directly via contract first approach some are exposed as a service via Apache Camel and its CXF extension. Up to now we used a PAYLOAD approach as data format for the CxfSpringEndpoint but as requirements changed I have to change the data format to POJO instead to enable the unmarshalled object directly via Camel's message body.</p>
  
  <p>After changing the code to enable POJO data format handling within Camel I'm stuck with the following exception: <code>Caused by: org.apache.cxf.binding.soap.SoapFault: Unmarshalling Error: cvc-elt.1.a: Cannot find the declaration of element 'ns1:RequestMetaData'.</code> which is only thrown on invoking a specific operation (<code>getMessageDetail</code>). </p>
  
  <p>The endpoint configuration does set the WSDL within the <code>CxfSpringEndpoint.setWsdlURL(...)</code> method of the factory and even adds the schemas for the defined schemas. Omitting the WSDL file results in  in an exception as <code>Invalid schema document passed to AbstractDataBinding.addSchemaDocument, not in W3C schema namespace: {http://www.w3.org/1999/xhtml}html</code> although the schema (and sub-schemas) have been added.</p>
  
  <p>The WSDL file looks something like:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;wsdl:definitions 
      xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
      xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" 
      xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/"
      xmlns:xs="http://www.w3.org/2001/XMLSchema"
      xmlns:http="http://schemas.xmlsoap.org/wsdl/http/" 
      xmlns:hub="http://namespace.hub.com"
      targetNamespace="http://namespace.hub.com"&gt;
  
      &lt;wsdl:types&gt;
          &lt;xs:schema&gt;
              &lt;xs:import namespace="http://namespace.hub.com" schemaLocation="xsd/hub.xsd" /&gt;
          &lt;/xs:schema&gt;
      &lt;/wsdl:types&gt;
  
      ...
  
      &lt;!-- listMessages --&gt;
      &lt;wsdl:message name="listMessagesRequest"&gt;
          &lt;wsdl:part name="in" element="hub:ListMessagesRequest" /&gt;
      &lt;/wsdl:message&gt;
      &lt;wsdl:message name="listMessagesResponse"&gt;
          &lt;wsdl:part name="out" element="hub:ListMessagesResponse" /&gt;
      &lt;/wsdl:message&gt;
  
      &lt;!-- getMessagDetail --&gt;
      &lt;wsdl:message name="getMessageDetailRequest"&gt;
          &lt;wsdl:part name="in" element="hub:GetMessageDetailRequest" /&gt;
      &lt;/wsdl:message&gt;
      &lt;wsdl:message name="getMessageDetailResponse"&gt;
          &lt;wsdl:part name="out" element="hub:GetMessageDetailResponse" /&gt;
      &lt;/wsdl:message&gt;
  
      ...
  &lt;/wsdl:definitions&gt;
  </code></pre>
  
  <p>The imported schema is defined as:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;xs:schema 
      targetNamespace="http://namespace.hub.com" 
      xmlns:tns="http://namespace.hub.com"
      xmlns:xs="http://www.w3.org/2001/XMLSchema"
      elementFormDefault="qualified"
      attributeFormDefault="qualified"&gt;
  
      ...
      &lt;xs:element name="ListMessagesRequest" type="tns:ListMessagesRequestType" /&gt;
      &lt;xs:element name="ListMessagesResponse" type="tns:ListMessagesResponseType" /&gt;
      &lt;xs:element name="GetMessageDetailRequest" type="tns:GetMessageDetailRequestType" /&gt;
      &lt;xs:element name="GetMessageDetailResponse" type="tns:GetMessageDetailResponseType" /&gt;
      ...
  
      &lt;xs:complexType name="AbstractRequestType" abstract="true"&gt;
          &lt;xs:sequence&gt;
              &lt;xs:element name="RequestMetaData" &gt;
                  &lt;xs:complexType&gt;
                      &lt;xs:sequence&gt;
                          &lt;!-- some meta data necessary for all messages --&gt;
                      &lt;/xs:sequence&gt;
                  &lt;/xs:complexType&gt;
              &lt;/xs:element&gt;
          &lt;/xs:sequence&gt;
      &lt;/xs:complexType&gt;
  
      &lt;xs:complexType name="ListMessagesRequestType"&gt;
          &lt;xs:complexContent&gt;
              &lt;xs:extension base="tns:AbstractRequestType"&gt;
                  &lt;xs:sequence&gt;
                      &lt;xs:element name="Limit" type="xs:int" minOccurs="0" maxOccurs="1" /&gt;
                      &lt;xs:element name="Offset" type="xs:int" minOccurs="0" maxOccurs="1" /&gt;
                  &lt;/xs:sequence&gt;
              &lt;/xs:extension&gt;
          &lt;/xs:complexContent&gt;
      &lt;/xs:complexType&gt;
  
      &lt;xs:complexType name="GetMessageDetailRequestType"&gt;
          &lt;xs:complexContent&gt;
              &lt;xs:extension base="tns:AbstractRequestType"&gt;
                  &lt;xs:sequence&gt;
                      &lt;xs:element name="MessageId" type="xs:string" minOccurs="1" maxOccurs="1" /&gt;
                  &lt;/xs:sequence&gt;
              &lt;/xs:extension&gt;
          &lt;/xs:complexContent&gt;
      &lt;/xs:complexType&gt;
  
      ...
  &lt;/xs:schema&gt;
  </code></pre>
  
  <p>Both, WSDL and XSD, are incomplete and the namespace has been changed to set the focus more on the necessary stuff. As hopefully can be seen from the WSDL file here two operations are defined: <code>listMessages</code> and <code>getMessageDetail</code> - the primer one returns a list of received messages which can further be paged through using limit and offset parameters. The latter one returns details on a received message, therefore it only requires the message ID. Both messages require additional meta data to be passed within the SOAP message.</p>
  
  <p>On executing the UnitTests all Tests except those for <code>getMessageDetail</code> succeed - this included invocations of <code>listMessages</code> operations, which are defined in the same way as <code>getMessageDetail</code>. Below is a code excerpt from the UnitTest</p>
  
  <pre><code>try
  {
      final DeliveryEndpoint client = createDeliveryClient(userid, userkey);
  
      // first send 3 valid messages
      this.sendMultipleMessages(client);
  
      ListMessagesResponse response = client.listMessages(
          new ListMessagesRequest()
              .withRequestMetaData(getRMD()));
  
      Assert.assertNotNull(response);
      List&lt;MessagesInfoType&gt; infos = response.getMessageInfos();
      Assert.assertEquals(3, infos.size());
  
      GetMessageDetailResponse detailResponse = client.getMessageDetail(
          new GetMessageDetailRequest()
              .withRequestMetaData(getRMD())
              .withMessageId(infos.get(1).getMessageId()));
  
      Assert.assertNotNull(detailResponse);
      MessageDetailType details = detailResponse.getMessageDetail();
      Assert.assertNotNull(details);
      ...
  }
  catch(Exception e)
  {
      e.printStackTrace();
      Assert.fail("Exception caught: "+e.getLocalizedMessage());
  }
  </code></pre>
  
  <p>On executing the UnitTest I get propper SOAP messages but as soon as Camel receives the following SOAP request it throws the exception listed below the SOAP message. Note that the previous invocation of the service succeeded so this only affects <code>getMessageDetail</code> operations!</p>
  
  <pre><code>&lt;soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"&gt;
      &lt;soap:Body&gt;
          &lt;ns1:GetMessageDetailRequest 
              xmlns:ns1="http://namespace.hub.com"&gt;
  
              &lt;ns1:RequestMetaData&gt;
                  &lt;!-- the specified meta data--&gt;
              &lt;/ns1:RequestMetaData&gt;
  
              &lt;ns1:MessageId&gt;someMessageId&lt;/ns1:MessageId&gt;
          &lt;/ns1:GetMessageDetailRequest&gt;
      &lt;/soap:Body&gt;
  &lt;/soap:Envelope&gt;
  </code></pre>
  
  <p>Stacktrace:</p>
  
  <pre><code>org.apache.cxf.interceptor.Fault: Unmarshalling Error: cvc-elt.1.a: Cannot find the declaration of element 'ns1:RequestMetaData'. 
      at org.apache.cxf.jaxb.JAXBEncoderDecoder.unmarshall(JAXBEncoderDecoder.java:808) ~[cxf-rt-databinding-jaxb-2.7.5.jar:2.7.5]
      at org.apache.cxf.jaxb.JAXBEncoderDecoder.unmarshall(JAXBEncoderDecoder.java:629) ~[cxf-rt-databinding-jaxb-2.7.5.jar:2.7.5]
      at org.apache.cxf.jaxb.io.DataReaderImpl.read(DataReaderImpl.java:157) ~[cxf-rt-databinding-jaxb-2.7.5.jar:2.7.5]
      at org.apache.cxf.interceptor.DocLiteralInInterceptor.getPara(DocLiteralInInterceptor.java:321) ~[cxf-api-2.7.4.jar:2.7.4]
      at org.apache.cxf.interceptor.DocLiteralInInterceptor.handleMessage(DocLiteralInInterceptor.java:121) ~[cxf-api-2.7.4.jar:2.7.4]
      at org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:271) ~[cxf-api-2.7.4.jar:2.7.4]
      at org.apache.cxf.transport.ChainInitiationObserver.onMessage(ChainInitiationObserver.java:121) ~[cxf-api-2.7.4.jar:2.7.4]
      at org.apache.cxf.transport.http_jetty.JettyHTTPDestination.serviceRequest(JettyHTTPDestination.java:355) ~[cxf-rt-transports-http-jetty-2.7.4.jar:2.7.4]
      at org.apache.cxf.transport.http_jetty.JettyHTTPDestination.doService(JettyHTTPDestination.java:319) ~[cxf-rt-transports-http-jetty-2.7.4.jar:2.7.4]
      at org.apache.cxf.transport.http_jetty.JettyHTTPHandler.handle(JettyHTTPHandler.java:72) ~[cxf-rt-transports-http-jetty-2.7.4.jar:2.7.4]
      at org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java:1040) ~[jetty-server-7.6.8.v20121106.jar:7.6.8.v20121106]
      at org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:976) ~[jetty-server-7.6.8.v20121106.jar:7.6.8.v20121106]
      at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:135) ~[jetty-server-7.6.8.v20121106.jar:7.6.8.v20121106]
      at org.eclipse.jetty.server.handler.ContextHandlerCollection.handle(ContextHandlerCollection.java:255) ~[jetty-server-7.6.8.v20121106.jar:7.6.8.v20121106]
      at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:116) ~[jetty-server-7.6.8.v20121106.jar:7.6.8.v20121106]
      at org.eclipse.jetty.server.Server.handle(Server.java:363) ~[jetty-server-7.6.8.v20121106.jar:7.6.8.v20121106]
      at org.eclipse.jetty.server.AbstractHttpConnection.handleRequest(AbstractHttpConnection.java:483) ~[jetty-server-7.6.8.v20121106.jar:7.6.8.v20121106]
      at org.eclipse.jetty.server.AbstractHttpConnection.content(AbstractHttpConnection.java:931) ~[jetty-server-7.6.8.v20121106.jar:7.6.8.v20121106]
      at org.eclipse.jetty.server.AbstractHttpConnection$RequestHandler.content(AbstractHttpConnection.java:992) ~[jetty-server-7.6.8.v20121106.jar:7.6.8.v20121106]
      at org.eclipse.jetty.http.HttpParser.parseNext(HttpParser.java:856) ~[jetty-http-7.6.8.v20121106.jar:7.6.8.v20121106]
      at org.eclipse.jetty.http.HttpParser.parseAvailable(HttpParser.java:240) ~[jetty-http-7.6.8.v20121106.jar:7.6.8.v20121106]
      at org.eclipse.jetty.server.AsyncHttpConnection.handle(AsyncHttpConnection.java:82) ~[jetty-server-7.6.8.v20121106.jar:7.6.8.v20121106]
      at org.eclipse.jetty.io.nio.SelectChannelEndPoint.handle(SelectChannelEndPoint.java:628) ~[jetty-io-7.6.8.v20121106.jar:7.6.8.v20121106]
      at org.eclipse.jetty.io.nio.SelectChannelEndPoint$1.run(SelectChannelEndPoint.java:52) ~[jetty-io-7.6.8.v20121106.jar:7.6.8.v20121106]
      at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:608) ~[jetty-util-7.6.8.v20121106.jar:7.6.8.v20121106]
      at org.eclipse.jetty.util.thread.QueuedThreadPool$3.run(QueuedThreadPool.java:543) ~[jetty-util-7.6.8.v20121106.jar:7.6.8.v20121106]
      at java.lang.Thread.run(Thread.java:724) ~[na:1.7.0_25]
  Caused by: javax.xml.bind.UnmarshalException: null
      at com.sun.xml.bind.v2.runtime.unmarshaller.UnmarshallerImpl.handleStreamException(UnmarshallerImpl.java:431) ~[jaxb-impl-2.2.2.jar:2.2.2]
      at com.sun.xml.bind.v2.runtime.unmarshaller.UnmarshallerImpl.unmarshal0(UnmarshallerImpl.java:368) ~[jaxb-impl-2.2.2.jar:2.2.2]
      at com.sun.xml.bind.v2.runtime.unmarshaller.UnmarshallerImpl.unmarshal(UnmarshallerImpl.java:345) ~[jaxb-impl-2.2.2.jar:2.2.2]
      at org.apache.cxf.jaxb.JAXBEncoderDecoder.doUnmarshal(JAXBEncoderDecoder.java:769) ~[cxf-rt-databinding-jaxb-2.7.5.jar:2.7.5]
      at org.apache.cxf.jaxb.JAXBEncoderDecoder.access$100(JAXBEncoderDecoder.java:94) ~[cxf-rt-databinding-jaxb-2.7.5.jar:2.7.5]
      at org.apache.cxf.jaxb.JAXBEncoderDecoder$1.run(JAXBEncoderDecoder.java:797) ~[cxf-rt-databinding-jaxb-2.7.5.jar:2.7.5]
      at java.security.AccessController.doPrivileged(Native Method) ~[na:1.7.0_25]
      at org.apache.cxf.jaxb.JAXBEncoderDecoder.unmarshall(JAXBEncoderDecoder.java:795) ~[cxf-rt-databinding-jaxb-2.7.5.jar:2.7.5]
      ... 26 common frames omitted
  Caused by: org.xml.sax.SAXParseException: cvc-elt.1.a: Cannot find the declaration of element 'ns1:RequestMetaData'.
      at org.apache.xerces.util.ErrorHandlerWrapper.createSAXParseException(Unknown Source) ~[xercesImpl-2.10.0.jar:na]
      at org.apache.xerces.util.ErrorHandlerWrapper.error(Unknown Source) ~[xercesImpl-2.10.0.jar:na]
      at org.apache.xerces.impl.XMLErrorReporter.reportError(Unknown Source) ~[xercesImpl-2.10.0.jar:na]
      at org.apache.xerces.impl.XMLErrorReporter.reportError(Unknown Source) ~[xercesImpl-2.10.0.jar:na]
      at org.apache.xerces.impl.XMLErrorReporter.reportError(Unknown Source) ~[xercesImpl-2.10.0.jar:na]
      at org.apache.xerces.impl.xs.XMLSchemaValidator.handleStartElement(Unknown Source) ~[xercesImpl-2.10.0.jar:na]
      at org.apache.xerces.impl.xs.XMLSchemaValidator.startElement(Unknown Source) ~[xercesImpl-2.10.0.jar:na]
      at org.apache.xerces.jaxp.validation.ValidatorHandlerImpl.startElement(Unknown Source) ~[xercesImpl-2.10.0.jar:na]
      at com.sun.xml.bind.v2.runtime.unmarshaller.ValidatingUnmarshaller.startElement(ValidatingUnmarshaller.java:101) ~[jaxb-impl-2.2.2.jar:2.2.2]
      at com.sun.xml.bind.v2.runtime.unmarshaller.StAXStreamConnector.handleStartElement(StAXStreamConnector.java:247) ~[jaxb-impl-2.2.2.jar:2.2.2]
      at com.sun.xml.bind.v2.runtime.unmarshaller.StAXStreamConnector.bridge(StAXStreamConnector.java:181) ~[jaxb-impl-2.2.2.jar:2.2.2]
      at com.sun.xml.bind.v2.runtime.unmarshaller.UnmarshallerImpl.unmarshal0(UnmarshallerImpl.java:366) ~[jaxb-impl-2.2.2.jar:2.2.2]
      ... 32 common frames omitted
  </code></pre>
  
  <p>So the questions is, why does the invocation of <code>listMessages</code> succeed (with and without optional parameters) but fails for <code>getMessageDetail</code>?</p>