com.caucho.server.http
Class AbstractHttpRequest

java.lang.Object
  extended by com.caucho.server.http.AbstractHttpRequest
All Implemented Interfaces:
ProtocolConnection, SecurityContextProvider
Direct Known Subclasses:
FastCgiRequest, HmuxRequest, HttpRequest

public abstract class AbstractHttpRequest
extends java.lang.Object
implements SecurityContextProvider, ProtocolConnection

Abstract request implementing methods common to the different request implementations.


Field Summary
protected static CaseInsensitiveIntMap _headerCodes
           
protected  CharSegment _hostHeader
           
static java.lang.String JSP_EXCEPTION
           
static java.lang.String SHUTDOWN
           
 
Constructor Summary
protected AbstractHttpRequest(Server server, SocketLink conn)
          Create a new Request.
 
Method Summary
protected  boolean addHeaderInt(char[] keyBuf, int keyOff, int keyLen, CharSegment value)
          Adds the header, checking for known values.
protected  Invocation buildInvocation(Invocation invocation, byte[] uri, int uriLength)
           
 void cleanup()
           
protected  void clearRequest()
           
 void clientDisconnect()
          Sets the client disconnect
protected abstract  AbstractHttpResponse createResponse()
           
protected  java.lang.String dbgId()
           
 java.lang.String findSessionIdFromConnection()
          For SSL connections, use the SSL identifier.
 void finishInvocation()
          Cleans up at the end of the invocation
 void finishRequest()
          Cleans up at the end of the request
protected  AbstractHttpResponse getAbstractHttpResponse()
           
 int getAvailable()
           
 java.lang.String getCharacterEncoding()
          Returns the character encoding of a post.
protected  CharBuffer getCharBuffer()
           
 SocketLink getConnection()
          Returns the connection.
 int getConnectionId()
           
 int getContentLength()
          Returns the content length of a post.
 java.lang.String getContentType()
          Returns the content-length of a post.
 CharSegment getContentTypeBuffer()
          Returns the content-length of a post.
 Cookie[] getCookies()
          Returns the cookies from the browser
 long getDateHeader(java.lang.String key)
          Returns a header interpreted as a date.
protected  ErrorPageManager getErrorManager()
          Returns the default error manager
protected  HashMapImpl<java.lang.String,java.lang.String[]> getForm()
           
protected  Form getFormParser()
           
abstract  java.lang.String getHeader(java.lang.String key)
          Returns the named header.
 CharSegment getHeaderBuffer(java.lang.String name)
          Fills the result with the header values as CharSegment values.
 void getHeaderBuffers(java.lang.String name, java.util.ArrayList<CharSegment> resultList)
          Fills the result with a list of the header values as CharSegment values.
 CharSegment getHeaderKey(int index)
          Returns the header key
abstract  java.util.Enumeration<java.lang.String> getHeaderNames()
          Enumerates the header keys
 java.util.Enumeration<java.lang.String> getHeaders(java.lang.String name)
          Returns an enumeration of the headers for the named attribute.
 int getHeaderSize()
          Returns the number of headers.
 CharSegment getHeaderValue(int index)
          Returns the header value
protected  java.lang.CharSequence getHost()
           
 ServletInputStream getInputStream()
          Returns a stream for reading POST data.
 int getIntHeader(java.lang.String key)
          Returns the named header, converted to an integer.
protected  Invocation getInvocation(java.lang.CharSequence host, byte[] uri, int uriLength)
           
 InvocationServer getInvocationServer()
          returns the dispatch server.
 java.util.Locale getLocale()
           
 java.util.Enumeration<java.util.Locale> getLocales()
           
 java.lang.String getLocalHost()
          Returns the server's address.
 int getLocalPort()
          Returns the local port.
 byte[] getLogBuffer()
          Returns the log buffer.
 long getLongContentLength()
          Returns the content length of a post.
abstract  java.lang.String getMethod()
           
abstract  java.lang.String getProtocol()
           
 java.lang.String getProtocolRequestURL()
          Returns a request URL for debugging/management.
 ReadStream getRawInput()
          Returns the raw input stream.
 ReadStream getRawRead()
           
 byte[] getRawReadBuffer()
          Returns the raw read buffer.
 WriteStream getRawWrite()
           
 java.io.BufferedReader getReader()
          Returns a Reader for the POST contents
 ReadStream getReadStream()
           
 java.lang.String getRemoteAddr()
           
 java.lang.String getRemoteHost()
           
 int getRemotePort()
          Returns the local port.
 HttpServletRequestImpl getRequestFacade()
           
 java.lang.String getRequestURI()
           
 java.lang.StringBuffer getRequestURL()
           
 AbstractHttpResponse getResponse()
          Returns the response for this request.
 HttpServletResponseImpl getResponseFacade()
           
 java.lang.String getScheme()
          Returns the request's scheme.
 Server getServer()
           
 java.lang.String getServerName()
          Returns the local server name.
 int getServerPort()
          Returns the server's port.
 long getStartTime()
          Returns the date for the current request.
 ReadStream getStream()
          Returns the requests underlying read stream, e.g.
 ReadStream getStream(boolean isReader)
          Returns the requests underlying read stream, e.g.
abstract  byte[] getUriBuffer()
           
abstract  int getUriLength()
           
 java.security.Principal getUserPrincipal()
          Returns the Principal for the context.
protected  WebApp getWebApp()
           
protected  void handleConnectionClose()
          Called for a connection: close
 boolean handleResume()
          Handles a comet-style resume.
 boolean hasRequest()
          Returns true if a request has been set
 void init()
          Initialization.
protected  void initAttributes(HttpServletRequestImpl facade)
           
protected abstract  boolean initStream(ReadStream readStream, ReadStream rawStream)
          Initialize the read stream from the raw stream.
 boolean isCometActive()
           
 boolean isConnectionClosed()
          Returns true if the client has disconnected
 boolean isDuplex()
           
 boolean isIgnoreClientDisconnect()
          Returns true if client disconnects should be ignored.
protected  boolean isKeepalive()
          Returns true if the keepalive is active.
 boolean isSecure()
          Returns true if the request is secure.
 boolean isSuspend()
           
 boolean isTransportSecure()
          Returns true if the transport is secure.
 boolean isUserInRole(java.lang.String role)
          Returns true if the user principal plays the named role.
 void killKeepalive(java.lang.String reason)
          Kills the keepalive.
 void onCloseConnection()
          Handles a close event when the connection is closed.
 void onStartConnection()
          Called when the connection starts
 int printRemoteAddr(byte[] buffer, int offset)
           
protected  void restartServer()
          Restarts the server.
 java.lang.String runAs(java.lang.String string)
          Sets the current runAs role/principal.
protected  void sendRequestError(java.lang.Throwable e)
           
 void setCharacterEncoding(java.lang.String encoding)
          Sets the character encoding of a post.
protected  void setContentLength(CharSegment value)
           
 void setHeader(java.lang.String key, java.lang.String value)
          Sets the header.
 void shutdown()
          Called by server shutdown to kill any active threads
protected  void skip()
           
 SocketLinkDuplexController startDuplex(SocketLinkDuplexListener handler)
          Starts duplex mode.
protected  void startInvocation()
          Prepare the Request object for a new request.
protected  void startRequest(HttpBufferStore httpBuffer)
          Prepare the Request object for a new request.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface com.caucho.network.listen.ProtocolConnection
handleRequest, isWaitForRead
 

Field Detail

_headerCodes

protected static final CaseInsensitiveIntMap _headerCodes

JSP_EXCEPTION

public static final java.lang.String JSP_EXCEPTION
See Also:
Constant Field Values

SHUTDOWN

public static final java.lang.String SHUTDOWN
See Also:
Constant Field Values

_hostHeader

protected CharSegment _hostHeader
Constructor Detail

AbstractHttpRequest

protected AbstractHttpRequest(Server server,
                              SocketLink conn)
Create a new Request. Because the actual initialization occurs with the start() method, this just allocates statics.

Parameters:
server - the parent server
Method Detail

getServer

public Server getServer()

createResponse

protected abstract AbstractHttpResponse createResponse()

getAbstractHttpResponse

protected AbstractHttpResponse getAbstractHttpResponse()

init

public void init()
Initialization.

Specified by:
init in interface ProtocolConnection

getConnection

public final SocketLink getConnection()
Returns the connection.


getConnectionId

public final int getConnectionId()

getInvocationServer

public final InvocationServer getInvocationServer()
returns the dispatch server.


getCharBuffer

protected final CharBuffer getCharBuffer()

onStartConnection

public void onStartConnection()
Called when the connection starts

Specified by:
onStartConnection in interface ProtocolConnection

startRequest

protected void startRequest(HttpBufferStore httpBuffer)
                     throws java.io.IOException
Prepare the Request object for a new request.

Parameters:
httpBuffer - the raw connection stream
Throws:
java.io.IOException

clearRequest

protected void clearRequest()

hasRequest

public boolean hasRequest()
Returns true if a request has been set


getRawWrite

public WriteStream getRawWrite()

getUriBuffer

public abstract byte[] getUriBuffer()

getUriLength

public abstract int getUriLength()

isIgnoreClientDisconnect

public boolean isIgnoreClientDisconnect()
Returns true if client disconnects should be ignored.


getWebApp

protected WebApp getWebApp()

getRequestURL

public java.lang.StringBuffer getRequestURL()

getRequestURI

public java.lang.String getRequestURI()

getProtocolRequestURL

public java.lang.String getProtocolRequestURL()
Description copied from interface: ProtocolConnection
Returns a request URL for debugging/management.

Specified by:
getProtocolRequestURL in interface ProtocolConnection

isConnectionClosed

public boolean isConnectionClosed()
Returns true if the client has disconnected


clientDisconnect

public void clientDisconnect()
Sets the client disconnect


getRequestFacade

public final HttpServletRequestImpl getRequestFacade()

getResponseFacade

public final HttpServletResponseImpl getResponseFacade()

getResponse

public AbstractHttpResponse getResponse()
Returns the response for this request.


getServerName

public java.lang.String getServerName()
Returns the local server name.


getHost

protected java.lang.CharSequence getHost()

getServerPort

public int getServerPort()
Returns the server's port.


getLocalPort

public int getLocalPort()
Returns the local port.


getLocalHost

public java.lang.String getLocalHost()
Returns the server's address.


getRemoteAddr

public java.lang.String getRemoteAddr()

printRemoteAddr

public int printRemoteAddr(byte[] buffer,
                           int offset)
                    throws java.io.IOException
Throws:
java.io.IOException

getRemoteHost

public java.lang.String getRemoteHost()

getRemotePort

public int getRemotePort()
Returns the local port.


getScheme

public java.lang.String getScheme()
Returns the request's scheme.


getProtocol

public abstract java.lang.String getProtocol()

getMethod

public abstract java.lang.String getMethod()

getHeader

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

Parameters:
key - the header key

getHeaderSize

public int getHeaderSize()
Returns the number of headers.


getHeaderKey

public CharSegment getHeaderKey(int index)
Returns the header key


getHeaderValue

public CharSegment getHeaderValue(int index)
Returns the header value


getHeaderBuffer

public CharSegment getHeaderBuffer(java.lang.String name)
Fills the result with the header values as CharSegment values. Most implementations will implement this directly.

Parameters:
name - the header name

getHeaderNames

public abstract java.util.Enumeration<java.lang.String> getHeaderNames()
Enumerates the header keys


setHeader

public void setHeader(java.lang.String key,
                      java.lang.String value)
Sets the header. setHeader is used for Resin's caching to simulate If-None-Match.


addHeaderInt

protected boolean addHeaderInt(char[] keyBuf,
                               int keyOff,
                               int keyLen,
                               CharSegment value)
Adds the header, checking for known values.


setContentLength

protected void setContentLength(CharSegment value)

handleConnectionClose

protected void handleConnectionClose()
Called for a connection: close


getHeaders

public java.util.Enumeration<java.lang.String> getHeaders(java.lang.String name)
Returns an enumeration of the headers for the named attribute.

Parameters:
name - the header name

getHeaderBuffers

public void getHeaderBuffers(java.lang.String name,
                             java.util.ArrayList<CharSegment> resultList)
Fills the result with a list of the header values as CharSegment values. Most implementations will implement this directly.

Parameters:
name - the header name
resultList - the resulting buffer

getIntHeader

public int getIntHeader(java.lang.String key)
Returns the named header, converted to an integer.

Parameters:
key - the header key.
Returns:
the value of the header as an integer.

getDateHeader

public long getDateHeader(java.lang.String key)
Returns a header interpreted as a date.

Parameters:
key - the header key.
Returns:
the value of the header as an integer.

getContentLength

public int getContentLength()
Returns the content length of a post.


getLongContentLength

public long getLongContentLength()
Returns the content length of a post.


getContentType

public java.lang.String getContentType()
Returns the content-length of a post.


getContentTypeBuffer

public CharSegment getContentTypeBuffer()
Returns the content-length of a post.


getCharacterEncoding

public java.lang.String getCharacterEncoding()
Returns the character encoding of a post.


setCharacterEncoding

public void setCharacterEncoding(java.lang.String encoding)
                          throws java.io.UnsupportedEncodingException
Sets the character encoding of a post.

Throws:
java.io.UnsupportedEncodingException

getCookies

public Cookie[] getCookies()
Returns the cookies from the browser


findSessionIdFromConnection

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


isTransportSecure

public boolean isTransportSecure()
Returns true if the transport is secure.

Specified by:
isTransportSecure in interface SecurityContextProvider

getStream

public ReadStream getStream()
                     throws java.io.IOException
Returns the requests underlying read stream, e.g. the post stream.

Throws:
java.io.IOException

getStream

public ReadStream getStream(boolean isReader)
                     throws java.io.IOException
Returns the requests underlying read stream, e.g. the post stream.

Throws:
java.io.IOException

getRawRead

public final ReadStream getRawRead()

getReadStream

public final ReadStream getReadStream()

getRawReadBuffer

public byte[] getRawReadBuffer()
Returns the raw read buffer.


getAvailable

public int getAvailable()
                 throws java.io.IOException
Throws:
java.io.IOException

skip

protected void skip()
             throws java.io.IOException
Throws:
java.io.IOException

initStream

protected abstract boolean initStream(ReadStream readStream,
                                      ReadStream rawStream)
                               throws java.io.IOException
Initialize the read stream from the raw stream.

Throws:
java.io.IOException

getRawInput

public ReadStream getRawInput()
Returns the raw input stream.


getInputStream

public final ServletInputStream getInputStream()
                                        throws java.io.IOException
Returns a stream for reading POST data.

Throws:
java.io.IOException

getReader

public final java.io.BufferedReader getReader()
                                       throws java.io.IOException
Returns a Reader for the POST contents

Throws:
java.io.IOException

initAttributes

protected void initAttributes(HttpServletRequestImpl facade)

getLocale

public java.util.Locale getLocale()

getLocales

public java.util.Enumeration<java.util.Locale> getLocales()

isSecure

public boolean isSecure()
Returns true if the request is secure.


runAs

public java.lang.String runAs(java.lang.String string)
Description copied from interface: SecurityContextProvider
Sets the current runAs role/principal. This should affect isUserInRole and getUserPrincipal.

Specified by:
runAs in interface SecurityContextProvider
Parameters:
string - the new role
Returns:
the old run-as role

isUserInRole

public boolean isUserInRole(java.lang.String role)
Description copied from interface: SecurityContextProvider
Returns true if the user principal plays the named role.

Specified by:
isUserInRole in interface SecurityContextProvider
Parameters:
role - the permission to test against.

getUserPrincipal

public java.security.Principal getUserPrincipal()
Description copied from interface: SecurityContextProvider
Returns the Principal for the context.

Specified by:
getUserPrincipal in interface SecurityContextProvider
Returns:
the principal in the context or null.

getStartTime

public final long getStartTime()
Returns the date for the current request.


getLogBuffer

public final byte[] getLogBuffer()
Returns the log buffer.


getInvocation

protected Invocation getInvocation(java.lang.CharSequence host,
                                   byte[] uri,
                                   int uriLength)
                            throws java.io.IOException
Throws:
java.io.IOException

buildInvocation

protected Invocation buildInvocation(Invocation invocation,
                                     byte[] uri,
                                     int uriLength)
                              throws java.io.IOException
Throws:
java.io.IOException

handleResume

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

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

startDuplex

public SocketLinkDuplexController startDuplex(SocketLinkDuplexListener handler)
Starts duplex mode.


sendRequestError

protected void sendRequestError(java.lang.Throwable e)
                         throws java.io.IOException
Throws:
java.io.IOException

getErrorManager

protected ErrorPageManager getErrorManager()
Returns the default error manager


killKeepalive

public void killKeepalive(java.lang.String reason)
Kills the keepalive.


isKeepalive

protected boolean isKeepalive()
Returns true if the keepalive is active.


isCometActive

public boolean isCometActive()

isSuspend

public boolean isSuspend()

isDuplex

public boolean isDuplex()

getForm

protected HashMapImpl<java.lang.String,java.lang.String[]> getForm()

getFormParser

protected Form getFormParser()

restartServer

protected void restartServer()
Restarts the server.


startInvocation

protected void startInvocation()
                        throws java.io.IOException
Prepare the Request object for a new request.

Throws:
java.io.IOException

finishInvocation

public void finishInvocation()
Cleans up at the end of the invocation


finishRequest

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

Throws:
java.io.IOException

onCloseConnection

public void onCloseConnection()
Description copied from interface: ProtocolConnection
Handles a close event when the connection is closed.

Specified by:
onCloseConnection in interface ProtocolConnection

cleanup

public void cleanup()

shutdown

public void shutdown()
Called by server shutdown to kill any active threads


dbgId

protected java.lang.String dbgId()