Search code examples
javaweb-servicessoapwsdl

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


I have a 3rd party web service, here is a part of it's 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>

Notice that soapAction is empty, but for some reason the service can't process requests which Content-type contains action="", 3rd party support says that requests shouldn't contain action parameter at all to be processed.

I've used JAX-WS to generate necessary objects by the WSDL and now my requests have the next Content-type in the HTTP header:

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

I wonder how to get rid of the empty action parameter in the Content-type?


Solution

  • I've found the solution.

    First I tried to use a local copy of the WSDL file without this annoying action description line: <soap12:operation soapAction=""/> It doesn't help, action="" was still present in the Content-Type. But then I remembered about the SOAPHandler interface.

    I wrote something like this:

    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;
        }
    
        ...
    }
    

    and then used it this way:

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