【问题标题】:how to call soap webservice using spring integration java dsl with operation name如何使用带有操作名称的spring集成java dsl调用soap webservice
【发布时间】:2019-08-26 05:51:33
【问题描述】:

我正在尝试使用 spring 集成的 MarshallingWebServiceOutboundGateway 调用一个肥皂网络服务。以下是我的流程,非常简单:

@Bean
public IntegrationFlow asghar() throws Exception {
    Map<String, Object> action = new HashMap<>();
    action.put("ws_soapAction", "getCardTypes");

    return IntegrationFlows.from("inputChannel")
            .enrichHeaders(action)
            .handle(asgharWebserviceGateway()).get();
} 

来自“inputChannel”的消息负载中的对象属于 CardGroup 类型。然后我按如下方式创建网关:

    @Bean
    public MarshallingWebServiceOutboundGateway asgharWebserviceGateway() throws Exception {
        SaajSoapMessageFactory messageFactory = new SaajSoapMessageFactory(
                MessageFactory.newInstance(SOAPConstants.SOAP_1_1_PROTOCOL));
        messageFactory.afterPropertiesSet();

        WebServiceTemplate webServiceTemplate = new WebServiceTemplate(messageFactory);

        Jaxb2Marshaller marshaller = new Jaxb2Marshaller();

        marshaller.setContextPath("my.package.to.webservice.entities");
        marshaller.setCheckForXmlRootElement(false);
        marshaller.afterPropertiesSet();

        webServiceTemplate.setMarshaller(marshaller);
        webServiceTemplate.afterPropertiesSet();
        MarshallingWebServiceOutboundGateway asghar = new MarshallingWebServiceOutboundGateway("http://uri.to.webservice/MobileService", webServiceTemplate);

        asghar.setReplyChannel(replyChannel());
        return asghar;
    }

这是cxf从wsdl生成的服务接口的一部分

@WebMethod
@WebResult(name = "return", targetNamespace = "http://ws.gateway.manager.br.com/", partName = "return")
public CardTypesResponse getCardTypes(

        @WebParam(partName = "cardGroup", name = "cardGroup")
                CardGroup cardGroup
);

这是同一部分的 wsdl:

  <wsdl:message name="getCardTypes">
    <wsdl:part name="cardGroup" type="tns:cardGroup">
    </wsdl:part>
  </wsdl:message>

  <wsdl:message name="getCardTypesResponse">
    <wsdl:part name="return" type="tns:cardTypesResponse">
    </wsdl:part>
  </wsdl:message>

  <wsdl:operation name="getCardTypes">
    <wsdl:input message="tns:getCardTypes" name="getCardTypes">
    </wsdl:input>
    <wsdl:output message="tns:getCardTypesResponse" name="getCardTypesResponse">
    </wsdl:output>
  </wsdl:operation>
  <wsdl:operation name="getCardTypes">
    <soap:operation soapAction="" style="rpc"/>
      <wsdl:input name="getCardTypes">
        <soap:body namespace="http://ws.gateway.manager.br.com/" use="literal"/>
      </wsdl:input>
      <wsdl:output name="getCardTypesResponse">
        <soap:body namespace="http://ws.gateway.manager.br.com/" use="literal"/>
      </wsdl:output>
  </wsdl:operation>

如您所见,wsdl 中没有 soapAction,上面提到的代码会生成以下 soap 消息:

<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">
    <SOAP-ENV:Header>
    </SOAP-ENV:Header>
    <SOAP-ENV:Body>
        <tns:cardGroup xmlns:tns="http://ws.gateway.manager.br.com/">
            <code>9865421</code>
            <title>654965587</title>
        </tns:cardGroup>
    </SOAP-ENV:Body>
</SOAP-ENV:Envelope>

现在我想知道如何使用操作名称 (getCardTypes) 以及应该在哪里设置它以便正确创建肥皂消息,必须是这样的:

<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">

    <SOAP-ENV:Header>

    </SOAP-ENV:Header>
    <SOAP-ENV:Body>
        <tns:getCardTypes xmlns:tns="http://ws.gateway.manager.br.com/">
             <tns:cardGroup xmlns:tns="http://ws.gateway.manager.br.com/">
                <code>9865421</code>
                <title>654965587</title>
            </tns:cardGroup>
        </tns:getCardTypes>
    </SOAP-ENV:Body>
</SOAP-ENV:Envelope>

【问题讨论】:

    标签: spring-integration spring-ws spring-integration-dsl


    【解决方案1】:
    <wsdl:message name="getCardTypes">
        <wsdl:part name="cardGroup" type="tns:cardGroup">
        </wsdl:part>
    </wsdl:message>
    

    因此,您的 CardGroup 对象必须包装到 GetCardTypes 对象中。 Spring WS 不是 CXF,所以你需要习惯它的 Contract First 方法。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-01-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-11-20
      • 2017-06-08
      相关资源
      最近更新 更多