简体   繁体   English

Spring 开机调用 SOAP web 服务

[英]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.我正在尝试从 Spring 引导调用 SOAP web 服务,但我遇到了问题。 I have auto generated classes from this WSDL with maven-jaxb2-plugin:我使用 maven-jaxb2-plugin 从这个WSDL自动生成类:

<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/遵循本指南: https://spring.io/guides/gs/consuming-web-service/

I have also created SOAP client to call TR069CheckDeviceAvailability .我还创建了 SOAP 客户端来调用TR069CheckDeviceAvailability

My client class looks like this:我的客户 class 看起来像这样:

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:我的 SoapClient 配置 class 是这样的:

@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:问题是我收到了 unmarshall 异常:

"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.因为我不太确定应该将什么传递给此 marshalSendAndReceive 方法。 Any1 has any ideas what am I doing wrong? Any1 有任何想法我做错了什么?

PS.附言。 I have also addes SOAPUI screenshot underneath.我还在下面添加了 SOAPUI 屏幕截图。

SOAP UI Screenshot SOAP 界面截图

Solved this by adding @XmlRootElement("tr069actionresult") annotation in TR069ActionResult class. Apparently it is case sensitive so it did not work as @XmlRootElement("TR069ActionResult") .通过在TR069ActionResult class 中添加@XmlRootElement("tr069actionresult")注释解决了这个问题。显然它区分大小写,所以它不能作为@XmlRootElement("TR069ActionResult")工作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM