| HTTP converter from Servlet calls to Restlet calls. This class can be used in
any Servlet, just create a new instance and override the service() method in
your Servlet to delegate all those calls to this class's service() method.
Remember to set the target Restlet, for example using a Restlet Router
instance. You can get the Restlet context directly on instances of this
class, it will be based on the parent Servlet's context for logging purpose.
This class is especially useful when directly integrating Restlets with
Spring managed Web applications. Here is a simple usage example:
public class TestServlet extends HttpServlet {
private ServletConverter converter;
public void init() throws ServletException {
super.init();
this.converter = new ServletConverter(getServletContext());
Restlet trace = new Restlet(this.converter.getContext()) {
public void handle(Request req, Response res) {
getLogger().info("Hello World");
res.setEntity("Hello World!", MediaType.TEXT_PLAIN);
}
};
this.converter.setTarget(trace);
}
protected void service(HttpServletRequest req, HttpServletResponse res)
throws ServletException, IOException {
this.converter.service(req, res);
}
}
author: Jerome Louvel (contact@noelios.com) |