Reputation: 935
I am trying to put together a very simple "hello world" service with Tomcat and RESTeasy. But when I try to test it, all I get are 404 responses from Tomcat. Here are the steps I followed, hopefully someone can point out where I went wrong:
Created a new Dynamic Web Project in Eclipse. The Target Runtime is set for Apache Tomcat 7.0, Dynamic web module version 3.0.
Copied all of the jar files from resteasy-jaxrs-2.3.1.GA-all.zip into WEB-INF\lib
Added one class:
package com.eshayne.resteasy;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
@Path("/sampleservice")
public class SampleService {
@GET
@Path("/hello")
@Produces(MediaType.TEXT_HTML)
public String hello()
{
return "hello world";
}
}
web.xml
to: <?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" version="3.0" metadata-complete="true">
<display-name>resteasy</display-name>
<listener>
<listener-class>org.jboss.resteasy.plugins.server.servlet.ResteasyBootstrap</listener-class>
</listener>
<servlet>
<servlet-name>Resteasy</servlet-name>
<servlet-class>org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>Resteasy</servlet-name>
<url-pattern>/restful-services/*</url-pattern>
</servlet-mapping>
<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>/restful-services</param-value>
</context-param>
</web-app>
Added the new project to Tomcat and restarted Tomcat (within Eclipse)
Opened a web browser and requested /resteasy/restful-services/sampleservice/hello
This returns a 404 response from Tomcat with the description:
The requested resource (/resteasy/restful-services/sampleservice/hello) is not available.
What am I missing?
Upvotes: 2
Views: 6906
Reputation: 12988
A quote from RESTEasy tutorial: The URL to access a resource consists of
<web context>/<class level @Path>/<Method level @Path>
For example, if you deploy demo.war
, it looks like this:
http://localhost:8080/demo/sampleservice/hello
And there must be a servlet-mapping
in web.xml
, for example:
<servlet-mapping>
<servlet-name>Resteasy</servlet-name>
<url-pattern>/sampleservice/*</url-pattern>
</servlet-mapping>
Upvotes: 1
Reputation: 935
It turns out that the URL for a given resource is not in fact <display-name>/<servlet-mapping>/<class Path>/<method Path>
. It is actually <project-name>/<servlet-mapping>/<class Path>/<method Path>
.
Upvotes: 1
Reputation: 2439
Have you tried visiting variations on the URL - e.g. /restful-services/sampleservice/hello
Upvotes: 1