At first in my web server I only had one REST servlet. Something like:
@Path("/")
public class Controller {
@GET
@Produces({ MediaType.TEXT_HTML })
public Response get(@Context UriInfo info) throws Exception {
...
}
@GET
@Path("resource1")
@Produces({ MediaType.TEXT_HTML })
public Response resource1() throws Exception {
...
}
...
}
And the web.xml:
<servlet>
<servlet-name>rest</servlet-name>
<servlet-class>com.sun.jersey.spi.container.servlet.ServletContainer</servlet-class>
<init-param>
<param-name>com.sun.jersey.config.property.packages</param-name>
<param-value>xpto.mypack1;xpto.mypack2</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>rest</servlet-name>
<url-pattern>/*</url-pattern>
</servlet-mapping>
But then I wanted to add some static html to the server, so I updated the servlet mapping to /rest/*
and the @Path directive of Controller servlet class from "/" to "/rest". Everything works fine but the sub-resources or methods of controller with the @path directive that stopped working.. ie:
- / works fine since I have an index.html page at root
- /rest works fine, it invokes the get method of my servlet
- /rest/resource1 returns 404 http code...
Any help? I already tried a list of combinations of / after and before each @Path directive, with no success... Many thanks
One update:
I used the trace util and got the following results:
for /[app-name]/rest (it works):
- X-Jersey-Trace-002 accept right hand path java.util.regex.Matcher[pattern=/rest(/.*)? region=0,11 lastmatch=/rest]: "/rest" -> "/rest" : ""
- X-Jersey-Trace-003 accept resource: "rest" -> @Path("/rest") xpto.mypack.Controller
- X-Jersey-Trace-000 accept root resource classes: "/rest"
- X-Jersey-Trace-001 match path "/rest" -> "/application.wadl(/.)?", "/rest(/.)?"
for /[app-name]/rest/resource1 (it doesn't work):
- X-Jersey-Trace-002 matched exception mapper: com.sun.jersey.api.NotFoundException@4fd41dc3 -> xpto.myclass
- X-Jersey-Trace-003 mapped exception to response: com.sun.jersey.api.NotFoundException@4fd41dc3 -> 404 (Not Found) X-Jersey-Trace-000 accept root resource classes: "/resource1" X-Jersey-Trace-001 match path "/resource1" -> "/application.wadl(/.)?", "/rest(/.)?"
I hope it helps someone to help me..
("/resource1")- ant