helen66
helen66

Reputation: 31

RESTful application without web.xml

I have created a sample project and used EJB 3.1 with a RESTful web service. In the sample I have a class which extends Application. I expect the class works like a servlet and dispatch requests to appropriate classes but it does not. When I use web.xml my sample project works fine. What is wrong with my sample project?

@ApplicationPath("/rest")
public class ApplicationServlet extends Application {

    @Override
    public Set<Class<?>> getClasses() {
        Set<Class<?>> classes = new HashSet<Class<?>>();
        classes.add(UserWS.class);
        return classes;
    }
}

I use UserWS as a EJB session bean which exposes web service:

@Stateless
@LocalBean
@Path("/user")
public class UserWS {

    private int count;

    public UserWS() {
        this.count=0;
    }

    @GET
    @Path("/name/{username}")
    public void getUserName(@PathParam("username") String username) {
        count++;
        System.out.println("count is:"+ count);
    }
}

Upvotes: 2

Views: 816

Answers (1)

cassiomolin
cassiomolin

Reputation: 131147

I'm afraid it won't be possible once JBoss 5.0 supports only Servlet 2.5. For more details, see here.

To avoid the web.xml deployment descriptor, you need a servlet container the supports at least Servlet 3.0.


So, what could you do to solve it?

These are the options that came up to my mind:

  1. You could try upgrading the JBoss Web (Tomcat fork used by JBoss AS) as described here, but try that at you own risk.

  2. Consider using a recent version of JBoss/WildFly.

Upvotes: 4

Related Questions