如何从 SOAP 请求的 HTTP Content-type 中删除操作参数?

How to remove the action parameter from HTTP Content-type of SOAP request?

我有一个第 3 方 Web 服务,这是它的 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 生成必要的 objects,现在我的请求在 HTTP header 中有下一个 Content-type:

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

我想知道如何去掉 Content-type 中的空操作参数?

我找到了解决方案。

首先,我尝试使用 WSDL 文件的本地副本,而没有这个恼人的操作描述行:<soap12:operation soapAction=""/> 它没有帮助,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()));