当前位置: 首页 > 知识库问答 >
问题:

Spring boot调用SOAP web服务

史俊德
2023-03-14

我正在尝试从Spring Boot调用SOAP Web服务,但我遇到了问题。我使用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>

遵循本指南:https://spring.io/guides/gs/consuming-web-service/

我还创建了SOAP客户端来调用TR069CheckDevice可用性。

我的客户端类如下所示:

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;
}

问题是我得到了未经马歇尔的例外:

"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方法。Any1知道我做错了什么吗?

另外,我还在下面添加了SOAPUI屏幕截图。

SOAP UI屏幕截图

共有1个答案

何禄
2023-03-14

通过在TR069ActionResult类中添加@XmlRootElement("tr069action结果")注释来解决这个问题。显然它区分大小写,因此它不能作为@XmlRootElement("TR069ActionResult")工作。

 类似资料:
  • 我不熟悉单元测试。参考google之后,我创建了一个测试类来测试我的控制器,如下所示: 我有以下控制器和服务类: 当我调试单元测试时,控制器中的p对象为null。我的状态是200,但不是预期的JSON响应 我错过了什么?

  • 我刚刚开始使用Spring Boot,我想使用RestTemplate调用一个查询并返回它的结果。 如何使用RESTTemplate调用查询?还是有更好的办法做这件事?

  • 我有一个DTO,它在控制器层通过BeanValidation(javax.validation)和定制验证器(org.springframework.validation.Validator)的组合进行验证。通过这种方式,我可以检查提供的输入是否有效,然后转换实体中的DTO并将其转发到服务层。 然后是业务逻辑验证。例如:@Entity用户的startDate必须在某个事件发生之后,如果最后创建的用

  • 在异步HTTP SERVER中使用服务 全局方法service_center() 使用service_center($service)获取服务地址,然后使用call()方法调用公开的服务方法 $service = (yield service_center('User')); $user = (yield $service->call("User::getUser", ['id'

  • 主要内容:1.概述,2. 消费者调用服务,3. 提供者提供服务1.概述 在 dubbo:// 协议的调用,一共分成三种: sync 同步调用 async 异步调用 oneway 单向调用 前两种比较好理解,都是基于 Request Response 模型,差异点在异步调用,服务消费者不阻塞等待结果,而是通过回调的方式,处理服务提供者返回的结果。 最后一种,基于 Message 模型,发起调用,而不关注等待和关注执行结果。 因此,从性能上:oneway > a

  • 问题内容: 注意:这旨在作为常见问题的规范答案。 我有一个带有字段()的Spring 类(),但是该字段是我尝试使用它时所用的。日志显示同时创建了bean和bean,但是每当尝试在服务bean上调用方法时,我都会得到一个。Spring为什么不自动接线该领域? 控制器类: 服务等级: 应该自动连接的服务bean,但不是: 当我尝试时,出现以下异常: 问题答案: 带注释的字段是因为Spring不知道您

  • 本文向大家介绍SpringBoot开启异步调用方法,包括了SpringBoot开启异步调用方法的使用技巧和注意事项,需要的朋友参考一下 异步调用无需等待,方法相当于子线程,后台执行,主线程执行完成,子线程开始执行。 SpringBoot 开启异步执行仅需两步: 方法上加 @Async main 方法 开启 @EnableAsync controller 执行结果 可以看到 controller 先

  • 我想从作为web服务使用的cfc中调用cfc。web服务只是向调用者返回一个状态通知,但是我需要启动另一个cfc来启动一些进程,打开一个ftp获取一个文件并将其下载到我们的服务器。目前我得到了这个错误。操作GetFile原因550无法打开文件。详细错误:550无法打开文件。.消息FTP GetFile操作过程中出现错误。打开文件。. 当我从一个url直接调用流程cfc或从另一个页面调用时,它工作正