com.caucho.server.http
Class HttpRequest

java.lang.Object
  extended by com.caucho.server.connection.AbstractHttpRequest
      extended by com.caucho.server.http.HttpRequest
All Implemented Interfaces:
SecurityContextProvider, CauchoRequest, ServerRequest, TcpServerRequest, HttpServletRequest, ServletRequest
Direct Known Subclasses:
CompileRequest, SocketPolicyRequest

public class HttpRequest
extends AbstractHttpRequest
implements TcpServerRequest

Handles a new request from an HTTP connection.


Field Summary
 
Fields inherited from class com.caucho.server.connection.AbstractHttpRequest
_calendar, _cb, _conn, _expect100Continue, _hasReadStream, _headerCodes, _hostHeader, _invocation, _rawRead, _readStream, _response, _server, _sessionGroup, _tcpConn, CONTEXT_PATH, ERROR_URI, EXCEPTION, EXCEPTION_TYPE, JSP_EXCEPTION, MESSAGE, PATH_INFO, QUERY_STRING, REQUEST_URI, SERVLET_NAME, SERVLET_PATH, SHUTDOWN, STATUS_CODE
 
Fields inherited from interface javax.servlet.http.HttpServletRequest
BASIC_AUTH, CLIENT_CERT_AUTH, DIGEST_AUTH, FORM_AUTH
 
Constructor Summary
HttpRequest(DispatchServer server, Connection conn)
          Creates a new HttpRequest.
 
Method Summary
protected  boolean checkLogin()
           
protected  java.lang.String dbgId()
           
 java.lang.String findSessionIdFromConnection()
          For SSL connections, use the SSL identifier.
 void finish()
          Cleans up at the end of the request
 java.lang.Object getAttribute(java.lang.String name)
          Returns the named attribute.
 java.util.Enumeration<java.lang.String> getAttributeNames()
          Returns an enumeration of the attribute names.
 java.lang.String getHeader(java.lang.String key)
          Returns the header.
 CharSegment getHeaderBuffer(char[] testBuf, int length)
          Returns the matching header.
 CharSegment getHeaderBuffer(java.lang.String key)
          Returns the header value for the key, returned as a CharSegment.
 void getHeaderBuffers(java.lang.String key, java.util.ArrayList<CharSegment> values)
          Fills an ArrayList with the header values matching the key.
 CharSegment getHeaderKey(int index)
          Returns the header key
 java.util.Enumeration getHeaderNames()
          Returns an enumeration of all the header keys.
 java.util.Enumeration getHeaders(java.lang.String key)
          Return an enumeration of headers matching a key.
 int getHeaderSize()
          Returns the number of headers.
 CharSegment getHeaderValue(int index)
          Returns the header value
protected  java.lang.CharSequence getHost()
          Returns the virtual host of the request
 java.lang.String getMethod()
          Returns the header.
 CharSegment getMethodBuffer()
          Returns a buffer containing the request method.
 java.lang.String getProtocol()
          Returns the protocol.
 CharSegment getProtocolBuffer()
          Returns a char segment containing the protocol.
 ReadStream getRawInput()
          Returns the raw input stream.
 byte[] getUriBuffer()
          Returns the byte buffer containing the request URI
 int getUriLength()
          Returns the length of the request URI
 boolean handleRequest()
          Handles a new HTTP request.
 boolean handleResume()
          Handles a comet-style resume.
 boolean initStream(ReadStream readStream, ReadStream rawRead)
          Returns a stream for reading POST data.
 boolean isSecure()
          Returns true for a secure connection.
 boolean isTop()
          Returns true for the top-level request, but false for any include() or forward()
 boolean isWaitForRead()
          Return true if the request waits for a read before beginning.
 void protocolCloseEvent()
          Handles a close event when the connection is closed.
 void setHeader(java.lang.String key, java.lang.String value)
          Adds a new header.
protected  void skip()
           
protected  void start()
          Clear the request variables in preparation for a new request.
 java.lang.String toString()
           
 
Methods inherited from class com.caucho.server.connection.AbstractHttpRequest
addCloseOnExit, addHeaderInt, allowKeepalive, authenticate, cleanup, complete, connectionClose, getAuthType, getCharacterEncoding, getConnection, getContentLength, getContentType, getContentTypeBuffer, getContextPath, getCookie, getCookies, getDateHeader, getDispatchServer, getHasCookie, getInputStream, getIntHeader, getInvocation, getLoadedSession, getLocalAddr, getLocale, getLocales, getLocalName, getLocalPort, getLogBuffer, getLongContentLength, getMemorySession, getPageContextPath, getPagePathInfo, getPageQueryString, getPageServletPath, getPageURI, getParameter, getParameterMap, getParameterNames, getParameterValues, getPathInfo, getPathTranslated, getQueryString, getRawReadBuffer, getReader, getRealPath, getRemoteAddr, getRemoteHost, getRemotePort, getRemoteUser, getRemoteUser, getRequestDepth, getRequestDepth, getRequestDispatcher, getRequestedSessionId, getRequestedSessionIdNoVary, getRequestURI, getRequestURL, getResponse, getScheme, getServerName, getServerPort, getServletContext, getServletName, getServletPath, getServletResponse, getSession, getSession, getSessionCookie, getSessionGroup, getSessionManager, getStartTime, getStream, getStream, getUserPrincipal, getVaryCookie, getVaryCookies, getWebApp, init, isIgnoreClientDisconnect, isInitial, isKeepalive, isRequestedSessionIdFromCookie, isRequestedSessionIdFromUrl, isRequestedSessionIdFromURL, isRequestedSessionIdValid, isResumed, isSuspended, isTimeout, isTransportSecure, isUserInRole, killKeepalive, logout, logoutUserPrincipal, printRemoteAddr, removeAttribute, restartServer, resume, runAs, setAttribute, setCharacterEncoding, setHasCookie, setInvocation, setStartTime, setVaryCookie, startConnection, startResume, suspend, suspend
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface com.caucho.server.port.TcpServerRequest
getConnection
 
Methods inherited from interface com.caucho.server.port.ServerRequest
init, startConnection
 

Constructor Detail

HttpRequest

public HttpRequest(DispatchServer server,
                   Connection conn)
Creates a new HttpRequest. New connections reuse the request.

Parameters:
server - the owning server.
Method Detail

isWaitForRead

public final boolean isWaitForRead()
Return true if the request waits for a read before beginning.

Specified by:
isWaitForRead in interface ServerRequest

handleRequest

public boolean handleRequest()
                      throws java.io.IOException
Handles a new HTTP request.

Note: ClientDisconnectException must be rethrown to the caller.

Specified by:
handleRequest in interface ServerRequest
Returns:
true if the connection should stay open (keepalive)
Throws:
java.io.IOException

handleResume

public boolean handleResume()
                     throws java.io.IOException
Handles a comet-style resume.

Specified by:
handleResume in interface ServerRequest
Overrides:
handleResume in class AbstractHttpRequest
Returns:
true if the connection should stay open (keepalive)
Throws:
java.io.IOException

isTop

public boolean isTop()
Returns true for the top-level request, but false for any include() or forward()

Specified by:
isTop in interface CauchoRequest
Overrides:
isTop in class AbstractHttpRequest

checkLogin

protected boolean checkLogin()

start

protected void start()
              throws java.io.IOException
Clear the request variables in preparation for a new request.

Overrides:
start in class AbstractHttpRequest
Parameters:
s - the read stream for the request
Throws:
java.io.IOException

isSecure

public boolean isSecure()
Returns true for a secure connection.

Specified by:
isSecure in interface ServletRequest
Overrides:
isSecure in class AbstractHttpRequest

getMethod

public java.lang.String getMethod()
Returns the header.

Specified by:
getMethod in interface HttpServletRequest
Specified by:
getMethod in class AbstractHttpRequest

getMethodBuffer

public CharSegment getMethodBuffer()
Returns a buffer containing the request method.


getHost

protected java.lang.CharSequence getHost()
Returns the virtual host of the request

Overrides:
getHost in class AbstractHttpRequest

getUriBuffer

public byte[] getUriBuffer()
Returns the byte buffer containing the request URI

Specified by:
getUriBuffer in class AbstractHttpRequest

getUriLength

public int getUriLength()
Returns the length of the request URI

Specified by:
getUriLength in class AbstractHttpRequest

getProtocol

public java.lang.String getProtocol()
Returns the protocol.

Specified by:
getProtocol in interface ServletRequest
Specified by:
getProtocol in class AbstractHttpRequest

getProtocolBuffer

public CharSegment getProtocolBuffer()
Returns a char segment containing the protocol.


setHeader

public void setHeader(java.lang.String key,
                      java.lang.String value)
Adds a new header. Used only by the caching to simulate If-Modified-Since.

Specified by:
setHeader in interface CauchoRequest
Overrides:
setHeader in class AbstractHttpRequest
Parameters:
key - the key of the new header
value - the value for the new header

getHeaderSize

public int getHeaderSize()
Returns the number of headers.

Overrides:
getHeaderSize in class AbstractHttpRequest

getHeaderKey

public CharSegment getHeaderKey(int index)
Returns the header key

Overrides:
getHeaderKey in class AbstractHttpRequest

getHeaderValue

public CharSegment getHeaderValue(int index)
Returns the header value

Overrides:
getHeaderValue in class AbstractHttpRequest

getHeader

public java.lang.String getHeader(java.lang.String key)
Returns the header.

Specified by:
getHeader in interface HttpServletRequest
Specified by:
getHeader in class AbstractHttpRequest
Parameters:
key - the header key
Returns:
the header value

getHeaderBuffer

public CharSegment getHeaderBuffer(char[] testBuf,
                                   int length)
Returns the matching header.

Parameters:
testBuf - header key
length - length of the key.

getHeaderBuffer

public CharSegment getHeaderBuffer(java.lang.String key)
Returns the header value for the key, returned as a CharSegment.

Overrides:
getHeaderBuffer in class AbstractHttpRequest
Parameters:
key - the header name

getHeaderBuffers

public void getHeaderBuffers(java.lang.String key,
                             java.util.ArrayList<CharSegment> values)
Fills an ArrayList with the header values matching the key.

Overrides:
getHeaderBuffers in class AbstractHttpRequest
Parameters:
values - ArrayList which will contain the maching values.
key - the header key to select.

getHeaders

public java.util.Enumeration getHeaders(java.lang.String key)
Return an enumeration of headers matching a key.

Specified by:
getHeaders in interface HttpServletRequest
Overrides:
getHeaders in class AbstractHttpRequest
Parameters:
key - the header key to match.
Returns:
the enumeration of the headers.

getHeaderNames

public java.util.Enumeration getHeaderNames()
Returns an enumeration of all the header keys.

Specified by:
getHeaderNames in interface HttpServletRequest
Specified by:
getHeaderNames in class AbstractHttpRequest

initStream

public boolean initStream(ReadStream readStream,
                          ReadStream rawRead)
                   throws java.io.IOException
Returns a stream for reading POST data.

Specified by:
initStream in class AbstractHttpRequest
Throws:
java.io.IOException

skip

protected void skip()
             throws java.io.IOException
Overrides:
skip in class AbstractHttpRequest
Throws:
java.io.IOException

getAttribute

public java.lang.Object getAttribute(java.lang.String name)
Returns the named attribute.

Specified by:
getAttribute in interface ServletRequest
Overrides:
getAttribute in class AbstractHttpRequest
Parameters:
name - the attribute name.
Returns:
the attribute value.

getAttributeNames

public java.util.Enumeration<java.lang.String> getAttributeNames()
Returns an enumeration of the attribute names.

Specified by:
getAttributeNames in interface ServletRequest
Overrides:
getAttributeNames in class AbstractHttpRequest

findSessionIdFromConnection

public java.lang.String findSessionIdFromConnection()
For SSL connections, use the SSL identifier.

Overrides:
findSessionIdFromConnection in class AbstractHttpRequest

getRawInput

public ReadStream getRawInput()
Returns the raw input stream.

Overrides:
getRawInput in class AbstractHttpRequest

protocolCloseEvent

public final void protocolCloseEvent()
Description copied from interface: ServerRequest
Handles a close event when the connection is closed.

Specified by:
protocolCloseEvent in interface ServerRequest

finish

public void finish()
            throws java.io.IOException
Cleans up at the end of the request

Overrides:
finish in class AbstractHttpRequest
Throws:
java.io.IOException

dbgId

protected java.lang.String dbgId()
Overrides:
dbgId in class AbstractHttpRequest

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object