Search code examples
eclipseresttomcatapache-axisrestlet

Use Eclipse to export a unique war holding RESTlet and Servlet working together for Tomcat


I'm still reading about REST solutions and decided to use RESTlet to implement WebServices, serving responses as JSON using Jackson.

Prior to that I used Axis2, but its performance scared me: a simple request was taking many hundred miliseconds to come back to client, and both client and server were on the same machine! (I will redo benchmarks, doing them better then before, now comparing direct call, Axis2 and RESTlet+Jackson.)

I know RESTlet can be used over many containers, and I found some tutorials to integrate Tomcat and RESTlet. But as I understood, it was meant to bind a RESTlet app directly into Tomcat.

My issue is that with Axis2 I'm able to have a unique eclipse project, where I develop servlets to handle browser requests and serve HTML pages, together with Axis2 WebService serving non-browser clients. This Eclipse project is exported as a unique war holding all my codes and all required jars, then I deploy it on Tomcat and from a unique server I can have it all working.

In example:

I wanna do same thing with RESTlet:

As you can see, the "magic" must be done by Eclipse on creating this war with proper web.xml configs. It works for Axis2 but I can't find out how to do it with RESTlet.

Another question. If I don't need Servlet and want only a RESTlet WebService, which container would be the most efficient for like a dozen clients doing concurrent hundreds of requests?


Solution

  • Can definitely done: I personally tend to use NetBeans/Maven so can provide only pointers to the final xml setup but...

    My web.xml contains:

    <servlet>
        <servlet-name>ServerServlet</servlet-name>
        <servlet-class>org.restlet.ext.servlet.ServerServlet</servlet-class>
        <init-param>
            <param-name>org.restlet.application</param-name>
            <param-value>my.Application</param-value>
        </init-param>
    </servlet>
    <servlet-mapping>
        <servlet-name>ServerServlet</servlet-name>
        <url-pattern>/*</url-pattern>
    </servlet-mapping>
    

    With for Tomcat the context.xml:

    <Context path="/rootPath"></Context>
    

    You can of course add datasources and parameters to these as required.

    My remaining routing is handled by Restlet itself set up in my.Application class by overriding createInboundRoute() from org.restlet.Application and by the Annotations on my mapped (routed) classes extending ServerResource.