org.apache.tomcat.core
Class Request

java.lang.Object
  extended byorg.apache.tomcat.core.Request
Direct Known Subclasses:
JNIRequestAdapter

public class Request
extends java.lang.Object

This is a low-level, efficient representation of a server request. Most fields are GC-free, expensive operations are delayed until the user code needs the information. Most processing is delegated to modules, using a hook mechanism. This class is not intended for user code - it is used internally by tomcat for processing the request in the most efficient way. Users ( servlets ) can access the information using a facade, which provides the high-level view of the request. For lazy evaluation, the request uses the getInfo() hook. The following ids are defined:

Tomcat defines a number of attributes:

Author:
James Duncan Davidson [duncan@eng.sun.com], James Todd [gonzo@eng.sun.com], Jason Hunter [jch@eng.sun.com], Harish Prabandham, Alex Cruikshank [alex@epitonic.com], Hans Bergsten [hans@gefionsoftware.com], Costin Manolache

Field Summary
static java.lang.String ATTRIB_REAL_REQUEST
          Magic attribute that allows access to the real request from facade - for trusted applications
protected  java.util.Hashtable attributes
           
protected  java.lang.String authType
           
protected  int available
           
protected  java.lang.String charEncoding
           
protected  Request child
           
protected  Container container
           
protected  int contentLength
           
protected  MessageBytes contentTypeMB
           
protected  Context context
           
protected  ContextManager contextM
           
protected  MessageBytes contextMB
           
static java.lang.String DEFAULT_CHARACTER_ENCODING
           
protected  boolean didReadFormData
           
protected  java.lang.Exception errorException
           
protected  Handler handler
           
protected  MimeHeaders headers
           
protected  java.lang.String jvmRoute
           
protected  java.lang.String localHost
           
static int MAX_INCLUDE
           
protected  MessageBytes methodMB
           
protected  boolean notAuthenticated
           
protected  Parameters params
           
protected  Request parent
           
protected  MessageBytes pathInfoMB
           
protected  java.security.Principal principal
           
protected  MessageBytes protoMB
           
protected  MessageBytes queryMB
           
protected  MessageBytes remoteAddrMB
           
protected  MessageBytes remoteHostMB
           
protected  java.lang.String remoteUser
           
protected  java.lang.String[] reqRoles
           
protected  java.lang.String reqSessionId
           
protected  java.lang.Object requestFacade
           
protected  Response response
           
protected  MessageBytes schemeMB
           
protected  Cookies scookies
           
protected  Container security
           
protected  MessageBytes serverNameMB
           
protected  int serverPort
           
protected  ServerSession serverSession
           
protected  MessageBytes servletPathMB
           
protected  java.lang.String sessionId
           
static java.lang.String SESSIONID_FROM_COOKIE
           
static java.lang.String SESSIONID_FROM_URL
           
protected  java.lang.String sessionIdSource
           
protected  int state
           
static int STATE_CONTEXT_MAPPED
           
static int STATE_INVALID
           
static int STATE_MAPPED
           
static int STATE_NEW
           
static int STATE_UNUSED
           
protected  Request top
           
protected  MessageBytes unparsedURIMB
           
protected  MessageBytes uriMB
           
protected  UDecoder urlDecoder
           
protected  java.lang.String[] userRoles
           
 
Constructor Summary
Request()
           
 
Method Summary
 MessageBytes contentType()
           
 int doRead()
           
 int doRead(byte[] b, int off, int len)
          Fill in the buffer.
 java.lang.Object getAttribute(java.lang.String name)
           
 java.util.Enumeration getAttributeNames()
           
 java.lang.String getAuthType()
           
 int getAvailable()
          How many bytes from the body are still available
 java.lang.String getCharacterEncoding()
           
 java.lang.String getCharEncoding()
           
 Request getChild()
          During include, a sub-request will be created.
 Container getContainer()
          Return the container ( URL pattern ) where this request has been mapped.
 int getContentLength()
           
 java.lang.String getContentType()
          Deprecated.  
 Context getContext()
           
 ContextManager getContextManager()
           
 Cookies getCookies()
           
 java.lang.Object getFacade()
           
 Handler getHandler()
          As result of mapping the request a "handler" will be associated and called to generate the result.
 java.lang.String getHeader(java.lang.String name)
          Deprecated.  
 java.util.Enumeration getHeaderNames()
          Deprecated.  
 java.util.Enumeration getHeaders(java.lang.String name)
          Deprecated.  
 java.lang.String getJvmRoute()
           
 java.lang.String getLocalHost()
           
 java.lang.String getMethod()
          Deprecated. After Tomcat 3.2, use method() instead
 MimeHeaders getMimeHeaders()
           
 java.lang.Object getNote(int pos)
           
 java.lang.Object getNote(java.lang.String name)
           
 Request getParent()
          If this is a sub-request, return the parent ( the request embeding this request )
 java.lang.String getRemoteUser()
           
 java.lang.String getRequestedSessionId()
          Session ID requested by client as a cookie or any other method.
 java.lang.String getRequestURI()
          Deprecated. After Tomcat 3.2, use requestURI() instead
 java.lang.String[] getRequiredRoles()
          Deprecated. use getSecurityContext
 Response getResponse()
           
 Container getSecurityContext()
          Return the associated security properties for the request.
 int getServerPort()
           
 ServerSession getSession(boolean create)
           
 java.lang.String getSessionId()
           
 java.lang.String getSessionIdSource()
          Method used to determine requestedSessionId
 int getState()
           
 Request getTop()
          This is the top request ( for a sub-request )
 UDecoder getURLDecoder()
           
 java.security.Principal getUserPrincipal()
          Return the principal - the adapter will set it
 java.lang.String[] getUserRoles()
           
 void handlePostParameters()
          Read the body, if POST, and add the post parameters.
 void handleQueryParameters()
           
 void initRequest()
           
 boolean isSecure()
           
 boolean isUserInRole(java.lang.String role)
           
 MessageBytes method()
           
 Parameters parameters()
           
 MessageBytes pathInfo()
           
 MessageBytes protocol()
           
 MessageBytes query()
           
 MessageBytes queryString()
           
 int readBody(byte[] body, int len)
          Read request data, filling a byte[]
 void recycle()
           
 MessageBytes remoteAddr()
           
 MessageBytes remoteHost()
           
 void removeAttribute(java.lang.String name)
           
 MessageBytes requestURI()
           
 MessageBytes scheme()
           
 MessageBytes serverName()
          Return the buffer holding the server name, if any.
 MessageBytes servletPath()
           
 void setAttribute(java.lang.String name, java.lang.Object value)
           
 void setAuthType(java.lang.String authType)
           
 void setAvailable(int len)
           
 void setCharEncoding(java.lang.String enc)
           
 void setChild(Request req)
           
 void setContainer(Container container)
           
 void setContentLength(int len)
           
 void setContentType(MessageBytes mb)
          Deprecated.  
 void setContentType(java.lang.String type)
          Deprecated.  
 void setContext(Context context)
          Called by mapper interceptors after the context is found or directly by server adapters when this is known in advance
 void setContextManager(ContextManager cm)
           
 void setFacade(java.lang.Object facade)
           
 void setHandler(Handler handler)
           
 void setJvmRoute(java.lang.String jvmRoute)
           
 void setLocalHost(java.lang.String host)
           
 void setMethod(java.lang.String method)
          Deprecated. After Tomcat 3.2, use method() instead
 void setNote(int pos, java.lang.Object value)
           
 void setNote(java.lang.String name, java.lang.Object value)
           
 void setParent(Request req)
           
 void setRemoteUser(java.lang.String s)
           
 void setRequestedSessionId(java.lang.String reqSessionId)
           
 void setRequestURI(java.lang.String r)
          Deprecated. After Tomcat 3.2, use requestURI() instead
 void setRequiredRoles(java.lang.String[] roles)
           
 void setResponse(Response response)
           
 void setSecurityContext(Container ct)
           
 void setServerPort(int serverPort)
           
 void setSession(ServerSession serverSession)
          Set the session associated with this request.
 void setSessionId(java.lang.String id)
          "Real" session Id, coresponding to an existing ServerSession
 void setSessionIdSource(java.lang.String s)
           
 void setState(int state)
           
 void setUserPrincipal(java.security.Principal p)
           
 void setUserRoles(java.lang.String[] roles)
          Deprecated. use setSecurityContext
 java.lang.String toString()
           
 MessageBytes unparsedURI()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

DEFAULT_CHARACTER_ENCODING

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

SESSIONID_FROM_COOKIE

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

SESSIONID_FROM_URL

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

MAX_INCLUDE

public static final int MAX_INCLUDE
See Also:
Constant Field Values

ATTRIB_REAL_REQUEST

public static final java.lang.String ATTRIB_REAL_REQUEST
Magic attribute that allows access to the real request from facade - for trusted applications

See Also:
Constant Field Values

STATE_UNUSED

public static final int STATE_UNUSED
See Also:
Constant Field Values

STATE_INVALID

public static final int STATE_INVALID
See Also:
Constant Field Values

STATE_NEW

public static final int STATE_NEW
See Also:
Constant Field Values

STATE_CONTEXT_MAPPED

public static final int STATE_CONTEXT_MAPPED
See Also:
Constant Field Values

STATE_MAPPED

public static final int STATE_MAPPED
See Also:
Constant Field Values

serverPort

protected int serverPort

localHost

protected java.lang.String localHost

state

protected int state

schemeMB

protected MessageBytes schemeMB

unparsedURIMB

protected MessageBytes unparsedURIMB

methodMB

protected MessageBytes methodMB

uriMB

protected MessageBytes uriMB

queryMB

protected MessageBytes queryMB

protoMB

protected MessageBytes protoMB

contextMB

protected MessageBytes contextMB

servletPathMB

protected MessageBytes servletPathMB

pathInfoMB

protected MessageBytes pathInfoMB

remoteAddrMB

protected MessageBytes remoteAddrMB

remoteHostMB

protected MessageBytes remoteHostMB

jvmRoute

protected java.lang.String jvmRoute

attributes

protected java.util.Hashtable attributes

headers

protected MimeHeaders headers

params

protected Parameters params

didReadFormData

protected boolean didReadFormData

contentLength

protected int contentLength

available

protected int available

contentTypeMB

protected MessageBytes contentTypeMB

charEncoding

protected java.lang.String charEncoding

serverNameMB

protected MessageBytes serverNameMB

authType

protected java.lang.String authType

notAuthenticated

protected boolean notAuthenticated

remoteUser

protected java.lang.String remoteUser

principal

protected java.security.Principal principal

userRoles

protected java.lang.String[] userRoles

security

protected Container security

reqRoles

protected java.lang.String[] reqRoles

response

protected Response response

contextM

protected ContextManager contextM

context

protected Context context

requestFacade

protected java.lang.Object requestFacade

reqSessionId

protected java.lang.String reqSessionId

sessionIdSource

protected java.lang.String sessionIdSource

sessionId

protected java.lang.String sessionId

serverSession

protected ServerSession serverSession

handler

protected Handler handler

container

protected Container container

scookies

protected Cookies scookies

top

protected Request top

parent

protected Request parent

child

protected Request child

urlDecoder

protected UDecoder urlDecoder

errorException

protected java.lang.Exception errorException
Constructor Detail

Request

public Request()
Method Detail

getState

public final int getState()

setState

public final void setState(int state)

setContext

public void setContext(Context context)
Called by mapper interceptors after the context is found or directly by server adapters when this is known in advance


getContext

public Context getContext()

getURLDecoder

public UDecoder getURLDecoder()

setContextManager

public void setContextManager(ContextManager cm)

getContextManager

public ContextManager getContextManager()

getFacade

public java.lang.Object getFacade()

setFacade

public void setFacade(java.lang.Object facade)

setResponse

public void setResponse(Response response)

getResponse

public Response getResponse()

getMimeHeaders

public MimeHeaders getMimeHeaders()

scheme

public MessageBytes scheme()

method

public MessageBytes method()

getMethod

public java.lang.String getMethod()
Deprecated. After Tomcat 3.2, use method() instead


setMethod

public void setMethod(java.lang.String method)
Deprecated. After Tomcat 3.2, use method() instead


requestURI

public MessageBytes requestURI()

getRequestURI

public java.lang.String getRequestURI()
Deprecated. After Tomcat 3.2, use requestURI() instead


setRequestURI

public void setRequestURI(java.lang.String r)
Deprecated. After Tomcat 3.2, use requestURI() instead


unparsedURI

public MessageBytes unparsedURI()

query

public MessageBytes query()

queryString

public MessageBytes queryString()

servletPath

public MessageBytes servletPath()

pathInfo

public MessageBytes pathInfo()

protocol

public MessageBytes protocol()

serverName

public MessageBytes serverName()
Return the buffer holding the server name, if any. Use isNull() to check if there is no value set. This is the "virtual host", derived from the Host: header.


getServerPort

public int getServerPort()

setServerPort

public void setServerPort(int serverPort)

remoteAddr

public MessageBytes remoteAddr()

remoteHost

public MessageBytes remoteHost()

getLocalHost

public java.lang.String getLocalHost()

setLocalHost

public void setLocalHost(java.lang.String host)

handlePostParameters

public void handlePostParameters()
Read the body, if POST, and add the post parameters. Before this method is called, only query-line parameters are available.


handleQueryParameters

public void handleQueryParameters()

parameters

public Parameters parameters()

getCharacterEncoding

public java.lang.String getCharacterEncoding()

getCharEncoding

public java.lang.String getCharEncoding()

setCharEncoding

public void setCharEncoding(java.lang.String enc)

setContentLength

public void setContentLength(int len)

getContentLength

public int getContentLength()

getContentType

public java.lang.String getContentType()
Deprecated.  


setContentType

public void setContentType(java.lang.String type)
Deprecated.  


contentType

public MessageBytes contentType()

setContentType

public void setContentType(MessageBytes mb)
Deprecated.  


setAuthType

public void setAuthType(java.lang.String authType)

getAuthType

public java.lang.String getAuthType()

setRemoteUser

public void setRemoteUser(java.lang.String s)

getRemoteUser

public java.lang.String getRemoteUser()

isSecure

public boolean isSecure()

setUserPrincipal

public void setUserPrincipal(java.security.Principal p)

getUserPrincipal

public java.security.Principal getUserPrincipal()
Return the principal - the adapter will set it


setRequiredRoles

public void setRequiredRoles(java.lang.String[] roles)

getSecurityContext

public Container getSecurityContext()
Return the associated security properties for the request. This is set up during mapping using the configured constraints. The container holds various security properties that are checked using authorize() hook. If no security context is set the authorize hook will not be called.


setSecurityContext

public void setSecurityContext(Container ct)

getRequiredRoles

public java.lang.String[] getRequiredRoles()
Deprecated. use getSecurityContext


setUserRoles

public void setUserRoles(java.lang.String[] roles)
Deprecated. use setSecurityContext


getUserRoles

public java.lang.String[] getUserRoles()

isUserInRole

public boolean isUserInRole(java.lang.String role)

getJvmRoute

public java.lang.String getJvmRoute()

setJvmRoute

public void setJvmRoute(java.lang.String jvmRoute)

getRequestedSessionId

public java.lang.String getRequestedSessionId()
Session ID requested by client as a cookie or any other method. It may be a valid ( and existing ) session or not.


setRequestedSessionId

public void setRequestedSessionId(java.lang.String reqSessionId)

getSessionIdSource

public java.lang.String getSessionIdSource()
Method used to determine requestedSessionId


setSessionIdSource

public void setSessionIdSource(java.lang.String s)

setSessionId

public void setSessionId(java.lang.String id)
"Real" session Id, coresponding to an existing ServerSession


getSessionId

public java.lang.String getSessionId()

setSession

public void setSession(ServerSession serverSession)
Set the session associated with this request. This can be the current session or a new session, set by a session interceptor. Important: you also need to set the session id ( this is needed to cleanly separate the layers, and will be improved soon - the whole session management will follow after core is done )


getSession

public ServerSession getSession(boolean create)

getCookies

public Cookies getCookies()

getHandler

public Handler getHandler()
As result of mapping the request a "handler" will be associated and called to generate the result. The handler is null if no mapping was found ( so far ). The handler can be set if the request is found to match any of the rules defined in web.xml ( and as a result, a container will be set ), or if a special interceptor will define a tomcat-specific handler ( like static, jsp, or invoker ).


setHandler

public void setHandler(Handler handler)

getContainer

public Container getContainer()
Return the container ( URL pattern ) where this request has been mapped. If the request is invalid ( context can't be determined ) the ContextManager.container will be returned. If the request is not mapped ( requestMap not called yet ) or the request corresponds to the "default" map ( * ) or a special implicit map ( *.jsp, invoker ), then the context's default container is returned


setContainer

public void setContainer(Container container)

getAttribute

public java.lang.Object getAttribute(java.lang.String name)

setAttribute

public void setAttribute(java.lang.String name,
                         java.lang.Object value)

removeAttribute

public void removeAttribute(java.lang.String name)

getAttributeNames

public java.util.Enumeration getAttributeNames()

getParent

public Request getParent()
If this is a sub-request, return the parent ( the request embeding this request )


setParent

public void setParent(Request req)

getChild

public Request getChild()
During include, a sub-request will be created. This represents the current included request


setChild

public void setChild(Request req)

getTop

public Request getTop()
This is the top request ( for a sub-request )


getHeaders

public java.util.Enumeration getHeaders(java.lang.String name)
Deprecated.  


getHeader

public java.lang.String getHeader(java.lang.String name)
Deprecated.  


getHeaderNames

public java.util.Enumeration getHeaderNames()
Deprecated.  


setAvailable

public void setAvailable(int len)

getAvailable

public int getAvailable()
How many bytes from the body are still available


doRead

public int doRead(byte[] b,
                  int off,
                  int len)
           throws java.io.IOException
Fill in the buffer. This method is probably easier to implement than previous. This method should only be called from SerlvetInputStream implementations. No need to implement it if your adapter implements ServletInputStream.

Throws:
java.io.IOException

doRead

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

readBody

public int readBody(byte[] body,
                    int len)
             throws java.io.IOException
Read request data, filling a byte[]

Throws:
java.io.IOException

toString

public java.lang.String toString()

setNote

public final void setNote(int pos,
                          java.lang.Object value)

getNote

public final java.lang.Object getNote(int pos)

getNote

public java.lang.Object getNote(java.lang.String name)
                         throws TomcatException
Throws:
TomcatException

setNote

public void setNote(java.lang.String name,
                    java.lang.Object value)
             throws TomcatException
Throws:
TomcatException

recycle

public void recycle()

initRequest

public void initRequest()


Copyright © 2001 Apache Software Foundation. All Rights Reserved.