public class ServerServlet
extends javax.servlet.http.HttpServlet
Mode | Description |
---|---|
1 | A "/WEB-INF/restlet.xml" file exists and contains a valid XML
configuration as described in the documentation of the Component
class. It is used to instantiate and attach the described component,
contained applications and connectors. Please note that you can combine the
usage of such configuration file and method 2. |
2 | The "/WEB-INF/web.xml" file contains a parameter named
"org.restlet.component". Its value must be the path of a class that inherits
from Component . It is used to instantiate and attach the described
component, contained applications and connectors. Please note that you can
combine the definition of your own custom Component subclass and method 1. |
3 | The "/WEB-INF/web.xml" file contains a parameter named
"org.restlet.application". Its value must be the path of a class that
inherits from Application . It is used to instantiate the application
and to attach it to an implicit Restlet Component. |
Component
instance.<?xml version="1.0" encoding="UTF-8"?> <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5"> <display-name>Restlet adapters</display-name> <servlet> <servlet-name>Restlet1</servlet-name> <servlet-class>org.restlet.ext.servlet.ServerServlet</servlet-class> <init-param> <param-name>org.restlet.application</param-name> <param-value>test.MyApplication1</param-value> </init-param> </servlet> <servlet-mapping> <servlet-name>Restlet1</servlet-name> <url-pattern>/1/*</url-pattern> </servlet-mapping> <servlet> <servlet-name>Restlet2</servlet-name> <servlet-class>org.restlet.ext.servlet.ServerServlet</servlet-class> <init-param> <param-name>org.restlet.application</param-name> <param-value>test.MyApplication2</param-value> </init-param> </servlet> <servlet-mapping> <servlet-name>Restlet2</servlet-name> <url-pattern>/2/*</url-pattern> </servlet-mapping> </web-app>Now, here is a more detailed template configuration showing you more configuration options:
<?xml version="1.0" encoding="UTF-8"?> <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5"> <display-name>Restlet adapters</display-name> <!-- Servlet to Restlet adapter declaration (Mandatory) --> <servlet> <servlet-name>RestletAdapter</servlet-name> <servlet-class>org.restlet.ext.servlet.ServerServlet</servlet-class> <!-- Your component class name (Optional - For mode 2) --> <init-param> <param-name>org.restlet.component</param-name> <param-value>test.MyComponent</param-value> </init-param> <!-- Your application class name (Optional - For mode 3) --> <init-param> <param-name>org.restlet.application</param-name> <param-value>test.MyApplication</param-value> </init-param> <!-- List of supported client protocols (Optional - Only in mode 3) --> <init-param> <param-name>org.restlet.clients</param-name> <param-value>HTTP HTTPS FILE</param-value> </init-param> <!-- Add the Servlet context path to routes (Optional) --> <init-param> <param-name>org.restlet.autoWire</param-name> <param-value>true</param-value> </init-param> </servlet> <!-- Mapping catching all requests on a given path (Mandatory) --> <servlet-mapping> <servlet-name>RestletAdapter</servlet-name> <url-pattern>/*</url-pattern> </servlet-mapping> </web-app>Note that the enumeration of "initParameters" of your Servlet will be copied to the "context.parameters" property of your Restlet Application. This way, you can pass additional initialization parameters to your application, and maybe share them with other Servlets.
Context.getClientDispatcher()
in your application.Constructor and Description |
---|
ServerServlet()
Constructor.
|
Modifier and Type | Method and Description |
---|---|
protected Application |
createApplication(Context parentContext)
Creates the single Application used by this Servlet.
|
protected ServerCall |
createCall(Server server,
javax.servlet.http.HttpServletRequest request,
javax.servlet.http.HttpServletResponse response)
Creates a new Servlet call wrapping a Servlet request/response couple and
a Server connector.
|
protected Component |
createComponent()
Creates the single Component used by this Servlet.
|
protected HttpServerHelper |
createServer(javax.servlet.http.HttpServletRequest request)
Creates the associated HTTP server handling calls.
|
protected Client |
createWarClient(Context context,
javax.servlet.ServletConfig config)
Creates a new client for the WAR protocol.
|
void |
destroy() |
Application |
getApplication()
Returns the application.
|
Component |
getComponent()
Returns the component.
|
protected java.lang.String |
getContextPath(javax.servlet.http.HttpServletRequest request)
Intercepter method need for subclasses such as XdbServerServlet.
|
java.lang.String |
getInitParameter(java.lang.String name,
java.lang.String defaultValue)
Returns the value of a given initialization parameter, first from the
Servlet configuration, then from the Web Application context.
|
protected java.lang.String |
getLocalAddr(javax.servlet.http.HttpServletRequest request)
Intercepter method need for subclasses such as XdbServerServlet.
|
protected int |
getLocalPort(javax.servlet.http.HttpServletRequest request)
Intercepter method need for subclasses such as XdbServerServlet.
|
HttpServerHelper |
getServer(javax.servlet.http.HttpServletRequest request)
Returns the associated HTTP server handling calls.
|
void |
init() |
protected void |
init(Application application)
Initialize a application.
|
protected void |
init(Component component)
Initialize a component.
|
protected java.lang.Class<?> |
loadClass(java.lang.String className)
Returns a class for a given qualified class name.
|
void |
service(javax.servlet.http.HttpServletRequest request,
javax.servlet.http.HttpServletResponse response)
Services a HTTP Servlet request as an uniform call.
|
doDelete, doGet, doHead, doOptions, doPost, doPut, doTrace, getLastModified, service
protected Application createApplication(Context parentContext)
parentContext
- The parent component context.protected ServerCall createCall(Server server, javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response)
server
- The Server connector.request
- The Servlet request.response
- The Servlet response.protected Component createComponent()
protected HttpServerHelper createServer(javax.servlet.http.HttpServletRequest request)
request
- The HTTP Servlet request.protected Client createWarClient(Context context, javax.servlet.ServletConfig config)
context
- The parent context.config
- The Servlet config.public void destroy()
destroy
in interface javax.servlet.Servlet
destroy
in class javax.servlet.GenericServlet
public Application getApplication()
public Component getComponent()
protected java.lang.String getContextPath(javax.servlet.http.HttpServletRequest request)
request
- The Servlet request.public java.lang.String getInitParameter(java.lang.String name, java.lang.String defaultValue)
name
- The parameter name.defaultValue
- The default to use in case the parameter is not found.protected java.lang.String getLocalAddr(javax.servlet.http.HttpServletRequest request)
request
- The Servlet request.protected int getLocalPort(javax.servlet.http.HttpServletRequest request)
request
- The Servlet request.public HttpServerHelper getServer(javax.servlet.http.HttpServletRequest request)
request
- The HTTP Servlet request.public void init() throws javax.servlet.ServletException
init
in class javax.servlet.GenericServlet
javax.servlet.ServletException
protected void init(Application application)
application
- The application to configure.protected void init(Component component)
component
- The component to configure.protected java.lang.Class<?> loadClass(java.lang.String className) throws java.lang.ClassNotFoundException
className
- The class name to lookup.java.lang.ClassNotFoundException
public void service(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response) throws javax.servlet.ServletException, java.io.IOException
service
in class javax.servlet.http.HttpServlet
request
- The HTTP Servlet request.response
- The HTTP Servlet response.javax.servlet.ServletException
java.io.IOException
Copyright © 2005-2024 Restlet.