org.apache.jserv
Class JServConnection

java.lang.Object
  |
  +--org.apache.jserv.JServConnection

public class JServConnection
extends java.lang.Object
implements Stoppable, javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse, JServSendError, JServLogChannels

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)

Version:
$Revision: 1.80 $ $Date: 2000/05/21 19:46:14 $

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 tag support - RZ.
 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
, clone, equals, finalize, getClass, hashCode, notify, notifyAll, registerNatives, toString, wait, wait, wait
 

Field Detail

client

protected java.net.Socket client

in

protected Ajpv12InputStream in

out

protected java.io.OutputStream out

mgr

protected JServServletManager mgr

context

protected JServContext context

servlet

protected javax.servlet.Servlet servlet

servletmethod

protected java.lang.String servletmethod

servletname

protected java.lang.String servletname

servletzone

protected java.lang.String servletzone

hostname

protected java.lang.String hostname

stm_servlet

protected boolean stm_servlet

auth

protected java.lang.String auth

signal

protected int signal

servlet_in

protected JServConnection.JServInputStream servlet_in

servlet_out

protected JServConnection.JServOutputStream servlet_out

servlet_reader

protected java.io.BufferedReader servlet_reader

called_getInput

protected boolean called_getInput

servlet_writer

protected java.io.PrintWriter servlet_writer

called_getOutput

protected boolean called_getOutput

headers_in

protected java.util.Hashtable headers_in

headers_out

protected java.util.Hashtable headers_out

env_vars

protected java.util.Hashtable env_vars

cookies_in

protected javax.servlet.http.Cookie[] cookies_in

cookies_out

protected java.util.Vector cookies_out

status

protected int status

status_string

protected java.lang.String status_string

params

protected java.util.Hashtable params

got_input

protected boolean got_input

sent_header

protected boolean sent_header

session

protected JServSession session

requestedSessionId

protected java.lang.String requestedSessionId

idCameAsCookie

protected boolean idCameAsCookie

idCameAsUrl

protected boolean idCameAsUrl

semaphore

private Semaphore semaphore
Constructor Detail

JServConnection

public JServConnection()
Method Detail

init

public void init(java.net.Socket clientSocket,
                 Semaphore s)
Initalize the connection handler with the client socket.

run

public void run()
This methods provides and incapsulates the Servlet service.
Specified by:
run in interface Stoppable

processRequest

protected void processRequest()

stop

public 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.
Specified by:
stop in interface Stoppable

readData

protected void readData()
                 throws java.lang.Exception
Read all the data.

sendHttpHeaders

protected void sendHttpHeaders()
Send the HTTP headers and prepare to send response.

getHostName

public java.lang.String getHostName()
Return the hostname

getJServRoute

public java.lang.String getJServRoute()
Returns the JServ Identifier for this server it is passed in through the env_vars as "JSERV_ROUTE"

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 java.lang.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 java.lang.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 java.lang.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 java.lang.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 java.lang.String getRemoteAddr()
Returns the IP address of the agent that sent the request. Same as the CGI variable REMOTE_ADDR.

getRemoteHost

public java.lang.String getRemoteHost()
Returns the fully qualified host name of the agent that sent the request. Same as the CGI variable REMOTE_HOST.

getRealPath

public 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. 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 javax.servlet.ServletInputStream getInputStream()
                                                throws java.io.IOException
Returns an input stream for reading binary data in the request body.
Throws:
IllegalStateException - if getReader has been called on this same request.
java.io.IOException - n other I/O related errors.

parseParams

protected void parseParams()
Parse parameter stuff. This code now implements parameter merging when parameters are found in both the query string and the input stream. In such cases, parameter values retrieved from the query string will be the first one(s) in the result from calling getParameterValues().

This method unconditionally creates the params Hashtable. If a parsing error occurred, the Hashtable will be empty.


getParameter

public java.lang.String getParameter(java.lang.String name)
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(java.lang.String name,
                         java.lang.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 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. 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 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. The input stream would be empty if all the data had been read from the stream returned by the method getInputStream.

getAttribute

public 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. 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 java.io.BufferedReader getReader()
                                 throws java.io.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.
java.io.IOException - on other I/O related errors.
java.io.UnsupportedEncodingException - if the character set encoding is unsupported, so the text can't be correctly decoded.

getCookies

public javax.servlet.http.Cookie[] getCookies()
Gets the array of cookies found in this request.
Specified by:
getCookies in interface javax.servlet.http.HttpServletRequest
Returns:
the array of cookies found in this request.

getMethod

public java.lang.String getMethod()
Gets the HTTP method (for example, GET, POST, PUT) with which this request was made. Same as the CGI variable REQUEST_METHOD.
Specified by:
getMethod in interface javax.servlet.http.HttpServletRequest
Returns:
the HTTP method with which this request was made.

getRequestURI

public java.lang.String getRequestURI()
Gets this request's URI as a URL.
Specified by:
getRequestURI in interface javax.servlet.http.HttpServletRequest
Returns:
this request's URI as a URL.

getServletPath

public java.lang.String getServletPath()
Gets the part of this request's URI that refers to the servlet being invoked. Analogous to the CGI variable SCRIPT_NAME.
Specified by:
getServletPath in interface javax.servlet.http.HttpServletRequest
Returns:
the servlet being invoked, as contained in this request's URI.

getPathInfo

public 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. Same as the CGI variable PATH_INFO.
Specified by:
getPathInfo in interface javax.servlet.http.HttpServletRequest
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 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. Same as the CGI variable PATH_TRANSLATED.
Specified by:
getPathTranslated in interface javax.servlet.http.HttpServletRequest
Returns:
extra path information translated to a real path or null if no extra path information is in the request's URI.

getQueryString

public java.lang.String getQueryString()
Gets any query string that is part of the servlet URI. Same as the CGI variable QUERY_STRING.
Specified by:
getQueryString in interface javax.servlet.http.HttpServletRequest
Returns:
query string that is part of this request's URI, or null if it contains no query string.

getRemoteUser

public java.lang.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.
Specified by:
getRemoteUser in interface javax.servlet.http.HttpServletRequest
Returns:
the name of the user making this request, or null if not known.

getAuthType

public java.lang.String getAuthType()
Gets the authentication scheme of this request. Same as the CGI variable AUTH_TYPE.
Specified by:
getAuthType in interface javax.servlet.http.HttpServletRequest
Returns:
this request's authentication scheme, or null if none.

getHeader

public java.lang.String getHeader(java.lang.String name)
Gets the value of the requested header field of this request. The case of the header field name is ignored.
Specified by:
getHeader in interface javax.servlet.http.HttpServletRequest
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(java.lang.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.
Specified by:
getIntHeader in interface javax.servlet.http.HttpServletRequest
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(java.lang.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
 
Specified by:
getDateHeader in interface javax.servlet.http.HttpServletRequest
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 java.util.Enumeration getHeaderNames()
Gets the header names for this request.
Specified by:
getHeaderNames in interface javax.servlet.http.HttpServletRequest
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 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.

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.

Specified by:
getSession in interface javax.servlet.http.HttpServletRequest
Returns:
the session associated with this request or null if create was false and no valid session is associated with this request.

getRequestedSessionId

public java.lang.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.
Specified by:
getRequestedSessionId in interface javax.servlet.http.HttpServletRequest
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.
Specified by:
isRequestedSessionIdValid in interface javax.servlet.http.HttpServletRequest
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.)
Specified by:
isRequestedSessionIdFromCookie in interface javax.servlet.http.HttpServletRequest
Returns:
true if the session id specified by this request came in as a cookie; false otherwise.
See Also:
getSession( boolean )

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.)
Specified by:
isRequestedSessionIdFromUrl in interface javax.servlet.http.HttpServletRequest
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( boolean )

setContentLength

public void setContentLength(int len)
Sets the content length for this response.
Parameters:
len - the content length.

setContentType

public void setContentType(java.lang.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 javax.servlet.ServletOutputStream getOutputStream()
                                                  throws java.io.IOException
Returns an output stream for writing binary response data.
Throws:
IllegalStateException - if getWriter has been called on this same request.
java.io.IOException - if an I/O exception has occurred.
See Also:
getWriter()

getWriter

public java.io.PrintWriter getWriter()
                              throws java.io.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.
java.io.IOException - on other errors.
java.io.UnsupportedEncodingException - if the character set encoding
See Also:
getOutputStream(), setContentType(java.lang.String)

getCharacterEncoding

public java.lang.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(javax.servlet.http.Cookie cookie)
Adds the specified cookie to the response. It can be called multiple times to set more than one cookie.
Specified by:
addCookie in interface javax.servlet.http.HttpServletResponse
Parameters:
cookie - the Cookie to return to the client

containsHeader

public boolean containsHeader(java.lang.String name)
Checks whether the response message header has a field with the specified name.
Specified by:
containsHeader in interface javax.servlet.http.HttpServletResponse
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,
                      java.lang.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>).
Specified by:
setStatus in interface javax.servlet.http.HttpServletResponse
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.
Specified by:
setStatus in interface javax.servlet.http.HttpServletResponse
Parameters:
sc - the status code
See Also:
sendError(int, java.lang.String)

setHeader

public void setHeader(java.lang.String name,
                      java.lang.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.
Specified by:
setHeader in interface javax.servlet.http.HttpServletResponse
Parameters:
name - the name of the header field
value - the header field's value
See Also:
containsHeader(java.lang.String)

setIntHeader

public void setIntHeader(java.lang.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.
Specified by:
setIntHeader in interface javax.servlet.http.HttpServletResponse
Parameters:
name - the name of the header field
value - the header field's integer value
See Also:
containsHeader(java.lang.String)

setDateHeader

public void setDateHeader(java.lang.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.
Specified by:
setDateHeader in interface javax.servlet.http.HttpServletResponse
Parameters:
name - the name of the header field
value - the header field's date value
See Also:
containsHeader(java.lang.String)

sendError

public void sendError(int sc,
                      java.lang.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>).
Specified by:
sendError in interface javax.servlet.http.HttpServletResponse
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.
Specified by:
sendError in interface javax.servlet.http.HttpServletResponse
Parameters:
sc - the status code

sendError

public void sendError(java.lang.Throwable e)
JServSendError method. This sends an error message to Apache when an exception occur in the ServletEngine.
Specified by:
sendError in interface JServSendError

sendRedirect

public void sendRedirect(java.lang.String location)
                  throws java.io.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.
Specified by:
sendRedirect in interface javax.servlet.http.HttpServletResponse
Parameters:
location - the redirect location URL
Throws:
java.io.IOException - If an I/O error has occurred.

encodeUrl

public 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. 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.

Specified by:
encodeUrl in interface javax.servlet.http.HttpServletResponse
Parameters:
url - the url to be encoded.
Returns:
the encoded URL if encoding is needed; the unchanged URL otherwise.

encodeRedirectUrl

public 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. 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.

Specified by:
encodeRedirectUrl in interface javax.servlet.http.HttpServletResponse
Parameters:
url - the url to be encoded.
Returns:
the encoded URL if encoding is needed; the unchanged URL otherwise.
See Also:
sendRedirect(java.lang.String), encodeUrl(java.lang.String)

findStatusString

public static final java.lang.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.