com.caucho.server.hmux
Class HmuxRequest

java.lang.Object
  extended by com.caucho.server.connection.AbstractHttpRequest
      extended by com.caucho.server.hmux.HmuxRequest
All Implemented Interfaces:
SecurityContextProvider, CauchoRequest, ServerRequest, HttpServletRequest, ServletRequest

public class HmuxRequest
extends AbstractHttpRequest
implements ServerRequest

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_ACK
           
static int CSE_AUTH_TYPE
           
static int CSE_CLIENT_CERT
           
static int CSE_CLOSE
           
static int CSE_CONTENT_LENGTH
           
static int CSE_CONTENT_TYPE
           
static int CSE_DATA
           
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_PING
           
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 HMTP_ERROR
           
static int HMTP_MESSAGE
           
static int HMTP_PACKET
           
static int HMTP_QUERY_GET
           
static int HMTP_QUERY_RESULT
           
static int HMTP_QUERY_SET
           
static int HMUX_ACK
           
static int HMUX_BINARY
           
static int HMUX_CHANNEL
           
static int HMUX_CLUSTER_PROTOCOL
           
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_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_URI
           
static int HMUX_YIELD
           
 
Fields inherited from class com.caucho.server.connection.AbstractHttpRequest
_calendar, _cb, _conn, _expect100Continue, _hasReadStream, _headerCodes, _hostHeader, _invocation, _rawRead, _readStream, _response, _sessionGroup, _tcpConn, CONTEXT_PATH, ERROR_URI, EXCEPTION, EXCEPTION_TYPE, JSP_EXCEPTION, MESSAGE, PATH_INFO, QUERY_STRING, REQUEST_URI, SERVLET_NAME, SERVLET_PATH, SHUTDOWN, STATUS_CODE
 
Fields inherited from interface javax.servlet.http.HttpServletRequest
BASIC_AUTH, CLIENT_CERT_AUTH, DIGEST_AUTH, FORM_AUTH
 
Constructor Summary
HmuxRequest(DispatchServer server, Connection conn, HmuxProtocol protocol)
           
 
Method Summary
protected  boolean checkLogin()
           
protected  void connectionClose()
          Called for a connection: close
 java.lang.String dbgId()
           
 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 getHeaderNames()
          Enumerates the header keys
protected  CharBuffer getHost()
          Returns a char buffer containing the host.
 java.lang.String getMethod()
          Returns the header.
 CharSegment getMethodBuffer()
           
 java.lang.String getProtocol()
          Returns the protocol.
 CharSegment getProtocolBuffer()
           
 java.lang.String getRemoteAddr()
          Returns the IP address of the remote host, i.e.
 void getRemoteAddr(CharBuffer cb)
           
 java.lang.String getRemoteHost()
          Returns the DNS hostname of the remote host, i.e.
 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()
           
 boolean handleRequest()
          Handles a new request.
protected  boolean initStream(ReadStream readStream, ReadStream rawStream)
          Initialize the read stream from the raw stream.
 boolean isSecure()
          Returns true if the request is secure.
 boolean isTop()
          Returns true for the top-level request, but false for any include() or forward()
 boolean isWaitForRead()
          Return true if the connection should wait for a read before handling the request.
 int printRemoteAddr(byte[] buffer, int offset)
           
 void protocolCloseEvent()
          Handles a close event when the connection is closed.
 void setHeader(java.lang.String key, java.lang.String value)
          Sets the header.
protected  void start()
          Clears variables at the start of a new request.
 void startConnection()
          Called when the connection starts.
 java.lang.String toString()
           
 
Methods inherited from class com.caucho.server.connection.AbstractHttpRequest
addCloseOnExit, addHeaderInt, allowKeepalive, authenticate, cleanup, complete, findSessionIdFromConnection, finish, getAttribute, getAttributeNames, getAuthType, getCharacterEncoding, getConnection, getContentLength, getContentType, getContentTypeBuffer, getContextPath, getCookie, getCookies, getDateHeader, getDispatchServer, getHasCookie, getHeaderKey, getHeaders, getHeaderSize, getHeaderValue, getInputStream, getIntHeader, getInvocation, getLoadedSession, getLocalAddr, getLocale, getLocales, getLocalName, getLocalPort, getLogBuffer, getLongContentLength, getMemorySession, getPageContextPath, getPagePathInfo, getPageQueryString, getPageServletPath, getPageURI, getParameter, getParameterMap, getParameterNames, getParameterValues, getPathInfo, getPathTranslated, getQueryString, getRawInput, getRawReadBuffer, getReader, getRealPath, getRemotePort, getRemoteUser, getRemoteUser, getRequestDepth, getRequestDepth, getRequestDispatcher, getRequestedSessionId, getRequestedSessionIdNoVary, getRequestURL, getResponse, getScheme, getServletContext, getServletName, getServletPath, getServletResponse, getSession, getSession, getSessionCookie, getSessionGroup, getSessionManager, getStartTime, getStream, getStream, getUserPrincipal, getVaryCookie, getVaryCookies, getWebApp, handleResume, init, isIgnoreClientDisconnect, isInitial, isKeepalive, isRequestedSessionIdFromCookie, isRequestedSessionIdFromUrl, isRequestedSessionIdFromURL, isRequestedSessionIdValid, isResumed, isSuspended, isTimeout, isTransportSecure, isUserInRole, killKeepalive, logout, logoutUserPrincipal, removeAttribute, restartServer, resume, runAs, setAttribute, setCharacterEncoding, setHasCookie, setInvocation, setStartTime, setVaryCookie, skip, startResume, suspend, suspend
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface com.caucho.server.port.ServerRequest
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_DATA

public static final int CSE_DATA
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_ACK

public static final int CSE_ACK
See Also:
Constant Field Values

CSE_END

public static final int CSE_END
See Also:
Constant Field Values

CSE_CLOSE

public static final int CSE_CLOSE
See Also:
Constant Field Values

CSE_QUERY

public static final int CSE_QUERY
See Also:
Constant Field Values

CSE_PING

public static final int CSE_PING
See Also:
Constant Field Values

HMTP_MESSAGE

public static final int HMTP_MESSAGE
See Also:
Constant Field Values

HMTP_QUERY_GET

public static final int HMTP_QUERY_GET
See Also:
Constant Field Values

HMTP_QUERY_SET

public static final int HMTP_QUERY_SET
See Also:
Constant Field Values

HMTP_QUERY_RESULT

public static final int HMTP_QUERY_RESULT
See Also:
Constant Field Values

HMTP_ERROR

public static final int HMTP_ERROR
See Also:
Constant Field Values

HMTP_PACKET

public static final int HMTP_PACKET
See Also:
Constant Field Values

HMUX_CLUSTER_PROTOCOL

public static final int HMUX_CLUSTER_PROTOCOL
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(DispatchServer server,
                   Connection conn,
                   HmuxProtocol protocol)
Method Detail

isWaitForRead

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

Specified by:
isWaitForRead in interface ServerRequest

startConnection

public void startConnection()
Called when the connection starts.

Specified by:
startConnection in interface ServerRequest
Overrides:
startConnection in class AbstractHttpRequest

handleRequest

public boolean handleRequest()
                      throws java.io.IOException
Handles a new request. Initializes the protocol handler and the request streams.

Note: ClientDisconnectException must be rethrown to the caller.

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

initStream

protected 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

isTop

public boolean isTop()
Returns true for the top-level request, but false for any include() or forward()

Specified by:
isTop in interface CauchoRequest
Overrides:
isTop in class AbstractHttpRequest

checkLogin

protected boolean checkLogin()

start

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

Overrides:
start in class AbstractHttpRequest
Throws:
java.io.IOException

getMethod

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

Specified by:
getMethod in interface HttpServletRequest
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 interface ServletRequest
Specified by:
getProtocol in class AbstractHttpRequest

getProtocolBuffer

public CharSegment getProtocolBuffer()

isSecure

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

Specified by:
isSecure in interface ServletRequest
Overrides:
isSecure in class AbstractHttpRequest

getHeader

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

Specified by:
getHeader in interface HttpServletRequest
Specified by:
getHeader in class AbstractHttpRequest
Parameters:
key - the header key
Returns:
the header value

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.

Specified by:
setHeader in interface CauchoRequest
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 getHeaderNames()
Description copied from class: AbstractHttpRequest
Enumerates the header keys

Specified by:
getHeaderNames in interface HttpServletRequest
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.

Specified by:
getRequestURI in interface HttpServletRequest
Overrides:
getRequestURI in class AbstractHttpRequest

getServerName

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

Specified by:
getServerName in interface ServletRequest
Overrides:
getServerName in class AbstractHttpRequest

getServerPort

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

Specified by:
getServerPort in interface ServletRequest
Overrides:
getServerPort in class AbstractHttpRequest

getRemoteAddr

public java.lang.String getRemoteAddr()
Description copied from interface: ServletRequest
Returns the IP address of the remote host, i.e. the client browser.

Specified by:
getRemoteAddr in interface ServletRequest
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()
Description copied from interface: ServletRequest
Returns the DNS hostname of the remote host, i.e. the client browser.

Specified by:
getRemoteHost in interface ServletRequest
Overrides:
getRemoteHost in class AbstractHttpRequest

connectionClose

protected void connectionClose()
Called for a connection: close

Overrides:
connectionClose in class AbstractHttpRequest

protocolCloseEvent

public void protocolCloseEvent()
Description copied from interface: ServerRequest
Handles a close event when the connection is closed.

Specified by:
protocolCloseEvent in interface ServerRequest

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