6.2. Using Groovy REST service

Besides using Jax-RS, you can also develop a REST service as a Groovy script in your own extension that will be loaded at startup by the REST engine.

To do this, you first need to have your own extension project as described in Creating your extension project. The below process will instruct how to write a simple Groovy REST script in your own extension and make it work in eXo Platform.

  1. Create a Groovy script named custom-extension.war!/WEB-INF/groovy/demo/GroovyRest.groovy with the simple content:

    // simple groovy script
    import javax.ws.rs.Path
    import javax.ws.rs.GET
    import javax.ws.rs.PathParam

    public class GroovyRest {
      public String hello(@PathParam("name") String name) {
        return "Hello " + name
  2. Declare the Groovy file in the custom-extension.war!/WEB-INF/conf/configuration.xml file.

    <?xml version="1.0" encoding="ISO-8859-1"?>
                        <property name="autoload" value="true" />
                        <property name="path" value="war:/groovy/demo/GroovyRest.groovy" />

    The war custom-extension now looks like:

  3. Deploy your custom-extension into eXo Platform by putting custom-extension.war in the webapps folder and custom-extension-config.jar in the lib folder. See details about Registering your extension manually or Registering your extension with script for both Tomcat and JBoss.

  4. Start eXo Platform, then go to http://mycompany.com:8080/portal/rest/groovyrest/helloworld/eXo. The output (Hello eXo) will be shown.

Copyright ©. All rights reserved. eXo Platform SAS
blog comments powered byDisqus