Wednesday, February 9, 2011

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);

4 comments:

Fella said...

Why do we need to add a a custom HTTP header???
What is it for?

Ram Sadasiv said...

It makes analyzing your apache logs much easier.

Jac said...

Hey man, thanks a bunch for this great post! Saved me a lot of time. Axis2 isn't exactly the most transparent SOAP framework.

Much appreciated!

chenmeinv0 said...

ugg boots sale
coach outlet store online
coach outlet store online clearances
cheap jordan retro
tommy hilfiger clothing
air max 1
louis vuitton handbags
air max uk
canada goose outlet
louis vuitton outlet stores
2016.12.27xukaimin