How to do REST invocation with Axis2/Java ServiceClient?
By Eran Chinthaka
- 17 Jun, 2006
The difference between doing a SOAP invocation and a REST invocation depends on just one line (with default configuration). Just insert the following line of code:
Let's see the complete code snippet.
Options options = new Options();
ServiceClient sender = new ServiceClient();
OMElement result = sender.sendReceive(getPayload());
If you are invoking a Web service in RESTful manner, make sure the toEpr you give has all the information required to identify the operation and the service that you are invoking. The above code will invoke a resource using HTTP PUT method. To change it to use GET method simply set another option as shown below.
Can I change the content type of the request? Yes, you can.
The content type should be one of the following:
- MEDIA_TYPE_X_WWW_FORM - application/x-www-form-urlencoded
- MEDIA_TYPE_TEXT_XML - text/xml
- MEDIA_TYPE_MULTIPART_RELATED - multipart/related
- MEDIA_TYPE_APPLICATION_XML - application/xml