I discovered a new feature in java restful when using EJB 3.1 while reading an article at Adam Bien's blog.
The thing is that Stateless and Singleton beans can be exposed as root resources. But how? I tried to do it this way:
@Stateless
@LocalBean
@Path("Hybrid")
public class RESTEJBSample {
@GET
@Path("/demo")
@Produces(MediaType.TEXT_PLAIN)
public String something() {
return "I am a Hybrid!!!";
}
}
When i call the URL http://localhost:8080/HybridSample/resources/Hybrid/demo i get a 404 error.
Appart of this and just to make sure that JAXRS is is working in my project, i created a simple pojo resource just to test if it works fine.
@Path("/genericresource")
public class GenericResource {
@GET
@Path("/samplemethod")
@Produces(MediaType.TEXT_PLAIN)
public String saySomething() {
return "Something!";
}
}
Here when i call the URL http://localhost:8080/HybridSample/resources/genericresource/samplemethod It works fine!
So my questions are:
what is missing in my EJB so it can work as a web service resource such as the class GenericResource is doing?
Is there some extra configuration needed?
What are the limitations when using EJB as a web service?