org.enhydra.servlet.connectionMethods.EnhydraDirector
Class EnhydraDirectorProtocol

java.lang.Object
  extended byorg.enhydra.servlet.connectionMethods.EnhydraDirector.EnhydraDirectorProtocol
Direct Known Subclasses:
EnhydraDirectorConnection

public abstract class EnhydraDirectorProtocol
extends java.lang.Object


Field Summary
protected  boolean active
          Whether or not this connection is active.
protected  int clientMajor
          Client side protocol major version.
protected  int clientMinor
          Client side protocol minor version.
protected static int MAJOR_VERSION
           
protected static int MAX_AUTHDATA_LENGTH
           
protected static int MAX_FUNCDATA_LENGTH
           
protected static int MAX_SMALL_PACKET_LENGTH
           
protected static int MINOR_VERSION
           
protected static int PKT_HEADER_SIZE
           
protected static int PKT_OPENFLAGS_HEADERCB
           
protected static int PKT_OPENFLAGS_OPENCB
           
protected static int PKT_SUBTYPE_AUTH_CLI
           
protected static int PKT_SUBTYPE_AUTH_FAIL
           
protected static int PKT_SUBTYPE_AUTH_OK
           
protected static int PKT_SUBTYPE_AUTH_SVR
           
protected static int PKT_SUBTYPE_CTRL_CLI_ACTIVATE
           
protected static int PKT_SUBTYPE_CTRL_CLI_CLOSE
           
protected static int PKT_SUBTYPE_CTRL_CLI_DEACTIVATE
           
protected static int PKT_SUBTYPE_CTRL_SVR_REFRESH
           
protected static int PKT_SUBTYPE_FUNC_CALL
           
protected static int PKT_SUBTYPE_FUNC_END
           
protected static int PKT_SUBTYPE_FUNC_FAIL
           
protected static int PKT_SUBTYPE_FUNC_OK
           
protected static int PKT_SUBTYPE_FUNC_ONEWAY
           
protected static int PKT_SUBTYPE_HEADER_COOKIE
           
protected static int PKT_SUBTYPE_HEADER_HEADER
           
protected static int PKT_SUBTYPE_HEADER_HTTP
           
protected static int PKT_SUBTYPE_HEADER_LAST
           
protected static int PKT_SUBTYPE_PROTO_CLOSE
           
protected static int PKT_SUBTYPE_PROTO_FATAL
           
protected static int PKT_SUBTYPE_PROTO_VERSION
           
protected static int PKT_SUBTYPE_REQ_DATA
           
protected static int PKT_SUBTYPE_REQ_LASTDATA
           
protected static int PKT_SUBTYPE_RESP_DATA
           
protected static int PKT_SUBTYPE_RESP_END
           
protected static int PKT_SUBTYPE_RESP_ERROR
           
protected static int PKT_SUBTYPE_RESP_LOGS
           
protected static int PKT_SUBTYPE_RESP_WARNING
           
protected static int PKT_TYPE_AUTH
           
protected static int PKT_TYPE_CTRL_CLI
           
protected static int PKT_TYPE_CTRL_SVR
           
protected static int PKT_TYPE_FUNC
           
protected static int PKT_TYPE_HEADER
           
protected static int PKT_TYPE_PROTO
           
protected static int PKT_TYPE_REQ
           
protected static int PKT_TYPE_RESP
           
protected  int state
          The current state of this connection's state machine.
protected static int STATE_CHECK_AUTH
           
protected static int STATE_CLOSED
           
protected static int STATE_HAVE_HEADERS
           
protected static int STATE_NEWCONNECT
           
protected static int STATE_OPEN
           
protected static int STATE_OPENING
           
protected static int STATE_PROCESSING_ENTITY_FUNC
           
protected static int STATE_PROCESSING_FUNC
           
protected static int STATE_PROCESSING_HEADER
           
protected static int STATE_PROCESSING_REQUEST
           
protected static int STATE_RECEIVING_ENTITY
           
protected static int STATE_RECEIVING_HEADERS
           
protected static int STATE_WAIT_AUTH
           
protected static int STATE_WAIT_ENTITY_CALLBACK
           
protected static int STATE_WAIT_HEADER_CALLBACK
           
protected static int STATE_WAIT_OPEN_CALLBACK
           
protected static int STATE_WAIT_VERSION
           
 
Constructor Summary
EnhydraDirectorProtocol()
          Create a new EnhydraDirector connection object.
 
Method Summary
 void activate()
          Complete connection establishment after authentication.
 void authenticate()
          Causes the authentication challenge to be sent to the client.
 void authenticate(boolean openCB, boolean headerCB)
          Second version of authenticate that allows a request for post-open and post-header callbacks.
protected abstract  boolean authRequired()
          Implementation class must provide this method.
 boolean callback(int number, byte[] argsIn, byte[][] dataOut)
          Send a callback to the client.
 void closeConnection()
          Method to close output stream.
 void closeInput()
          Discards any further incoming request entity data and marks the input stream as "closed".
 void closeOutput()
          Method to close output stream.
 void connect(java.net.Socket socket)
          This method causes a new EnhydraDirectorProtocol instance to accept the next socket connection from a server socket.
 void deactivate()
          Cause this connection to go into an inactive state.
protected  long discardEntity()
          Discard the entire entity body We don't care about it.
 void finishHeaders()
          Method to send an HTTP cookie.
protected abstract  byte[] getAuthData()
          Abstract method to get authentication secret data.
protected abstract  EnhydraDirectorFunction getFunction(int type)
          Internal dispatch table for server side function handlers.
protected  java.lang.String getStateName()
          Returns a text name for the current state of this instance.
protected  java.lang.String getStateName(int stateNum)
          Returns a text name for the specified state number.
 int inputAvailable()
          Returns a maximum number of bytes which can be read without blocking.
 boolean isAuthenticated()
          Returns true if the client has successfully authenticated itself for this connection.
 boolean isConnected()
          Returns false if this connection is in the CLOSED state, otherwise returns true.
 boolean isOpen()
          Returns if the connection is fully established.
protected abstract  void processCgiHeader(byte[] name, byte[] value)
          Abstract method to process a CGI-BIN header.
protected abstract  void processCookie(byte[] name, byte[] value)
          Abstract method to process a cookie.
protected abstract  void processHttpHeader(byte[] name, byte[] value)
          Abstract method to process an HTTP request header.
 int read()
          Read a single byte of entity input and return it as an integer from 0 to 255.
 int read(byte[] inBuf)
          Read at least one and at most inBuf.length bytes.
 int read(byte[] inBuf, int off, int len)
          Read at least one and at most len request entity bytes.
 int readExactly(byte[] inBuf)
          Read request entity bytes with Java read semantics.
 int readExactly(byte[] inBuf, int off, int len)
          Read exactly len request entity bytes.
 void sendCookie(java.lang.String name, java.lang.String value)
          Method to send an HTTP cookie.
 void sendHeader(java.lang.String name, java.lang.String value)
          Method to send an HTTP header.
 long skip(long n)
          Skip over nbytes bytes of entity input data.
 java.lang.String toString()
          Generates a string that displays the current state of this instance.
 void write(byte[] buf)
          Method to write a single byte of response data.
 void write(byte[] buf, int off, int len)
          Method to write a single byte of response data.
 void write(int b)
          Method to write a single byte of response data.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

MAJOR_VERSION

protected static final int MAJOR_VERSION
See Also:
Constant Field Values

MINOR_VERSION

protected static final int MINOR_VERSION
See Also:
Constant Field Values

STATE_CLOSED

protected static final int STATE_CLOSED
See Also:
Constant Field Values

STATE_NEWCONNECT

protected static final int STATE_NEWCONNECT
See Also:
Constant Field Values

STATE_WAIT_AUTH

protected static final int STATE_WAIT_AUTH
See Also:
Constant Field Values

STATE_WAIT_VERSION

protected static final int STATE_WAIT_VERSION
See Also:
Constant Field Values

STATE_CHECK_AUTH

protected static final int STATE_CHECK_AUTH
See Also:
Constant Field Values

STATE_OPENING

protected static final int STATE_OPENING
See Also:
Constant Field Values

STATE_WAIT_OPEN_CALLBACK

protected static final int STATE_WAIT_OPEN_CALLBACK
See Also:
Constant Field Values

STATE_OPEN

protected static final int STATE_OPEN
See Also:
Constant Field Values

STATE_PROCESSING_FUNC

protected static final int STATE_PROCESSING_FUNC
See Also:
Constant Field Values

STATE_PROCESSING_HEADER

protected static final int STATE_PROCESSING_HEADER
See Also:
Constant Field Values

STATE_RECEIVING_HEADERS

protected static final int STATE_RECEIVING_HEADERS
See Also:
Constant Field Values

STATE_HAVE_HEADERS

protected static final int STATE_HAVE_HEADERS
See Also:
Constant Field Values

STATE_WAIT_HEADER_CALLBACK

protected static final int STATE_WAIT_HEADER_CALLBACK
See Also:
Constant Field Values

STATE_RECEIVING_ENTITY

protected static final int STATE_RECEIVING_ENTITY
See Also:
Constant Field Values

STATE_WAIT_ENTITY_CALLBACK

protected static final int STATE_WAIT_ENTITY_CALLBACK
See Also:
Constant Field Values

STATE_PROCESSING_ENTITY_FUNC

protected static final int STATE_PROCESSING_ENTITY_FUNC
See Also:
Constant Field Values

STATE_PROCESSING_REQUEST

protected static final int STATE_PROCESSING_REQUEST
See Also:
Constant Field Values

PKT_TYPE_AUTH

protected static final int PKT_TYPE_AUTH
See Also:
Constant Field Values

PKT_SUBTYPE_AUTH_SVR

protected static final int PKT_SUBTYPE_AUTH_SVR
See Also:
Constant Field Values

PKT_SUBTYPE_AUTH_CLI

protected static final int PKT_SUBTYPE_AUTH_CLI
See Also:
Constant Field Values

PKT_SUBTYPE_AUTH_OK

protected static final int PKT_SUBTYPE_AUTH_OK
See Also:
Constant Field Values

PKT_SUBTYPE_AUTH_FAIL

protected static final int PKT_SUBTYPE_AUTH_FAIL
See Also:
Constant Field Values

PKT_TYPE_REQ

protected static final int PKT_TYPE_REQ
See Also:
Constant Field Values

PKT_SUBTYPE_REQ_DATA

protected static final int PKT_SUBTYPE_REQ_DATA
See Also:
Constant Field Values

PKT_SUBTYPE_REQ_LASTDATA

protected static final int PKT_SUBTYPE_REQ_LASTDATA
See Also:
Constant Field Values

PKT_TYPE_FUNC

protected static final int PKT_TYPE_FUNC
See Also:
Constant Field Values

PKT_SUBTYPE_FUNC_FAIL

protected static final int PKT_SUBTYPE_FUNC_FAIL
See Also:
Constant Field Values

PKT_SUBTYPE_FUNC_OK

protected static final int PKT_SUBTYPE_FUNC_OK
See Also:
Constant Field Values

PKT_SUBTYPE_FUNC_CALL

protected static final int PKT_SUBTYPE_FUNC_CALL
See Also:
Constant Field Values

PKT_SUBTYPE_FUNC_ONEWAY

protected static final int PKT_SUBTYPE_FUNC_ONEWAY
See Also:
Constant Field Values

PKT_SUBTYPE_FUNC_END

protected static final int PKT_SUBTYPE_FUNC_END
See Also:
Constant Field Values

PKT_TYPE_RESP

protected static final int PKT_TYPE_RESP
See Also:
Constant Field Values

PKT_SUBTYPE_RESP_DATA

protected static final int PKT_SUBTYPE_RESP_DATA
See Also:
Constant Field Values

PKT_SUBTYPE_RESP_LOGS

protected static final int PKT_SUBTYPE_RESP_LOGS
See Also:
Constant Field Values

PKT_SUBTYPE_RESP_WARNING

protected static final int PKT_SUBTYPE_RESP_WARNING
See Also:
Constant Field Values

PKT_SUBTYPE_RESP_ERROR

protected static final int PKT_SUBTYPE_RESP_ERROR
See Also:
Constant Field Values

PKT_SUBTYPE_RESP_END

protected static final int PKT_SUBTYPE_RESP_END
See Also:
Constant Field Values

PKT_TYPE_HEADER

protected static final int PKT_TYPE_HEADER
See Also:
Constant Field Values

PKT_SUBTYPE_HEADER_HEADER

protected static final int PKT_SUBTYPE_HEADER_HEADER
See Also:
Constant Field Values

PKT_SUBTYPE_HEADER_HTTP

protected static final int PKT_SUBTYPE_HEADER_HTTP
See Also:
Constant Field Values

PKT_SUBTYPE_HEADER_COOKIE

protected static final int PKT_SUBTYPE_HEADER_COOKIE
See Also:
Constant Field Values

PKT_SUBTYPE_HEADER_LAST

protected static final int PKT_SUBTYPE_HEADER_LAST
See Also:
Constant Field Values

PKT_TYPE_CTRL_CLI

protected static final int PKT_TYPE_CTRL_CLI
See Also:
Constant Field Values

PKT_SUBTYPE_CTRL_CLI_ACTIVATE

protected static final int PKT_SUBTYPE_CTRL_CLI_ACTIVATE
See Also:
Constant Field Values

PKT_SUBTYPE_CTRL_CLI_DEACTIVATE

protected static final int PKT_SUBTYPE_CTRL_CLI_DEACTIVATE
See Also:
Constant Field Values

PKT_SUBTYPE_CTRL_CLI_CLOSE

protected static final int PKT_SUBTYPE_CTRL_CLI_CLOSE
See Also:
Constant Field Values

PKT_TYPE_CTRL_SVR

protected static final int PKT_TYPE_CTRL_SVR
See Also:
Constant Field Values

PKT_SUBTYPE_CTRL_SVR_REFRESH

protected static final int PKT_SUBTYPE_CTRL_SVR_REFRESH
See Also:
Constant Field Values

PKT_TYPE_PROTO

protected static final int PKT_TYPE_PROTO
See Also:
Constant Field Values

PKT_SUBTYPE_PROTO_CLOSE

protected static final int PKT_SUBTYPE_PROTO_CLOSE
See Also:
Constant Field Values

PKT_SUBTYPE_PROTO_FATAL

protected static final int PKT_SUBTYPE_PROTO_FATAL
See Also:
Constant Field Values

PKT_SUBTYPE_PROTO_VERSION

protected static final int PKT_SUBTYPE_PROTO_VERSION
See Also:
Constant Field Values

PKT_OPENFLAGS_OPENCB

protected static final int PKT_OPENFLAGS_OPENCB
See Also:
Constant Field Values

PKT_OPENFLAGS_HEADERCB

protected static final int PKT_OPENFLAGS_HEADERCB
See Also:
Constant Field Values

PKT_HEADER_SIZE

protected static final int PKT_HEADER_SIZE
See Also:
Constant Field Values

MAX_AUTHDATA_LENGTH

protected static final int MAX_AUTHDATA_LENGTH
See Also:
Constant Field Values

MAX_FUNCDATA_LENGTH

protected static final int MAX_FUNCDATA_LENGTH
See Also:
Constant Field Values

MAX_SMALL_PACKET_LENGTH

protected static final int MAX_SMALL_PACKET_LENGTH
See Also:
Constant Field Values

state

protected int state
The current state of this connection's state machine.


clientMajor

protected int clientMajor
Client side protocol major version.


clientMinor

protected int clientMinor
Client side protocol minor version.


active

protected boolean active
Whether or not this connection is active.

Constructor Detail

EnhydraDirectorProtocol

public EnhydraDirectorProtocol()
Create a new EnhydraDirector connection object.

Sets the initial state to CLOSED. Before this instance may be used, it must be assigned a connection using the connect() method.

Method Detail

getFunction

protected abstract EnhydraDirectorFunction getFunction(int type)
Internal dispatch table for server side function handlers. Supported functions are permanently registered at compile time by placing them in this method's switch block.

Parameters:
type - Protocol-defined function type number.
Returns:
Reference to the appropriate function handler instance.

authRequired

protected abstract boolean authRequired()
Implementation class must provide this method. It should check the configuration data to determine if authentication is required for connections.

Returns:
true if authentication is required.

getAuthData

protected abstract byte[] getAuthData()
Abstract method to get authentication secret data.

This method must be provided by the implementation class. It checks the configuration and finds the secret authentication data used to verify authentication responses from clients.

Returns:
A byte array of authentication data, or null if authentication data does not exist.

processCgiHeader

protected abstract void processCgiHeader(byte[] name,
                                         byte[] value)
Abstract method to process a CGI-BIN header.

Returns:
A byte array of authentication data, or null if authentication data does not exist.

processHttpHeader

protected abstract void processHttpHeader(byte[] name,
                                          byte[] value)
Abstract method to process an HTTP request header.

Returns:
A byte array of authentication data, or null if authentication data does not exist.

processCookie

protected abstract void processCookie(byte[] name,
                                      byte[] value)
Abstract method to process a cookie.

Returns:
A byte array of authentication data, or null if authentication data does not exist.

connect

public void connect(java.net.Socket socket)
             throws EnhydraDirectorBadStateException,
                    java.io.IOException
This method causes a new EnhydraDirectorProtocol instance to accept the next socket connection from a server socket. This method may only be called if isConnected() returns false. Otherwise an exception is thrown.

Parameters:
socket - Server socket from which to obtain a new connection.
Throws:
java.io.IOException - If a network failure occurs.
EnhydraDirectorBadStateException - If this method is called while the state is not CLOSED.

isConnected

public boolean isConnected()
Returns false if this connection is in the CLOSED state, otherwise returns true.

After an exception is raised by this connection, this method should be checked to verify the state of the connection.

Returns:
True if not CLOSED, otherwise false.

authenticate

public void authenticate()
                  throws EnhydraDirectorBadStateException,
                         java.io.IOException
Causes the authentication challenge to be sent to the client.

Authentication data is retrieved in an implementation specific manner by the abstract getAuthData method.

This method must only be called after a connect() call and before any other calls. However, authentication can be delayed until a thread becomes available to process the authentication. Once authentication returns, this instance may be placed back in inactive status until it is re-activated to handle an incoming request. Upon authentication failure, this instance reverts to the CLOSED state, and the connection socket is closed. In such a case, this object must be deleted and a new one created in order to create a new connection.

Only call this method if isAuthenticated() returns false. Otherwise an exception will be thrown.

Throws:
java.io.IOException - If a network failure occurs.
EnhydraDirectorBadStateException - If this method is called while in a state other than NEWCONNECT.

authenticate

public void authenticate(boolean openCB,
                         boolean headerCB)
                  throws EnhydraDirectorBadStateException,
                         java.io.IOException
Second version of authenticate that allows a request for post-open and post-header callbacks.

If either of these options are set, performance will be degraded because the client must go into a wait state until it receives all of the callbacks and the final callback termination packet. Use these options sparingly.

Only call this method if isAuthenticated() returns false. Otherwise an exception will be thrown.

Note: If either callback option is set to true but callbacks are not made, the state machine automatically detects this and sends callback termination to prevent a mutual-receive deadlock condition from arising.

Parameters:
openCB - If true callbacks may be made to the client immediately prior to finishing the connection establishment.
headerCB - If true callbacks may be made to the client immediately after all HTTP request headers have been received.
Throws:
java.io.IOException - If a network failure occurs.
EnhydraDirectorBadStateException - If this method is called while in a state other than NEWCONNECT.
See Also:
authenticate(), activate()

isAuthenticated

public boolean isAuthenticated()
Returns true if the client has successfully authenticated itself for this connection.

Use this method to determine whether authenticate() must be called.

Returns:
True if the client has successfuly authenticted itself

activate

public void activate()
              throws java.io.IOException
Complete connection establishment after authentication.

After authenticate() returns, the connection is not fully open and available for requests until activate. has been called. This allows callbacks to be sent prior to full connection establishment. These callbacks happen only once in the lifetime of a connection, and not on a per-request basis, as would be the case with post-header or post-entity callbacks.

If post-open callbacks have not been requested, this method goes straight to the OPEN state. If callbacks were requested, the callback termination packet is sent to tell the client that there are no more callbacks.

Throws:
java.io.IOException

deactivate

public void deactivate()
                throws java.io.IOException
Cause this connection to go into an inactive state.

All buffers are freed and the state is reset to OPEN. This method is called by a higher level connection/thread manager to disassociate this instance with any thread. Usually this means the instance is being placed on an inactive list, awaiting future activation by a running client load manager.

Throws:
EnhydraDirectorBadStateException - If this instance is currently processing. Only instances in the OPEN state may be activated or deactivated.
java.io.IOException

isOpen

public boolean isOpen()
Returns if the connection is fully established.

Returns:
True if the connection is authenticated and established.

callback

public boolean callback(int number,
                        byte[] argsIn,
                        byte[][] dataOut)
                 throws java.lang.IllegalArgumentException,
                        EnhydraDirectorBadStateException,
                        java.io.IOException
Send a callback to the client.

This method may only be send in the following situations:
1. If post-open callbacks are requested, just before activate() is called. 2. If post-header callbacks are requested, just before calls to read() occur. 3. Once the request entity has been fully read.

Parameters:
number - The ID number (0..255) that identifies the callback to run on the client.
argsIn - Arguments to pass to the remote callback. Format depends on the function being called.
Returns:
True if the callback returned successful status, false if the callback failed.
Throws:
java.lang.IllegalArgumentException
EnhydraDirectorBadStateException
java.io.IOException

read

public int read(byte[] inBuf,
                int off,
                int len)
         throws java.io.IOException
Read at least one and at most len request entity bytes.

If no EOF or error condition occurs, at least one byte will be read into the buffer, up to the length of the buffer. This method returns immediately when bytes become available and may read fewer bytes than the allocated buffer length.

Parameters:
inBuf - Buffer to read into.
off - Offset within the buffer.
len - Number of bytes to read. The read will stop before reaching the end of the buffer, so fewer than len bytes may be read if inBuf.length - off is less than len.
Returns:
The number of bytes actually read.
Throws:
java.io.IOException

read

public int read(byte[] inBuf)
         throws java.io.IOException
Read at least one and at most inBuf.length bytes.

If no EOF or error condition occurs, at least one byte will be read into the buffer, up to the length of the buffer. This method returns immediately when bytes become available and may read fewer bytes than the allocated buffer length.

Parameters:
inBuf - Buffer to read into.
Returns:
The number of bytes actually read.
Throws:
java.io.IOException

read

public int read()
         throws java.io.IOException
Read a single byte of entity input and return it as an integer from 0 to 255.

Returns -1 if the end-of-data is reached.

Returns:
The value of the next input byte from 0 to 255, as a signed integer. Returns -1 on end-of-data.
Throws:
java.io.IOException - If an I/O error occurs.

readExactly

public int readExactly(byte[] inBuf,
                       int off,
                       int len)
                throws java.io.IOException
Read exactly len request entity bytes.

If no EOF or error condition occurs, at least one byte will be read into the buffer, up to the length of the buffer. This method returns only after the buffer is full, end-of-data is reached, or an error occurs. This is convenient when an exact number of bytes are expected.

The actual number of bytes read is returned. This may be less than the buffer length if an error occurs, or if end-of-data is reached.

Parameters:
inBuf - Buffer to read into.
Returns:
The actual number of bytes read. On end-of-data, returns 0. Receiving more than one byte, but fewer bytes than the buffer size also indicates an end-of-data condition. Once end-of-data occurs, all further calls return zero.
Throws:
java.io.IOException - If a network failure occurs.

readExactly

public int readExactly(byte[] inBuf)
                throws java.io.IOException
Read request entity bytes with Java read semantics.

If no EOF or error condition occurs, at least one byte will be read into the buffer, up to the length of the buffer. This method returns only after the buffer is full, end-of-data is reached, or an error occurs. This is convenient when an exact number of bytes are expected.

The actual number of bytes read is returned. This may be less than the buffer length if an error occurs, or if end-of-data is reached.

Parameters:
inBuf - Buffer to read into.
Returns:
The actual number of bytes read. On end-of-data, returns 0. Receiving more than one byte, but fewer bytes than the buffer size also indicates an end-of-data condition. Once end-of-data occurs, all further calls return zero.
Throws:
java.io.IOException - If a network failure occurs.

skip

public long skip(long n)
          throws java.io.IOException
Skip over nbytes bytes of entity input data.

Receives and discards n bytes of entity data and returns the number of bytes discarded. Returns 0 when end-of-data is reached, or if n is 0.

Parameters:
n - The number of bytes to discard.
Returns:
The number of bytes skipped, or 0 when end-of-data reached.
Throws:
java.io.IOException - If a network failure occurs.

closeInput

public void closeInput()
                throws java.io.IOException
Discards any further incoming request entity data and marks the input stream as "closed".

Throws:
java.io.IOException - if an error occurs while discarding entity data. This usually will cause the protocol to go out of sync.

inputAvailable

public int inputAvailable()
                   throws java.io.IOException
Returns a maximum number of bytes which can be read without blocking.

No internal byte[] buffer is kept around. The read() methods read directly from the socket to the passed-in buffer. This means that the number of bytes guaranteed to be available in a non-blocking readExactly() is the minimum of the available bytes on the input socket, and the number of bytes remaining in the current incoming data packet. We can't just read the next packet header, because it may contain a callback, and thus require a block. We don't have a way to make the state machine go backwards in a "putback" fashion. (which would be ugly)

Returns:
The number of bytes which can be read with a guarantee of not blocking on the input stream.
Throws:
java.io.IOException - If an I/O error occurs.

discardEntity

protected long discardEntity()
                      throws java.io.IOException
Discard the entire entity body We don't care about it.

Returns:
The number of bytes skipped.
Throws:
java.io.IOException - If a network failure occurs.

write

public void write(int b)
           throws java.io.IOException
Method to write a single byte of response data.

Throws:
java.io.IOException

write

public void write(byte[] buf)
           throws java.io.IOException
Method to write a single byte of response data.

Throws:
java.io.IOException

write

public void write(byte[] buf,
                  int off,
                  int len)
           throws java.io.IOException
Method to write a single byte of response data.

Throws:
java.io.IOException

closeOutput

public void closeOutput()
                 throws java.io.IOException
Method to close output stream.

Throws:
java.io.IOException

closeConnection

public void closeConnection()
                     throws java.io.IOException
Method to close output stream.

Throws:
java.io.IOException

sendHeader

public void sendHeader(java.lang.String name,
                       java.lang.String value)
                throws java.io.IOException
Method to send an HTTP header.

Throws:
java.io.IOException

sendCookie

public void sendCookie(java.lang.String name,
                       java.lang.String value)
                throws java.io.IOException
Method to send an HTTP cookie.

Throws:
java.io.IOException

finishHeaders

public void finishHeaders()
                   throws java.io.IOException
Method to send an HTTP cookie.

Throws:
java.io.IOException

getStateName

protected java.lang.String getStateName()
Returns a text name for the current state of this instance.

Returns:
The text state name.

getStateName

protected java.lang.String getStateName(int stateNum)
Returns a text name for the specified state number.

Returns:
The text state name.

toString

public java.lang.String toString()
Generates a string that displays the current state of this instance.

Useful for debugging and logging.

Returns:
String that shows the current state of this instance.