Enhydra 5.1 API

org.enhydra.servlet.connectionMethods.https
Class HttpsRequest

java.lang.Object
  |
  +--org.enhydra.servlet.connectionMethods.https.HttpsRequestProcessor
        |
        +--org.enhydra.servlet.connectionMethods.https.HttpsRequest
All Implemented Interfaces:
javax.servlet.http.HttpServletRequest, org.apache.tomcat.core.RequestAdapter, javax.servlet.ServletRequest

public class HttpsRequest
extends org.enhydra.servlet.connectionMethods.https.HttpsRequestProcessor
implements javax.servlet.http.HttpServletRequest, org.apache.tomcat.core.RequestAdapter

Implementation of a HTTP servlet request for the HTTP connection method.

Version:
$Revision: 1.1 $
Author:
Mark Diekhans
See Also:
javax.servlet.http.HttpsServletRequest, ServletRequest

Field Summary
protected  java.util.Hashtable attributes
          Request attributes.
protected  java.lang.String authType
          The auth type, specified externally.
protected  javax.servlet.http.Cookie[] cookies
          Parser Cookies.
protected  boolean getInputStreamCalled
          , * Has getInputStream() been called on the current request?
protected  HttpsHeaders headers
          Parsed MIME headers.
protected  java.lang.String httpVersion
          Request HTTP Version.
protected  org.enhydra.servlet.connectionMethods.https.HttpsInputStream inputStream
          Input stream associated with the socket.
protected  boolean keepAlive
          Was a keep-alive connection requested?
protected  java.lang.String method
          Request method.
protected  java.util.Hashtable parameters
          Parsed parameters from query string or POST.
protected  java.lang.String queryString
          Query string from URI.
protected  java.io.BufferedReader reader
          Reader for stream.
protected  java.lang.String remoteUser
          The remote user, specified externally.
protected  java.lang.String requestUri
          Request URI (less query string).
protected  java.lang.String serverName
          The server name.
protected  int serverPort
          The server port.
protected  javax.servlet.ServletContext servletContext
          ServletContext object for the current servlet.
protected  java.lang.String servletPath
          The servlet path.
protected  java.net.Socket socket
          The socket associated with the request.
 
Constructor Summary
protected HttpsRequest()
          Construct a new request object.
 
Method Summary
protected  void close()
          Close the socket associate with this object.
 int doRead()
           
 int doRead(byte[] b, int off, int len)
           
protected static java.lang.String filePathToUrlPath(java.lang.String filePath)
          Convert the a platform-specific file path to a URL file path.
protected  void finish()
          Indicate the end of handing a request.
 java.lang.Object getAttribute(java.lang.String name)
          Returns the value of an attribute of the request.
 java.util.Enumeration getAttributeNames()
           
 java.lang.String getAuthType()
          Gets the authentication scheme of this request.
 java.lang.String getCharacterEncoding()
          Get the character set encoding for the input of this request.
 int getContentLength()
          Get the size of the request data.
 java.lang.String getContentType()
          Get the content type of the request.
 java.lang.String getContextPath()
           
 java.lang.String[] getCookieHeaders()
           
 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.util.Enumeration getHeaders(java.lang.String name)
           
 javax.servlet.ServletInputStream getInputStream()
          Get 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.util.Locale getLocale()
           
 java.util.Enumeration getLocales()
           
 java.lang.String getMethod()
          Gets the HTTP method (for example, GET, POST, PUT) with which this request was made.
 org.apache.tomcat.util.MimeHeaders getMimeHeaders()
           
 java.lang.String getParameter(java.lang.String name)
          Get a string containing the lone value of the specified parameter.
 java.util.Enumeration getParameterNames()
          Get the parameter names for this request.
 java.lang.String[] getParameterValues(java.lang.String name)
          Get the values of the specified parameter for the request.
protected  void getParsedParameters()
          Parse either the query string or POST input parameters.
 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()
          Get the protocol and version of the request.
 java.lang.String getQueryString()
          Gets any query string that is part of the HTTP request 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()
          Get the IP address of the agent that sent the request.
 java.lang.String getRemoteHost()
          Get 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.
 javax.servlet.RequestDispatcher getRequestDispatcher(java.lang.String name)
           
 java.lang.String getRequestedSessionId()
          Gets the session id specified with this request.
 java.lang.String getRequestURI()
          Get the part of this request's URI that is to the left of any query string.
 java.lang.String getScheme()
          Get the scheme of the URL used in this request, for example "http", "https", or "ftp".
 java.lang.String getServerName()
          Get the host name of the server that received the request.
 int getServerPort()
          Get the port number on which this request was received.
 java.lang.String getServletName()
           
 java.lang.String getServletPath()
          Gets the part of this request's URI that refers to the servlet being invoked.
 java.lang.String getServletPrefix()
           
 javax.servlet.http.HttpSession getSession()
           
 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.security.Principal getUserPrincipal()
           
 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 isRequestedSessionIdFromURL()
           
 boolean isRequestedSessionIdValid()
          Checks whether this request is associated with a session that is valid in the current session context.
 boolean isSecure()
           
 boolean isUserInRole(java.lang.String role)
           
protected  boolean keepAliveRequested()
          Check if keep-alive requested?.
protected static java.lang.String mergeFilePathNames(java.lang.String path1, java.lang.String path2)
          Merge two file path names, avoiding double path seperators.
protected  boolean next()
          Initialize for a request on a socket.
 void recycle()
           
 void removeAttribute(java.lang.String name)
           
 void setAttribute(java.lang.String name, java.lang.Object value)
           
 void setAuthType(java.lang.String reqAuthType)
          Sets the authentication scheme of this request.
protected  void setConnection(java.net.Socket requestSocket)
          Associate a connected socket with this object.
 void setQueryString(java.lang.String queryString)
          Sets any query string that is part of the HTTP request URI.
 void setRemoteUser(java.lang.String reqRemoteUser)
          Sets the name of the user making this request.
protected  void setServletInfo(java.lang.String reqServletPath, javax.servlet.ServletContext context)
          Sets information that can not be obtained from the request.
protected static java.lang.String urlPathToFilePath(java.lang.String urlPath)
          Convert the file portion of a URL path to a platform-specific file path.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

attributes

protected java.util.Hashtable attributes
Request attributes.


socket

protected java.net.Socket socket
The socket associated with the request.


inputStream

protected org.enhydra.servlet.connectionMethods.https.HttpsInputStream inputStream
Input stream associated with the socket.


method

protected java.lang.String method
Request method.


requestUri

protected java.lang.String requestUri
Request URI (less query string).


httpVersion

protected java.lang.String httpVersion
Request HTTP Version.


queryString

protected java.lang.String queryString
Query string from URI.


servletPath

protected java.lang.String servletPath
The servlet path. Must be set externally before the servlet is called. We can't set it here, since its not known until the connection manager has looked at the path.


serverName

protected java.lang.String serverName
The server name.


serverPort

protected int serverPort
The server port.


remoteUser

protected java.lang.String remoteUser
The remote user, specified externally.


authType

protected java.lang.String authType
The auth type, specified externally.


headers

protected HttpsHeaders headers
Parsed MIME headers. Values are either a string or an array of strings if multiple copies of the same header where supplied.


cookies

protected javax.servlet.http.Cookie[] cookies
Parser Cookies.


parameters

protected java.util.Hashtable parameters
Parsed parameters from query string or POST.


servletContext

protected javax.servlet.ServletContext servletContext
ServletContext object for the current servlet.


getInputStreamCalled

protected boolean getInputStreamCalled
, * Has getInputStream() been called on the current request?


reader

protected java.io.BufferedReader reader
Reader for stream.


keepAlive

protected boolean keepAlive
Was a keep-alive connection requested?

Constructor Detail

HttpsRequest

protected HttpsRequest()
Construct a new request object. This object is designed to be reused for multiple requests, with the setConnection function being called for each connection.

See Also:
HttpsRequestProcessor#setConnection, HttpsRequestProcessor#next, HttpsRequestProcessor#setServletInfo
Method Detail

mergeFilePathNames

protected static java.lang.String mergeFilePathNames(java.lang.String path1,
                                                     java.lang.String path2)
Merge two file path names, avoiding double path seperators.


filePathToUrlPath

protected static java.lang.String filePathToUrlPath(java.lang.String filePath)
Convert the a platform-specific file path to a URL file path.


urlPathToFilePath

protected static java.lang.String urlPathToFilePath(java.lang.String urlPath)
Convert the file portion of a URL path to a platform-specific file path.


getContentLength

public int getContentLength()
Get the size of the request data.

Specified by:
getContentLength in interface javax.servlet.ServletRequest

getContentType

public java.lang.String getContentType()
Get the content type of the request.

Specified by:
getContentType in interface javax.servlet.ServletRequest
Returns:
The Internet Media Type of the request entity data, or null if not known.

getProtocol

public java.lang.String getProtocol()
Get the protocol and version of the request. .

Specified by:
getProtocol in interface javax.servlet.ServletRequest
Returns:
The protocol and version of the request as a string of the form <protocol>/<major version>.<minor version>.

getScheme

public java.lang.String getScheme()
Get the scheme of the URL used in this request, for example "http", "https", or "ftp".

Specified by:
getScheme in interface javax.servlet.ServletRequest
Returns:
The scheme of the URL.

getServerName

public java.lang.String getServerName()
Get the host name of the server that received the request.

Specified by:
getServerName in interface javax.servlet.ServletRequest
Returns:
The host name.

getServerPort

public int getServerPort()
Get the port number on which this request was received.

Specified by:
getServerPort in interface javax.servlet.ServletRequest

getRemoteAddr

public java.lang.String getRemoteAddr()
Get the IP address of the agent that sent the request.

Specified by:
getRemoteAddr in interface javax.servlet.ServletRequest

getRemoteHost

public java.lang.String getRemoteHost()
Get the fully qualified host name of the agent that sent the request.

Specified by:
getRemoteHost in interface javax.servlet.ServletRequest
Returns:
The host name.

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.

Specified by:
getRealPath in interface javax.servlet.ServletRequest
Parameters:
path - The virtual path to be translated to a real path.
Returns:
The real path.

getInputStream

public javax.servlet.ServletInputStream getInputStream()
                                                throws java.io.IOException
Get an input stream for reading binary data in the request body.

Specified by:
getInputStream in interface javax.servlet.ServletRequest
Throws:
java.lang.IllegalStateException - if getReader has been called on this same request.
java.io.IOException - on other I/O related errors.
See Also:
getReader

getParameter

public java.lang.String getParameter(java.lang.String name)
Get a string containing the lone value of the specified parameter.

Specified by:
getParameter in interface javax.servlet.ServletRequest
Parameters:
name - The name of the parameter whose value is required.
Returns:
The parameter value or null if the parameter does not exist.
See Also:
getParameterValues(java.lang.String)

getParameterValues

public java.lang.String[] getParameterValues(java.lang.String name)
Get the values of the specified parameter for the request.

Specified by:
getParameterValues in interface javax.servlet.ServletRequest
Parameters:
name - the name of the parameter whose value is required.
Returns:
The values of the specified parameter for the request as an array of strings, or null if the named parameter does not exist.
See Also:
ServletRequest.getParameter(java.lang.String)

getParameterNames

public java.util.Enumeration getParameterNames()
Get the parameter names for this request.

Specified by:
getParameterNames in interface javax.servlet.ServletRequest
Returns:
The parameter names for this request as an enumeration.

getAttribute

public java.lang.Object getAttribute(java.lang.String name)
Returns the value of an attribute of the request.

Specified by:
getAttribute in interface javax.servlet.ServletRequest
Parameters:
name - The name of the attribute whose value is required.
Returns:
The value of the named attribute of the request, or null if the attribute does not exist.

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.

Specified by:
getReader in interface javax.servlet.ServletRequest
Returns:
A buffered reader object.
Throws:
UnsupportedEncodingException - if the character set encoding is unsupported, so the text can't be correctly decoded.
java.lang.IllegalStateException - if getInputStream has been called on this same request.
java.io.IOException - on other I/O related errors.
See Also:
getInputStream

getCharacterEncoding

public java.lang.String getCharacterEncoding()
Get the character set encoding for the input of this request.

Specified by:
getCharacterEncoding in interface javax.servlet.ServletRequest
Returns:
The character set encoding.

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.

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()
Get the part of this request's URI that is to the left of any query string.

Specified by:
getRequestURI in interface javax.servlet.http.HttpServletRequest
Returns:
This request's URI
See Also:
javax.servlet.http.HttpsUtils#getRequestURL

getServletPath

public java.lang.String getServletPath()
Gets the part of this request's URI that refers to the servlet being invoked.

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.

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.

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 HTTP request URI.

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

setQueryString

public void setQueryString(java.lang.String queryString)
Sets any query string that is part of the HTTP request URI. The querystring can be set by a RequestDispatcher forward.

Specified by:
setQueryString in interface org.apache.tomcat.core.RequestAdapter

getRemoteUser

public java.lang.String getRemoteUser()
Gets the name of the user making this request. The user name is set with HTTP authentication.

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.

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.

Specified by:
getHeader in interface javax.servlet.http.HttpServletRequest
Parameters:
name - The String containing the name of the requested header field. The comparison is case insensitive.
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.

Specified by:
getIntHeader in interface javax.servlet.http.HttpServletRequest
Parameters:
name - The String containing the name of the requested header field. The comparison is case insensitive.
Returns:
the value of the requested header field, or -1 if not found.
Throws:
java.lang.NumberFormatException - If value of header can't be converted to an int.

getDateHeader

public long getDateHeader(java.lang.String name)
Gets the value of the requested date header field of this request.

Specified by:
getDateHeader in interface javax.servlet.http.HttpServletRequest
Parameters:
name - the String containing the name of the requested header field. The comparison is case insensitive.
Returns:
the value the requested date header field, or -1 if not found.
Throws:
java.lang.IllegalArgumentException - If value of header can't be converted to an int.

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.

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.

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.

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.

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(), javax.servlet.http.HttpsSessionContext, getSession(boolean)

isRequestedSessionIdFromCookie

public boolean isRequestedSessionIdFromCookie()
Checks whether the session id specified by this request came in as a cookie.

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.

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)

isUserInRole

public boolean isUserInRole(java.lang.String role)
Specified by:
isUserInRole in interface javax.servlet.http.HttpServletRequest

getLocale

public java.util.Locale getLocale()
Specified by:
getLocale in interface javax.servlet.ServletRequest

getUserPrincipal

public java.security.Principal getUserPrincipal()
Specified by:
getUserPrincipal in interface javax.servlet.http.HttpServletRequest

getLocales

public java.util.Enumeration getLocales()
Specified by:
getLocales in interface javax.servlet.ServletRequest

getContextPath

public java.lang.String getContextPath()
Specified by:
getContextPath in interface javax.servlet.http.HttpServletRequest

getHeaders

public java.util.Enumeration getHeaders(java.lang.String name)
Specified by:
getHeaders in interface javax.servlet.http.HttpServletRequest

removeAttribute

public void removeAttribute(java.lang.String name)
Specified by:
removeAttribute in interface javax.servlet.ServletRequest

isSecure

public boolean isSecure()
Specified by:
isSecure in interface javax.servlet.ServletRequest

isRequestedSessionIdFromURL

public boolean isRequestedSessionIdFromURL()
Specified by:
isRequestedSessionIdFromURL in interface javax.servlet.http.HttpServletRequest

getSession

public javax.servlet.http.HttpSession getSession()
Specified by:
getSession in interface javax.servlet.http.HttpServletRequest

getAttributeNames

public java.util.Enumeration getAttributeNames()
Specified by:
getAttributeNames in interface javax.servlet.ServletRequest

setAttribute

public void setAttribute(java.lang.String name,
                         java.lang.Object value)
Specified by:
setAttribute in interface javax.servlet.ServletRequest

getRequestDispatcher

public javax.servlet.RequestDispatcher getRequestDispatcher(java.lang.String name)
Specified by:
getRequestDispatcher in interface javax.servlet.ServletRequest

recycle

public void recycle()
Specified by:
recycle in interface org.apache.tomcat.core.RequestAdapter

getMimeHeaders

public org.apache.tomcat.util.MimeHeaders getMimeHeaders()
Specified by:
getMimeHeaders in interface org.apache.tomcat.core.RequestAdapter

getCookieHeaders

public java.lang.String[] getCookieHeaders()
Specified by:
getCookieHeaders in interface org.apache.tomcat.core.RequestAdapter

getServletPrefix

public java.lang.String getServletPrefix()
Specified by:
getServletPrefix in interface org.apache.tomcat.core.RequestAdapter

getServletName

public java.lang.String getServletName()
Specified by:
getServletName in interface org.apache.tomcat.core.RequestAdapter

doRead

public int doRead()
           throws java.io.IOException
Specified by:
doRead in interface org.apache.tomcat.core.RequestAdapter
java.io.IOException

doRead

public int doRead(byte[] b,
                  int off,
                  int len)
           throws java.io.IOException
Specified by:
doRead in interface org.apache.tomcat.core.RequestAdapter
java.io.IOException

setConnection

protected void setConnection(java.net.Socket requestSocket)
                      throws java.io.IOException
Associate a connected socket with this object. The next function must be called before a request can be processed.

Parameters:
requestSocket - The HTTP connected socket.
Throws:
java.io.IOException - If an error occured setting up the socket input stream.

close

protected void close()
              throws java.io.IOException
Close the socket associate with this object.

Throws:
java.io.IOException - If an error occured setting up the socket input stream.

getParsedParameters

protected void getParsedParameters()
Parse either the query string or POST input parameters. To conform with the behavior of the Java WWW server, this should be call only when parameters are first requested. Otherwise, on a POST, the input stream will be read in an unexpected way. This turns all IOExceptions into FatalExceptionErrors as the servlet methods that call this don't return exceptions.


next

protected boolean next()
                throws java.io.IOException
Initialize for a request on a socket. With keep-alive, multiple requests can be made on a single connection. This parses the headers for the request and saves them in this object for access.

Returns:
True if a request has been processed; false if the socket was closed and there are no more requests.
Throws:
java.io.IOException - If a parse error or IOException occurs reading the request.

finish

protected void finish()
Indicate the end of handing a request.


setServletInfo

protected void setServletInfo(java.lang.String reqServletPath,
                              javax.servlet.ServletContext context)
Sets information that can not be obtained from the request. This should be called after next() and before servlet.service() is called.

Parameters:
reqServletPath - The servlet path portion of the URL.

setRemoteUser

public void setRemoteUser(java.lang.String reqRemoteUser)
Sets the name of the user making this request. The user name is set with HTTP authentication.


setAuthType

public void setAuthType(java.lang.String reqAuthType)
Sets the authentication scheme of this request.


keepAliveRequested

protected boolean keepAliveRequested()
Check if keep-alive requested?.

Returns:
True if a keep-alive connection was requested.

Enhydra 5.1 API