Search code examples
javarestletrestlet-2.0

Restlet RIAP protocol deployed in Java App server


I have deployed our Restlet services to a Jetty Java Application server using the ServerServlet mechanism. Some of the services are called from the GWT front-end, but I would also need to call them directly from our server logic.

The Restlet RIAP system seems perfect for this, but I'm not sure how to use this here. It seems I would need to get a hold off the Context of the Restlet component somehow.

I found one post which indicated that the RiapServerHelper would be useful for this. But I found no documentation on how to use this. Any examples would be helpful.


Solution

  • The RiapServerHelper class is the implementation of the server connector. You do not have to use it explicitly.

    To use RIAP, you need to implement all entities of your application as usual (server resource, application...). The difference comes when attaching applications to the component virtual hosts. Resources that need to be accessed through RIAP also have to attach to the internal router, as follows:

    Component component = new Component();
    component.getServers().add(Protocol.HTTP, 8182);
    
    MyApplication app = new MyApplication();
    component.getDefaultHost().attachDefault(app);
    component.getInternalRouter().attachDefault(app);
    

    Note that you do not have to specify RIAP protocol to the component. It's supported by default.

    Accessing resources of the application through RIAP is then simple since you can use the Restlet client support as with other protocols:

    Request request = new Request(Method.GET, "riap://component/ping");
    Response response = getContext().getClientDispatcher().handle(request);
    Representation repr = response.getEntity();
    

    or

    ClientResource cr = new ClientResource("riap://component/ping");
    Representation repr = cr.get();
    

    For more details, you can have a look at the page http://wiki.restlet.org/docs_1.1/13-restlet/27-restlet/48-restlet/86-restlet/45-restlet.html.

    Hope that answers your question. Thierry