Our application built using Seam and Rest Easy was running without any issues until we upgraded or Jboss
from
Jboss 4
to JbossAs-7
. As soon as we upgraded to JbossAs-7
our
REST API stopped working, with the error message on browser as
HTTP Status 404 - Could not find resource without giving any exception. With initial
investigation we went clue-less because Seam resource
servlet configures the rest easy internally.
Investigation
More investigation and debugging the seam
ResourceServlet
uncovered why is this happening.
Later, I found that ResourceServlet
tries to find the resource provider for the rest url and
throws HTTP-404 because there is no resource provider configured for the rest.
New modular approach
This issue appeared in JbossAs-7 because of new modular approach instead of regular application deployment. We need to register every library and the application as modules in JbossAs-7. Also JbossAs-7 comes with some pre-loaded modules like JPA, CDI, Rest easy etc. I went through the Rest easy documents and some of the forum-threads and came across a solution for this problem of not finding resource. I am hoping this may help others, hence writing this blog.Why ResourceServlet is not able to configure Rest easy
Its because JbossAs-7 is already having rest easy module registered. Hence,ResourceServlet
is
not able to register the module again, as a result it throws HTTP-404
.
Solution
There are a couple of solutions available for this problem, I will be listing them here.Web.xml
approach of registering the providers along with the
HttpServletDispatcher
HttpServletDispatcher Configuration
HttpServletDispatcher Mapping
Configuring providers using annotation
Context and Listener Configuration
Servlet Configuration and Mapping
@provider
annotation on the top of the
provider resource class, so that it can be registered as a resource provider in the ResteasyBootstrap.
4 Comments
Could you give us an example of how to use the @provider annotation?
ReplyDeleteJose you can use provider annotation something like this available at http://docs.oracle.com/javaee/6/tutorial/doc/gilik.html
Delete@Consumes("application/x-www-form-urlencoded")
@Provider
public class FormReader implements MessageBodyReader {
The following example shows how to use MessageBodyWriter with the @Produces and @Provider annotations:
@Produces("text/html")
@Provider
public class FormWriter implements
MessageBodyWriter> {..}
Hi,
ReplyDeleteI have class like below
@Name("menuHandler")
@Path("/menu")
public class MenuHandler implements Serializable
With above config it did not work
Seam 2.1.2, Wildfly 8
Hi,
ReplyDeleteI have migrate app from Jboss 4.3 to Wildfly 8.
Facing the same issue. Above solutions did not worked.
@Name("menuHandler")
@Path("/menu")
public class MenuHandler implements Serializable
Seam 2.1.2
Post a Comment