Cannot create a SOAP client using Spring

2019-03-04 01:00发布

Following my previous question,this question, this one and this one I try to create a SOAP client using Spring but I receive following exceptions.

I have following code

<bean id="webServiceTemplate" 
class="org.springframework.ws.client.core.WebServiceTemplate">
        <property name="marshaller" ref="marshaller" />
        <property name="unmarshaller" ref="marshaller" />
        <property name="defaultUri"
            value="http://ticketmaster.productserve.com/v2/soap.php" />
    </bean>

When I add following code it returns below exception

Code

   <oxm:jaxb2-marshaller id="marshaller" contextPath="com.project.sample"/>

Exception

   javax.xml.bind.JAXBException: "com.project.sample" doesnt contain ObjectFactory.class or jaxb.index

And when I add following code it returns below exception

Code

<oxm:jaxb2-marshaller id="marshaller">
    <oxm:class-to-be-bound name="com.project.sample.SoapMessage"/> 
    <oxm:class-to-be-bound name="com.project.sample.SearchResponse"/>
    </oxm:jaxb2-marshaller>

Exception

[com.sun.istack.internal.SAXException2: unable to marshal type "java.lang.Class" as an element because it is missing an @XmlRootElement annotation]

Both classes have @XmlRootElement as following one

SoapMessage

@XmlRootElement(name="SoapMessage")
@XmlAccessorType(XmlAccessType.FIELD)
public class SoapMessage {
    @XmlElement(name="Username")
    private String username;
    @XmlElement(name="Password")
    private String password;
    @XmlElement(name="LanguageCode")
    private String languageCode;
    @XmlElement(name="ErrorMessage")
    private String errorMessage;
    @XmlElement(name="ErrorCode")
    private int errorCode;
    @XmlElement(name="AppVersion")
    private String appVersion;
    @XmlElement(name="Request")
    private Request request;
    @XmlElement(name="Response")
    private Response response;

    getters and setters

SearchFlightsResponse

@XmlRootElement(name="SearchFlightsResponse")
@XmlAccessorType(XmlAccessType.FIELD)
public class SearchFlightsResponse {
    @XmlElement(name = "SoapMessage")
    private SoapMessage soapMessage;

    public SoapMessage getSoapMessage() {
        return soapMessage;
    }

    public void setSoapMessage(SoapMessage soapMessage) {
        this.soapMessage = soapMessage;
    }

}

0条回答
登录 后发表回答