com.caucho.server.hmux
Class HmuxRequest

java.lang.Object
  extended by com.caucho.server.http.AbstractHttpRequest
      extended by com.caucho.server.hmux.HmuxRequest
All Implemented Interfaces:
ProtocolConnection, SecurityContextProvider

public class HmuxRequest
extends AbstractHttpRequest
implements ProtocolConnection

Handles requests from a remote dispatcher. For example, mod_caucho and the IIS plugin use this protocol to talk to the backend.

Packets are straightforward:

code l2 l1 l0 contents
Where code is the code of the packet and l2-0 give 12 bits of length.

The protocol is designed to allow pipelining and buffering whenever possible. So most commands are not acked. Data from the frontend (POST) does need acks to prevent deadlocks at either end while waiting for new data.

The overriding protocol is controlled by requests from the frontend server.

A ping request:

 Frontend       Backend
 CSE_PING
 CSE_END
                CSE_END
 

 

A GET request:

 Frontend       Backend
 CSE_METHOD
 ...
 CSE_HEADER/CSE_VALUE
 CSE_END
                CSE_DATA
                CSE_DATA
                CSE_END
 

 

Short POST:

 Frontend       Backend
 CSE_METHOD
 ...
 CSE_HEADER/CSE_VALUE
 CSE_DATA
 CSE_END
                CSE_DATA
                CSE_DATA
                CSE_END
 

 

Long POST:

 Frontend       Backend
 CSE_METHOD
 ...
 CSE_HEADER/CSE_VALUE
 CSE_DATA
                CSE_DATA (optional)
 CSE_DATA
                CSE_ACK
                CSE_DATA (optional)
 CSE_DATA
                CSE_ACK
 CSE_END
                CSE_DATA
                CSE_END
 


Nested Class Summary
static class HmuxRequest.ProtocolResult
           
 
Field Summary
static int CSE_AUTH_TYPE
           
static int CSE_CLIENT_CERT
           
static int CSE_CONTENT_LENGTH
           
static int CSE_CONTENT_TYPE
           
static int CSE_END
           
static int CSE_FLUSH
           
static int CSE_IS_SECURE
           
static int CSE_KEEPALIVE
           
static int CSE_NULL
           
static int CSE_PATH_INFO
           
static int CSE_PROTOCOL
           
static int CSE_QUERY
           
static int CSE_QUERY_STRING
           
static int CSE_REAL_PATH
           
static int CSE_REMOTE_ADDR
           
static int CSE_REMOTE_HOST
           
static int CSE_REMOTE_PORT
           
static int CSE_REMOTE_USER
           
static int CSE_SCRIPT_FILENAME
           
static int CSE_SEND_HEADER
           
static int CSE_SERVER_PORT
           
static int CSE_SERVER_TYPE
           
static int CSE_URI
           
static int HMUX_ACK
           
static int HMUX_BINARY
           
static int HMUX_CHANNEL
           
static int HMUX_DATA
           
static int HMUX_DISPATCH_PROTOCOL
           
static int HMUX_ERROR
           
static int HMUX_EXIT
           
static int HMUX_FLUSH
           
static int HMUX_HEADER
           
static int HMUX_HMTP_OK
           
static int HMUX_JMS_PROTOCOL
           
static int HMUX_META_HEADER
           
static int HMUX_METHOD
           
static int HMUX_PROTOCOL
           
static int HMUX_QUIT
           
static int HMUX_SERVER_NAME
           
static int HMUX_STATUS
           
static int HMUX_STRING
           
static int HMUX_SWITCH_TO_HMTP
           
static int HMUX_TO_UNIDIR_HMTP
           
static int HMUX_URI
           
static int HMUX_YIELD
           
 
Fields inherited from class com.caucho.server.http.AbstractHttpRequest
_headerCodes, _hostHeader, JSP_EXCEPTION, SHUTDOWN
 
Constructor Summary
HmuxRequest(Server server, SocketLink conn, HmuxProtocol protocol)
           
 
Method Summary
protected  boolean checkLogin()
           
 HmuxResponse createResponse()
           
 java.lang.String dbgId()
           
protected  void flushNext()
           
protected  void flushNextBuffer()
           
 java.lang.String getHeader(java.lang.String key)
          Returns the header.
 CharSegment getHeaderBuffer(char[] buf, int length)
           
 CharSegment getHeaderBuffer(java.lang.String key)
          Fills the result with the header values as CharSegment values.
 void getHeaderBuffers(java.lang.String key, java.util.ArrayList<CharSegment> values)
          Fills the result with a list of the header values as CharSegment values.
 java.util.Enumeration<java.lang.String> getHeaderNames()
          Enumerates the header keys
protected  CharBuffer getHost()
          Returns a char buffer containing the host.
 java.lang.String getMethod()
          Returns the header.
 CharSegment getMethodBuffer()
           
protected  byte[] getNextBuffer()
           
protected  int getNextBufferOffset()
           
protected  int getNextStartOffset()
           
 java.lang.String getProtocol()
          Returns the protocol.
 CharSegment getProtocolBuffer()
           
 java.lang.String getRemoteAddr()
           
 void getRemoteAddr(CharBuffer cb)
           
 java.lang.String getRemoteHost()
           
protected  java.lang.String getRequestId()
           
 java.lang.String getRequestURI()
          Returns the URI for the request, special casing the IIS issues.
 java.lang.String getServerName()
          Returns the server name.
 int getServerPort()
          Returns the server's port.
 byte[] getUriBuffer()
           
 int getUriLength()
           
protected  void handleConnectionClose()
          Called for a connection: close
 boolean handleRequest()
          Handles a new request.
 boolean hasRequest()
          Returns true if a valid HTTP request has started.
 boolean initStream(ReadStream readStream, ReadStream rawStream)
          Initialize the read stream from the raw stream.
 boolean isSecure()
          Returns true if the request is secure.
 boolean isSuspend()
           
 boolean isWaitForRead()
          Return true if the connection should wait for a read before handling the request.
 void onCloseConnection()
          Close when the socket closes.
 void onStartConnection()
          Called when the connection starts
 int printRemoteAddr(byte[] buffer, int offset)
           
 void setHeader(java.lang.String key, java.lang.String value)
          Sets the header.
protected  void setNextBufferOffset(int offset)
           
protected  void startRequest(HttpBufferStore httpBuffer)
          Clears variables at the start of a new request.
 java.lang.String toString()
           
protected  byte[] writeNextBuffer(int offset)
           
protected  void writeTail()
           
 
Methods inherited from class com.caucho.server.http.AbstractHttpRequest
addHeaderInt, buildInvocation, cleanup, clearRequest, clientDisconnect, findSessionIdFromConnection, finishInvocation, finishRequest, getAbstractHttpResponse, getAvailable, getCharacterEncoding, getCharBuffer, getConnection, getConnectionId, getContentLength, getContentType, getContentTypeBuffer, getCookies, getDateHeader, getErrorManager, getForm, getFormParser, getHeaderKey, getHeaders, getHeaderSize, getHeaderValue, getInputStream, getIntHeader, getInvocation, getInvocationServer, getLocale, getLocales, getLocalHost, getLocalPort, getLogBuffer, getLongContentLength, getProtocolRequestURL, getRawInput, getRawRead, getRawReadBuffer, getRawWrite, getReader, getReadStream, getRemotePort, getRequestFacade, getRequestURL, getResponse, getResponseFacade, getScheme, getServer, getStartTime, getStream, getStream, getUserPrincipal, getWebApp, handleResume, init, initAttributes, isCometActive, isConnectionClosed, isDuplex, isIgnoreClientDisconnect, isKeepalive, isTransportSecure, isUserInRole, killKeepalive, restartServer, runAs, sendRequestError, setCharacterEncoding, setContentLength, shutdown, skip, startDuplex, startInvocation
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface com.caucho.network.listen.ProtocolConnection
getProtocolRequestURL, handleResume, init
 

Field Detail

HMUX_CHANNEL

public static final int HMUX_CHANNEL
See Also:
Constant Field Values

HMUX_ACK

public static final int HMUX_ACK
See Also:
Constant Field Values

HMUX_ERROR

public static final int HMUX_ERROR
See Also:
Constant Field Values

HMUX_YIELD

public static final int HMUX_YIELD
See Also:
Constant Field Values

HMUX_QUIT

public static final int HMUX_QUIT
See Also:
Constant Field Values

HMUX_EXIT

public static final int HMUX_EXIT
See Also:
Constant Field Values

HMUX_DATA

public static final int HMUX_DATA
See Also:
Constant Field Values

HMUX_URI

public static final int HMUX_URI
See Also:
Constant Field Values

HMUX_STRING

public static final int HMUX_STRING
See Also:
Constant Field Values

HMUX_HEADER

public static final int HMUX_HEADER
See Also:
Constant Field Values

HMUX_BINARY

public static final int HMUX_BINARY
See Also:
Constant Field Values

HMUX_PROTOCOL

public static final int HMUX_PROTOCOL
See Also:
Constant Field Values

HMUX_META_HEADER

public static final int HMUX_META_HEADER
See Also:
Constant Field Values

CSE_NULL

public static final int CSE_NULL
See Also:
Constant Field Values

CSE_PATH_INFO

public static final int CSE_PATH_INFO
See Also:
Constant Field Values

CSE_PROTOCOL

public static final int CSE_PROTOCOL
See Also:
Constant Field Values

CSE_REMOTE_USER

public static final int CSE_REMOTE_USER
See Also:
Constant Field Values

CSE_QUERY_STRING

public static final int CSE_QUERY_STRING
See Also:
Constant Field Values

HMUX_FLUSH

public static final int HMUX_FLUSH
See Also:
Constant Field Values

CSE_SERVER_PORT

public static final int CSE_SERVER_PORT
See Also:
Constant Field Values

CSE_REMOTE_HOST

public static final int CSE_REMOTE_HOST
See Also:
Constant Field Values

CSE_REMOTE_ADDR

public static final int CSE_REMOTE_ADDR
See Also:
Constant Field Values

CSE_REMOTE_PORT

public static final int CSE_REMOTE_PORT
See Also:
Constant Field Values

CSE_REAL_PATH

public static final int CSE_REAL_PATH
See Also:
Constant Field Values

CSE_SCRIPT_FILENAME

public static final int CSE_SCRIPT_FILENAME
See Also:
Constant Field Values

HMUX_METHOD

public static final int HMUX_METHOD
See Also:
Constant Field Values

CSE_AUTH_TYPE

public static final int CSE_AUTH_TYPE
See Also:
Constant Field Values

CSE_URI

public static final int CSE_URI
See Also:
Constant Field Values

CSE_CONTENT_LENGTH

public static final int CSE_CONTENT_LENGTH
See Also:
Constant Field Values

CSE_CONTENT_TYPE

public static final int CSE_CONTENT_TYPE
See Also:
Constant Field Values

CSE_IS_SECURE

public static final int CSE_IS_SECURE
See Also:
Constant Field Values

HMUX_STATUS

public static final int HMUX_STATUS
See Also:
Constant Field Values

CSE_CLIENT_CERT

public static final int CSE_CLIENT_CERT
See Also:
Constant Field Values

CSE_SERVER_TYPE

public static final int CSE_SERVER_TYPE
See Also:
Constant Field Values

HMUX_SERVER_NAME

public static final int HMUX_SERVER_NAME
See Also:
Constant Field Values

CSE_SEND_HEADER

public static final int CSE_SEND_HEADER
See Also:
Constant Field Values

CSE_FLUSH

public static final int CSE_FLUSH
See Also:
Constant Field Values

CSE_KEEPALIVE

public static final int CSE_KEEPALIVE
See Also:
Constant Field Values

CSE_END

public static final int CSE_END
See Also:
Constant Field Values

CSE_QUERY

public static final int CSE_QUERY
See Also:
Constant Field Values

HMUX_TO_UNIDIR_HMTP

public static final int HMUX_TO_UNIDIR_HMTP
See Also:
Constant Field Values

HMUX_SWITCH_TO_HMTP

public static final int HMUX_SWITCH_TO_HMTP
See Also:
Constant Field Values

HMUX_HMTP_OK

public static final int HMUX_HMTP_OK
See Also:
Constant Field Values

HMUX_DISPATCH_PROTOCOL

public static final int HMUX_DISPATCH_PROTOCOL
See Also:
Constant Field Values

HMUX_JMS_PROTOCOL

public static final int HMUX_JMS_PROTOCOL
See Also:
Constant Field Values
Constructor Detail

HmuxRequest

public HmuxRequest(Server server,
                   SocketLink conn,
                   HmuxProtocol protocol)
Method Detail

createResponse

public HmuxResponse createResponse()
Specified by:
createResponse in class AbstractHttpRequest

isWaitForRead

public boolean isWaitForRead()
Description copied from interface: ProtocolConnection
Return true if the connection should wait for a read before handling the request.

Specified by:
isWaitForRead in interface ProtocolConnection

hasRequest

public boolean hasRequest()
Returns true if a valid HTTP request has started.

Overrides:
hasRequest in class AbstractHttpRequest

isSuspend

public boolean isSuspend()
Overrides:
isSuspend in class AbstractHttpRequest

handleRequest

public boolean handleRequest()
                      throws java.io.IOException
Description copied from interface: ProtocolConnection
Handles a new request. The controlling TcpServer may call handleRequest again after the connection completes, so the implementation must initialize any variables for each connection.

Specified by:
handleRequest in interface ProtocolConnection
Throws:
java.io.IOException

initStream

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

Specified by:
initStream in class AbstractHttpRequest
Throws:
java.io.IOException

checkLogin

protected boolean checkLogin()

onStartConnection

public void onStartConnection()
Description copied from class: AbstractHttpRequest
Called when the connection starts

Specified by:
onStartConnection in interface ProtocolConnection
Overrides:
onStartConnection in class AbstractHttpRequest

startRequest

protected void startRequest(HttpBufferStore httpBuffer)
                     throws java.io.IOException
Clears variables at the start of a new request.

Overrides:
startRequest in class AbstractHttpRequest
Parameters:
httpBuffer - the raw connection stream
Throws:
java.io.IOException

getMethod

public java.lang.String getMethod()
Returns the header.

Specified by:
getMethod in class AbstractHttpRequest

getMethodBuffer

public CharSegment getMethodBuffer()

getHost

protected CharBuffer getHost()
Returns a char buffer containing the host.

Overrides:
getHost in class AbstractHttpRequest

getUriBuffer

public final byte[] getUriBuffer()
Specified by:
getUriBuffer in class AbstractHttpRequest

getUriLength

public final int getUriLength()
Specified by:
getUriLength in class AbstractHttpRequest

getProtocol

public java.lang.String getProtocol()
Returns the protocol.

Specified by:
getProtocol in class AbstractHttpRequest

getProtocolBuffer

public CharSegment getProtocolBuffer()

isSecure

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

Overrides:
isSecure in class AbstractHttpRequest

getHeader

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

Specified by:
getHeader in class AbstractHttpRequest
Parameters:
key - the header key

getHeaderBuffer

public CharSegment getHeaderBuffer(java.lang.String key)
Description copied from class: AbstractHttpRequest
Fills the result with the header values as CharSegment values. Most implementations will implement this directly.

Overrides:
getHeaderBuffer in class AbstractHttpRequest
Parameters:
key - the header name

getHeaderBuffer

public CharSegment getHeaderBuffer(char[] buf,
                                   int length)

setHeader

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

Overrides:
setHeader in class AbstractHttpRequest

getHeaderBuffers

public void getHeaderBuffers(java.lang.String key,
                             java.util.ArrayList<CharSegment> values)
Description copied from class: AbstractHttpRequest
Fills the result with a list of the header values as CharSegment values. Most implementations will implement this directly.

Overrides:
getHeaderBuffers in class AbstractHttpRequest
Parameters:
key - the header name
values - the resulting buffer

getHeaderNames

public java.util.Enumeration<java.lang.String> getHeaderNames()
Description copied from class: AbstractHttpRequest
Enumerates the header keys

Specified by:
getHeaderNames in class AbstractHttpRequest

getRequestURI

public java.lang.String getRequestURI()
Returns the URI for the request, special casing the IIS issues. Because IIS already escapes the URI before sending it, the URI needs to be re-escaped.

Overrides:
getRequestURI in class AbstractHttpRequest

getServerName

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

Overrides:
getServerName in class AbstractHttpRequest

getServerPort

public int getServerPort()
Description copied from class: AbstractHttpRequest
Returns the server's port.

Overrides:
getServerPort in class AbstractHttpRequest

getRemoteAddr

public java.lang.String getRemoteAddr()
Overrides:
getRemoteAddr in class AbstractHttpRequest

getRemoteAddr

public void getRemoteAddr(CharBuffer cb)

printRemoteAddr

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

getRemoteHost

public java.lang.String getRemoteHost()
Overrides:
getRemoteHost in class AbstractHttpRequest

handleConnectionClose

protected void handleConnectionClose()
Called for a connection: close

Overrides:
handleConnectionClose in class AbstractHttpRequest

getNextBuffer

protected byte[] getNextBuffer()

getNextStartOffset

protected int getNextStartOffset()

getNextBufferOffset

protected int getNextBufferOffset()
                           throws java.io.IOException
Throws:
java.io.IOException

setNextBufferOffset

protected void setNextBufferOffset(int offset)
                            throws java.io.IOException
Throws:
java.io.IOException

writeNextBuffer

protected byte[] writeNextBuffer(int offset)
                          throws java.io.IOException
Throws:
java.io.IOException

flushNext

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

flushNextBuffer

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

writeTail

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

onCloseConnection

public void onCloseConnection()
Close when the socket closes.

Specified by:
onCloseConnection in interface ProtocolConnection
Overrides:
onCloseConnection in class AbstractHttpRequest

getRequestId

protected java.lang.String getRequestId()

dbgId

public final java.lang.String dbgId()
Overrides:
dbgId in class AbstractHttpRequest

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object