|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--org.apache.jserv.JServConnection
This class is the thread that handles all communications between the Java VM and the web server. Note: this class is highly optimized for speed and we sacrificed some code readability for that. We already know this code is a mess and it's a huge class with C-like design style. So, we apologize for the lack of elegance in this code but we hope you'll appreciate its stability and performance. (SM)
Inner Class Summary | |
protected class |
JServConnection.JServInputStream
ServletInputStream implementation as inner class |
(package private) class |
JServConnection.JServOutputStream
ServletOutputStream implementation as inner class |
Field Summary | |
protected java.lang.String |
auth
|
protected boolean |
called_getInput
|
protected boolean |
called_getOutput
|
protected java.net.Socket |
client
|
protected JServContext |
context
|
protected javax.servlet.http.Cookie[] |
cookies_in
|
protected java.util.Vector |
cookies_out
|
protected java.util.Hashtable |
env_vars
|
protected boolean |
got_input
|
protected java.util.Hashtable |
headers_in
|
protected java.util.Hashtable |
headers_out
|
protected java.lang.String |
hostname
|
protected boolean |
idCameAsCookie
|
protected boolean |
idCameAsUrl
|
protected Ajpv12InputStream |
in
|
protected JServServletManager |
mgr
|
protected java.io.OutputStream |
out
|
protected java.util.Hashtable |
params
|
protected java.lang.String |
requestedSessionId
|
private Semaphore |
semaphore
|
protected boolean |
sent_header
|
protected javax.servlet.Servlet |
servlet
|
protected JServConnection.JServInputStream |
servlet_in
|
protected JServConnection.JServOutputStream |
servlet_out
|
protected java.io.BufferedReader |
servlet_reader
|
protected java.io.PrintWriter |
servlet_writer
|
protected java.lang.String |
servletmethod
|
protected java.lang.String |
servletname
|
protected java.lang.String |
servletzone
|
protected JServSession |
session
|
protected int |
signal
|
protected int |
status
|
protected java.lang.String |
status_string
|
protected boolean |
stm_servlet
|
Constructor Summary | |
JServConnection()
|
Method Summary | |
void |
addCookie(javax.servlet.http.Cookie cookie)
Adds the specified cookie to the response. |
boolean |
containsHeader(java.lang.String name)
Checks whether the response message header has a field with the specified name. |
java.lang.String |
encodeRedirectUrl(java.lang.String url)
Encodes the specified URL for use in the sendRedirect method or, if encoding is not needed,
returns the URL unchanged. |
java.lang.String |
encodeUrl(java.lang.String url)
Encodes the specified URL by including the session ID in it, or, if encoding is not needed, returns the URL unchanged. |
static java.lang.String |
findStatusString(int sc)
Finds a status string from one of the standard status code. |
java.lang.Object |
getAttribute(java.lang.String name)
Returns the value of the named attribute of the request, or null if the attribute does not exist. |
java.lang.String |
getAuthType()
Gets the authentication scheme of this request. |
java.lang.String |
getCharacterEncoding()
Returns the character set encoding used for this MIME body. |
int |
getContentLength()
Returns the size of the request entity data, or -1 if not known. |
java.lang.String |
getContentType()
Returns the Internet Media Type of the request entity data, or null if not known. |
javax.servlet.http.Cookie[] |
getCookies()
Gets the array of cookies found in this request. |
long |
getDateHeader(java.lang.String name)
Gets the value of the requested date header field of this request. |
java.lang.String |
getHeader(java.lang.String name)
Gets the value of the requested header field of this request. |
java.util.Enumeration |
getHeaderNames()
Gets the header names for this request. |
java.lang.String |
getHostName()
Return the hostname |
javax.servlet.ServletInputStream |
getInputStream()
Returns an input stream for reading binary data in the request body. |
int |
getIntHeader(java.lang.String name)
Gets the value of the specified integer header field of this request. |
java.lang.String |
getJServRoute()
Returns the JServ Identifier for this server it is passed in through the env_vars as "JSERV_ROUTE" |
java.lang.String |
getMethod()
Gets the HTTP method (for example, GET, POST, PUT) with which this request was made. |
javax.servlet.ServletOutputStream |
getOutputStream()
Returns an output stream for writing binary response data. |
java.lang.String |
getParameter(java.lang.String name)
Deprecated. Please use getParameterValues |
java.util.Enumeration |
getParameterNames()
Returns the parameter names for this request as an enumeration of strings, or an empty enumeration if there are no parameters or the input stream is empty. |
java.lang.String[] |
getParameterValues(java.lang.String name)
Returns the values of the specified parameter for the request as an array of strings, or null if the named parameter does not exist. |
java.lang.String |
getPathInfo()
Gets any optional extra path information following the servlet path of this request's URI, but immediately preceding its query string. |
java.lang.String |
getPathTranslated()
Gets any optional extra path information following the servlet path of this request's URI, but immediately preceding its query string, and translates it to a real path. |
java.lang.String |
getProtocol()
Returns the protocol and version of the request as a string of the form <protocol>/<major version>.<minor
version> . |
java.lang.String |
getQueryString()
Gets any query string that is part of the servlet URI. |
java.io.BufferedReader |
getReader()
Returns a buffered reader for reading text in the request body. |
java.lang.String |
getRealPath(java.lang.String path)
Applies alias rules to the specified virtual path and returns the corresponding real path, or null if the translation can not be performed for any reason. |
java.lang.String |
getRemoteAddr()
Returns the IP address of the agent that sent the request. |
java.lang.String |
getRemoteHost()
Returns the fully qualified host name of the agent that sent the request. |
java.lang.String |
getRemoteUser()
Gets the name of the user making this request. |
java.lang.String |
getRequestedSessionId()
Gets the session id specified with this request. |
java.lang.String |
getRequestURI()
Gets this request's URI as a URL. |
java.lang.String |
getScheme()
Returns the scheme of the URL used in this request, for example "http", "https", or "ftp". |
java.lang.String |
getServerName()
Returns the host name of the server that received the request. |
int |
getServerPort()
Returns the port number on which this request was received. |
java.lang.String |
getServletPath()
Gets the part of this request's URI that refers to the servlet being invoked. |
javax.servlet.http.HttpSession |
getSession(boolean create)
Gets the current valid session associated with this request, if create is false or, if necessary, creates a new session for the request, if create is true. |
java.io.PrintWriter |
getWriter()
Returns a print writer for writing formatted text responses. |
void |
init(java.net.Socket clientSocket,
Semaphore s)
Initalize the connection handler with the client socket. |
boolean |
isRequestedSessionIdFromCookie()
Checks whether the session id specified by this request came in as a cookie. |
boolean |
isRequestedSessionIdFromUrl()
Checks whether the session id specified by this request came in as part of the URL. |
boolean |
isRequestedSessionIdValid()
Checks whether this request is associated with a session that is valid in the current session context. |
protected void |
parseParams()
Parse parameter stuff. |
protected void |
processRequest()
|
protected void |
readData()
Read all the data. |
void |
run()
This methods provides and incapsulates the Servlet service. |
void |
sendError(int sc)
Sends an error response to the client using the specified status code and a default message. |
void |
sendError(int sc,
java.lang.String msg)
Sends an error response to the client using the specified status code and descriptive message. |
void |
sendError(java.lang.Throwable e)
JServSendError method. |
protected void |
sendHttpHeaders()
Send the HTTP headers and prepare to send response. |
void |
sendRedirect(java.lang.String location)
Sends a temporary redirect response to the client using the specified redirect location URL. |
void |
setContentLength(int len)
Sets the content length for this response. |
void |
setContentType(java.lang.String type)
Sets the content type for this response. |
void |
setDateHeader(java.lang.String name,
long date)
Adds a field to the response header with the given name and date-valued field. |
void |
setHeader(java.lang.String name,
java.lang.String value)
Adds a field to the response header with the given name and value. |
void |
setIntHeader(java.lang.String name,
int value)
Adds a field to the response header with the given name and integer value. |
void |
setParameter(java.lang.String name,
java.lang.String value)
Added for the |
void |
setStatus(int sc)
Sets the status code for this response. |
void |
setStatus(int sc,
java.lang.String sm)
Sets the status code and message for this response. |
void |
stop()
This method is now empty but will be used when thread timing will be in place to allow graceful signaling of execution timeout. |
Methods inherited from class java.lang.Object |
|
Field Detail |
protected java.net.Socket client
protected Ajpv12InputStream in
protected java.io.OutputStream out
protected JServServletManager mgr
protected JServContext context
protected javax.servlet.Servlet servlet
protected java.lang.String servletmethod
protected java.lang.String servletname
protected java.lang.String servletzone
protected java.lang.String hostname
protected boolean stm_servlet
protected java.lang.String auth
protected int signal
protected JServConnection.JServInputStream servlet_in
protected JServConnection.JServOutputStream servlet_out
protected java.io.BufferedReader servlet_reader
protected boolean called_getInput
protected java.io.PrintWriter servlet_writer
protected boolean called_getOutput
protected java.util.Hashtable headers_in
protected java.util.Hashtable headers_out
protected java.util.Hashtable env_vars
protected javax.servlet.http.Cookie[] cookies_in
protected java.util.Vector cookies_out
protected int status
protected java.lang.String status_string
protected java.util.Hashtable params
protected boolean got_input
protected boolean sent_header
protected JServSession session
protected java.lang.String requestedSessionId
protected boolean idCameAsCookie
protected boolean idCameAsUrl
private Semaphore semaphore
Constructor Detail |
public JServConnection()
Method Detail |
public void init(java.net.Socket clientSocket, Semaphore s)
public void run()
protected void processRequest()
public void stop()
protected void readData() throws java.lang.Exception
protected void sendHttpHeaders()
public java.lang.String getHostName()
public java.lang.String getJServRoute()
public int getContentLength()
public java.lang.String getContentType()
public java.lang.String getProtocol()
<protocol>/<major version>.<minor
version>
. Same as the CGI variable SERVER_PROTOCOL.public java.lang.String getScheme()
public java.lang.String getServerName()
public int getServerPort()
public java.lang.String getRemoteAddr()
public java.lang.String getRemoteHost()
public java.lang.String getRealPath(java.lang.String path)
path
- The virtual path to be translated to a real path.public javax.servlet.ServletInputStream getInputStream() throws java.io.IOException
protected void parseParams()
This method unconditionally creates the params
Hashtable. If a parsing error occurred, the Hashtable will be
empty.
public java.lang.String getParameter(java.lang.String name)
name
- the name of the parameter whose value is required.public void setParameter(java.lang.String name, java.lang.String value)
public java.lang.String[] getParameterValues(java.lang.String name)
name
- the name of the parameter whose value is required.public java.util.Enumeration getParameterNames()
public java.lang.Object getAttribute(java.lang.String name)
Attribute Name | Attribute Type | Description |
---|---|---|
javax.net.ssl.cipher_suite | string | The string name of the SSL cipher suite in use, if the request was made using SSL |
javax.net.ssl.peer_certificates | array of java.security.cert.X509Certificate | The chain of X.509 certificates which authenticates the client. This is only available when SSL is used with client authentication is used. |
javax.net.ssl.session | javax.net.ssl.SSLSession | An SSL session object, if the request was made using SSL. |
The package (and hence attribute) names beginning with java.*, and javax.* are reserved for use by Javasoft. Similarly, com.sun.* is reserved for use by Sun Microsystems.
Note The above attributes are not yet implemented by JServ.
On the other hand, attribute named "org.apache.jserv.<variable>" returns the content of the environment (CGI) variable "<variable>".
public java.io.BufferedReader getReader() throws java.io.IOException
public javax.servlet.http.Cookie[] getCookies()
public java.lang.String getMethod()
public java.lang.String getRequestURI()
public java.lang.String getServletPath()
public java.lang.String getPathInfo()
public java.lang.String getPathTranslated()
public java.lang.String getQueryString()
public java.lang.String getRemoteUser()
public java.lang.String getAuthType()
public java.lang.String getHeader(java.lang.String name)
name
- the String containing the name of the requested
header field.public int getIntHeader(java.lang.String name)
name
- the String containing the name of the requested
header field.public long getDateHeader(java.lang.String name)
From RFC2068: 3.3.1 Full Date HTTP applications have historically allowed three different formats for the representation of date/time stamps: Sun, 06 Nov 1994 08:49:37 GMT ; RFC 822, updated by RFC 1123 Sunday, 06-Nov-94 08:49:37 GMT ; RFC 850, obsoleted by RFC 1036 Sun Nov 6 08:49:37 1994 ; ANSI C's asctime() format The first format is preferred as an Internet standard and represents a fixed-length subset of that defined by RFC 1123 (an update to RFC 822). The second format is in common use, but is based on the obsolete RFC 850 [12] date format and lacks a four-digit year. HTTP/1.1 clients and servers that parse the date value MUST accept all three formats (for compatibility with HTTP/1.0), though they MUST only generate the RFC 1123 format for representing HTTP-date values in header fields
name
- the String containing the name of the requested
header field.public java.util.Enumeration getHeaderNames()
public javax.servlet.http.HttpSession getSession(boolean create)
Note: to ensure the session is properly maintained, the servlet developer must call this method (at least once) before any output is written to the response.
Additionally, application-writers need to be aware that newly
created sessions (that is, sessions for which
HttpSession.isNew
returns true) do not have any
application-specific state.
public java.lang.String getRequestedSessionId()
isRequestedSessionIdValid()
public boolean isRequestedSessionIdValid()
getSession
method.getRequestedSessionId()
public boolean isRequestedSessionIdFromCookie()
getSession
method.)getSession( boolean )
public boolean isRequestedSessionIdFromUrl()
getSession
method.)getSession( boolean )
public void setContentLength(int len)
len
- the content length.public void setContentType(java.lang.String type)
type
- the content's MIME typepublic javax.servlet.ServletOutputStream getOutputStream() throws java.io.IOException
getWriter()
public java.io.PrintWriter getWriter() throws java.io.IOException
getOutputStream()
,
setContentType(java.lang.String)
public java.lang.String getCharacterEncoding()
public void addCookie(javax.servlet.http.Cookie cookie)
cookie
- the Cookie to return to the clientpublic boolean containsHeader(java.lang.String name)
name
- the header field name.public void setStatus(int sc, java.lang.String sm)
sc
- the status code.sm
- the status message.public void setStatus(int sc)
sendError
method should be used
instead.sc
- the status codesendError(int, java.lang.String)
public void setHeader(java.lang.String name, java.lang.String value)
containsHeader
method can be
used to test for the presence of a header before setting its
value.name
- the name of the header fieldvalue
- the header field's valuecontainsHeader(java.lang.String)
public void setIntHeader(java.lang.String name, int value)
containsHeader
method can be used to test for the presence of a header before
setting its value.name
- the name of the header fieldvalue
- the header field's integer valuecontainsHeader(java.lang.String)
public void setDateHeader(java.lang.String name, long date)
containsHeader
method can be used to test for the
presence of a header before setting its value.name
- the name of the header fieldvalue
- the header field's date valuecontainsHeader(java.lang.String)
public void sendError(int sc, java.lang.String msg)
sc
- the status codemsg
- the detail messagepublic void sendError(int sc)
sc
- the status codepublic void sendError(java.lang.Throwable e)
public void sendRedirect(java.lang.String location) throws java.io.IOException
https://hostname/path/file.html
).
Relative URLs are not permitted here.location
- the redirect location URLpublic java.lang.String encodeUrl(java.lang.String url)
All URLs emitted by a Servlet should be run through this method. Otherwise, URL rewriting cannot be used with browsers which do not support cookies.
url
- the url to be encoded.public java.lang.String encodeRedirectUrl(java.lang.String url)
sendRedirect
method or, if encoding is not needed,
returns the URL unchanged. The implementation of this method
should include the logic to determine whether the session ID
needs to be encoded in the URL. Because the rules for making
this determination differ from those used to decide whether to
encode a normal link, this method is seperate from the
encodeUrl
method.
All URLs sent to the HttpServletResponse.sendRedirect method should be run through this method. Otherwise, URL rewriting canont be used with browsers which do not support cookies.
url
- the url to be encoded.sendRedirect(java.lang.String)
,
encodeUrl(java.lang.String)
public static final java.lang.String findStatusString(int sc)
sc
- The status code to find a descriptive string.
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |