org.atmosphere.cpr
Class AtmosphereRequest

java.lang.Object
  extended by javax.servlet.ServletRequestWrapper
      extended by javax.servlet.http.HttpServletRequestWrapper
          extended by org.atmosphere.cpr.AtmosphereRequest
All Implemented Interfaces:
javax.servlet.http.HttpServletRequest, javax.servlet.ServletRequest

public class AtmosphereRequest
extends javax.servlet.http.HttpServletRequestWrapper

An Atmosphere request representation. An AtmosphereRequest is a two-way communication channel between the client and the server. If the isDestroyable() is set to false, or if its associated AtmosphereResource has been suspended, this object can be re-used at any moment between requests. You can use its associated AtmosphereResponse to write bytes at any moment, making this object bi-directional.

Author:
Jeanfrancois Arcand

Nested Class Summary
static class AtmosphereRequest.Body
           
static class AtmosphereRequest.Builder
           
 
Field Summary
 
Fields inherited from interface javax.servlet.http.HttpServletRequest
BASIC_AUTH, CLIENT_CERT_AUTH, DIGEST_AUTH, FORM_AUTH
 
Method Summary
 Map<String,Object> attributes()
          Return the locally added attributes.
 boolean authenticate(javax.servlet.http.HttpServletResponse response)
          
 AtmosphereRequest.Body body()
          Return the request's body.
 AtmosphereRequest body(byte[] bytes)
           
 AtmosphereRequest body(InputStream body)
           
 AtmosphereRequest body(String body)
           
static AtmosphereRequest cloneRequest(javax.servlet.http.HttpServletRequest request, boolean loadInMemory, boolean copySession, boolean isDestroyable)
          Copy the HttpServletRequest content inside an AtmosphereRequest.
 AtmosphereRequest contentType(String m)
           
 AtmosphereRequest contextPath(String contextPath)
           
 void destroy()
           
 void destroy(boolean force)
           
 AtmosphereRequest destroyable(boolean destroyable)
           
 boolean destroyed()
           
 boolean dispatchRequestAsynchronously()
          Dispatch the request asynchronously to container.
 javax.servlet.AsyncContext getAsyncContext()
          
 Object getAttribute(String s)
          
 Enumeration<String> getAttributeNames()
          
 String getAuthType()
          
 String getCharacterEncoding()
          
 int getContentLength()
          
 String getContentType()
          
 String getContextPath()
          
 javax.servlet.http.Cookie[] getCookies()
          
 long getDateHeader(String name)
          
 javax.servlet.DispatcherType getDispatcherType()
          
 String getHeader(String s)
          
 String getHeader(String s, boolean checkCase)
           
 Enumeration<String> getHeaderNames()
          
 Enumeration getHeaders(String name)
          
 javax.servlet.ServletInputStream getInputStream()
          
 int getIntHeader(String name)
          
 String getLocalAddr()
          
 Locale getLocale()
          
 Enumeration<Locale> getLocales()
          
 String getLocalName()
          
 int getLocalPort()
          
 String getMethod()
          
 String getParameter(String s)
          
 Map<String,String[]> getParameterMap()
          
 Enumeration<String> getParameterNames()
          
 String[] getParameterValues(String s)
          
 javax.servlet.http.Part getPart(String name)
          
 Collection<javax.servlet.http.Part> getParts()
          
 String getPathInfo()
          
 String getPathTranslated()
          
 String getProtocol()
          
 String getQueryString()
          
 BufferedReader getReader()
          
 String getRealPath(String path)
          
 String getRemoteAddr()
          
 String getRemoteHost()
          
 int getRemotePort()
          
 String getRemoteUser()
          
 javax.servlet.RequestDispatcher getRequestDispatcher(String path)
          
 String getRequestedSessionId()
          
 String getRequestURI()
          
 StringBuffer getRequestURL()
          
 String getScheme()
          
 String getServerName()
          
 int getServerPort()
          
 javax.servlet.ServletContext getServletContext()
          
 String getServletPath()
          
 javax.servlet.http.HttpSession getSession()
          
 javax.servlet.http.HttpSession getSession(boolean create)
          
 Principal getUserPrincipal()
          
 AtmosphereRequest header(String name, String value)
          Add a header.
 AtmosphereRequest headers(Map<String,String> headers)
          Add all headers contained within the Map.
 Map<String,String> headersMap()
           
 boolean isAsyncStarted()
          
 boolean isAsyncSupported()
          
 boolean isDestroyable()
          Cjeck if this object can be destroyed.
 boolean isRequestedSessionIdFromCookie()
          
 boolean isRequestedSessionIdFromUrl()
          
 boolean isRequestedSessionIdFromURL()
          
 boolean isRequestedSessionIdValid()
          
 boolean isSecure()
          
 boolean isUserInRole(String role)
          
 void login(String username, String password)
          
 void logout()
          
 AtmosphereRequest method(String m)
           
static AtmosphereRequest newInstance()
          Create an instance of this class without an associated HttpServletRequest.
 AtmosphereRequest pathInfo(String pathInfo)
           
 AtmosphereRequest queryString(String qs)
          Set the query string.
 Map<String,String[]> queryStringsMap()
           
 void removeAttribute(String name)
          
 AtmosphereResource resource()
          The AtmosphereResource associated with this request.
 AtmosphereRequest servletPath(String servletPath)
           
 void setAttribute(String s, Object o)
          
 void setCharacterEncoding(String env)
          
 void setRequest(javax.servlet.ServletRequest request)
          
 javax.servlet.AsyncContext startAsync()
          
 javax.servlet.AsyncContext startAsync(javax.servlet.ServletRequest request, javax.servlet.ServletResponse response)
          
 String toString()
           
static AtmosphereRequest wrap(javax.servlet.http.HttpServletRequest request)
          Wrap an HttpServletRequest.
 javax.servlet.http.HttpServletRequest wrappedRequest()
           
 
Methods inherited from class javax.servlet.http.HttpServletRequestWrapper
changeSessionId, upgrade
 
Methods inherited from class javax.servlet.ServletRequestWrapper
getContentLengthLong, getRequest, isWrapperFor, isWrapperFor
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface javax.servlet.ServletRequest
getContentLengthLong
 

Method Detail

destroyed

public boolean destroyed()

destroyable

public AtmosphereRequest destroyable(boolean destroyable)

getPathInfo

public String getPathInfo()

Specified by:
getPathInfo in interface javax.servlet.http.HttpServletRequest
Overrides:
getPathInfo in class javax.servlet.http.HttpServletRequestWrapper

getPathTranslated

public String getPathTranslated()

Specified by:
getPathTranslated in interface javax.servlet.http.HttpServletRequest
Overrides:
getPathTranslated in class javax.servlet.http.HttpServletRequestWrapper

getQueryString

public String getQueryString()

Specified by:
getQueryString in interface javax.servlet.http.HttpServletRequest
Overrides:
getQueryString in class javax.servlet.http.HttpServletRequestWrapper

getRemoteUser

public String getRemoteUser()

Specified by:
getRemoteUser in interface javax.servlet.http.HttpServletRequest
Overrides:
getRemoteUser in class javax.servlet.http.HttpServletRequestWrapper

getRequestedSessionId

public String getRequestedSessionId()

Specified by:
getRequestedSessionId in interface javax.servlet.http.HttpServletRequest
Overrides:
getRequestedSessionId in class javax.servlet.http.HttpServletRequestWrapper

getMethod

public String getMethod()

Specified by:
getMethod in interface javax.servlet.http.HttpServletRequest
Overrides:
getMethod in class javax.servlet.http.HttpServletRequestWrapper

getPart

public javax.servlet.http.Part getPart(String name)
                                throws IOException,
                                       javax.servlet.ServletException

Specified by:
getPart in interface javax.servlet.http.HttpServletRequest
Overrides:
getPart in class javax.servlet.http.HttpServletRequestWrapper
Throws:
IOException
javax.servlet.ServletException

getParts

public Collection<javax.servlet.http.Part> getParts()
                                             throws IOException,
                                                    javax.servlet.ServletException

Specified by:
getParts in interface javax.servlet.http.HttpServletRequest
Overrides:
getParts in class javax.servlet.http.HttpServletRequestWrapper
Throws:
IOException
javax.servlet.ServletException

getContentType

public String getContentType()

Specified by:
getContentType in interface javax.servlet.ServletRequest
Overrides:
getContentType in class javax.servlet.ServletRequestWrapper

getDispatcherType

public javax.servlet.DispatcherType getDispatcherType()

Specified by:
getDispatcherType in interface javax.servlet.ServletRequest
Overrides:
getDispatcherType in class javax.servlet.ServletRequestWrapper

getServletPath

public String getServletPath()

Specified by:
getServletPath in interface javax.servlet.http.HttpServletRequest
Overrides:
getServletPath in class javax.servlet.http.HttpServletRequestWrapper

getRequestURI

public String getRequestURI()

Specified by:
getRequestURI in interface javax.servlet.http.HttpServletRequest
Overrides:
getRequestURI in class javax.servlet.http.HttpServletRequestWrapper

getRequestURL

public StringBuffer getRequestURL()

Specified by:
getRequestURL in interface javax.servlet.http.HttpServletRequest
Overrides:
getRequestURL in class javax.servlet.http.HttpServletRequestWrapper

getHeaders

public Enumeration getHeaders(String name)

Specified by:
getHeaders in interface javax.servlet.http.HttpServletRequest
Overrides:
getHeaders in class javax.servlet.http.HttpServletRequestWrapper

getIntHeader

public int getIntHeader(String name)

Specified by:
getIntHeader in interface javax.servlet.http.HttpServletRequest
Overrides:
getIntHeader in class javax.servlet.http.HttpServletRequestWrapper

getHeaderNames

public Enumeration<String> getHeaderNames()

Specified by:
getHeaderNames in interface javax.servlet.http.HttpServletRequest
Overrides:
getHeaderNames in class javax.servlet.http.HttpServletRequestWrapper

authenticate

public boolean authenticate(javax.servlet.http.HttpServletResponse response)
                     throws IOException,
                            javax.servlet.ServletException

Specified by:
authenticate in interface javax.servlet.http.HttpServletRequest
Overrides:
authenticate in class javax.servlet.http.HttpServletRequestWrapper
Throws:
IOException
javax.servlet.ServletException

getAuthType

public String getAuthType()

Specified by:
getAuthType in interface javax.servlet.http.HttpServletRequest
Overrides:
getAuthType in class javax.servlet.http.HttpServletRequestWrapper

getContextPath

public String getContextPath()

Specified by:
getContextPath in interface javax.servlet.http.HttpServletRequest
Overrides:
getContextPath in class javax.servlet.http.HttpServletRequestWrapper

getCookies

public javax.servlet.http.Cookie[] getCookies()

Specified by:
getCookies in interface javax.servlet.http.HttpServletRequest
Overrides:
getCookies in class javax.servlet.http.HttpServletRequestWrapper

getDateHeader

public long getDateHeader(String name)

Specified by:
getDateHeader in interface javax.servlet.http.HttpServletRequest
Overrides:
getDateHeader in class javax.servlet.http.HttpServletRequestWrapper

getHeader

public String getHeader(String s)

Specified by:
getHeader in interface javax.servlet.http.HttpServletRequest
Overrides:
getHeader in class javax.servlet.http.HttpServletRequestWrapper

wrappedRequest

public javax.servlet.http.HttpServletRequest wrappedRequest()

getHeader

public String getHeader(String s,
                        boolean checkCase)

getParameter

public String getParameter(String s)

Specified by:
getParameter in interface javax.servlet.ServletRequest
Overrides:
getParameter in class javax.servlet.ServletRequestWrapper

getParameterMap

public Map<String,String[]> getParameterMap()

Specified by:
getParameterMap in interface javax.servlet.ServletRequest
Overrides:
getParameterMap in class javax.servlet.ServletRequestWrapper

getParameterNames

public Enumeration<String> getParameterNames()

Specified by:
getParameterNames in interface javax.servlet.ServletRequest
Overrides:
getParameterNames in class javax.servlet.ServletRequestWrapper

getParameterValues

public String[] getParameterValues(String s)

Specified by:
getParameterValues in interface javax.servlet.ServletRequest
Overrides:
getParameterValues in class javax.servlet.ServletRequestWrapper

getProtocol

public String getProtocol()

Specified by:
getProtocol in interface javax.servlet.ServletRequest
Overrides:
getProtocol in class javax.servlet.ServletRequestWrapper

getInputStream

public javax.servlet.ServletInputStream getInputStream()
                                                throws IOException

Specified by:
getInputStream in interface javax.servlet.ServletRequest
Overrides:
getInputStream in class javax.servlet.ServletRequestWrapper
Throws:
IOException

getReader

public BufferedReader getReader()
                         throws IOException

Specified by:
getReader in interface javax.servlet.ServletRequest
Overrides:
getReader in class javax.servlet.ServletRequestWrapper
Throws:
IOException

getRealPath

public String getRealPath(String path)

Specified by:
getRealPath in interface javax.servlet.ServletRequest
Overrides:
getRealPath in class javax.servlet.ServletRequestWrapper

headers

public AtmosphereRequest headers(Map<String,String> headers)
Add all headers contained within the Map.

Parameters:
headers -
Returns:
this;

header

public AtmosphereRequest header(String name,
                                String value)
Add a header.

Parameters:
name -
value -
Returns:
this

queryString

public AtmosphereRequest queryString(String qs)
Set the query string.

Parameters:
qs -
Returns:
this

headersMap

public Map<String,String> headersMap()

queryStringsMap

public Map<String,String[]> queryStringsMap()

method

public AtmosphereRequest method(String m)

contentType

public AtmosphereRequest contentType(String m)

body

public AtmosphereRequest body(String body)

body

public AtmosphereRequest body(byte[] bytes)

body

public AtmosphereRequest body(InputStream body)

body

public AtmosphereRequest.Body body()
Return the request's body. This method will return an empty Body if the underlying container or framework is using InputStream or Reader.

Returns:
the request body;

servletPath

public AtmosphereRequest servletPath(String servletPath)

contextPath

public AtmosphereRequest contextPath(String contextPath)

setAttribute

public void setAttribute(String s,
                         Object o)

Specified by:
setAttribute in interface javax.servlet.ServletRequest
Overrides:
setAttribute in class javax.servlet.ServletRequestWrapper

setCharacterEncoding

public void setCharacterEncoding(String env)
                          throws UnsupportedEncodingException

Specified by:
setCharacterEncoding in interface javax.servlet.ServletRequest
Overrides:
setCharacterEncoding in class javax.servlet.ServletRequestWrapper
Throws:
UnsupportedEncodingException

startAsync

public javax.servlet.AsyncContext startAsync()

Specified by:
startAsync in interface javax.servlet.ServletRequest
Overrides:
startAsync in class javax.servlet.ServletRequestWrapper

startAsync

public javax.servlet.AsyncContext startAsync(javax.servlet.ServletRequest request,
                                             javax.servlet.ServletResponse response)

Specified by:
startAsync in interface javax.servlet.ServletRequest
Overrides:
startAsync in class javax.servlet.ServletRequestWrapper

getAsyncContext

public javax.servlet.AsyncContext getAsyncContext()

Specified by:
getAsyncContext in interface javax.servlet.ServletRequest
Overrides:
getAsyncContext in class javax.servlet.ServletRequestWrapper

getAttribute

public Object getAttribute(String s)

Specified by:
getAttribute in interface javax.servlet.ServletRequest
Overrides:
getAttribute in class javax.servlet.ServletRequestWrapper

removeAttribute

public void removeAttribute(String name)

Specified by:
removeAttribute in interface javax.servlet.ServletRequest
Overrides:
removeAttribute in class javax.servlet.ServletRequestWrapper

attributes

public Map<String,Object> attributes()
Return the locally added attributes.

Returns:

getSession

public javax.servlet.http.HttpSession getSession()

Specified by:
getSession in interface javax.servlet.http.HttpServletRequest
Overrides:
getSession in class javax.servlet.http.HttpServletRequestWrapper

getSession

public javax.servlet.http.HttpSession getSession(boolean create)

Specified by:
getSession in interface javax.servlet.http.HttpServletRequest
Overrides:
getSession in class javax.servlet.http.HttpServletRequestWrapper

getUserPrincipal

public Principal getUserPrincipal()

Specified by:
getUserPrincipal in interface javax.servlet.http.HttpServletRequest
Overrides:
getUserPrincipal in class javax.servlet.http.HttpServletRequestWrapper

isRequestedSessionIdFromCookie

public boolean isRequestedSessionIdFromCookie()

Specified by:
isRequestedSessionIdFromCookie in interface javax.servlet.http.HttpServletRequest
Overrides:
isRequestedSessionIdFromCookie in class javax.servlet.http.HttpServletRequestWrapper

isRequestedSessionIdFromUrl

public boolean isRequestedSessionIdFromUrl()

Specified by:
isRequestedSessionIdFromUrl in interface javax.servlet.http.HttpServletRequest
Overrides:
isRequestedSessionIdFromUrl in class javax.servlet.http.HttpServletRequestWrapper

isRequestedSessionIdFromURL

public boolean isRequestedSessionIdFromURL()

Specified by:
isRequestedSessionIdFromURL in interface javax.servlet.http.HttpServletRequest
Overrides:
isRequestedSessionIdFromURL in class javax.servlet.http.HttpServletRequestWrapper

isRequestedSessionIdValid

public boolean isRequestedSessionIdValid()

Specified by:
isRequestedSessionIdValid in interface javax.servlet.http.HttpServletRequest
Overrides:
isRequestedSessionIdValid in class javax.servlet.http.HttpServletRequestWrapper

isUserInRole

public boolean isUserInRole(String role)

Specified by:
isUserInRole in interface javax.servlet.http.HttpServletRequest
Overrides:
isUserInRole in class javax.servlet.http.HttpServletRequestWrapper

login

public void login(String username,
                  String password)
           throws javax.servlet.ServletException

Specified by:
login in interface javax.servlet.http.HttpServletRequest
Overrides:
login in class javax.servlet.http.HttpServletRequestWrapper
Throws:
javax.servlet.ServletException

logout

public void logout()
            throws javax.servlet.ServletException

Specified by:
logout in interface javax.servlet.http.HttpServletRequest
Overrides:
logout in class javax.servlet.http.HttpServletRequestWrapper
Throws:
javax.servlet.ServletException

getRemoteAddr

public String getRemoteAddr()

Specified by:
getRemoteAddr in interface javax.servlet.ServletRequest
Overrides:
getRemoteAddr in class javax.servlet.ServletRequestWrapper

getRemoteHost

public String getRemoteHost()

Specified by:
getRemoteHost in interface javax.servlet.ServletRequest
Overrides:
getRemoteHost in class javax.servlet.ServletRequestWrapper

getRemotePort

public int getRemotePort()

Specified by:
getRemotePort in interface javax.servlet.ServletRequest
Overrides:
getRemotePort in class javax.servlet.ServletRequestWrapper

getRequestDispatcher

public javax.servlet.RequestDispatcher getRequestDispatcher(String path)

Specified by:
getRequestDispatcher in interface javax.servlet.ServletRequest
Overrides:
getRequestDispatcher in class javax.servlet.ServletRequestWrapper

getScheme

public String getScheme()

Specified by:
getScheme in interface javax.servlet.ServletRequest
Overrides:
getScheme in class javax.servlet.ServletRequestWrapper

getServerName

public String getServerName()

Specified by:
getServerName in interface javax.servlet.ServletRequest
Overrides:
getServerName in class javax.servlet.ServletRequestWrapper

getServerPort

public int getServerPort()

Specified by:
getServerPort in interface javax.servlet.ServletRequest
Overrides:
getServerPort in class javax.servlet.ServletRequestWrapper

getServletContext

public javax.servlet.ServletContext getServletContext()

Specified by:
getServletContext in interface javax.servlet.ServletRequest
Overrides:
getServletContext in class javax.servlet.ServletRequestWrapper

isAsyncStarted

public boolean isAsyncStarted()

Specified by:
isAsyncStarted in interface javax.servlet.ServletRequest
Overrides:
isAsyncStarted in class javax.servlet.ServletRequestWrapper

isAsyncSupported

public boolean isAsyncSupported()

Specified by:
isAsyncSupported in interface javax.servlet.ServletRequest
Overrides:
isAsyncSupported in class javax.servlet.ServletRequestWrapper

isSecure

public boolean isSecure()

Specified by:
isSecure in interface javax.servlet.ServletRequest
Overrides:
isSecure in class javax.servlet.ServletRequestWrapper

getLocalName

public String getLocalName()

Specified by:
getLocalName in interface javax.servlet.ServletRequest
Overrides:
getLocalName in class javax.servlet.ServletRequestWrapper

getLocalPort

public int getLocalPort()

Specified by:
getLocalPort in interface javax.servlet.ServletRequest
Overrides:
getLocalPort in class javax.servlet.ServletRequestWrapper

getLocalAddr

public String getLocalAddr()

Specified by:
getLocalAddr in interface javax.servlet.ServletRequest
Overrides:
getLocalAddr in class javax.servlet.ServletRequestWrapper

getLocale

public Locale getLocale()

Specified by:
getLocale in interface javax.servlet.ServletRequest
Overrides:
getLocale in class javax.servlet.ServletRequestWrapper

resource

public AtmosphereResource resource()
The AtmosphereResource associated with this request. If the request hasn't been suspended, this method will return null.

Returns:
an AtmosphereResource, or null if no resource has ben associated yet.

getLocales

public Enumeration<Locale> getLocales()

Specified by:
getLocales in interface javax.servlet.ServletRequest
Overrides:
getLocales in class javax.servlet.ServletRequestWrapper

dispatchRequestAsynchronously

public boolean dispatchRequestAsynchronously()
Dispatch the request asynchronously to container. The default is false.

Returns:
true to dispatch the request asynchronously to container.

isDestroyable

public boolean isDestroyable()
Cjeck if this object can be destroyed. Default is true.


pathInfo

public AtmosphereRequest pathInfo(String pathInfo)

getAttributeNames

public Enumeration<String> getAttributeNames()

Specified by:
getAttributeNames in interface javax.servlet.ServletRequest
Overrides:
getAttributeNames in class javax.servlet.ServletRequestWrapper

getCharacterEncoding

public String getCharacterEncoding()

Specified by:
getCharacterEncoding in interface javax.servlet.ServletRequest
Overrides:
getCharacterEncoding in class javax.servlet.ServletRequestWrapper

getContentLength

public int getContentLength()

Specified by:
getContentLength in interface javax.servlet.ServletRequest
Overrides:
getContentLength in class javax.servlet.ServletRequestWrapper

destroy

public void destroy()

destroy

public void destroy(boolean force)

setRequest

public void setRequest(javax.servlet.ServletRequest request)

Overrides:
setRequest in class javax.servlet.ServletRequestWrapper

newInstance

public static final AtmosphereRequest newInstance()
Create an instance of this class without an associated HttpServletRequest.

Returns:
an instance of this class without an associated HttpServletRequest

wrap

public static final AtmosphereRequest wrap(javax.servlet.http.HttpServletRequest request)
Wrap an HttpServletRequest.

Parameters:
request - HttpServletRequest
Returns:
an AtmosphereRequest

cloneRequest

public static final AtmosphereRequest cloneRequest(javax.servlet.http.HttpServletRequest request,
                                                   boolean loadInMemory,
                                                   boolean copySession,
                                                   boolean isDestroyable)
Copy the HttpServletRequest content inside an AtmosphereRequest. By default the returned AtmosphereRequest is not destroyable.

Parameters:
request - HttpServletRequest
Returns:
an AtmosphereRequest

toString

public String toString()
Overrides:
toString in class Object


Copyright © 2014. All Rights Reserved.