How to remove unwanted SOAP header elements in JAX-WS


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:

About Author

Frank Houweling is an Oracle ADF, Java and performance specialist. During the past years he has been requested several times as troubleshooter of ADF projects with bad performance. As such he has been performing performance analysis, bottleneck detection and developing mitigating solutions based on these analysis. He is also the creator of the ADF Performance Monitor, an advanced monitor that can identify, report and help solve performance bottlenecks in ADF applications.

Comments are closed.