Adding custom HTTP headers via Axis2 Client

This post explains how to add custom HTTP headers to a web service request initiated from an Axis2 client.

You may also have a look at this blog post by Keith, which explains how to add custom HTTP header to a response message from Axis2 service end.
// Create an instance of org.apache.axis2.client.ServiceClient
ServiceClient client = ...

// Create an instance of org.apache.axis2.client.Options
Options options = new Options();

List list = new ArrayList();

// Create an instance of org.apache.commons.httpclient.Header
Header header = new Header();

// Http header. Name : user, Value : admin
header.setName("user");
header.setValue("admin");
  
list.add(header);
options.setProperty(org.apache.axis2.transport.http.HTTPConstants.HTTP_HEADERS, list);

client.setOptions(options);