|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.restlet.engine.http.adapter.Adapter
org.restlet.engine.http.adapter.ServerAdapter
org.restlet.ext.servlet.ServletAdapter
public class ServletAdapter
HTTP adapter 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 next Restlet
, for example using a 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 ServletAdapter adapter; public void init() throws ServletException { super.init(); this.adapter = new ServletAdapter(getServletContext()); Restlet trace = new Restlet(this.adapter.getContext()) { public void handle(Request req, Response res) { getLogger().info("Hello World"); res.setEntity("Hello World!", MediaType.TEXT_PLAIN); } }; this.adapter.setNext(trace); } protected void service(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException { this.adapter.service(req, res); } }
Constructor Summary | |
---|---|
ServletAdapter(ServletContext context)
Constructor. |
|
ServletAdapter(ServletContext context,
Restlet next)
Constructor. |
Method Summary | |
---|---|
Reference |
getBaseRef(HttpServletRequest request)
Returns the base reference of new Restlet requests. |
Restlet |
getNext()
Returns the next Restlet. |
Reference |
getRootRef(HttpServletRequest request)
Returns the root reference of new Restlet requests. |
void |
service(HttpServletRequest request,
HttpServletResponse response)
Services a HTTP Servlet request as a Restlet request handled by the "target" Restlet. |
void |
setNext(Restlet next)
Sets the next Restlet. |
HttpRequest |
toRequest(org.restlet.ext.servlet.internal.ServletCall servletCall)
Converts a low-level Servlet call into a high-level Restlet request. |
Methods inherited from class org.restlet.engine.http.adapter.ServerAdapter |
---|
addEntityHeaders, addResponseHeaders, commit, toRequest |
Methods inherited from class org.restlet.engine.http.adapter.Adapter |
---|
getContext, getLogger |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public ServletAdapter(ServletContext context)
context
- The Servlet context.public ServletAdapter(ServletContext context, Restlet next)
context
- The Servlet context.next
- The next Restlet.Method Detail |
---|
public Reference getBaseRef(HttpServletRequest request)
request
- The Servlet request.
public Restlet getNext()
public Reference getRootRef(HttpServletRequest request)
request
- The Servlet request.
public void service(HttpServletRequest request, HttpServletResponse response)
request
- The HTTP Servlet request.response
- The HTTP Servlet response.public void setNext(Restlet next)
next
- The next Restlet.public HttpRequest toRequest(org.restlet.ext.servlet.internal.ServletCall servletCall)
ServerAdapter
, it also copies the
Servlet's request attributes into the Restlet's request attributes map.
servletCall
- The low-level Servlet call.
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |