|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.noelios.restlet.http.HttpConverter
com.noelios.restlet.http.HttpServerConverter
com.noelios.restlet.ext.servlet.ServletConverter
public class ServletConverter
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); } }
Constructor Summary | |
---|---|
ServletConverter(ServletContext context)
Constructor. |
|
ServletConverter(ServletContext context,
Restlet target)
Constructor. |
Method Summary | |
---|---|
Reference |
getBaseRef(HttpServletRequest request)
Returns the base reference of new Restlet requests. |
Reference |
getRootRef(HttpServletRequest request)
Returns the root reference of new Restlet requests. |
Restlet |
getTarget()
Returns the target Restlet. |
void |
service(HttpServletRequest request,
HttpServletResponse response)
Services a HTTP Servlet request as a Restlet request handled by the "target" Restlet. |
void |
setTarget(Restlet target)
Sets the target Restlet. |
HttpRequest |
toRequest(ServletCall servletCall)
Converts a low-level Servlet call into a high-level Restlet request. |
Methods inherited from class com.noelios.restlet.http.HttpServerConverter |
---|
addEntityHeaders, addEntityHeaders, addResponseHeaders, addResponseHeaders, commit, toRequest |
Methods inherited from class com.noelios.restlet.http.HttpConverter |
---|
addAdditionalHeaders, getContext, getLogger |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public ServletConverter(ServletContext context)
context
- The Servlet context.public ServletConverter(ServletContext context, Restlet target)
context
- The Servlet context.target
- The target Restlet.Method Detail |
---|
public Reference getBaseRef(HttpServletRequest request)
request
- The Servlet request.
public Reference getRootRef(HttpServletRequest request)
request
- The Servlet request.
public Restlet getTarget()
public void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, java.io.IOException
request
- The HTTP Servlet request.response
- The HTTP Servlet response.
ServletException
java.io.IOException
public void setTarget(Restlet target)
target
- The target Restlet.public HttpRequest toRequest(ServletCall servletCall)
servletCall
- The low-level Servlet call.
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |