Results 1 to 2 of 2

Thread: JAXB unmarshalling exception: unexpected element (uri:

  1. #1
    Join Date
    Nov 2009
    Posts
    10

    Default JAXB unmarshalling exception: unexpected element (uri:

    Hi,

    i've got a problem with my web service. So here are my files:

    First I wrote an xsd file:
    Code:
    <?xml version="1.0" encoding="utf-8"?>
    <schema targetNamespace="http://terminportal.org/webapp/ws/address" elementFormDefault="qualified" xmlns="http://www.w3.org/2001/XMLSchema" xmlns:p="http://terminportal.org/webapp/ws/address">
      <element name="Address">
        <complexType>
          <sequence>
            <element name="Recipient" type="string" />
            <element name="House" type="string" />
            <element name="Street" type="string" />
            <element name="Town" type="string" />
            <element name="County" type="string" minOccurs="0" />
            <element name="PostCode" type="string" />
            <element name="Country">
              <simpleType>
                <restriction base="string">
                  <enumeration value="FR" />
                </restriction>
              </simpleType>
            </element>
          </sequence>
        </complexType>
      </element>
    </schema>
    Created my domain classes and wrote an endpoint:
    Code:
    <bean
    		class="org.springframework.ws.server.endpoint.mapping.PayloadRootQNameEndpointMapping">
    		<property name="mappings">
    			<props>
    				<prop key="{http://terminportal.org/webapp/ws/product}ProductRequest">ProductServiceEndpoint</prop>
    				<prop key="{http://terminportal.org/webapp/ws/address}Address">AddressServiceEndpoint</prop>
    			</props>
    		</property>
    Code:
    public class AddressServiceEndpoint extends AbstractMarshallingPayloadEndpoint {
    ...}
    Now I'm trying to connect to this Endpoint via webserviceTemplate:
    Code:
    public AddressServiceClient(){
    		webServiceTemplate = new WebServiceTemplate();
    		webServiceTemplate.setDefaultUri("http://localhost:8080/wm2010-webservice/addressService");
    	}
    
        public void simpleSendAndReceive() {
            StreamSource source = new StreamSource(getClass().getResourceAsStream("/AddressServiceRequest.xml"));
            StreamResult result = new StreamResult(System.out);
            webServiceTemplate.sendSourceAndReceiveToResult(source, result);
        }
    Heres the xml:
    Code:
    <?xml version="1.0" encoding="UTF-8"?>
    <Address xmlns="http://terminportal.org/webapp/ws/address">
    	<address>
    	<post-code>8000</post-code>
    	<town>Zurich</town>
    	<house>76</house>
    	<county>ZH</county>
    	<country>CH</country>
    	<street>Bahnhofstrasse</street>
    	</address>
    </Address>
    And now i get the following message running the addressserviceclient:
    JAXB unmarshalling exception: unexpected element (uri:"http://terminportal.org/webapp/ws/address", local:"Address"). Expected elements are <{}Address>; nested exception is javax.xml.bind.UnmarshalException: unexpected element (uri:"http://terminportal.org/webapp/ws/address", local:"Address"). Expected elements are <{}Address>

    And I don't know wheres my fault. Has anyone an idea? It seems that the marshaller can't parse the namespace in the xml-file, but when the namespace is remove, the endpoint can't map the request.

    Thanks for reading

  2. #2
    Join Date
    Aug 2007
    Location
    Mexico city
    Posts
    3

    Default @XMLRootElement annotation

    The problem is that you must specify the namespace in your JAXB generated classes using the @XMLRootElement annotation, for example:

    @XMLRootElement(namespace = "http://terminportal.org/webapp/ws/address", name = "MyClass" )

Posting Permissions

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