Home > Software engineering >  How to Configure Resteasy With A Standalone Jetty Server?
How to Configure Resteasy With A Standalone Jetty Server?

Time:10-22

I'm trying to deploy an application to a standalone Jetty 9.4 server. I'm using resteasy for my web services, but so far I'm struggling to find clear examples or tutorials that explain exactly how I need to configure everything to get this working. Every example I have found so far either seems to be for a jboss server, a different rest framework (like Jersey), or for an embedded jetty server. I've tried to piece something together from the few bits I was able to dig up but had no success. When I try to make a GET request to my web services I just end up with a 404 error. Any help to get me pointed in the right direction would me greatly appreciated.

Here are some files to demonstrate my current configuration:

jetty-web.xml

<Configure id="eyerep-data" class="org.eclipse.jetty.webapp.WebAppContext">
    <Set name="contextPath">/eyerep-data</Set>
    <Set name="war"><SystemProperty name="jetty.monitorDir" default="./webapps" />/eyerep-data.war</Set>
</Configure>

web.xml

<web-app xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
  metadata-complete="false" version="3.0"
>
  <context-param>
    <param-name>appName</param-name>
    <param-value>eyerep</param-value>
  </context-param>
  <context-param>
        <param-name>resteasy.scan</param-name>
        <param-value>true</param-value>
  </context-param>
  <context-param>
        <param-name>resteasy.servlet.mapping.prefix</param-name>
        <param-value>/api</param-value>
  </context-param>     
  <context-param>
    <param-name>resteasy.guice.modules</param-name>
    <param-value>com.google.inject.servlet.ServletModule,com.tura.eyerep.guice.EyerepGuiceModule</param-value>
  </context-param>
  <context-param>
    <param-name>resteasy.guice.holder</param-name>
    <param-value>com.tura.eyerep.guice.Guice</param-value>
  </context-param>
 
  <listener>
    <listener-class>com.tura.eyerep.guice.resteasy.MyGuiceResteasyBootstrapServletContextListener
    </listener-class>
  </listener>
  <listener>
    <listener-class>com.tura.eyerep.servlet.StartupShutdownListener</listener-class>
  </listener>
 
  <filter>
    <filter-name>GuiceFilter</filter-name>
    <filter-class>com.google.inject.servlet.GuiceFilter</filter-class>
  </filter>
  <servlet>
    <servlet-name>Resteasy</servlet-name>
    <servlet-class>org.jboss.resteasy.plugins.server.servlet.HttpServlet30Dispatcher</servlet-class>
    <async-supported>true</async-supported>
  </servlet>
 
  <filter-mapping>
    <filter-name>GuiceFilter</filter-name>
    <servlet-name>Resteasy</servlet-name>
  </filter-mapping>
  <servlet-mapping>
    <servlet-name>Resteasy</servlet-name>
    <url-pattern>/api/*</url-pattern>
    <url-pattern>/auth/*</url-pattern>
  </servlet-mapping>
  <session-config>
    <session-timeout>10</session-timeout>
  </session-config>     
</web-app>

My Service Class:

@Path("/api")
public class ExportDataApi {
     @GET
     @Path("/data/export/repName/{repId}")
     public Response getRepName(@PathParam("repId") String repId)
     {
       ...
     }
}

CodePudding user response:

I think I finally found the answer. I based this project on an application using an older version of jetty 9. From what I can tell, at some point jetty.monitorDir was removed from the command line options for jetty. Since that option was invalid, it was falling back to the default, which is why my app worked when I put the war directly under webapps/ .

To get it working, I need to make two changes. In jetty-web.xml I needed to change the war config to:

<Set name="war"><SystemProperty name="jetty.base" default="./webapps" />/eyerep-data/eyerep-data.war</Set>

Then in the start.ini I had to locate the section for the 'deploy' module, uncomment the setting for jetty.deploy.monitoredDir, and change it to

jetty.deploy.monitoredDir=webapps/eyerep-data
  • Related