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.



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:
‹return›Hello windu‹/return›

but the reality, output like this:
‹return›Hello null‹/return›

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?