Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Apache CXF 2.2.7 Spring 3 Web Service Unmarshalling Error: unexpected element

Tags:

spring

cxf

I have developed a simple web service application using Apache CXF 2.2.7 and Spring 3, deployed onto Tomcat as a WAR file, but I'm getting the following error message:

12-Apr-2010 15:56:12 org.apache.cxf.phase.PhaseInterceptorChain doDefaultLogging WARNING: Interceptor for {http://services.aristabi.com/}ReportingServiceImplService#{http://services.aristabi.com/}getNewBusinessVolumeByCreateDate_v2 has thrown exception, unwinding now org.apache.cxf.interceptor.Fault: Unmarshalling Error: unexpected element (uri:"http://services.aristabi.com/", local:"searchCriteria"). Expected elements are <{}searchCriteria> at org.apache.cxf.jaxb.JAXBEncoderDecoder.unmarshall(JAXBEncoderDecoder.java:764) at org.apache.cxf.jaxb.JAXBEncoderDecoder.unmarshall(JAXBEncoderDecoder.java:623) at org.apache.cxf.jaxb.io.DataReaderImpl.read(DataReaderImpl.java:128) at org.apache.cxf.interceptor.DocLiteralInInterceptor.handleMessage(DocLiteralInInterceptor.java:106) at org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:243) at org.apache.cxf.transport.ChainInitiationObserver.onMessage(ChainInitiationObserver.java:109) at org.apache.cxf.transport.servlet.ServletDestination.invoke(ServletDestination.java:98) at org.apache.cxf.transport.servlet.ServletController.invokeDestination(ServletController.java:406) at org.apache.cxf.transport.servlet.ServletController.invoke(ServletController.java:178) at org.apache.cxf.transport.servlet.AbstractCXFServlet.invoke(AbstractCXFServlet.java:142) at org.apache.cxf.transport.servlet.AbstractHTTPServlet.handleRequest(AbstractHTTPServlet.java:179) at org.apache.cxf.transport.servlet.AbstractHTTPServlet.doPost(AbstractHTTPServlet.java:103) at javax.servlet.http.HttpServlet.service(HttpServlet.java:637) at org.apache.cxf.transport.servlet.AbstractHTTPServlet.service(AbstractHTTPServlet.java:159) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206) at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233) at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191) at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128) at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102) at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109) at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:293) at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:849) at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:583) at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:454) at java.lang.Thread.run(Thread.java:619) Caused by: javax.xml.bind.UnmarshalException - with linked exception: [javax.xml.bind.UnmarshalException: unexpected element (uri:"http://services.aristabi.com/", local:"searchCriteria"). Expected elements are <{}searchCriteria>] at com.sun.xml.bind.v2.runtime.unmarshaller.UnmarshallerImpl.handleStreamException(UnmarshallerImpl.java:425) at com.sun.xml.bind.v2.runtime.unmarshaller.UnmarshallerImpl.unmarshal0(UnmarshallerImpl.java:362) at com.sun.xml.bind.v2.runtime.unmarshaller.UnmarshallerImpl.unmarshal(UnmarshallerImpl.java:339) at org.apache.cxf.jaxb.JAXBEncoderDecoder.unmarshall(JAXBEncoderDecoder.java:749) ... 25 more Caused by: javax.xml.bind.UnmarshalException: unexpected element (uri:"http://services.aristabi.com/", local:"searchCriteria"). Expected elements are <{}searchCriteria> at com.sun.xml.bind.v2.runtime.unmarshaller.UnmarshallingContext.handleEvent(UnmarshallingContext.java:642) at com.sun.xml.bind.v2.runtime.unmarshaller.Loader.reportError(Loader.java:254) at com.sun.xml.bind.v2.runtime.unmarshaller.Loader.reportError(Loader.java:249) at com.sun.xml.bind.v2.runtime.unmarshaller.Loader.reportUnexpectedChildElement(Loader.java:116) at com.sun.xml.bind.v2.runtime.unmarshaller.Loader.childElement(Loader.java:101) at com.sun.xml.bind.v2.runtime.unmarshaller.StructureLoader.childElement(StructureLoader.java:245) at com.sun.xml.bind.v2.runtime.unmarshaller.UnmarshallingContext._startElement(UnmarshallingContext.java:478) at com.sun.xml.bind.v2.runtime.unmarshaller.UnmarshallingContext.startElement(UnmarshallingContext.java:459) at com.sun.xml.bind.v2.runtime.unmarshaller.StAXStreamConnector.handleStartElement(StAXStreamConnector.java:242) at com.sun.xml.bind.v2.runtime.unmarshaller.StAXStreamConnector.bridge(StAXStreamConnector.java:176) at com.sun.xml.bind.v2.runtime.unmarshaller.UnmarshallerImpl.unmarshal0(UnmarshallerImpl.java:360) ... 27 more Caused by: javax.xml.bind.UnmarshalException: unexpected element (uri:"http://services.aristabi.com/", local:"searchCriteria"). Expected elements are <{}searchCriteria> ... 38 more

This is probably a simple issue, but I can't seem to be able to resolve it. Can anyone point me in the right direction to solve this issue?

Thanks, Zahanghir

Btw, this is what my wsdl looks like

<?xml version='1.0' encoding='UTF-8'?><wsdl:definitions name="ReportingServiceImplService" targetNamespace="http://services.aristabi.com/" xmlns:ns1="http://cxf.apache.org/bindings/xformat" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:tns="http://services.aristabi.com/" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<wsdl:types>
<xs:schema attributeFormDefault="unqualified" elementFormDefault="unqualified"   targetNamespace="http://services.aristabi.com/" xmlns:tns="http://services.aristabi.com/" xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="getNewBusinessVolumeByCreateDate" type="tns:getNewBusinessVolumeByCreateDate" />
<xs:element name="getNewBusinessVolumeByCreateDateResponse" type="tns:getNewBusinessVolumeByCreateDateResponse" />
<xs:element name="getNewBusinessVolumeByCreateDate_v2" type="tns:getNewBusinessVolumeByCreateDate_v2" />
<xs:element name="getNewBusinessVolumeByCreateDate_v2Response" type="tns:getNewBusinessVolumeByCreateDate_v2Response" />
<xs:element name="newBusinessLead" type="tns:newBusinessLead" />
<xs:element name="quotes" type="tns:quotes" />
<xs:element name="searchCriteria" type="tns:searchCriteria" />
<xs:complexType name="getNewBusinessVolumeByCreateDate">
<xs:sequence>
  <xs:element minOccurs="0" name="agent" type="xs:string" />
  <xs:element minOccurs="0" name="broker" type="xs:string" />
  <xs:element minOccurs="0" name="businessUnit" type="xs:string" />
  <xs:element minOccurs="0" name="fromMonth" type="xs:string" />
  <xs:element minOccurs="0" name="fromYear" type="xs:string" />
  <xs:element minOccurs="0" name="region" type="xs:string" />
  <xs:element minOccurs="0" name="toMonth" type="xs:string" />
  <xs:element minOccurs="0" name="toYear" type="xs:string" />
</xs:sequence>
</xs:complexType>
<xs:complexType name="getNewBusinessVolumeByCreateDateResponse">
<xs:sequence>
  <xs:element minOccurs="0" name="return" type="tns:newBusinessLead" />
</xs:sequence>
</xs:complexType>
<xs:complexType name="newBusinessLead">
<xs:sequence>
  <xs:element maxOccurs="unbounded" minOccurs="0" name="convertedQuotes" nillable="true" type="tns:quotes" />
  <xs:element maxOccurs="unbounded" minOccurs="0" name="declinedQuotes" nillable="true" type="tns:quotes" />
  <xs:element maxOccurs="unbounded" minOccurs="0" name="ntuQuotes" nillable="true" type="tns:quotes" />
  <xs:element maxOccurs="unbounded" minOccurs="0" name="pendingQuotes" nillable="true" type="tns:quotes" />
  </xs:sequence>
</xs:complexType>
<xs:complexType name="quotes">
<xs:sequence>
  <xs:element minOccurs="0" name="month" type="xs:string" />
  <xs:element name="premium" type="xs:int" />
  <xs:element minOccurs="0" name="quoteStatus" type="xs:string" />
  <xs:element name="volume" type="xs:int" />
  <xs:element minOccurs="0" name="year" type="xs:string" />
</xs:sequence>
</xs:complexType>
<xs:complexType name="arrayList">
<xs:complexContent>
  <xs:extension base="tns:abstractList">
    <xs:sequence />
  </xs:extension>
</xs:complexContent>
</xs:complexType>
<xs:complexType abstract="true" name="abstractList">
<xs:complexContent>
  <xs:extension base="tns:abstractCollection">
    <xs:sequence />
  </xs:extension>
</xs:complexContent>
</xs:complexType>
<xs:complexType abstract="true" name="abstractCollection">
<xs:sequence />
</xs:complexType>
<xs:complexType name="getNewBusinessVolumeByCreateDate_v2">
<xs:sequence>
  <xs:element minOccurs="0" name="searchCriteria" type="tns:searchCriteria" />
</xs:sequence>
</xs:complexType>
<xs:complexType name="searchCriteria">
<xs:sequence>
  <xs:element minOccurs="0" name="agent" type="xs:string" />
  <xs:element minOccurs="0" name="broker" type="xs:string" />
  <xs:element minOccurs="0" name="businessUnit" type="xs:string" />
  <xs:element minOccurs="0" name="fromMonth" type="xs:string" />
  <xs:element minOccurs="0" name="fromYear" type="xs:string" />
  <xs:element minOccurs="0" name="region" type="xs:string" />
  <xs:element minOccurs="0" name="toMonth" type="xs:string" />
  <xs:element minOccurs="0" name="toYear" type="xs:string" />
</xs:sequence>
</xs:complexType>
<xs:complexType name="getNewBusinessVolumeByCreateDate_v2Response">
<xs:sequence>
  <xs:element minOccurs="0" name="return" type="tns:newBusinessLead" />
</xs:sequence>
</xs:complexType>
<xs:element name="InvalidUserCredentialsException" type="tns:InvalidUserCredentialsException" />
<xs:complexType name="InvalidUserCredentialsException">
<xs:sequence />
</xs:complexType>
<xs:element name="tokenString" nillable="true" type="xs:string" />
</xs:schema>
</wsdl:types>
<wsdl:message name="InvalidUserCredentialsException">
<wsdl:part element="tns:InvalidUserCredentialsException" name="InvalidUserCredentialsException">
</wsdl:part>
</wsdl:message>
<wsdl:message name="getNewBusinessVolumeByCreateDateResponse">
<wsdl:part element="tns:getNewBusinessVolumeByCreateDateResponse" name="parameters">
</wsdl:part>
</wsdl:message>
<wsdl:message name="getNewBusinessVolumeByCreateDate">
<wsdl:part element="tns:getNewBusinessVolumeByCreateDate" name="parameters">
</wsdl:part>
<wsdl:part element="tns:tokenString" name="tokenString">
</wsdl:part>
</wsdl:message>
<wsdl:message name="getNewBusinessVolumeByCreateDate_v2Response">
<wsdl:part element="tns:getNewBusinessVolumeByCreateDate_v2Response" name="parameters">
</wsdl:part>
</wsdl:message>
<wsdl:message name="getNewBusinessVolumeByCreateDate_v2">
<wsdl:part element="tns:getNewBusinessVolumeByCreateDate_v2" name="parameters">
</wsdl:part>
</wsdl:message>
<wsdl:portType name="IReportingService">
<wsdl:operation name="getNewBusinessVolumeByCreateDate">
  <wsdl:input message="tns:getNewBusinessVolumeByCreateDate" name="getNewBusinessVolumeByCreateDate">
</wsdl:input>
  <wsdl:output message="tns:getNewBusinessVolumeByCreateDateResponse" name="getNewBusinessVolumeByCreateDateResponse">
</wsdl:output>
</wsdl:operation>
<wsdl:operation name="getNewBusinessVolumeByCreateDate_v2">
  <wsdl:input message="tns:getNewBusinessVolumeByCreateDate_v2" name="getNewBusinessVolumeByCreateDate_v2">
</wsdl:input>
  <wsdl:output message="tns:getNewBusinessVolumeByCreateDate_v2Response" name="getNewBusinessVolumeByCreateDate_v2Response">
</wsdl:output>
  <wsdl:fault message="tns:InvalidUserCredentialsException" name="InvalidUserCredentialsException">
</wsdl:fault>
</wsdl:operation>
</wsdl:portType>
<wsdl:binding name="ReportingServiceImplServiceSoapBinding" type="tns:IReportingService">
<soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http" />
<wsdl:operation name="getNewBusinessVolumeByCreateDate">
  <soap:operation soapAction="" style="document" />
  <wsdl:input name="getNewBusinessVolumeByCreateDate">
    <soap:header message="tns:getNewBusinessVolumeByCreateDate" part="tokenString" use="literal">
    </soap:header>
    <soap:body parts="parameters" use="literal" />
  </wsdl:input>
  <wsdl:output name="getNewBusinessVolumeByCreateDateResponse">
    <soap:body use="literal" />
  </wsdl:output>
</wsdl:operation>
<wsdl:operation name="getNewBusinessVolumeByCreateDate_v2">
  <soap:operation soapAction="" style="document" />
  <wsdl:input name="getNewBusinessVolumeByCreateDate_v2">
    <soap:body use="literal" />
  </wsdl:input>
  <wsdl:output name="getNewBusinessVolumeByCreateDate_v2Response">
    <soap:body use="literal" />
  </wsdl:output>
  <wsdl:fault name="InvalidUserCredentialsException">
    <soap:fault name="InvalidUserCredentialsException" use="literal" />
  </wsdl:fault>
</wsdl:operation>
</wsdl:binding>
<wsdl:service name="ReportingServiceImplService">
<wsdl:port binding="tns:ReportingServiceImplServiceSoapBinding" name="ReportingServiceImplPort">
  <soap:address location="http://localhost:8889/AristaInsuranceServices/reportingService" />
</wsdl:port>
</wsdl:service>
</wsdl:definitions>

I don't have a XSD. Can you please point out what is wrong with the WSDL?

like image 803
Zahanghir Avatar asked Apr 12 '10 15:04

Zahanghir


2 Answers

I know this question is a year old with no accepted answer but I had exactly the same error today.

Like the original question poster, I have a Java-First service with a method that returns an object. The problem for me was that I added an extra property to the bean that gets returned by the service method.

Once I republished/redeployed the service, the client side jaxb generated class for the return object was no longer the same as the server side WSDL complex-type (i.e. the client side classes lacked the new property) and so I had the "unexpected element" exception with the name of the missing property.

Once I regenated all the jaxb objects using WsdlToJava the client side code worked as normal.

I also came across a suggested workaround for this situation where you might not want to regenerate your client code every time a property changes on the server side. The solution is basically to ignore the unexpected element exception on the client side because it is for new elements that your existing code doesn't use. Link here to the solution:
http://whileonefork.blogspot.com/2010/11/cxf-backwards-compatibility-adding.html

like image 133
DarrenC Avatar answered Oct 29 '22 17:10

DarrenC


The incoming message is invalid. Basically, it doesn't match the schema. (or at least what JAXB is expecting) Basically, someplace in the message, you have an element like:

<ns1:searchCriteria> ..... </ns1:searchCriteria>

or possibly with no namespace prefix, but with a default namespace set someplace. However, JAXB is expecting the element to be unqualified. something like:

<searchCriteria> ..... </searchCriteria>

Definitely check the sending side to see what they are sending as well as check the schema to see what the schema says it should look like. (elementFormDefault=unqualified is the default if not specified)

like image 37
Daniel Kulp Avatar answered Oct 29 '22 17:10

Daniel Kulp