Monday, June 06, 2011

Seemingly common RESTEasy error and a solution

So I was playing with RESTeasy a bit and using the standalone servlet method of exposing REST services was very easy and straightforward.

And then I thought, ok, let me now do the EJB integration on a JBoss AS 4.2.3 - and ran into the following error:

java.lang.RuntimeException: Class is not a root resource.  It, or one of its interfaces must be annotated with @Path: $Proxy862 implements: org.jboss.ejb3.JBossProxy

Which was strange as I did have the @Path annotation present:

public interface ResourceHandlerLocal {

Googling around showed, others have/had the same issue; but as so often, no solution was given. After some digging around I found the issue: the error message is a bit misleading, and I was actually missing a @ApplicationPath("/rest") annotation, which defines the "root context" and which is not needed in the simple standalone war case.

So I implemented a subclass of which is marked with this ApplicationPath annotation and registered it in web.xml:

"-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
"" >

<display-name>RHQ Rest interface</display-name>

<description>List of jndi names of EJBs local interfaces that define REST stuff</description>


</init-param> <init-param>



And now the REST provider is starting nicely :)

Of course, if you are using JBoss AS 6 or the upcoming AS7, you do not need to go through all this, as they have RESTeasy already integrated and ready to go.

1 comment:

Gimby said...

Nice post; misleading error messages are only too common in the Java world unfortunately :/ Decent error reporting should be even more important than proper API design IMO. Design flaws you can work around; getting wrong information is just too costly!

But Servlet spec 2.3? You take backwards compatibility seriously!