【问题标题】:Using SOAPAction in HTTP header to consume SOAP Service in JAVA在 HTTP 标头中使用 SOAPAction 在 JAVA 中使用 SOAP 服务
【发布时间】:2020-07-06 13:39:35
【问题描述】:

我正在尝试使用 spring WebServiceGatewaySupport 在 Java 中实现一个肥皂服务消费者。

当我使用curl 使用以下服务时,它会给出正确的响应。

 curl -d @request.xml -H 'SOAPAction:abc:mnEvent#DoAction' https://myhost.org/cd/doAction.jsp

我正在尝试使用 JAVA 来实现相同的功能,方法是在继承自 WebServiceGatewaySupport 的模板类中添加以下 HttpHeaders

public O callWebService(String url, I request) {
    return (O) getWebServiceTemplate().marshalSendAndReceive(url, request, new WebServiceMessageCallback() {
        @Override
        public void doWithMessage(WebServiceMessage message) {
            TransportContext transportContext = TransportContextHolder.getTransportContext();
            HttpComponentsConnection connection = (HttpComponentsConnection) transportContext.getConnection();
            connection.getHttpPost().addHeader("SOAPAction", "abc:mnEvent#DoAction");
        }
    });
}

使用此代码,我收到如下错误消息。

SOP-330006 方法 'DoAction, ""' 未在 SOAP 服务 'abc:mnEvent' 中定义。

curl 命令移至 JAVA 时我错过了什么?

【问题讨论】:

    标签: java web-services spring-mvc curl soap-client


    【解决方案1】:

    错误信息SOP-330006 The method 'DoAction, ""' is not defined in SOAP service 'abc:mnEvent'.表示,请求中有两个soap动作。

    1. 在 HttpHeader 中添加了显式 SoapAction
    2. SoapMessage 中的隐式 SoapAction

    为了避免这个问题,我们需要从 header 中删除 soapAction 并将其设置在 SoapMessage 中。

    SaajSoapMessage soapMessage = (SaajSoapMessage) message;
    soapMessage.setSoapAction("abc:mnEvent#DoAction");
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-11-16
      • 1970-01-01
      • 1970-01-01
      • 2012-02-22
      相关资源
      最近更新 更多