'Spring boot calling SOAP web service
I am trying to call SOAP web service from Spring boot, but I am having an issue with it. I have auto generated classes from this WSDL with maven-jaxb2-plugin:
<definitions targetNamespace="urn:hr:bulb:acs">
<types>
<xsd:schema targetNamespace="urn:hr:bulb:acs">
<xsd:complexType name="TR069ActionRequestDataSet">
<xsd:sequence>
<xsd:element name="osssystemid" type="xsd:string"/>
<xsd:element name="assetid" type="xsd:string"/>
<xsd:element name="maxWaitTime" type="xsd:int" minOccurs="0" maxOccurs="1"/>
</xsd:sequence>
</xsd:complexType>
<xsd:complexType name="TR069GetActionResultDataSet">
<xsd:sequence>
<xsd:element name="osssystemid" type="xsd:string"/>
<xsd:element name="eventid" type="xsd:int"/>
<xsd:element name="maxWaitTime" type="xsd:int" minOccurs="0" maxOccurs="1"/>
</xsd:sequence>
</xsd:complexType>
<!-- elements for input messages binding -->
<xsd:element name="tr069checkdeviceavailabilitydata" type="tns:TR069ActionRequestDataSet"/>
<!-- end elements for input messages binding -->
<!-- elements for output messages binding -->
<xsd:complexType name="TR069ActionResult">
<xsd:all>
<xsd:element name="eventid" type="xsd:string" minOccurs="0" maxOccurs="1"/>
<xsd:element name="errorcode" type="xsd:int"/>
<xsd:element name="errordesc" type="xsd:string"/>
</xsd:all>
</xsd:complexType>
<!-- end elements for output messages binding -->
</xsd:schema>
</types>
<!-- Input messages -->
<message name="TR069CheckDeviceAvailabilityInMsg">
<part name="Input" element="tns:tr069checkdeviceavailabilitydata"/>
</message>
<!-- End output messages -->
<!-- Ports -->
<portType name="AcsProvisioning">
<operation name="TR069CheckDeviceAvailability">
<input message="tns:TR069CheckDeviceAvailabilityInMsg"/>
<output message="tns:TR069ActionResultOutMsg"/>
</operation>
</portType>
<!-- Binding -->
<binding name="AcsProvisioningBinding" type="tns:AcsProvisioning">
<soap:binding transport="http://schemas.xmlsoap.org/soap/http"/>
<operation name="TR069CheckDeviceAvailability">
<soap:operation soapAction="TR069CheckDeviceAvailability"/>
<input>
<soap:body use="literal"/>
</input>
<output>
<soap:body use="literal"/>
</output>
</operation>
<!-- end new BDMT methods -->
</binding>
<!-- Endpoint -->
<service name="AcsProvisioningService">
<port name="tns:AcsProvisioning" binding="tns:AcsProvisioningBinding">
<soap:address location="http://ACS/AcsProvisioningService"/>
</port>
</service>
</definitions>
following this guide: https://spring.io/guides/gs/consuming-web-service/
I have also created SOAP client to call TR069CheckDeviceAvailability.
My client class looks like this:
public class SoapClient extends WebServiceGatewaySupport {
public TR069ActionResult checkDeviceAvailability(String osssystemid, String assetid) {
TR069ActionRequestDataSet tr069ActionRequestDataSet = new TR069ActionRequestDataSet();
tr069ActionRequestDataSet.setOsssystemid(osssystemid);
tr069ActionRequestDataSet.setAssetid(assetid);
JAXBElement<TR069ActionRequestDataSet> jAXBElement = new ObjectFactory().createTr069Checkdeviceavailabilitydata(tr069ActionRequestDataSet);
JAXBElement<TR069ActionResult> aXBElementResponse = (JAXBElement<TR069ActionResult>) getWebServiceTemplate().marshalSendAndReceive("http://ACS/AcsProvisioningService/TR069CheckDeviceAvailability", jAXBElement, new SoapActionCallback("TR069ActionRequestDataSet"));
return aXBElementResponse.getValue();
}
and my SoapClient config class is this:
@Configuration
public class SoapClientConfig {
@Bean
public Jaxb2Marshaller marshaller() {
Jaxb2Marshaller marshaller = new Jaxb2Marshaller();
marshaller.setContextPath("com.example.SINP_api.SOAP");
return marshaller;
}
@Bean
public SoapClient soapConnector(Jaxb2Marshaller marshaller) {
SoapClient client = new SoapClient();
client.setDefaultUri("http://ACS/AcsProvisioningService");
client.setMarshaller(marshaller);
client.setUnmarshaller(marshaller);
return client;
}
The problem is that I am getting the unmarshall exception:
"JAXB unmarshalling exception; nested exception is javax.xml.bind.UnmarshalException: unexpected element (uri:\"urn:hr:bulb:acs\", local:\"tr069actionresult\"). Expected elements are <{urn:hr:bulb:acs}suspenddslamport>,<{urn:hr:bulb:acs}tr069checkdeviceavailabilitydata>
And i think the problem is in this part:
.marshalSendAndReceive("http://ACS/AcsProvisioningService/TR069CheckDeviceAvailability", jAXBElement, new SoapActionCallback("TR069ActionRequestDataSet"))
as I am not really sure what should I pass to this marshalSendAndReceive method. Any1 has any ideas what am I doing wrong?
PS. I have also addes SOAPUI screenshot underneath.
Solution 1:[1]
Solved this by adding @XmlRootElement("tr069actionresult")
annotation in TR069ActionResult
class. Apparently it is case sensitive so it did not work as @XmlRootElement("TR069ActionResult")
.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | fatih |