Wednesday, October 8, 2008

Axis2 - Setting the HTTP Method when sending request

Apache Axis2 supports sending (and receiving) requests over GET, POST, PUT and DELETE. This can be done by setting the "Constants.Configuration.HTTP_METHOD" property on the options object. If the HTTP Method is not set explicitly then it defaults to POST.

Most often that not when changing the HTTP Method you may want to change the serialization format as well. This can be done by setting the "Constants.Configuration.MESSAGE_TYPE" property on the options object (You can change the Serialization format even without changing the HTTP Method. For e.g Send a POX message via POST).

The following code Snippet shows how to send a message as "application/x-www-form-urlencoded" over GET.

options.setProperty(Constants.Configuration.HTTP_METHOD,HTTPConstants.HTTP_METHOD_GET);
options.setProperty(Constants.Configuration.MESSAGE_TYPE,HTTPConstants.MEDIA_TYPE_X_WWW_FORM);

2 comments:

Windu Purnomo said...

Hello, good morning...

I create a simple service in Axis2. The service is return Hello + variable input by client.
I test this service in browser, it is running well, The problem is, I can't assign value to parameter input.
The URL like this: http://localhost:8080/axis2/services/HelloWorld/sayHello?name="windu"

I hope, I get output like this:
‹ns:sayHelloResponse›
‹return›Hello windu‹/return›
‹/ns:sayHelloResponse›


but the reality, output like this:
&lsaquons;:sayHelloResponse›
‹return›Hello null‹/return›
‹/ns:sayHelloResponse›

whats wrong in my code? is there relation with HTTP method?

Ravi Prakash Reddy said...

Hi Keith,

In case of async requests (service1 calls service2 asynchronously), when I access HttpServletRequest at service2 , I get getMethod() as null. What you said is by default the method will be set to "POST". Then why in this case method is returned as null?

Ravi