首页 > 解决方案 > 在 HTTP 标头中使用 SOAPAction 在 JAVA 中使用 SOAP 服务

问题描述

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

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

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

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

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时,我在这里错过了什么?

标签: javaweb-servicesspring-mvccurlsoap-client

解决方案


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

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

为避免此问题,我们需要从标头中删除soapAction 并将其设置在SoapMessage 中。

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

推荐阅读