RESTEasy - @Path requiring a full path?
Solution: add the following in your web.xml
<context-param>
<param-name>resteasy.servlet.mapping.prefix</param-name>
<param-value>/rest</param-value>
</context-param>
Where /rest is the beginning of your <url-pattern>/rest/*</url-pattern>
(Source: http://docs.jboss.org/resteasy/docs/2.0.0.GA/userguide/html/Installation_Configuration.html#d0e72)
Related videos on Youtube
Bastien Jansen
Ceylon & Java developer; Occasional blogger at https://bjansen.github.io
Updated on July 09, 2022Comments
-
Bastien Jansen almost 2 years
I was messing around with JAX-RS and made an application which calls REST services which produce JSON. I tried Jersey and everything went fine, but I had to switch to RESTEasy as my application needs to be built with JDK5. I changed my web.xml to something like this:
<web-app> <context-param> <param-name>resteasy.scan</param-name> <param-value>true</param-value> </context-param> <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>/rest/*</url-pattern> </servlet-mapping> <!-- ... --> </web-app>
So I expect every URL starting with /rest to be handled by RESTEasy. My services are as follows:
@Path("/services") public class MyRESTServices { @GET @Path("service1") @Produces(MediaType.APPLICATION_JSON) public Object service1(Blah blah) { } }
This worked fine using Jersey, http://localhost/MyContext/rest/services/service1 was bound to my service1() method. When I change to RESTEasy, though, I had a 404:
HTTP Status 404 - Could not find resource for relative : /rest/services/service1 of full path: http://localhost/MyContext/rest/services/service1
Which means that RESTEasy handled the request but could not find any service bound to this URL.
On my class, changing
@Path("/services")
to@Path("/rest/services")
worked, though. Do you have any idea why I got this strange behaviour? All the tutorials/docs I read mentionned only relative paths, not including the /rest prefix...-
Donal Fellows over 13 yearsHow are you configuring RESTEasy internally? With CXF, I have to configure the removal of the
/rest
fragment in my Spring config file. -
Bastien Jansen over 13 yearsI don't configure anything else that what you can see in the web.xml (scan for annotations). I'll see if the removal can be configured.
-
Bastien Jansen over 13 yearsShame on me, it was right in front of me in the docs: "The resteasy.servlet.mapping.prefix <context param> variable must be set if your servlet-mapping for the Resteasy servlet has a url-pattern other than /*"
-
fmucar over 13 yearsI dont think it is strange. Your regular expression does not mention anything about /rest path so resteasy cant know about it if you dont add it to regular exp or web.xml as a prefix.
-
-
bmauter over 10 yearsThanks. Your "Where..." sentence is what straightened me out. I was using /rest/* in the param-value element.
-
09Q71AO534 over 9 years@Nebelmann I want to have my url
"http://localhost:8080/MyContent/rest/services/service1"
as"http://localhost:8080/MyContent/services/service1"
i dont want to have rest in my url pattern. Can you help me out how to define that