Reputation: 1038
I would like some clarification on how a restful service deployed on a servlet starts up. Currently I am using JBOSS AS7.1.1 which includes resteasy. Below my web.xml is like
<servlet>
<servlet-name>RESTEasy</servlet-name>
<servlet-class>org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>RESTEasy</servlet-name>
<url-pattern>/api/*</url-pattern>
</servlet-mapping>
It would be great to know the use of the above code when Jboss service start up.
Thanks, Ashley
Upvotes: 0
Views: 39
Reputation: 17435
Ultimately you don't even need web.xml anymore and you certainly don't need the above configuration. The only file needed to get JAX-RS going is something like:
RestApplication.java
import javax.ws.rs.ApplicationPath;
import javax.ws.rs.core.Application;
/**
* Used to bootstrap JAX-RS. Otherwise this class is
* not directly used.
*
*/
@ApplicationPath("/api")
public class RestApplicationConfig extends Application {
// intentionally empty
}
After that, you'll create your service:
HelloWorld.java
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
@Path("/hello")
public class HelloWorld {
@Produces({MediaType.TEXT_PLAIN})
@GET
public Response getHeartBeat() {
return Response.ok("Hi There").build();
}
}
This service would then be callable at something like http://localhost:8080/app-name/api/hello
where app-name
is the name of your web application (assuming it isn't deployed to /
).
Upvotes: 2