java - 在 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时,我在这里错过了什么?
解决方案
错误消息SOP-330006 The method 'DoAction, ""' is not defined in SOAP service 'abc:mnEvent'.
表明,请求中有两个肥皂动作。
- 在 HttpHeader 中添加了显式 SoapAction
- SoapMessage 中的隐式 SoapAction
为避免此问题,我们需要从标头中删除soapAction 并将其设置在SoapMessage 中。
SaajSoapMessage soapMessage = (SaajSoapMessage) message;
soapMessage.setSoapAction("abc:mnEvent#DoAction");
推荐阅读
- c# - C# LINQ - 分组方式
- maven - 如何在 jaxb2-maven-plugin 版本 2.5.0 中排除剧集文件的生成?
- sitemap - 仅允许访问 Googlebot - robots.txt
- flutter - 使用带有颤振的 Googleapis_auth 包时,ClientException“无法解析标头值”
- amazon-cloudformation - 打印到控制台 Cloudfront 域
- phpstorm - IntelliJ 的搜索模板语言是否有办法识别没有被 if 语句包装的函数调用
- flutter - 如何从这种类型的列表中访问单个值?
- fortran - fortran 有一流的功能吗?
- javascript - Imodeljs - 如何在 IModelJs 中创建图块?如何在 imodelJs 中创建根图块?
- python-3.x - 如何将 .txt 文件中的图像从一个文件夹复制到另一个文件夹