REST is providing access to the resources through the two methods GET and POST. The REST Web services are reduced subset of the usual Web Service stack, and the Axis2 REST implementation assumes following properties.
Axis2 can be configured as REST Container and can be used to send and receive restful web services requests and responses. The REST Web Services can be access in two ways, using HTTP GET and POST.
REST support can be enabled in the Server side by adding the following line to the axis2.xml file.
< parameter name="enableREST" locked="xsd:false" > true </parameter>But it acts both as a REST endpoint as well as a SOAP endpoint. When a Message is received if the content type is text/xml and if the SOAP Action Headers are missing, then the Message is treated as a RESTful Message. Else they are treated as usual SOAP Messages.
On sending a message out, the fact that the message is RESTful or not, can be decided from the client API or by deployment descriptor of the client.
call.setDoREST(true);
There's a userguide.clients.RESTClient.java which demonstrates the usage
of the above, using the
echooperation of the
userguide.example1.MyService
public class MyServiceClient { private static String toEpr = "http://localhost:8080/axis2/services/MyService/echo"; public static void main(String[] args) throws AxisFault { OMElement payload = ... Call call = new Call(); call.setTo(new EndpointReference(toEpr)); call.setTransportInfo(Constants.TRANSPORT_HTTP,Constants.TRANSPORT_HTTP,false); call.setDoREST(true); OMElement result = call.invokeBlocking("thiscanbeanything", payload); .... use the result call.close(); } }
Axis2 let the users access Web Service that has simple type parameters via the HTTP GET. For example following URL requests the version service Via HTTP GET. But the Web Services arrived via GET assumes REST . Other parameter are converted in to the XML and put them in to the SOAP Body.
http://127.0.0.1:8080/axis2/services/version/getVersion
Result can be shown in the browser as follows.
For an example request
http://127.0.0.1:8080/axis2/services/version/getVersionwill be converted to the following SOAP Message for processing by Axis2
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"> <soapenv:Body> <axis2:getVersion xmlns:axis2="http://ws.apache.org/goGetWithREST" /> </soapenv:Body> </soapenv:Envelope>