Jai’s Weblog – Tech, Security & Fun…

Tech, Security & Fun…

  • Jaibeer Malik

    Jaibeer Malik
  • View Jaibeer Malik's profile on LinkedIn
  • Subscribe

  • Feedburner

  • Enter your email address to subscribe to this blog and receive notifications of new posts by email.

    Join 32 other followers

  • Archives

  • Categories

  • Stats

    • 414,576
  • Live Traffic

  • Advertisements

Tips&Tricks: How to add soap header using JAX-WS RI

Posted by Jai on October 26, 2012

This post shares the tip how to add the soap header using jax-ws. One of the quick example could be web service authentication mechanism based on session id or some unique key based on soap headers in the request.

An example of how to do it using jax-ws, add-soap-header-object-using-pure-jax-ws

If you want to use jax-ws RI, adding_soap_header and jax-ws-adding-soap-headers

import com.sun.xml.ws.developer.WSBindingProvider;

//user logged in /authenticated session id retrieved from the server
//The same session if will be used for future communication with the server, rather than authenticating user on every request.
String userAuthenticatedSessionId = "asdasd-ad-saas-asdsda-d";

// Create the authentication header based on react id
final HeaderAuthenticateType authenticate = new HeaderAuthenticateType();

final ObjectFactory objectFactory = new ObjectFactory();
final JAXBElement<HeaderAuthenticateType> authToken = objectFactory.createHeaderAuthenticate(authenticate);

WSBindingProvider bp = (WSBindingProvider)webClientTestService;
List<Header> headers = new ArrayList<Header>();
headers.add(Headers.create(JAXBRIContext.newInstance(new Class[]{HeaderAuthenticateType.class}, null, null, null, false, null), authToken));

Maven dependency,


You can use soap header approach for different purposes, session authentication is one such example.


One Response to “Tips&Tricks: How to add soap header using JAX-WS RI”

  1. […] https://jaibeermalik.wordpress.com/2012/10/26/tipstricks-how-to-add-soap-header-using-jax-ws-ri/ […]

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: