我正在尝试从Spring启动调用SOAP web服务,但是我遇到了一个问题。我已经从这个WSDL自动生成了类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>
遵循此指南:https://spring.io/guides/gs/consuming-web-service/
我还创建了SOAP客户端来调用TR069CheckDeviceAvailability.
我的客户端类是这样的:
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();
}
和我的SoapClient配置类是这样的:
@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;
}
问题是我得到了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>
我认为问题出在这部分:
.marshalSendAndReceive("http://ACS/AcsProvisioningService/TR069CheckDeviceAvailability", jAXBElement, new SoapActionCallback("TR069ActionRequestDataSet"))
,因为我不确定我应该传递给这个marshalSendAndReceive方法。有人知道我哪里做错了吗?
p。我还在下面添加了SOAPUI截图。
SOAP UI截图
通过在TR069ActionResult
类中添加@XmlRootElement("tr069actionresult")
注释来解决这个问题。显然,它是大小写敏感的,所以它不能作为@XmlRootElement("TR069ActionResult")
工作。