Showing posts with label HTTP. Show all posts
Showing posts with label HTTP. Show all posts

Monday, July 14, 2008

How to access HTTP headers from an Axis2 service implementation class

I have seen some users in axis user mailing list ask the question on how to access HTTP headers of the request SOAP message using the service implementation class.
It's easy and straightforward with messageContext class.
Lets see with an example.

1. Create a service implementation class as follows

import javax.servlet.http.HttpServletRequest;

import org.apache.axis2.context.MessageContext;

public class TestService {

public String MyOperation(String s){

MessageContext msgCtx = MessageContext.getCurrentMessageContext();
HttpServletRequest obj =(HttpServletRequest)msgCtx.getProperty("transport.http.servletRequest");
System.out.println("Acceptable Encoding type: "+obj.getHeader("Accept-Encoding"));
System.out.println("Acceptable character set: " +obj.getHeader("Accept-Charset"));
System.out.println("Acceptable Media Type: "+obj.getHeader("Accept"));
return s;

}
}

As you can see in the highlighted statements, first we need to get the current messageContext. Then from the messageContext, we can get the HTTPServletRequest object from which we can get whatever HTTP headers we want.

2. Write service descriptor(services.xml) for the above service class and deploy the service in Axis2 (If you are not familiar with Axis2 deployment, please read Axis2 user's guide )

3. Invoke the service in RESTful manner
http://:/services/TestService/MyOperation?s=hi

You will see the following in Axis2 run time console.

Acceptable Encoding type: gzip,deflate
Acceptable character set: ISO-8859-1,utf-8;q=0.7,*;q=0.7
Acceptable Media Type: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8

Sunday, May 25, 2008

HTTP Compression

I wasn't much aware of HTTP compression though I heard the term often. Thanks to a nice article written by Martin Brown, I was able to get a basic understanding as well as how to get Apache and IIS servers configured to use HTTP compression.
HTTP compression is an mechanism to utilize the available bandwidth effectively. HTTP protocol data is compressed before it is sent from the server. No specific configuration is required at the client side and server configuration is also relatively simple.
If you are involved in web performance testing, It would be worthwhile to get some knowledge on HTTP compression.