org.apache.ajp

Class RequestHandler


public class RequestHandler
extends AjpHandler

Handle messages related with basic request information. This object can handle the following incoming messages: - "FORWARD_REQUEST" input message ( sent when a request is passed from the web server ) - "PING REQUEST" input message (sent by the web server to determine if tomcat is not frozen, a PONG REPLY will be sent back) - "RECEIVE_BODY_CHUNK" input ( sent by container to pass more body, in response to GET_BODY_CHUNK ) It can handle the following outgoing messages: - SEND_HEADERS. Pass the status code and headers. - SEND_BODY_CHUNK. Send a chunk of body - GET_BODY_CHUNK. Request a chunk of body data - END_RESPONSE. Notify the end of a request processing.

Authors:
Henri Gomez [hgomez@apache.org]
Dan Milstein [danmil@shore.net]
Keith Wannamaker [Keith@Wannamaker.org]
Costin Manolache

Field Summary

static byte
JK_AJP13_CPING_REQUEST
static byte
JK_AJP13_CPONG_REPLY
static byte
JK_AJP13_END_RESPONSE
static byte
JK_AJP13_FORWARD_REQUEST
static byte
JK_AJP13_GET_BODY_CHUNK
static byte
JK_AJP13_PING_REQUEST
static byte
JK_AJP13_SEND_BODY_CHUNK
static byte
JK_AJP13_SEND_HEADERS
static byte
JK_AJP13_SHUTDOWN
static byte
SC_A_ARE_DONE
static byte
SC_A_AUTH_TYPE
static byte
SC_A_CONTEXT
static byte
SC_A_JVM_ROUTE
static byte
SC_A_QUERY_STRING
static byte
SC_A_REMOTE_USER
static byte
SC_A_REQ_ATTRIBUTE
static byte
SC_A_SECRET
static byte
SC_A_SERVLET_PATH
static byte
SC_A_SSL_CERT
static byte
SC_A_SSL_CIPHER
static byte
SC_A_SSL_KEY_SIZE
static byte
SC_A_SSL_SESSION
static byte
SC_A_STORED_METHOD
static int
SC_M_JK_STORED
static int
SC_REQ_ACCEPT
static int
SC_REQ_ACCEPT_CHARSET
static int
SC_REQ_ACCEPT_ENCODING
static int
SC_REQ_ACCEPT_LANGUAGE
static int
SC_REQ_AUTHORIZATION
static int
SC_REQ_CONNECTION
static int
SC_REQ_CONTENT_LENGTH
static int
SC_REQ_CONTENT_TYPE
static int
SC_REQ_COOKIE
static int
SC_REQ_COOKIE2
static int
SC_REQ_HOST
static int
SC_REQ_PRAGMA
static int
SC_REQ_REFERER
static int
SC_REQ_USER_AGENT
static int
SC_RESP_CONTENT_LANGUAGE
static int
SC_RESP_CONTENT_LENGTH
static int
SC_RESP_CONTENT_TYPE
static int
SC_RESP_DATE
static int
SC_RESP_LAST_MODIFIED
static int
SC_RESP_LOCATION
static int
SC_RESP_SERVLET_ENGINE
static int
SC_RESP_SET_COOKIE
static int
SC_RESP_SET_COOKIE2
static int
SC_RESP_STATUS
static int
SC_RESP_WWW_AUTHENTICATE
static String[]
headerTransArray
static String[]
methodTransArray

Fields inherited from class org.apache.ajp.AjpHandler

UNKNOWN

Constructor Summary

RequestHandler()

Method Summary

int
available(Ajp13 ch)
void
beginSendHeaders(Ajp13 ch, Ajp13Packet outBuf, int status, String statusMessage, int numHeaders)
protected int
decodeRequest(Ajp13 ch, Ajp13Packet msg, BaseRequest req)
Parse a FORWARD_REQUEST packet from the web server and store its properties in the passed-in request object.
int
doRead(Ajp13 ch)
Return the next byte of request body data (to a servlet).
int
doRead(Ajp13 ch, byte[] b, int off, int len)
Store a chunk of request data into the passed-in byte buffer.
void
doWrite(Ajp13 ch, Ajp13Packet outBuf, b[] , int off, int len)
Send a chunk of response body data to the web server and on to the browser.
void
endSendHeaders(Ajp13 ch, Ajp13Packet outBuf)
void
finish(Ajp13 ch, Ajp13Packet outBuf)
Signal the web server that the servlet has finished handling this request, and that the connection can be reused.
int
handleAjpMessage(int type, Ajp13 channel, Ajp13Packet ajp, BaseRequest req)
protected int
headerNameToSc(String name)
Translate an HTTP response header name to an integer code if possible.
void
init(Ajp13 ajp14)
boolean
refillReadBuffer(Ajp13 ch)
Get more request body data from the web server and store it in the internal buffer.
int
sendCPong(Ajp13 ch, Ajp13Packet outBuf)
Send a CPONG REPLY to web server to its CPING request
void
sendHeader(Ajp13Packet outBuf, String name, String value)
void
sendHeaders(Ajp13 ch, Ajp13Packet outBuf, int status, String statusMessage, MimeHeaders headers)
Send the HTTP headers back to the web server and on to the browser.
void
sendHeaders(Ajp13 ch, Ajp13Packet outBuf, int status, MimeHeaders headers)
Send the HTTP headers back to the web server and on to the browser.
void
setDebug(int debug)
void
setLogger(Logger l)

Methods inherited from class org.apache.ajp.AjpHandler

handleAjpMessage, init

Field Details

JK_AJP13_CPING_REQUEST

public static final byte JK_AJP13_CPING_REQUEST

Field Value:
10


JK_AJP13_CPONG_REPLY

public static final byte JK_AJP13_CPONG_REPLY

Field Value:
9


JK_AJP13_END_RESPONSE

public static final byte JK_AJP13_END_RESPONSE

Field Value:
5


JK_AJP13_FORWARD_REQUEST

public static final byte JK_AJP13_FORWARD_REQUEST

Field Value:
2


JK_AJP13_GET_BODY_CHUNK

public static final byte JK_AJP13_GET_BODY_CHUNK

Field Value:
6


JK_AJP13_PING_REQUEST

public static final byte JK_AJP13_PING_REQUEST

Field Value:
8


JK_AJP13_SEND_BODY_CHUNK

public static final byte JK_AJP13_SEND_BODY_CHUNK

Field Value:
3


JK_AJP13_SEND_HEADERS

public static final byte JK_AJP13_SEND_HEADERS

Field Value:
4


JK_AJP13_SHUTDOWN

public static final byte JK_AJP13_SHUTDOWN

Field Value:
7


SC_A_ARE_DONE

public static final byte SC_A_ARE_DONE

Field Value:
-1


SC_A_AUTH_TYPE

public static final byte SC_A_AUTH_TYPE

Field Value:
4


SC_A_CONTEXT

public static final byte SC_A_CONTEXT

Field Value:
1


SC_A_JVM_ROUTE

public static final byte SC_A_JVM_ROUTE

Field Value:
6


SC_A_QUERY_STRING

public static final byte SC_A_QUERY_STRING

Field Value:
5


SC_A_REMOTE_USER

public static final byte SC_A_REMOTE_USER

Field Value:
3


SC_A_REQ_ATTRIBUTE

public static final byte SC_A_REQ_ATTRIBUTE

Field Value:
10


SC_A_SECRET

public static final byte SC_A_SECRET

Field Value:
12


SC_A_SERVLET_PATH

public static final byte SC_A_SERVLET_PATH

Field Value:
2


SC_A_SSL_CERT

public static final byte SC_A_SSL_CERT

Field Value:
7


SC_A_SSL_CIPHER

public static final byte SC_A_SSL_CIPHER

Field Value:
8


SC_A_SSL_KEY_SIZE

public static final byte SC_A_SSL_KEY_SIZE

Field Value:
11


SC_A_SSL_SESSION

public static final byte SC_A_SSL_SESSION

Field Value:
9


SC_A_STORED_METHOD

public static final byte SC_A_STORED_METHOD

Field Value:
13


SC_M_JK_STORED

public static final int SC_M_JK_STORED

Field Value:
-1


SC_REQ_ACCEPT

public static final int SC_REQ_ACCEPT

Field Value:
1


SC_REQ_ACCEPT_CHARSET

public static final int SC_REQ_ACCEPT_CHARSET

Field Value:
2


SC_REQ_ACCEPT_ENCODING

public static final int SC_REQ_ACCEPT_ENCODING

Field Value:
3


SC_REQ_ACCEPT_LANGUAGE

public static final int SC_REQ_ACCEPT_LANGUAGE

Field Value:
4


SC_REQ_AUTHORIZATION

public static final int SC_REQ_AUTHORIZATION

Field Value:
5


SC_REQ_CONNECTION

public static final int SC_REQ_CONNECTION

Field Value:
6


SC_REQ_CONTENT_LENGTH

public static final int SC_REQ_CONTENT_LENGTH

Field Value:
8


SC_REQ_CONTENT_TYPE

public static final int SC_REQ_CONTENT_TYPE

Field Value:
7


SC_REQ_COOKIE

public static final int SC_REQ_COOKIE

Field Value:
9


SC_REQ_COOKIE2

public static final int SC_REQ_COOKIE2

Field Value:
10


SC_REQ_HOST

public static final int SC_REQ_HOST

Field Value:
11


SC_REQ_PRAGMA

public static final int SC_REQ_PRAGMA

Field Value:
12


SC_REQ_REFERER

public static final int SC_REQ_REFERER

Field Value:
13


SC_REQ_USER_AGENT

public static final int SC_REQ_USER_AGENT

Field Value:
14


SC_RESP_CONTENT_LANGUAGE

public static final int SC_RESP_CONTENT_LANGUAGE

Field Value:
40962


SC_RESP_CONTENT_LENGTH

public static final int SC_RESP_CONTENT_LENGTH

Field Value:
40963


SC_RESP_CONTENT_TYPE

public static final int SC_RESP_CONTENT_TYPE

Field Value:
40961


SC_RESP_DATE

public static final int SC_RESP_DATE

Field Value:
40964


SC_RESP_LAST_MODIFIED

public static final int SC_RESP_LAST_MODIFIED

Field Value:
40965


SC_RESP_LOCATION

public static final int SC_RESP_LOCATION

Field Value:
40966


SC_RESP_SERVLET_ENGINE

public static final int SC_RESP_SERVLET_ENGINE

Field Value:
40969


SC_RESP_SET_COOKIE

public static final int SC_RESP_SET_COOKIE

Field Value:
40967


SC_RESP_SET_COOKIE2

public static final int SC_RESP_SET_COOKIE2

Field Value:
40968


SC_RESP_STATUS

public static final int SC_RESP_STATUS

Field Value:
40970


SC_RESP_WWW_AUTHENTICATE

public static final int SC_RESP_WWW_AUTHENTICATE

Field Value:
40971


headerTransArray

public static final String[] headerTransArray


methodTransArray

public static final String[] methodTransArray

Constructor Details

RequestHandler

public RequestHandler()

Method Details

available

public int available(Ajp13 ch)
            throws IOException


beginSendHeaders

public void beginSendHeaders(Ajp13 ch,
                             Ajp13Packet outBuf,
                             int status,
                             String statusMessage,
                             int numHeaders)
            throws IOException


decodeRequest

protected int decodeRequest(Ajp13 ch,
                            Ajp13Packet msg,
                            BaseRequest req)
            throws IOException
Parse a FORWARD_REQUEST packet from the web server and store its properties in the passed-in request object.

Parameters:
msg - Holds the packet which has just been sent by the web server, with its read position just past the packet header (which in this case includes the prefix code for FORWARD_REQUEST).
req - An empty (newly-recycled) request object.

Returns:
200 in case of a successful decoduing, 500 in case of error.


doRead

public int doRead(Ajp13 ch)
            throws IOException
Return the next byte of request body data (to a servlet).

See Also:
Request.doRead


doRead

public int doRead(Ajp13 ch,
                  byte[] b,
                  int off,
                  int len)
            throws IOException
Store a chunk of request data into the passed-in byte buffer.

Parameters:
b - A buffer to fill with data from the request.
off - The offset in the buffer at which to start filling.
len - The number of bytes to copy into the buffer.

Returns:
The number of bytes actually copied into the buffer, or -1 if the end of the stream has been reached.

See Also:
Request.doRead


doWrite

public void doWrite(Ajp13 ch,
                    Ajp13Packet outBuf,
                    b[] ,
                    int off,
                    int len)
            throws IOException
Send a chunk of response body data to the web server and on to the browser.

Parameters:
off - The offset into the buffer from which to start sending.
len - The number of bytes to send.


endSendHeaders

public void endSendHeaders(Ajp13 ch,
                           Ajp13Packet outBuf)
            throws IOException


finish

public void finish(Ajp13 ch,
                   Ajp13Packet outBuf)
            throws IOException
Signal the web server that the servlet has finished handling this request, and that the connection can be reused.


handleAjpMessage

public int handleAjpMessage(int type,
                            Ajp13 channel,
                            Ajp13Packet ajp,
                            BaseRequest req)
            throws IOException
Overrides:
handleAjpMessage in interface AjpHandler


headerNameToSc

protected int headerNameToSc(String name)
Translate an HTTP response header name to an integer code if possible. Case is ignored.

Parameters:
name - The name of the response header to translate.

Returns:
The code for that header name, or -1 if no code exists.


init

public void init(Ajp13 ajp14)
Overrides:
init in interface AjpHandler


refillReadBuffer

public boolean refillReadBuffer(Ajp13 ch)
            throws IOException
Get more request body data from the web server and store it in the internal buffer.

Returns:
true if there is more data, false if not.


sendCPong

public int sendCPong(Ajp13 ch,
                     Ajp13Packet outBuf)
Send a CPONG REPLY to web server to its CPING request

Parameters:
ch - the Ajp13 channel
outBuf - the Ajp13Packet output packet to use


sendHeader

public void sendHeader(Ajp13Packet outBuf,
                       String name,
                       String value)
            throws IOException


sendHeaders

public void sendHeaders(Ajp13 ch,
                        Ajp13Packet outBuf,
                        int status,
                        String statusMessage,
                        MimeHeaders headers)
            throws IOException
Send the HTTP headers back to the web server and on to the browser.

Parameters:
status - The HTTP status code to send.
statusMessage - the HTTP status message to send.
headers - The set of all headers.


sendHeaders

public void sendHeaders(Ajp13 ch,
                        Ajp13Packet outBuf,
                        int status,
                        MimeHeaders headers)
            throws IOException
Send the HTTP headers back to the web server and on to the browser.

Parameters:
status - The HTTP status code to send.
headers - The set of all headers.


setDebug

public void setDebug(int debug)


setLogger

public void setLogger(Logger l)


Copyright B) 2000-2003 Apache Software Foundation. All Rights Reserved.