All Packages Class Hierarchy This Package Previous Next Index
Class org.apache.jserv.JServConnection
java.lang.Object
|
+----java.lang.Thread
|
+----org.apache.jserv.JServConnection
- public class JServConnection
- extends Thread
- implements HttpServletRequest, HttpServletResponse, JServSendError, JServDebug. DebugConstants
This class is the thread that handles all communications between
the Java BM and the web server.
- Author:
- Alexei Kosut, Francis J. Lacoste
-
JServConnection(Socket, Hashtable)
- Initalize the streams and starts the thread.
-
addCookie(Cookie)
- Adds the specified cookie to the response.
-
containsHeader(String)
- Checks whether the response message header has a field with
the specified name.
-
encodeRedirectUrl(String)
- Encodes the specified URL for use in the
sendRedirect
method or, if encoding is not needed,
returns the URL unchanged.
-
encodeUrl(String)
- Encodes the specified URL by including the session ID in it,
or, if encoding is not needed, returns the URL unchanged.
-
findStatusString(int)
- Finds a status string from one of the standard
status code.
-
getAttribute(String)
- Returns the value of the named attribute of the request, or
null if the attribute does not exist.
-
getAuthType()
- Gets the authentication scheme of this request.
-
getCharacterEncoding()
- Returns the character set encoding used for this MIME body.
-
getContentLength()
- Returns the size of the request entity data, or -1 if not
known.
-
getContentType()
- Returns the Internet Media Type of the request entity data,
or null if not known.
-
getCookies()
- Gets the array of cookies found in this request.
-
getDateHeader(String)
- Gets the value of the requested date header field of this
request.
-
getHeader(String)
- Gets the value of the requested header field of this request.
-
getHeaderNames()
- Gets the header names for this request.
-
getInputStream()
- Returns an input stream for reading binary data in the request body.
-
getIntHeader(String)
- Gets the value of the specified integer header field of this
request.
-
getMethod()
- Gets the HTTP method (for example, GET, POST, PUT) with which
this request was made.
-
getOutputStream()
- Returns an output stream for writing binary response data.
-
getParameter(String)
- Returns a string containing the lone value of the specified
parameter, or null if the parameter does not exist.
Deprecated.
-
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.
-
getParameterValues(String)
- Returns the values of the specified parameter for the request as
an array of strings, or null if the named parameter does not
exist.
-
getPathInfo()
- Gets any optional extra path information following the servlet
path of this request's URI, but immediately preceding its query
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.
-
getProtocol()
- Returns the protocol and version of the request as a string of
the form
<protocol>/<major version>.<minor
version>
.
-
getQueryString()
- Gets any query string that is part of the servlet URI.
-
getReader()
- Returns a buffered reader for reading text in the request body.
-
getRealPath(String)
- 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.
-
getRemoteAddr()
- Returns the IP address of the agent that sent the request.
-
getRemoteHost()
- Returns the fully qualified host name of the agent that sent the
request.
-
getRemoteUser()
- Gets the name of the user making this request.
-
getRequestedSessionId()
- Gets the session id specified with this request.
-
getRequestURI()
- Gets this request's URI as a URL.
-
getScheme()
- Returns the scheme of the URL used in this request, for example
"http", "https", or "ftp".
-
getServerName()
- Returns the host name of the server that received the request.
-
getServerPort()
- Returns the port number on which this request was received.
-
getServletPath()
- Gets the part of this request's URI that refers to the servlet
being invoked.
-
getSession(boolean)
- 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.
-
getWriter()
- Returns a print writer for writing formatted text responses.
-
isRequestedSessionIdFromCookie()
- Checks whether the session id specified by this request came in
as a cookie.
-
isRequestedSessionIdFromUrl()
- Checks whether the session id specified by this request came in
as part of the URL.
-
isRequestedSessionIdValid()
- Checks whether this request is associated with a session that
is valid in the current session context.
-
run()
-
-
sendError(int)
- Sends an error response to the client using the specified
status code and a default message.
-
sendError(int, String)
- Sends an error response to the client using the specified status
code and descriptive message.
-
sendError(Throwable)
- JServSendError method.
-
sendHttpHeaders()
-
-
sendRedirect(String)
- Sends a temporary redirect response to the client using the
specified redirect location URL.
-
setContentLength(int)
- Sets the content length for this response.
-
setContentType(String)
- Sets the content type for this response.
-
setDateHeader(String, long)
- Adds a field to the response header with the given name and
date-valued field.
-
setHeader(String, String)
- Adds a field to the response header with the given name and value.
-
setIntHeader(String, int)
- Adds a field to the response header with the given name and
integer value.
-
setParameter(String, String)
- added for the tag support - RZ.
-
setStatus(int)
-
Sets the status code for this response.
-
setStatus(int, String)
- Sets the status code and message for this response.
JServConnection
public JServConnection(Socket client_socket,
Hashtable mgrTable)
- Initalize the streams and starts the thread.
run
public void run()
- Overrides:
- run in class Thread
findStatusString
public static final String findStatusString(int sc)
- Finds a status string from one of the standard
status code.
- Parameters:
- sc - The status code to find a descriptive string.
- Returns:
- A string describing this status code.
sendHttpHeaders
protected void sendHttpHeaders()
getContentLength
public int getContentLength()
- Returns the size of the request entity data, or -1 if not
known. Same as the CGI variable CONTENT_LENGTH.
getContentType
public String getContentType()
- Returns the Internet Media Type of the request entity data,
or null if not known. Same as the CGI variable
CONTENT_TYPE.
getProtocol
public String getProtocol()
- Returns the protocol and version of the request as a string of
the form
<protocol>/<major version>.<minor
version>
. Same as the CGI variable SERVER_PROTOCOL.
getScheme
public String getScheme()
- Returns the scheme of the URL used in this request, for example
"http", "https", or "ftp". Different schemes have different
rules for constructing URLs, as noted in RFC 1738. The URL used
to create a request may be reconstructed using this scheme, the
server name and port, and additional information such as URIs.
getServerName
public String getServerName()
- Returns the host name of the server that received the request.
Same as the CGI variable SERVER_NAME.
getServerPort
public int getServerPort()
- Returns the port number on which this request was received.
Same as the CGI variable SERVER_PORT.
getRemoteAddr
public String getRemoteAddr()
- Returns the IP address of the agent that sent the request.
Same as the CGI variable REMOTE_ADDR.
getRemoteHost
public String getRemoteHost()
- Returns the fully qualified host name of the agent that sent the
request. Same as the CGI variable REMOTE_HOST.
getRealPath
public String getRealPath(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. For example, an HTTP servlet would
resolve the path using the virtual docroot, if virtual hosting
is enabled, and with the default docroot otherwise. Calling
this method with the string "/" as an argument returns the
document root.
- Parameters:
- path - The virtual path to be translated to a real path.
getInputStream
public ServletInputStream getInputStream() throws IOException
- Returns an input stream for reading binary data in the request body.
- Throws: IllegalStateException
- if getReader has been
called on this same request.
- Throws: IOException
- n other I/O related errors.
getParameter
public String getParameter(String name)
- Note: getParameter() is deprecated.
Please use getParameterValues
- Returns a string containing the lone value of the specified
parameter, or null if the parameter does not exist. For example,
in an HTTP servlet this method would return the value of the
specified query string parameter. Servlet writers should use
this method only when they are sure that there is only one value
for the parameter. If the parameter has (or could have)
multiple values, servlet writers should use
getParameterValues. If a multiple valued parameter name is
passed as an argument, the return value is implementation
dependent.
- Parameters:
- name - the name of the parameter whose value is required.
setParameter
public void setParameter(String name,
String value)
- added for the tag support - RZ.
provides the ability to add to the request object
the parameter of an embedded servlet.
getParameterValues
public String[] getParameterValues(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. For example, in an HTTP servlet this method would return
the values of the specified query string or posted form as an
array of strings.
- Parameters:
- name - the name of the parameter whose value is required.
getParameterNames
public 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. The input stream would be empty
if all the data had been read from the stream returned by the
method getInputStream.
getAttribute
public Object getAttribute(String name)
- Returns the value of the named attribute of the request, or
null if the attribute does not exist. This method allows
access to request information not already provided by the other
methods in this interface. Attribute names should follow the
same convention as package names.
The following predefined attributes are provided.
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>".
getReader
public BufferedReader getReader() throws IOException
- Returns a buffered reader for reading text in the request body.
This translates character set encodings as appropriate.
- Throws: IllegalStateException
- if getOutputStream has been
called on this same request.
- Throws: IOException
- on other I/O related errors.
- Throws: UnsupportedEncodingException
- if the character set encoding
is unsupported, so the text can't be correctly decoded.
getCookies
public Cookie[] getCookies()
- Gets the array of cookies found in this request.
- Returns:
- the array of cookies found in this request.
getMethod
public String getMethod()
- Gets the HTTP method (for example, GET, POST, PUT) with which
this request was made. Same as the CGI variable REQUEST_METHOD.
- Returns:
- the HTTP method with which this request was made.
getRequestURI
public String getRequestURI()
- Gets this request's URI as a URL.
- Returns:
- this request's URI as a URL.
getServletPath
public String getServletPath()
- Gets the part of this request's URI that refers to the servlet
being invoked. Analogous to the CGI variable SCRIPT_NAME.
- Returns:
- the servlet being invoked, as contained in this
request's URI.
getPathInfo
public String getPathInfo()
- Gets any optional extra path information following the servlet
path of this request's URI, but immediately preceding its query
string. Same as the CGI variable PATH_INFO.
- Returns:
- the optional path information following the servlet
path, but before the query string, in this request's URI; null
if this request's URI contains no extra path information.
getPathTranslated
public 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. Same as the CGI
variable PATH_TRANSLATED.
- Returns:
- extra path information translated to a real path or null
if no extra path information is in the request's URI.
getQueryString
public String getQueryString()
- Gets any query string that is part of the servlet URI. Same as
the CGI variable QUERY_STRING.
- Returns:
- query string that is part of this request's URI, or null
if it contains no query string.
getRemoteUser
public String getRemoteUser()
- Gets the name of the user making this request. The user name is
set with HTTP authentication. Whether the user name will
continue to be sent with each subsequent communication is
browser-dependent. Same as the CGI variable REMOTE_USER.
- Returns:
- the name of the user making this request, or null if not
known.
getAuthType
public String getAuthType()
- Gets the authentication scheme of this request. Same as the CGI
variable AUTH_TYPE.
- Returns:
- this request's authentication scheme, or null if none.
getHeader
public String getHeader(String name)
- Gets the value of the requested header field of this request.
The case of the header field name is ignored.
- Parameters:
- name - the String containing the name of the requested
header field.
- Returns:
- the value of the requested header field, or null if not
known.
getIntHeader
public int getIntHeader(String name)
- Gets the value of the specified integer header field of this
request. The case of the header field name is ignored. If the
header can't be converted to an integer, the method throws a
NumberFormatException.
- Parameters:
- name - the String containing the name of the requested
header field.
- Returns:
- the value of the requested header field, or -1 if not
found.
getDateHeader
public long getDateHeader(String name)
- Gets the value of the requested date header field of this
request. If the header can't be converted to a date, the method
throws an IllegalArgumentException. The case of the header
field name is ignored.
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
- Parameters:
- name - the String containing the name of the requested
header field.
- Returns:
- the value the requested date header field, or -1 if not
found.
getHeaderNames
public Enumeration getHeaderNames()
- Gets the header names for this request.
- Returns:
- an enumeration of strings representing the header names
for this request. Some server implementations do not allow
headers to be accessed in this way, in which case this method
will return null.
getSession
public 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.
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.
- Returns:
- the session associated with this request or null if
create was false and no valid session is associated
with this request.
getRequestedSessionId
public String getRequestedSessionId()
- Gets the session id specified with this request. This may
differ from the actual session id. For example, if the request
specified an id for an invalid session, then this will get a new
session with a new id.
- Returns:
- the session id specified by this request, or null if the
request did not specify a session id.
- See Also:
- isRequestedSessionIdValid
isRequestedSessionIdValid
public boolean isRequestedSessionIdValid()
- Checks whether this request is associated with a session that
is valid in the current session context. If it is not valid,
the requested session will never be returned from the
getSession
method.
- Returns:
- true if this request is assocated with a session that is
valid in the current session context.
- See Also:
- getRequestedSessionId
isRequestedSessionIdFromCookie
public boolean isRequestedSessionIdFromCookie()
- Checks whether the session id specified by this request came in
as a cookie. (The requested session may not be one returned by
the
getSession
method.)
- Returns:
- true if the session id specified by this request came in
as a cookie; false otherwise.
- See Also:
- getSession
isRequestedSessionIdFromUrl
public boolean isRequestedSessionIdFromUrl()
- Checks whether the session id specified by this request came in
as part of the URL. (The requested session may not be the one
returned by the
getSession
method.)
- Returns:
- true if the session id specified by the request for this
session came in as part of the URL; false otherwise.
- See Also:
- getSession
setContentLength
public void setContentLength(int len)
- Sets the content length for this response.
- Parameters:
- len - the content length.
setContentType
public void setContentType(String type)
- Sets the content type for this response. This type may later
be implicitly modified by addition of properties such as the MIME
charset=<value> if the service finds it necessary,
and the appropriate media type property has not been set. This
response property may only be assigned one time.
- Parameters:
- type - the content's MIME type
getOutputStream
public ServletOutputStream getOutputStream() throws IOException
- Returns an output stream for writing binary response data.
- Throws: IllegalStateException
- if getWriter has been
called on this same request.
- Throws: IOException
- if an I/O exception has occurred.
- See Also:
- getWriter
getWriter
public PrintWriter getWriter() throws IOException
- Returns a print writer for writing formatted text responses. The
MIME type of the response will be modified, if necessary, to reflect
the character encoding used, through the charset=...
property. This means that the content type must be set before
calling this method.
- Throws: IllegalStateException
- if getOutputStream has been
called on this same request.
- Throws: IOException
- on other errors.
- Throws: UnsupportedEncodingException
- if the character set encoding
- See Also:
- getOutputStream, setContentType
getCharacterEncoding
public String getCharacterEncoding()
- Returns the character set encoding used for this MIME body.
The character encoding is either the one specified in the
assigned content type, or one which the client understands.
If no content type has yet been assigned, it is implicitly
set to text/plain
addCookie
public void addCookie(Cookie cookie)
- Adds the specified cookie to the response. It can be called
multiple times to set more than one cookie.
- Parameters:
- cookie - the Cookie to return to the client
containsHeader
public boolean containsHeader(String name)
- Checks whether the response message header has a field with
the specified name.
- Parameters:
- name - the header field name.
- Returns:
- true if the response message header has a field with
the specified name; false otherwise.
setStatus
public void setStatus(int sc,
String sm)
- Sets the status code and message for this response. If the
field had already been set, the new value overwrites the
previous one. The message is sent as the body of an HTML
page, which is returned to the user to describe the problem.
The page is sent with a default HTML header; the message
is enclosed in simple body tags (<body></body>).
- Parameters:
- sc - the status code.
- sm - the status message.
setStatus
public void setStatus(int sc)
- Sets the status code for this response. This method is used to
set the return status code when there is no error (for example,
for the status codes SC_OK or SC_MOVED_TEMPORARILY). If there
is an error, the
sendError
method should be used
instead.
- Parameters:
- sc - the status code
- See Also:
- sendError
setHeader
public void setHeader(String name,
String value)
- Adds a field to the response header with the given name and value.
If the field had already been set, the new value overwrites the
previous one. The
containsHeader
method can be
used to test for the presence of a header before setting its
value.
- Parameters:
- name - the name of the header field
- value - the header field's value
- See Also:
- containsHeader
setIntHeader
public void setIntHeader(String name,
int value)
- Adds a field to the response header with the given name and
integer value. If the field had already been set, the new value
overwrites the previous one. The
containsHeader
method can be used to test for the presence of a header before
setting its value.
- Parameters:
- name - the name of the header field
- value - the header field's integer value
- See Also:
- containsHeader
setDateHeader
public void setDateHeader(String name,
long date)
- Adds a field to the response header with the given name and
date-valued field. The date is specified in terms of
milliseconds since the epoch. If the date field had already
been set, the new value overwrites the previous one. The
containsHeader
method can be used to test for the
presence of a header before setting its value.
- Parameters:
- name - the name of the header field
- value - the header field's date value
- See Also:
- containsHeader
sendError
public void sendError(int sc,
String msg)
- Sends an error response to the client using the specified status
code and descriptive message. If setStatus has previously been
called, it is reset to the error status code. The message is
sent as the body of an HTML page, which is returned to the user
to describe the problem. The page is sent with a default HTML
header; the message is enclosed in simple body tags
(<body></body>).
- Parameters:
- sc - the status code
- msg - the detail message
sendError
public void sendError(int sc)
- Sends an error response to the client using the specified
status code and a default message.
- Parameters:
- sc - the status code
sendError
public void sendError(Throwable e)
- JServSendError method. This sends an error message to Apache
when an exception occur in the ServletEngine.
sendRedirect
public void sendRedirect(String location) throws IOException
- Sends a temporary redirect response to the client using the
specified redirect location URL. The URL must be absolute (for
example,
https://hostname/path/file.html
).
Relative URLs are not permitted here.
- Parameters:
- location - the redirect location URL
- Throws: IOException
- If an I/O error has occurred.
encodeUrl
public String encodeUrl(String url)
- Encodes the specified URL by including the session ID in it,
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.
For example, if the browser supports cookies, or session
tracking is turned off, URL encoding is unnecessary.
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.
- Parameters:
- url - the url to be encoded.
- Returns:
- the encoded URL if encoding is needed; the unchanged URL
otherwise.
encodeRedirectUrl
public String encodeRedirectUrl(String url)
- Encodes the specified URL for use in the
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.
- Parameters:
- url - the url to be encoded.
- Returns:
- the encoded URL if encoding is needed; the unchanged URL
otherwise.
- See Also:
- sendRedirect, encodeUrl
All Packages Class Hierarchy This Package Previous Next Index