Chapter 7. REST Service Operations

Validate REST Service
Deploy/Undeploy REST Service
Using Autoload Property
Launch REST Service with set parameters and Preview Server Console Messages in Output Tab
Get REST Service URL
Review of the response headers from REST Service
Examples of using the REST Service
Example1: REST service with complex media types output preview

eXo IDE gadget provides original approach to operate with REST Service - ability to validate, deploy/undeploy and launch this applications, which are compatible with JSR-311 specification without restarting portal, or installing additional programs. Due to this application you can validate REST Service before saving, deploying, launching or undeploying service. Feedback from server is displayed in the Output Tab:

Picture 23. REST Service operations

All REST Service commands are placed at the right part of the Toolbar and in the special top menu item "Run".

To clear Output Panel use special button at the right top corner of Output Tab.

You can verify the content of REST Service content by using special validation service before saving. Just click on "Validate REST Service" button or select "Run->Validate" from top menu. If there are no errors in service, then the alike message will be shown in the Output Tab:

[INFO]rennes.groovy validated successfully".

Otherwise, there will be a error message displayed in the Output Tab:

[ERROR] rennes.groovyvalidation failed. Error (400: Bad Request)
Unexpected error. Error occurs when parse stream, compiler error:
startup failed, rennes.groovy: 4: unable to resolve class javax.ws.rs.Path1
@ line 4, column 1.rennes.groovy: 8: unable to resolve class Path , unable to find class for annotation
@ line 8, column 1.rennes.groovy: 11: unable to resolve class Path , unable to find class for annotation
@ line 11, column 3.
3 errors

To deploy some REST Service, please:

After that the deploy request will be sent to the server, and if there are no errors - the message like following:

[INFO]rennes.groovy deployed successfully

will be displayed in the Output Tab. Otherwise, error message will be shown, e.g.:

[ERROR] rennes.groovy deploy failed. Error (400: Bad Request)
Unexpected error. Error occurs when parse stream, compiler error:
startup failed, rennes.groovy: 4: unable to resolve class javax.ws.rs.Path1
@ line 4, column 1.rennes.groovy: 8: unable to resolve class Path , unable to
find class for annotation
@ line 8, column 1.rennes.groovy: 11: unable to resolve class Path , unable to
find class for annotation
@ line 11, column 3.
3 errors

Calling the "Undeploy" operation is similar to the "Deploy" you should:

If everything is fine, then you will get message like that:

[INFO] /repository/collaboration/rennes.groovy undeployed successfully.

You can deploy as many REST Services as you want, and double deploying is also possible. But you can't undeploy earlier non-deployed service - in this case you will get the error feedback from the server like this:

REST Service will be deployed automaticaly on the server just after saving, if the "Autoload" service property is set (has value true). You can view this property in the Property Tab which is shown by clicking "Show Properties" button. To set/unset "Autoload" property, please, use "Set REST Service autoload" or "Unset REST Service autoload" commands respectively. This commands are displayed according to the current state of autoload property so that you will be able to invert this property. Default value autoload property = false. See the picture below for details:

Picture 24. Change Autoload service property

You can not only write and deploy service With eXo IDE, but make request to them with your own header, query and path parameters and body content using one of supported methods, view WADL-description of method, launch those services methods and view service response in the Output Tab. To do these just call "Launch REST Service..." command by clicking on appropriate button or select "Run" menu item:

After this gadget verify whether path is correct and send formed request to the service or display error message, Response Service will be displayed in the Output Tab.

See example of launching in the illustration "REST Service operations" above.


Table2. Reproducing service annotations in the "Launch REST Service" dialog

From the send request window you can also get REST Service URL by clicking on "Get URL" button:

It is possible to view headers, status code and status text in the Output Panel after sending request. The message will be like this:

[OUTPUT] - -Status - - - - - - - -
200 OK
- -Headers- - - - - - - -
Content-Type : */*
Transfer-Encoding : chunked
Server : Jetty(6.1.x)
- -Text - - - - - - - - -
Hello steve

Then eXo IDE will create request to the service and send it. Response will be added into the Output Tab:

[OUTPUT] - -Status - - - - - - - -
200 OK
- -Headers- - - - - - - -
Server : Apache-Coyote/1.1
Content-Type : text/html
Transfer-Encoding : chunked
Date : Mon, 05 Jul 2010 09:06:55 GMT
- -Text - - - - - - - - -
PathParam 1:value1; Test Query Parameter 1: value2; Test-Header1: value3; Body: example