org.apache.ajp

Class Ajp13


public class Ajp13
extends java.lang.Object

Represents a single, persistent connection between the web server and the servlet container. Uses the Apache JServ Protocol version 1.3 for communication. Because this protocal does not multiplex requests, this connection can only be associated with a single request-handling cycle at a time.

This class contains knowledge about how an individual packet is laid out (via the Ajp13Packet class), and also about the stages of communicaton between the server and the servlet container. It translates from Tomcat's internal servlet support methods (e.g. doWrite) to the correct packets to send to the web server.

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

See Also:
Ajp13Interceptor

Field Summary

static int
H_SIZE
static int
JK_AJP13_BAD_BODY
static int
JK_AJP13_BAD_HEADER
static int
JK_AJP13_COMM_BROKEN
static int
JK_AJP13_COMM_CLOSED
static int
JK_AJP13_INCOMPLETE_BODY
static int
JK_AJP13_NO_HEADER
static int
MAX_PACKET_SIZE
static int
MAX_READ_SIZE
static int
MAX_SEND_SIZE
protected int
debug
Ajp13Packet
outBuf
RequestHandler
reqHandler

Constructor Summary

Ajp13()
Ajp13(RequestHandler reqHandler)

Method Summary

int
available()
Deprecated. -- Will use reqHandler, make sure nobody else calls this
void
beginSendHeaders(int status, String statusMessage, int numHeaders)
void
close()
Close the socket connection to the web server.
int
doRead()
int
doRead(byte[] b, int off, int len)
void
doWrite(b[] , int off, int len)
void
endSendHeaders()
void
finish()
String
getSecret()
int
handleMessage(int type, Ajp13Packet hBuf, BaseRequest req)
Override for ajp14, temporary
void
initBuf()
Will be overriden
boolean
isLogged()
int
receive(Ajp13Packet msg)
Read in a packet from the web server and store it in the passed-in Ajp13Packet object.
int
receiveNextRequest(BaseRequest req)
Read a new packet from the web server and decode it.
void
recycle()
int
registerMessageType(int id, String name, AjpHandler h, sig[] )
void
send(Ajp13Packet msg)
Send a packet to the web server.
void
sendHeader(String name, String value)
void
sendHeaders(int status, String statusMessage, MimeHeaders headers)
void
sendHeaders(int status, MimeHeaders headers)
void
setBackward(boolean b)
Backward compat mode, no login needed
void
setDebug(int debug)
void
setLogger(Logger l)
void
setSecret(String s)
void
setSocket(Socket socket)
Associate an open socket with this instance.

Field Details

H_SIZE

public static final int H_SIZE

Field Value:
4


JK_AJP13_BAD_BODY

public static final int JK_AJP13_BAD_BODY

Field Value:
-104


JK_AJP13_BAD_HEADER

public static final int JK_AJP13_BAD_HEADER

Field Value:
-100


JK_AJP13_COMM_BROKEN

public static final int JK_AJP13_COMM_BROKEN

Field Value:
-103


JK_AJP13_COMM_CLOSED

public static final int JK_AJP13_COMM_CLOSED

Field Value:
-102


JK_AJP13_INCOMPLETE_BODY

public static final int JK_AJP13_INCOMPLETE_BODY

Field Value:
-105


JK_AJP13_NO_HEADER

public static final int JK_AJP13_NO_HEADER

Field Value:
-101


MAX_PACKET_SIZE

public static final int MAX_PACKET_SIZE

Field Value:
8192


MAX_READ_SIZE

public static final int MAX_READ_SIZE

Field Value:
8186


MAX_SEND_SIZE

public static final int MAX_SEND_SIZE

Field Value:
8184


debug

protected int debug


outBuf

public Ajp13Packet outBuf


reqHandler

public RequestHandler reqHandler

Constructor Details

Ajp13

public Ajp13()


Ajp13

public Ajp13(RequestHandler reqHandler)

Method Details

available

public int available()
            throws IOException

Deprecated. -- Will use reqHandler, make sure nobody else calls this


beginSendHeaders

public void beginSendHeaders(int status,
                             String statusMessage,
                             int numHeaders)
            throws IOException


close

public void close()
            throws IOException
Close the socket connection to the web server. In general, sockets are maintained across many requests, so this will not be called after finish().

See Also:
Ajp13Interceptor.processConnection


doRead

public int doRead()
            throws IOException


doRead

public int doRead(byte[] b,
                  int off,
                  int len)
            throws IOException


doWrite

public void doWrite(b[] ,
                    int off,
                    int len)
            throws IOException


endSendHeaders

public void endSendHeaders()
            throws IOException


finish

public void finish()
            throws IOException


getSecret

public String getSecret()


handleMessage

public int handleMessage(int type,
                         Ajp13Packet hBuf,
                         BaseRequest req)
            throws IOException
Override for ajp14, temporary


initBuf

public void initBuf()
Will be overriden


isLogged

public boolean isLogged()


receive

public int receive(Ajp13Packet msg)
            throws IOException
Read in a packet from the web server and store it in the passed-in Ajp13Packet object.

Parameters:
msg - The object into which to store the incoming packet -- any current contents will be overwritten.

Returns:
The number of bytes read on a successful read or -1 if there was an error.


receiveNextRequest

public int receiveNextRequest(BaseRequest req)
            throws IOException
Read a new packet from the web server and decode it. If it's a forwarded request, store its properties in the passed-in AjpRequest object.

Parameters:
req - An empty (newly-recycled) request object.

Returns:
200 in case of a successful read of a forwarded request, 500 if there were errors in the reading of the request, and -2 if the server is asking the container to shut itself down.


recycle

public void recycle()


registerMessageType

public int registerMessageType(int id,
                               String name,
                               AjpHandler h,
                               sig[] )


send

public void send(Ajp13Packet msg)
            throws IOException
Send a packet to the web server. Works for any type of message.

Parameters:
msg - A packet with accumulated data to send to the server -- this method will write out the length in the header.


sendHeader

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


sendHeaders

public void sendHeaders(int status,
                        String statusMessage,
                        MimeHeaders headers)
            throws IOException


sendHeaders

public void sendHeaders(int status,
                        MimeHeaders headers)
            throws IOException


setBackward

public void setBackward(boolean b)
Backward compat mode, no login needed


setDebug

public void setDebug(int debug)


setLogger

public void setLogger(Logger l)


setSecret

public void setSecret(String s)


setSocket

public void setSocket(Socket socket)
            throws IOException
Associate an open socket with this instance.


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