spring ws soap client+jaxb2

2019-08-14 22:34发布

I am using the JAXb2 maven plugin to create the domain[bean ]classes.

When i try to hit the service thru WebServiceTemplate class, I am getting below error.

Exception:org.springframework.oxm.UnmarshallingFailureException: JAXB unmarshalling exception; nested exception is javax.xml.bind.UnmarshalException: unexpected element (uri:"http://services.abc.cde.efg.com", local:"xxxLookupResponse"). Expected elements are <{services.abc.cde.efg.com"}xxxLookupRequest>,<{services.abc.cde.efg.com"}xxxLookupResponse>,<{services.abc.cde.efg.com"}zzzUploadOrder>

and my bindings file looks as follows.

I am wondering how is it expecting three elements, that too the last one is not at all related with this webservice and not defined in jaxb binding file also. I have checked the created bean classes and they are not interrelated.

<jaxb:bindings schemaLocation="abcsServices.xsd" node="/xs:schema">
        <jaxb:bindings node="xs:complexType[@name='xxxxxLookupRequest']">
            <annox:annotate>
                <annox:annotate annox:class="javax.xml.bind.annotation.XmlRootElement"
                    name="xxxxxxLookupRequest" />
            </annox:annotate>
        </jaxb:bindings>
    </jaxb:bindings>

    <jaxb:bindings schemaLocation="abcsServices.xsd" node="/xs:schema">
        <jaxb:bindings node="xs:complexType[@name='xxxxxLookupResponse']">
            <annox:annotate>
                <annox:annotate annox:class="javax.xml.bind.annotation.XmlRootElement"
                    name="xxxxxLookupResponse" />
            </annox:annotate>
        </jaxb:bindings>
    </jaxb:bindings>

Please throw some light on this. I am stuck here.

Client code:

ObjectFactory objFactory = new ObjectFactory(); xxxxLookupRequest req = objFactory.createxxxxLookupRequest(); req.setxxxx("12344"); req.setxxxxx("34234"); xxxxxLookupResponse response = (xxxxxLookupResponse) xxxxClient .doDeliveryLookUp(req); 

========

spring client code:

response = (xxxxxLookupResponse) getWebServiceTemplate() .marshalSendAndReceive(xxxxLookupRequest, new SoapActionCallback("urn:xxxxxLookup")); 

1条回答
迷人小祖宗
2楼-- · 2019-08-14 23:24

How do you create your JAXBContext? Please show the Spring configuration.

The error message is also weird:

...unexpected element (uri:"http://services.abc.cde.efg.com", local:"xxxLookupResponse"). Expected elements are ... <{services.abc.cde.efg.com"}xxxxxLookupResponse>...

Do you have matching names (xxxLookupResponse vs. xxxxxLookupResponse) here?

My theory is that you have one package (services.abc.cde.efg.com) generated or defined in two places and JAXB is picking the wrong one.

The binding files you refer to are not directly considered by JAXB, they are only used during the code generation. JAXB works with the generated classes then.

查看更多
登录 后发表回答