How to remove unwanted SOAP header elements in JAX-WS

Frank Houweling
0 0
Read Time:1 Minute, 32 Second

In our current webservice project with JAX-WS in JDeveloper 11.1.1.3 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 Post Author

Frank Houweling

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.
Happy
Happy
0 %
Sad
Sad
0 %
Excited
Excited
0 %
Sleepy
Sleepy
0 %
Angry
Angry
0 %
Surprise
Surprise
0 %
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 CustomAssertion.java. This class has been repeated here below. In this post […]
%d bloggers like this: