DaveB
DaveB

Reputation: 3083

How to check JBoss deployers are working

I am trying to get resteasy working on JBoss AS6 Final (SEAM 2 app), but I cant seem the get the most basic example working, as I understand it, resteasy should be ready to go, I have tried the following example from here but the urls simply result in 404 errors with no response

package uk.co.rest.test;

import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.core.Application;

public class Library extends Application {

    @GET
    @Path("/books")
    public String getBooks() {
        System.out.println("Check");
        return "done";
    }

}

with the following added to my web.xml

<context-param>
    <param-name>resteasy.servlet.mapping.prefix</param-name>
    <param-value>/rest</param-value>
</context-param>

<servlet>
    <servlet-name>resteasy-servlet</servlet-name>
    <servlet-class>org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher</servlet-class>
    <init-param>
        <param-name>javax.ws.rs.Application</param-name>
        <param-value>uk.co.rest.test.Library</param-value>
    </init-param>
</servlet>

<servlet-mapping>
    <servlet-name>resteasy-servlet</servlet-name>
    <url-pattern>/rest/*</url-pattern>
</servlet-mapping>

I get the feeling that the resteasy.deployer that is bundled with JBoss is not doing its job, but im not sure how to go about debugging it

Any help would be great im pulling my hair out over this one!!

Upvotes: 0

Views: 1155

Answers (2)

MikkolidisMedius
MikkolidisMedius

Reputation: 4844

RESTEasy must be configured in order to be exposed as a service. You can do it either directly or via Seam's resource servlet.

To use RESTEasy directly, I find the easiest way is configuring it as a Servlet filter. There's little to do other than adding the filter to your web.xml as documented in http://docs.jboss.org/resteasy/docs/2.3.0.GA/userguide/html/Installation_Configuration.html#filter.

When using Seam this is however unnecessary, as Seam is capable of deploying RESTEasy services via its resource servlet quite simply (documented in http://docs.jboss.org/seam/2.2.0.GA/reference/en-US/html/webservices.html#d0e22093). You first declare RESTEasy's application component like this:

<resteasy:application resource-path-prefix="/rest" />

And create your providers that will be automatically deployed into the configured path, for example:

@Name("libraryService")
@Path("/library")
public class Library implements Serializable {

    @In(create=true) private transient BookHome bookHome;

    @GET @Path("/{book}")
    @Produces("text/plain")
    public String getBooks(@PathParam("book") String id) {
        bookHome.setId(id);
        return bookHome.getInstance().getTitle();
    }
}

You can then access the RESTEasy service via:

http://localhost:8080/yourapp/seam/resource/rest/library/1

The advantage of going the Seam way is mostly ease of use. You do need to include an extra jar: jboss-seam-resteasy.jar.

Upvotes: 1

eiden
eiden

Reputation: 2349

You seem to have misunderstood the role of javax.ws.rs.Application. Your Library class does not have to extend javax.ws.rs.Application in order to expose the getBooks()-method.

Create a class that extends javax.ws.rs.Application. Override the getSingletons()-methods and return a set of instances that has methods you wish to expose:

public class MyApplication extends javax.ws.rs.Application {
    @Override public Set<Object> getSingletons(){
        return Collections.<Object>singleton(new Library());
    }
}

In your web.xml, change the javax.ws.rs.Application init-param, so that it points to the MyApplication class.

Upvotes: 0

Related Questions