Using Restlet REST with Codenvy

Create a temporary workspace with a Restlet project using a Codenvy Factory:

Restlet is a lightweight, comprehensive, open source REST framework for the Java platform. Restlet is suitable for both server and client Web applications. It supports major Internet transport, data format, and service description standards like HTTP and HTTPS,SMTP, XML, JSON, Atom, and WADL.

Create a Project

Login to your codenvy workspace and create a New WAR Project say “restlet”. Project file structure is shown below:

GetImage (16)

Add Dependencies

Specify the below dependencies in pom.xml which are prerequisites. Make sure these jars are included under Maven Dependencies.

GetImage (17)

Pom.xml :

<name>Public online Restlet repository</name>

Create HelloWorldResource Class :

In this example, GET request is accepted/allowed.
We declare a Resource which has only one representation.
Code Logic :

package com.codenvy;
import org.restlet.resource.Get;
import org.restlet.resource.ServerResource;

public class HelloWorldResource extends ServerResource {

public String greet() {
return "Hello World!";

Create HelloWorldApplication class

Here we create a root Restlet that will receive all incoming calls. Declare a router Restlet that routes each call to a new instance of HelloWorldResource. Also we define only one route (/hello). We state this class in web.xml as Application Class Name under param-name [ org.restlet.application ].

package com.codenvy;

import org.restlet.Application;
import org.restlet.Restlet;
import org.restlet.routing.Router;

public class HelloWorldApplication extends Application {

public synchronized Restlet createInboundRoot() {
Router router = new Router(getContext());
router.attach("/hello", HelloWorldResource.class);
return router;

Create web.xml:

<display-name>Restlet Tutorial</display-name>
<!-- Application class name -->
<!-- Restlet adapter -->
<!-- Catch all requests -->

Upon successful building the application and navigating to url “projectURL/hello”, it displays.

GetImage (18)