Chapter 7. REST Service Operations

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

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

Illustration 23. REST Service operations

All REST Service commands are placed at the right part of the toolbar and in the Run on the top menu.

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

You can verify the content of REST Service by using the special validation service before saving. To do that, simply click the Validate REST Service button, or go to Run > Validate on the top menu. In case of no errors in the service, there will be a message 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 Services, do as follows:

or Go to Run > Deploy. The deploy request will be sent to the server. In case of no errors, one message will be displayed in the Output tab as below:

[INFO]rennes.groovy deployed successfully

Otherwise, one error message will be shown. For example,

[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

To do the Undeploy operation, do as follows:

In case of no error, you will receive a message as below:

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

You can deploy multiple REST Services, and double-deploy the services. But, you cannot undeploy services which were not previously deployed. In this case, you will receive an error message from the server as below:

The REST Service will be deployed automatically on the server after being saved, if the Autoload service property is set as true. You can view this property in the Property Tab which is shown by clicking the Show Properties button. To set or unset the "Autoload" property, use Set REST Service autoload or Unset REST Service autoload commands respectively. These commands are displayed to the current status of Autoload property, so you can invert this property. The default value of autoload property is set as false. For more details, see the illustration below:

Illustration 24. Change Autoload service property

With the eXo IDE, you can not only write and deploy the service, but also make requests 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 that, simply call the Launch REST Service... command by clicking the appropriate button, or select Run on the top menu as follows:

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

To learn about launching REST Service, see the REST Service operations illustration above.


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

From the send request window, you can also get the URL of REST Service as follows:

You can view headers, status code and status text in the Output Panel after sending your requests. The message will be the following:

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

The IDE will send OPTIONS-request and display the received response in the Output Tab. For example:

Then eXo IDE will create request and send it. The response will be added to 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