【问题标题】:How to remove the action parameter from HTTP Content-type of SOAP request?如何从 SOAP 请求的 HTTP Content-type 中删除 action 参数?
【发布时间】:2016-02-09 01:38:33
【问题描述】:

我有一个第 3 方网络服务,这是它的 WSDL 的一部分:

<wsdl:operation name="PerformOperation">
  <soap12:operation soapAction=""/>
  <wsdl:input name="PerformOperationRequest">
    <soap12:body use="literal"/>
  </wsdl:input>
  <wsdl:output name="PerformOperationResponse">
    <soap12:body use="literal"/>
  </wsdl:output>
</wsdl:operation>

请注意,soapAction 是空的,但由于某种原因,服务无法处理 Content-type 包含 action="" 的请求,第 3 方支持表示请求根本不应该包含要处理的 action 参数。

我已经使用 JAX-WS 通过 WSDL 生成必要的对象,现在我的请求在 HTTP 标头中有下一个 Content-type:

Content-type: application/soap+xml;charset="utf-8";action=""

不知道如何去掉Content-type中的空action参数?

【问题讨论】:

    标签: java web-services soap wsdl


    【解决方案1】:

    我找到了解决办法。

    首先,我尝试使用 WSDL 文件的本地副本,而不使用这个烦人的操作描述行:&lt;soap12:operation soapAction=""/&gt; 它没有帮助,action="" 仍然存在于 Content-Type 中。 但后来我想起了SOAPHandler 接口。

    我是这样写的:

    class RemoveActionHandler implements SOAPHandler<SOAPMessageContext> {
        @Override
        public boolean handleMessage(SOAPMessageContext context) {
            if ("".equals(context.get(BindingProvider.SOAPACTION_URI_PROPERTY)))
                context.put(BindingProvider.SOAPACTION_URI_PROPERTY, null);
    
            return true;
        }
    
        ...
    }
    

    然后这样使用:

    ((BindingProvider)soapServicePort).getBinding()
         .setHandlerChain(Collections.<Handler>singletonList(new RemoveActionHandler()));
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-03-28
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多