org.atmosphere.cpr
Class AtmosphereServlet

java.lang.Object
  extended by javax.servlet.GenericServlet
      extended by javax.servlet.http.HttpServlet
          extended by weblogic.servlet.http.AbstractAsyncServlet
              extended by org.atmosphere.cpr.AtmosphereServlet
All Implemented Interfaces:
Serializable, Servlet, ServletConfig, CometProcessor

public class AtmosphereServlet
extends AbstractAsyncServlet
implements CometProcessor

The AtmosphereServlet acts as a dispatcher for AtmosphereHandler defined in META-INF/atmosphere.xml, or if atmosphere.xml is missing, all classes that implements AtmosphereHandler will be discovered and mapped using the class's name. This Servlet can be defined inside an application's web.xml using the following:


    <servlet>
        <description>AtmosphereServlet</description>
        <servlet-name>AtmosphereServlet</servlet-name>
        <servlet-class>org.atmosphere.cpr.AtmosphereServlet</servlet-class>
        <load-on-startup>0 </load-on-startup>
    </servlet>
    <servlet-mapping>
         <servlet-name>AtmosphereServlet</servlet-name>
         <url-pattern>/Atmosphere </url-pattern>
    </servlet-mapping>
 

Author:
Jeanfrancois Arcand
See Also:
Serialized Form

Nested Class Summary
static class AtmosphereServlet.Action
          Simple class/struck that hold the current state.
static class AtmosphereServlet.AtmosphereHandlerWrapper
           
 
Field Summary
static String GLASSFISH_V2
           
static String GLASSFISH_V3
           
static String GRIZZLY
           
static String JETTY
           
static Logger logger
           
static String SERVLET_30
           
static String TOMCAT
           
static String WEBLOGIC
           
 
Constructor Summary
AtmosphereServlet()
          Create an Atmosphere Servlet.
 
Method Summary
protected  void autoDetectAtmosphereHandlers(ServletContext sc, URLClassLoader c)
          Auto detect instance of AtmosphereHandler in case META-INF/atmosphere.xml is missing.
protected  void autoDetectContainer()
          Auto detect the underlying Servlet Container we are running on.
 void doDelete(HttpServletRequest req, HttpServletResponse res)
          Delegate the request processing to an instance of CometSupport
 void doGet(HttpServletRequest req, HttpServletResponse res)
          Delegate the request processing to an instance of CometSupport
 void doHead(HttpServletRequest req, HttpServletResponse res)
          Delegate the request processing to an instance of CometSupport
 void doOptions(HttpServletRequest req, HttpServletResponse res)
          Delegate the request processing to an instance of CometSupport
 void doPost(HttpServletRequest req, HttpServletResponse res)
          Delegate the request processing to an instance of CometSupport
 void doPut(HttpServletRequest req, HttpServletResponse res)
          Delegate the request processing to an instance of CometSupport
protected  boolean doRequest(RequestResponseKey rrk)
          Weblogic specific comet based implementation.
protected  void doResponse(RequestResponseKey rrk, Object arg1)
          Weblogic specific comet based implementation.
protected  void doTimeout(RequestResponseKey rrk)
          Weblogic specific comet based implementation.
 void doTrace(HttpServletRequest req, HttpServletResponse res)
          Delegate the request processing to an instance of CometSupport
 void event(CometEvent cometEvent)
          Hack to support Tomcat AIO like other WebServer.
 void init(ServletConfig sc)
          Load the AtmosphereHandler associated with this AtmosphereServlet.
protected  void loadAtmosphereDotXml(InputStream stream, URLClassLoader c)
          Load AtmosphereHandler defined under META-INF/atmosphere.xml
 
Methods inherited from class javax.servlet.http.HttpServlet
getLastModified, service, service
 
Methods inherited from class javax.servlet.GenericServlet
destroy, 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
 
Methods inherited from interface javax.servlet.Servlet
destroy, getServletConfig, getServletInfo, service
 

Field Detail

SERVLET_30

public static final String SERVLET_30
See Also:
Constant Field Values

GLASSFISH_V2

public static final String GLASSFISH_V2
See Also:
Constant Field Values

TOMCAT

public static final String TOMCAT
See Also:
Constant Field Values

JETTY

public static final String JETTY
See Also:
Constant Field Values

GRIZZLY

public static final String GRIZZLY
See Also:
Constant Field Values

GLASSFISH_V3

public static final String GLASSFISH_V3
See Also:
Constant Field Values

WEBLOGIC

public static final String WEBLOGIC
See Also:
Constant Field Values

logger

public static final Logger logger
Constructor Detail

AtmosphereServlet

public AtmosphereServlet()
Create an Atmosphere Servlet.

Method Detail

init

public void init(ServletConfig sc)
          throws ServletException
Load the AtmosphereHandler associated with this AtmosphereServlet.

Specified by:
init in interface Servlet
Overrides:
init in class GenericServlet
Parameters:
sc - the ServletContext
Throws:
ServletException

loadAtmosphereDotXml

protected void loadAtmosphereDotXml(InputStream stream,
                                    URLClassLoader c)
                             throws IOException
Load AtmosphereHandler defined under META-INF/atmosphere.xml

Throws:
IOException

autoDetectContainer

protected void autoDetectContainer()
Auto detect the underlying Servlet Container we are running on.


autoDetectAtmosphereHandlers

protected void autoDetectAtmosphereHandlers(ServletContext sc,
                                            URLClassLoader c)
                                     throws MalformedURLException,
                                            URISyntaxException
Auto detect instance of AtmosphereHandler in case META-INF/atmosphere.xml is missing.

Parameters:
sc - ServletContext
c - URLClassLoaser to load the class.
Throws:
MalformedURLException
URISyntaxException

doHead

public void doHead(HttpServletRequest req,
                   HttpServletResponse res)
            throws IOException,
                   ServletException
Delegate the request processing to an instance of CometSupport

Overrides:
doHead in class HttpServlet
Parameters:
req - the HttpServletRequest
res - the HttpServletResponse
Throws:
IOException
ServletException

doOptions

public void doOptions(HttpServletRequest req,
                      HttpServletResponse res)
               throws IOException,
                      ServletException
Delegate the request processing to an instance of CometSupport

Overrides:
doOptions in class HttpServlet
Parameters:
req - the HttpServletRequest
res - the HttpServletResponse
Throws:
IOException
ServletException

doTrace

public void doTrace(HttpServletRequest req,
                    HttpServletResponse res)
             throws IOException,
                    ServletException
Delegate the request processing to an instance of CometSupport

Overrides:
doTrace in class HttpServlet
Parameters:
req - the HttpServletRequest
res - the HttpServletResponse
Throws:
IOException
ServletException

doDelete

public void doDelete(HttpServletRequest req,
                     HttpServletResponse res)
              throws IOException,
                     ServletException
Delegate the request processing to an instance of CometSupport

Overrides:
doDelete in class HttpServlet
Parameters:
req - the HttpServletRequest
res - the HttpServletResponse
Throws:
IOException
ServletException

doPut

public void doPut(HttpServletRequest req,
                  HttpServletResponse res)
           throws IOException,
                  ServletException
Delegate the request processing to an instance of CometSupport

Overrides:
doPut in class HttpServlet
Parameters:
req - the HttpServletRequest
res - the HttpServletResponse
Throws:
IOException
ServletException

doGet

public void doGet(HttpServletRequest req,
                  HttpServletResponse res)
           throws IOException,
                  ServletException
Delegate the request processing to an instance of CometSupport

Overrides:
doGet in class HttpServlet
Parameters:
req - the HttpServletRequest
res - the HttpServletResponse
Throws:
IOException
ServletException

doPost

public void doPost(HttpServletRequest req,
                   HttpServletResponse res)
            throws IOException,
                   ServletException
Delegate the request processing to an instance of CometSupport

Overrides:
doPost in class HttpServlet
Parameters:
req - the HttpServletRequest
res - the HttpServletResponse
Throws:
IOException
ServletException

event

public void event(CometEvent cometEvent)
           throws IOException,
                  ServletException
Hack to support Tomcat AIO like other WebServer. This method is invoked by Tomcat when it detect a Servlet implements the interface CometProcessor without invoking Servlet#service

Specified by:
event in interface CometProcessor
Parameters:
cometEvent - the CometEvent
Throws:
IOException
ServletException

doRequest

protected boolean doRequest(RequestResponseKey rrk)
                     throws IOException,
                            ServletException
Weblogic specific comet based implementation.

Specified by:
doRequest in class AbstractAsyncServlet
Parameters:
rrk -
Returns:
Throws:
IOException
ServletException

doResponse

protected void doResponse(RequestResponseKey rrk,
                          Object arg1)
                   throws IOException,
                          ServletException
Weblogic specific comet based implementation.

Specified by:
doResponse in class AbstractAsyncServlet
Parameters:
rrk -
Throws:
IOException
ServletException

doTimeout

protected void doTimeout(RequestResponseKey rrk)
                  throws IOException,
                         ServletException
Weblogic specific comet based implementation.

Specified by:
doTimeout in class AbstractAsyncServlet
Parameters:
rrk -
Throws:
IOException
ServletException


Copyright © 2009 SUN Microsystems. All Rights Reserved.