com.noelios.restlet.ext.xdb
Class XdbServletConverter

java.lang.Object
  extended by com.noelios.restlet.http.HttpConverter
      extended by com.noelios.restlet.http.HttpServerConverter
          extended by com.noelios.restlet.ext.xdb.XdbServletConverter

public class XdbServletConverter
extends HttpServerConverter

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 XDBServletConverter(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:
Marcelo F. Ochoa (mochoa@ieee.org)

Constructor Summary
XdbServletConverter(ServletContext context)
          Constructor.
XdbServletConverter(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(XdbServletCall 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

XdbServletConverter

public XdbServletConverter(ServletContext context)
Constructor. Remembers to manually set the "target" property before invoking the service() method.

Parameters:
context - The Servlet context.

XdbServletConverter

public XdbServletConverter(ServletContext context,
                           Restlet target)
Constructor. Remembers to manually set the "target" property before invoking the service() method.

Parameters:
context - The Servlet context.
target - The Restlet target.
Method Detail

getBaseRef

public Reference getBaseRef(HttpServletRequest request)
Returns the base reference of new Restlet requests.

Parameters:
request - The Servlet request.
Returns:
The base reference of new Restlet requests.

getRootRef

public Reference getRootRef(HttpServletRequest request)
Returns the root reference of new Restlet requests. By default it returns the result of getBaseRef().

Parameters:
request - The Servlet request.
Returns:
The root reference of new Restlet requests.

getTarget

public Restlet getTarget()
Returns the target Restlet.

Returns:
The target Restlet.

service

public void service(HttpServletRequest request,
                    HttpServletResponse response)
             throws ServletException,
                    java.io.IOException
Services a HTTP Servlet request as a Restlet request handled by the "target" Restlet.

Parameters:
request - The HTTP Servlet request.
response - The HTTP Servlet response.
Throws:
ServletException
java.io.IOException

setTarget

public void setTarget(Restlet target)
Sets the target Restlet.

Parameters:
target - The target Restlet.

toRequest

public HttpRequest toRequest(XdbServletCall servletCall)
Converts a low-level Servlet call into a high-level Restlet request. In addition to the parent HttpServerConverter class, it also copies the Servlet's request attributes into the Restlet's request attributes map.

Parameters:
servletCall - The low-level Servlet call.
Returns:
A new high-level uniform request.


Copyright © 2005-2008 Noelios Technologies.