How to remove unwanted SOAP header elements in JAX-WS

Frank Houweling

In our current webservice project with JAX-WS in JDeveloper we have a challenge with calling a webservice. This webservice from a remote organisation does not accept specific SOAP header elements our client application creates – although we followed the contract of the WSDL correctly. Of course this webservice must follow it as well as we have to, but for now we dont have a choice but to make a workaround. How can we remove unwanted elements from a SOAP header? In this blog I will show you how you can do that using a JAX-WS SOAPHandler that inspects the SOAP header and removes specific addressing elements.

In the WSDL file the element <wsaw:UsingAddressing wsdl:required=”true”/> is present. Following the contract of the WSDL – this means that the SOAP header must contain addressing elements. The runtime libraries of JAX-WS take care of this and creates in the SOAP header the elements (see picture):

  • <wsa:To>
  • <FaultTo>
  • <wsa:ReplyTo>
  • <wsa:MessageId>
  • <wsa:Action>

This remote webservice cannot accept <wsa:To>, <wsa:ReplyTo>, <FaultTo> elements (validation of incoming SOAP requests will fail), but <wsa:MessageId> and <wsa:Action> are mandatory. We cannot simply remove <wsaw:UsingAddressing wsdl:required=”true”/> from the WSDL and regenerate our client proxy in JDeveloper, because then we miss also the mandatory MessageId and Action elements.

We can use a JAX-WS SOAPHandler to inspect the SOAP header and remove certain elements. In the handleMessage() method we can get the SOAP header , retrieve the direct child elements of this header, inspect them and delete the unwanted ones:

Now the elements are removed from the SOAP header and we can call the webservice without validation errors:

Next Post

OWSM Custom x509 Assertion - Part 2 - Creating outgoing client assertion

In the previous post I explained how you can access the credential store and keystore using the configurations stored in the jsp-config.xml file. I also explained how you can read assertion properties. I put this code inside my base class This class has been repeated here below. In this post […]
%d bloggers like this: