Results 1 to 7 of 7

Thread: JAXB unmarshalling exception: unexpected element

  1. #1
    Join Date
    Sep 2010
    Posts
    5

    Default JAXB unmarshalling exception: unexpected element

    Hi

    I'm getting a 'JAXB unmarshalling exception: unexpected element' when calling a webservice endpoint from soapUI.
    URI & local of the element are OK, the message is validated by a PayloadValidatingInterceptor based on the xsd used to generate classes using xjc - but the service expects a void URI and local element.
    Any thoughts on what could be the issue or how to further debug?

    Thanks

    Frederik

  2. #2
    Join Date
    Oct 2008
    Location
    Poland, Wrocław
    Posts
    424

    Default

    Hi

    If you could send some code, I'll try to help.

    regards
    Grzegorz Grzybek

  3. #3
    Join Date
    Sep 2010
    Posts
    5

    Default

    Hi Grzegorz,

    Thanks for the offer
    As a bit of background: I'm experimenting with Spring WS to send user id and receive other credentials back.

    I'm getting this exception, actual request triggering it is included:

    Code:
    2010-10-08 22:38:24,169 DEBUG [org.springframework.ws.transport.http.WebServiceMessageReceiverHandlerAdapter] - Accepting incoming [org.springframework.ws.transport.http.HttpServletConnection@299481b2] to [http://localhost:8080/FrontEndServices/credentialservices]
    2010-10-08 22:38:24,172 DEBUG [org.springframework.ws.server.MessageTracing.received] - Received request [SaajSoapMessage {http://www.test.com/ws/domain/credential}UserCredentialsRequest]
    2010-10-08 22:38:24,172 DEBUG [org.springframework.ws.server.endpoint.mapping.PayloadRootQNameEndpointMapping] - Looking up endpoint for [{http://www.test.com/ws/domain/credential}UserCredentialsRequest]
    2010-10-08 22:38:24,172 DEBUG [org.springframework.ws.soap.server.SoapMessageDispatcher] - Endpoint mapping [org.springframework.ws.server.endpoint.mapping.PayloadRootQNameEndpointMapping@4e84f566] maps request to endpoint [com.test.ws.endpoint.credential.UserCredentialsEndpoint@10ea443f]
    2010-10-08 22:38:24,173 DEBUG [org.springframework.ws.server.endpoint.interceptor.PayloadLoggingInterceptor] - Request: <cred:UserCredentialsRequest xmlns:cred="http://www.test.com/ws/domain/credential">
             <cred:UserIdentification>
                <!--You may enter the following 2 items in any order-->
                <cred:UserId>John</cred:UserId>
                <cred:Password>mypassword</cred:Password>
             </cred:UserIdentification>
          </cred:UserCredentialsRequest>
    2010-10-08 22:38:24,174 DEBUG [org.springframework.ws.soap.server.endpoint.interceptor.PayloadValidatingInterceptor] - Request message validated
    2010-10-08 22:38:24,174 DEBUG [org.springframework.ws.soap.server.SoapMessageDispatcher] - Testing endpoint adapter [org.springframework.ws.server.endpoint.adapter.MessageEndpointAdapter@51f88fbd]
    2010-10-08 22:38:24,174 DEBUG [org.springframework.ws.soap.server.endpoint.SoapFaultMappingExceptionResolver] - Resolving exception from endpoint [com.test.ws.endpoint.credential.UserCredentialsEndpoint@10ea443f]: org.springframework.oxm.jaxb.JaxbUnmarshallingFailureException: JAXB unmarshalling exception: unexpected element (uri:"http://www.test.com/ws/domain/credential", local:"UserCredentialsRequest"). Expected elements are <{}UserCredentials>,<{}UserCredentialsRequest>,<{}UserCredentialsResponse>,<{}UserIdentification>; nested exception is javax.xml.bind.UnmarshalException: unexpected element (uri:"http://www.test.com/ws/domain/credential", local:"UserCredentialsRequest"). Expected elements are <{}UserCredentials>,<{}UserCredentialsRequest>,<{}UserCredentialsResponse>,<{}UserIdentification>
    2010-10-08 22:38:24,174 DEBUG [org.springframework.ws.soap.server.SoapMessageDispatcher] - Endpoint invocation resulted in exception - responding with Fault
    org.springframework.oxm.jaxb.JaxbUnmarshallingFailureException: JAXB unmarshalling exception: unexpected element (uri:"http://www.test.com/ws/domain/credential", local:"UserCredentialsRequest"). Expected elements are <{}UserCredentials>,<{}UserCredentialsRequest>,<{}UserCredentialsResponse>,<{}UserIdentification>; nested exception is javax.xml.bind.UnmarshalException: unexpected element (uri:"http://www.test.com/ws/domain/credential", local:"UserCredentialsRequest"). Expected elements are <{}UserCredentials>,<{}UserCredentialsRequest>,<{}UserCredentialsResponse>,<{}UserIdentification>
    The xsd is the following:
    Code:
    <?xml version="1.0" encoding="UTF-8"?>
    <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
    	targetNamespace="http://www.test.com/ws/domain/credential" xmlns:crd="http://www.test.com/ws/domain/credential"
    	xmlns:jxb="http://java.sun.com/xml/ns/jaxb" jxb:version="2.0"
    	xmlns:xjc="http://java.sun.com/xml/ns/jaxb/xjc"
    	jxb:extensionBindingPrefixes="xjc" elementFormDefault="qualified">
    
    	<xs:element name="UserCredentials">
    		<xs:complexType>
    			<xs:all>
    				<xs:element name="UserId" type="xs:long" />
    				<xs:element name="Password" type="xs:string" />
    			</xs:all>
    		</xs:complexType>
    	</xs:element>
    
    	<xs:element name="UserIdentification">
    		<xs:complexType>
    			<xs:all>
    				<xs:element name="UserId" type="xs:string" />
    				<xs:element name="Password" type="xs:string" />
    			</xs:all>
    		</xs:complexType>
    	</xs:element>
    
    	<xs:element name="UserCredentialsRequest">
    		<xs:complexType>
    			<xs:all>
    				<xs:element ref="crd:UserIdentification" />
    			</xs:all>
    		</xs:complexType>
    	</xs:element>
    
    	<xs:element name="UserCredentialsResponse">
    		<xs:complexType>
    			<xs:all>
    				<xs:element ref="crd:UserCredentials" />
    			</xs:all>
    		</xs:complexType>
    	</xs:element>
    
    </xs:schema>
    Java classes are generated from this xsd using
    Code:
    xjc -extension
    ObjectFactory is present; and package-info class contains annotation to bind to namespace:
    Code:
    @javax.xml.bind.annotation.XmlSchema(namespace = "http://www.test.com/ws/domain/credential", elementFormDefault = javax.xml.bind.annotation.XmlNsForm.QUALIFIED)
    All generated classes have proper annotations, e.g. for the UserCredentials class:
    Code:
    @XmlAccessorType(XmlAccessType.FIELD)
    @XmlType(name = "", propOrder = {
    
    })
    @XmlRootElement(name = "UserCredentials")
    And my spring xml:
    Code:
    <?xml version="1.0" encoding="UTF-8"?>
    <beans xmlns="http://www.springframework.org/schema/beans"
    	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:oxm="http://www.springframework.org/schema/oxm"
    	xsi:schemaLocation="http://www.springframework.org/schema/beans 
        http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
    		http://www.springframework.org/schema/oxm 
        http://www.springframework.org/schema/oxm/spring-oxm-1.5.xsd">
    
    	<bean id="credentialService" class="com.test.ws.service.credential.CredentialServiceImpl"
    		init-method="initialize" />
    
    	<bean id="Credential"
    		class="org.springframework.ws.wsdl.wsdl11.DefaultWsdl11Definition">
    		<property name="schema" ref="schema" />
    		<property name="portTypeName" value="Credential" />
    		<property name="locationUri" value="/credentialservices" />
    		<property name="targetNamespace" value="http://www.test.com/ws/domain/credential" />
    	</bean>
    
    	<bean id="schema" class="org.springframework.xml.xsd.SimpleXsdSchema">
    		<property name="xsd" value="/WEB-INF/credential.xsd" />
    	</bean>
    
    	<bean id="marshaller" class="org.springframework.oxm.jaxb.Jaxb2Marshaller">
    		<property name="contextPaths">
    			<list>
    			<value>com.test.ws.domain.credential</value>
    			</list>
    		</property>
    		</bean>
    
    	<bean id="unmarshaller" class="org.springframework.oxm.jaxb.Jaxb2Marshaller">
    		<property name = "contextPaths">
    			<list>
    			<value>com.test.ws.domain.credential</value>
    			</list>
    		</property>
    		</bean>
    
    	<bean id="userCredentialsEndpoint" class="com.test.ws.endpoint.credential.UserCredentialsEndpoint"
    		autowire="byName" />
    				
    	<bean id="validatingInterceptor"
    		class="org.springframework.ws.soap.server.endpoint.interceptor.PayloadValidatingInterceptor">
    		<property name="xsdSchema" ref="schema" />
    		<property name="validateRequest" value="true" />
    		<property name="validateResponse" value="true" />
    	</bean>
    
    	<bean id="loggingInterceptor"
    		class="org.springframework.ws.server.endpoint.interceptor.PayloadLoggingInterceptor" />
    
    	<bean name="endpointMapping"
    		class="org.springframework.ws.server.endpoint.mapping.PayloadRootQNameEndpointMapping">
    		<property name="interceptors">
    			<list>
    				<ref local="loggingInterceptor" />
    				<ref local="validatingInterceptor" />
    			</list>
    		</property>
    		<property name="mappings">
    			<props>
    				<prop key="{http://www.test.com/ws/domain/credential}UserCredentialsRequest">userCredentialsEndpoint</prop>
    			</props>
    		</property>
    	</bean>
    
    	<bean id="exceptionResolver"
    		class="org.springframework.ws.soap.server.endpoint.SoapFaultMappingExceptionResolver">
    		<property name="defaultFault" value="SERVER" />
    		<property name="exceptionMappings">
    			<props>
    				<prop key="org.springframework.oxm.ValidationFailureException">CLIENT,Invalid request</prop>
    				<prop key="com.test.ws.service.credential.CredentialException">SERVER</prop>
    			</props>
    		</property>
    	</bean>
    
    </beans>
    All pointers appreciated...

    Thanks

    Frederik

  4. #4
    Join Date
    Sep 2010
    Posts
    5

    Default

    Hi Grzegorz,

    Thanks for the offer

    As a bit of background: I'm just prototyping a service that receives user id and replies with some other credentials.

    Here's the exception I'm getting, message triggering it included:
    Code:
    2010-10-08 22:38:24,169 DEBUG [org.springframework.ws.transport.http.WebServiceMessageReceiverHandlerAdapter] - Accepting incoming [org.springframework.ws.transport.http.HttpServletConnection@299481b2] to [http://localhost:8080/FrontEndServices/credentialservices]
    2010-10-08 22:38:24,172 DEBUG [org.springframework.ws.server.MessageTracing.received] - Received request [SaajSoapMessage {http://www.test.com/ws/domain/credential}UserCredentialsRequest]
    2010-10-08 22:38:24,172 DEBUG [org.springframework.ws.server.endpoint.mapping.PayloadRootQNameEndpointMapping] - Looking up endpoint for [{http://www.test.com/ws/domain/credential}UserCredentialsRequest]
    2010-10-08 22:38:24,172 DEBUG [org.springframework.ws.soap.server.SoapMessageDispatcher] - Endpoint mapping [org.springframework.ws.server.endpoint.mapping.PayloadRootQNameEndpointMapping@4e84f566] maps request to endpoint [com.test.ws.endpoint.credential.UserCredentialsEndpoint@10ea443f]
    2010-10-08 22:38:24,173 DEBUG [org.springframework.ws.server.endpoint.interceptor.PayloadLoggingInterceptor] - Request: <cred:UserCredentialsRequest xmlns:cred="http://www.test.com/ws/domain/credential">
             <cred:UserIdentification>
                <!--You may enter the following 2 items in any order-->
                <cred:UserId>John</cred:UserId>
                <cred:Password>mypassword</cred:Password>
             </cred:UserIdentification>
          </cred:UserCredentialsRequest>
    2010-10-08 22:38:24,174 DEBUG [org.springframework.ws.soap.server.endpoint.interceptor.PayloadValidatingInterceptor] - Request message validated
    2010-10-08 22:38:24,174 DEBUG [org.springframework.ws.soap.server.SoapMessageDispatcher] - Testing endpoint adapter [org.springframework.ws.server.endpoint.adapter.MessageEndpointAdapter@51f88fbd]
    2010-10-08 22:38:24,174 DEBUG [org.springframework.ws.soap.server.endpoint.SoapFaultMappingExceptionResolver] - Resolving exception from endpoint [com.test.ws.endpoint.credential.UserCredentialsEndpoint@10ea443f]: org.springframework.oxm.jaxb.JaxbUnmarshallingFailureException: JAXB unmarshalling exception: unexpected element (uri:"http://www.test.com/ws/domain/credential", local:"UserCredentialsRequest"). Expected elements are <{}UserCredentials>,<{}UserCredentialsRequest>,<{}UserCredentialsResponse>,<{}UserIdentification>; nested exception is javax.xml.bind.UnmarshalException: unexpected element (uri:"http://www.test.com/ws/domain/credential", local:"UserCredentialsRequest"). Expected elements are <{}UserCredentials>,<{}UserCredentialsRequest>,<{}UserCredentialsResponse>,<{}UserIdentification>
    2010-10-08 22:38:24,174 DEBUG [org.springframework.ws.soap.server.SoapMessageDispatcher] - Endpoint invocation resulted in exception - responding with Fault
    org.springframework.oxm.jaxb.JaxbUnmarshallingFailureException: JAXB unmarshalling exception: unexpected element (uri:"http://www.test.com/ws/domain/credential", local:"UserCredentialsRequest"). Expected elements are <{}UserCredentials>,<{}UserCredentialsRequest>,<{}UserCredentialsResponse>,<{}UserIdentification>; nested exception is javax.xml.bind.UnmarshalException: unexpected element (uri:"http://www.test.com/ws/domain/credential", local:"UserCredentialsRequest"). Expected elements are <{}UserCredentials>,<{}UserCredentialsRequest>,<{}UserCredentialsResponse>,<{}UserIdentification>
    The xsd, from which classes are generated:
    Code:
    <?xml version="1.0" encoding="UTF-8"?>
    <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
    	targetNamespace="http://www.test.com/ws/domain/credential" xmlns:crd="http://www.test.com/ws/domain/credential"
    	xmlns:jxb="http://java.sun.com/xml/ns/jaxb" jxb:version="2.0"
    	xmlns:xjc="http://java.sun.com/xml/ns/jaxb/xjc"
    	jxb:extensionBindingPrefixes="xjc" elementFormDefault="qualified">
    
    
    
    	<xs:element name="UserCredentials">
    		<xs:complexType>
    			<xs:all>
    				<xs:element name="UserId" type="xs:long" />
    				<xs:element name="Password" type="xs:string" />
    			</xs:all>
    		</xs:complexType>
    	</xs:element>
    
    	<xs:element name="UserIdentification">
    		<xs:complexType>
    			<xs:all>
    				<xs:element name="UserId" type="xs:string" />
    				<xs:element name="Password" type="xs:string" />
    			</xs:all>
    		</xs:complexType>
    	</xs:element>
    
    	<xs:element name="UserCredentialsRequest">
    		<xs:complexType>
    			<xs:all>
    				<xs:element ref="crd:UserIdentification" />
    			</xs:all>
    		</xs:complexType>
    	</xs:element>
    
    	<xs:element name="UserCredentialsResponse">
    		<xs:complexType>
    			<xs:all>
    				<xs:element ref="crd:UserCredentials" />
    			</xs:all>
    		</xs:complexType>
    	</xs:element>
    </xs:schema>
    My spring xml:
    Code:
    <?xml version="1.0" encoding="UTF-8"?>
    <beans xmlns="http://www.springframework.org/schema/beans"
    	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:oxm="http://www.springframework.org/schema/oxm"
    	xsi:schemaLocation="http://www.springframework.org/schema/beans 
        http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
    		http://www.springframework.org/schema/oxm 
        http://www.springframework.org/schema/oxm/spring-oxm-1.5.xsd">
    
    	<bean id="credentialService" class="com.test.ws.service.credential.CredentialServiceImpl"
    		init-method="initialize" />
    
    	<bean id="Credential"
    		class="org.springframework.ws.wsdl.wsdl11.DefaultWsdl11Definition">
    		<property name="schema" ref="schema" />
    		<property name="portTypeName" value="Credential" />
    		<property name="locationUri" value="/credentialservices" />
    		<property name="targetNamespace" value="http://www.test.com/ws/domain/credential" />
    	</bean>
    
    	<bean id="schema" class="org.springframework.xml.xsd.SimpleXsdSchema">
    		<property name="xsd" value="/WEB-INF/credential.xsd" />
    	</bean>
    
    	<bean id="marshaller" class="org.springframework.oxm.jaxb.Jaxb2Marshaller">
    		<property name="contextPaths">
    			<list>
    			<value>com.test.ws.domain.credential</value>
    			</list>
    		</property>
    		</bean>
    
    	<bean id="unmarshaller" class="org.springframework.oxm.jaxb.Jaxb2Marshaller">
    		<property name = "contextPaths">
    			<list>
    			<value>com.test.ws.domain.credential</value>
    			</list>
    		</property>
    		</bean>
    
    	<bean id="userCredentialsEndpoint" class="com.test.ws.endpoint.credential.UserCredentialsEndpoint"
    		autowire="byName" />
    				
    	<bean id="validatingInterceptor"
    		class="org.springframework.ws.soap.server.endpoint.interceptor.PayloadValidatingInterceptor">
    		<property name="xsdSchema" ref="schema" />
    		<property name="validateRequest" value="true" />
    		<property name="validateResponse" value="true" />
    	</bean>
    
    	<bean id="loggingInterceptor"
    		class="org.springframework.ws.server.endpoint.interceptor.PayloadLoggingInterceptor" />
    
    	<bean name="endpointMapping"
    		class="org.springframework.ws.server.endpoint.mapping.PayloadRootQNameEndpointMapping">
    		<property name="interceptors">
    			<list>
    				<ref local="loggingInterceptor" />
    				<ref local="validatingInterceptor" />
    			</list>
    		</property>
    		<property name="mappings">
    			<props>
    				<prop key="{http://www.test.com/ws/domain/credential}UserCredentialsRequest">userCredentialsEndpoint</prop>
    			</props>
    		</property>
    	</bean>
    
    	<bean id="exceptionResolver"
    		class="org.springframework.ws.soap.server.endpoint.SoapFaultMappingExceptionResolver">
    		<property name="defaultFault" value="SERVER" />
    		<property name="exceptionMappings">
    			<props>
    				<prop key="org.springframework.oxm.ValidationFailureException">CLIENT,Invalid request</prop>
    				<prop key="com.test.ws.service.credential.CredentialException">SERVER</prop>
    			</props>
    		</property>
    	</bean>
    
    </beans>
    Any pointers would be greatly appreciated...

    Thanks

    Frederik

  5. #5
    Join Date
    Sep 2010
    Posts
    5

    Default

    I tried to post a couple of replies wih code, but none of them seems to appear. Anything specific I need to do to get them posted?
    Thx
    Frederik

  6. #6
    Join Date
    Oct 2008
    Location
    Poland, Wrocław
    Posts
    424

    Default

    Hi

    Try via github

  7. #7
    Join Date
    Sep 2010
    Posts
    5

    Default D'oh!

    I rebuilt the entire thing from scratch, and the error went away.
    I must have done something to corrupt the project structure.
    Thanks anyways, back to some real work

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •