How to remove unwanted SOAP header elements in JAX-WS
In our current webservice project with JAX-WS in Â JDeveloper Â 126.96.36.199 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 donâ€™t 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):
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:
Download this SoapHandler: Â SOAPHandler
- Java Callout in Mediator to Automatically Deal With Empty Elements
- First Steps with Apache WSIF – Calling out to WSIF-alized SOAP WebServices and Java Classes
- Unit testing with XFire â€“ How to test your SOAP server with a WSDL file
- Publish a WebService from a POJA (plain old Java application) – that is: out of the container using EndPoint class
- Publishing Java based WebServices using JAX-WS in JDeveloper 11g
This entry was posted by Frank Houweling on May 16, 2011 at 1:08 am, and is filed under General, J(2)EE/Java, Java, Java, JEE, OAS and WebLogic Server, Oracle, SOA & Oracle Fusion Middleware, Software Development. Follow any responses to this post through RSS 2.0.You can skip to the end and leave a response. Pinging is currently not allowed.
- Driedaagse Oracle Service Bus (OSB) 11g training – 29, 30 en 31 januari 2014
- The AMIS Summary of Oracle OpenWorld 2013 is available for download – 60-page white paper
- On the integrity of data in Java applications – presentation from JFall 2013
- Book Review of Building Modular Cloud Apps with OSGi by Bert Ertman and Paul Bakker (last edit: 25th October)
- Java 8 – Collection enhancements leveraging Lambda Expressions – or: How Java emulates SQL
- OOW13: summarizing one week and 2000 sessions in 3 hours and a bit – the yearly AMIS OOW Review session – 10th October
- JavaOne 2013: (Key) Notes of a conference – State of the Java platform and all the roadmaps
- OOW13 and JavaOne 13: Notes from a Conference – Part Two
- OOW13 and JavaOne 13: Notes from a Conference – Part One
- Getting started with Java EE 7 – Hands on in 10 minutes