com.noelios.restlet.ext.servlet
Class ServerServlet

java.lang.Object
  extended by javax.servlet.GenericServlet
      extended by javax.servlet.http.HttpServlet
          extended by com.noelios.restlet.ext.servlet.ServerServlet
All Implemented Interfaces:
Serializable, Servlet, ServletConfig

public class ServerServlet
extends HttpServlet

Servlet acting like an HTTP server connector. See Developper FAQ #2 for details on how to integrate a Restlet application into a servlet container.
Here is a sample configuration for your Restlet webapp:

 <?xml version="1.0" encoding="ISO-8859-1"?>
 <!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN" "http://java.sun.com/dtd/web-app_2_3.dtd">
 <web-app>
         <display-name>Restlet adapter</display-name>
                                                         
         <!-- Your application class name -->
         <context-param>
                 <param-name>org.restlet.application</param-name>
                 <param-value>com.noelios.restlet.test.TraceApplication</param-value>
         </context-param>
                                                         
         <!-- Restlet adapter -->
         <servlet>
                 <servlet-name>ServerServlet</servlet-name>
                 <servlet-class>com.noelios.restlet.ext.servlet.ServerServlet</servlet-class>
         </servlet>
                                                         
         <!-- Catch all requests -->
         <servlet-mapping>
                 <servlet-name>ServerServlet</servlet-name>
                 <url-pattern>/*</url-pattern>
         </servlet-mapping>
 </web-app>
 
The enumeration of initParameters of your Servlet will be copied to the "context.parameters" property of your application. This way, you can pass additional initialization parameters to your Restlet application, and share them with existing Servlets.

Author:
Jerome Louvel (contact@noelios.com)
See Also:
J2EE home page, Serialized Form

Constructor Summary
ServerServlet()
          Constructor.
 
Method Summary
 Application createApplication(Context context)
          Creates the single Application used by this Servlet.
 HttpServerHelper createServer(HttpServletRequest request)
          Creates the associated HTTP server handling calls.
 void destroy()
           
 Application getApplication()
          Returns the application.
 Component getComponent()
          Returns the component.
 String getInitParameter(String name, String defaultValue)
          Returns the value of a given initialization parameter, first from the Servlet configuration, then from the Web Application context.
 HttpServerHelper getServer(HttpServletRequest request)
          Returns the associated HTTP server handling calls.
 void init()
           
 void service(HttpServletRequest request, HttpServletResponse response)
          Services a HTTP Servlet request as an uniform call.
 
Methods inherited from class javax.servlet.http.HttpServlet
doDelete, doGet, doHead, doOptions, doPost, doPut, doTrace, getLastModified, service
 
Methods inherited from class javax.servlet.GenericServlet
getInitParameter, getInitParameterNames, getServletConfig, getServletContext, getServletInfo, getServletName, init, log, log
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ServerServlet

public ServerServlet()
Constructor.

Method Detail

createApplication

public Application createApplication(Context context)
Creates the single Application used by this Servlet.

Parameters:
context - The Context for the Application
Returns:
The newly created Application or null if unable to create

createServer

public HttpServerHelper createServer(HttpServletRequest request)
Creates the associated HTTP server handling calls.

Parameters:
request - The HTTP Servlet request.
Returns:
The new HTTP server handling calls.

destroy

public void destroy()
Specified by:
destroy in interface Servlet
Overrides:
destroy in class GenericServlet

getApplication

public Application getApplication()
Returns the application. It creates a new one if none exists.

Returns:
The application.

getComponent

public Component getComponent()
Returns the component. It creates a new one if none exists.

Returns:
The component.

getInitParameter

public String getInitParameter(String name,
                               String defaultValue)
Returns the value of a given initialization parameter, first from the Servlet configuration, then from the Web Application context.

Parameters:
name - The parameter name.
defaultValue - The default to use in case the parameter is not found.
Returns:
The value of the parameter or null.

getServer

public HttpServerHelper getServer(HttpServletRequest request)
Returns the associated HTTP server handling calls. It creates a new one if none exists.

Parameters:
request - The HTTP Servlet request.
Returns:
The HTTP server handling calls.

init

public void init()
          throws ServletException
Overrides:
init in class GenericServlet
Throws:
ServletException

service

public void service(HttpServletRequest request,
                    HttpServletResponse response)
             throws ServletException,
                    IOException
Services a HTTP Servlet request as an uniform call.

Overrides:
service in class HttpServlet
Parameters:
request - The HTTP Servlet request.
response - The HTTP Servlet response.
Throws:
ServletException
IOException


Copyright © 2005-2007 Noelios Technologies.