Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

com.meterware.servletunit
Class ServletUnitHttpRequest  view ServletUnitHttpRequest download ServletUnitHttpRequest.java

java.lang.Object
  extended bycom.meterware.servletunit.ServletUnitHttpRequest
All Implemented Interfaces:
javax.servlet.http.HttpServletRequest, javax.servlet.ServletRequest

class ServletUnitHttpRequest
extends java.lang.Object
implements javax.servlet.http.HttpServletRequest

This class represents a servlet request created from a WebRequest.


Nested Class Summary
(package private) static class ServletUnitHttpRequest.PrioritizedLocale
           
 
Field Summary
private  java.util.Hashtable _attributes
           
private  java.lang.String _charset
           
private  java.lang.String _contentType
           
private  ServletUnitContext _context
           
private  java.util.Vector _cookies
           
private  com.meterware.httpunit.WebClient.HeaderDictionary _headers
           
private  ServletInputStreamImpl _inputStream
           
private  java.util.Vector _locales
           
private  byte[] _messageBody
           
private  com.meterware.httpunit.WebRequest _request
           
private  RequestContext _requestContext
           
private  java.lang.String[] _roles
           
private  boolean _secure
           
private  ServletMetaData _servletRequest
           
private  ServletUnitHttpSession _session
           
private  java.lang.String _sessionID
           
private  java.lang.String _userName
           
private static java.lang.String LOOPBACK_ADDRESS
           
 
Fields inherited from interface javax.servlet.http.HttpServletRequest
BASIC_AUTH, CLIENT_CERT_AUTH, DIGEST_AUTH, FORM_AUTH
 
Constructor Summary
(package private) ServletUnitHttpRequest(ServletMetaData servletRequest, com.meterware.httpunit.WebRequest request, ServletUnitContext context, java.util.Dictionary clientHeaders, byte[] messageBody)
          Constructs a ServletUnitHttpRequest from a WebRequest object.
 
Method Summary
private  void addCookie(javax.servlet.http.Cookie cookie)
           
private  void addOneCookie(java.lang.String cookieDefinition)
           
private  java.lang.String combinedPath(java.lang.String basePath, java.lang.String relativePath)
           
 java.lang.Object getAttribute(java.lang.String name)
          Returns the value of the named attribute as an Object.
 java.util.Enumeration getAttributeNames()
          Returns an Enumeration containing the names of the attributes available to this request.
 java.lang.String getAuthType()
          Returns the name of the authentication scheme used to protect the servlet, for example, "BASIC" or "SSL," or null if the servlet was not protected.
 java.lang.String getCharacterEncoding()
          Returns the name of the character encoding style used in this request.
 int getContentLength()
          Returns the length, in bytes, of the content contained in the request and sent by way of the input stream or -1 if the length is not known.
 java.lang.String getContentType()
          Returns the MIME type of the content of the request, or null if the type is not known.
 java.lang.String getContextPath()
          Returns the portion of the request URI that indicates the context of the request.
 javax.servlet.http.Cookie[] getCookies()
          Returns an array containing all of the Cookie objects the client sent with this request.
 long getDateHeader(java.lang.String name)
          Returns the value of the specified request header as a long value that represents a Date object.
 java.lang.String getHeader(java.lang.String name)
          Returns the value of the specified request header as a String.
 java.util.Enumeration getHeaderNames()
          Returns an enumeration of all the header names this request contains.
 java.util.Enumeration getHeaders(java.lang.String name)
          Returns all the values of the specified request header as an Enumeration of String objects.
 javax.servlet.ServletInputStream getInputStream()
          Retrieves binary data from the body of the request as a javax.servlet.ServletInputStream, which gives you the ability to read one line at a time.
 int getIntHeader(java.lang.String name)
          Returns the value of the specified request header as an int.
 java.util.Locale getLocale()
          Returns the preferred Locale that the client will accept content in, based on the Accept-Language header.
 java.util.Enumeration getLocales()
          Returns an Enumeration of Locale objects indicating, in decreasing order starting with the preferred locale, the locales that are acceptable to the client based on the Accept-Language header.
 java.lang.String getMethod()
          Returns the name of the HTTP method with which this request was made, for example, GET, POST, or PUT.
 java.lang.String getParameter(java.lang.String name)
          Returns the value of a request parameter as a String, or null if the parameter does not exist.
 java.util.Map getParameterMap()
          Returns a java.util.Map of the parameters of this request.
 java.util.Enumeration getParameterNames()
          Returns an Enumeration of String objects containing the names of the parameters contained in this request.
 java.lang.String[] getParameterValues(java.lang.String name)
          Returns an array of String objects containing all of the values the given request parameter has, or null if the parameter does not exist.
 java.lang.String getPathInfo()
          Returns any extra path information associated with the URL the client sent when it made this request.
 java.lang.String getPathTranslated()
          Returns any extra path information after the servlet name but before the query string, and translates it to a real path.
private  java.util.Vector getPreferredLocales()
          Parses the accept-language header to obtain a vector of preferred locales
 java.lang.String getProtocol()
          Returns the name and version of the protocol the request uses in the form protocol/majorVersion.minorVersion, for example, HTTP/1.1.
 java.lang.String getQueryString()
          Returns the query string that is contained in the request URL after the path.
 java.io.BufferedReader getReader()
          Returns the body of the request as a BufferedReader that translates character set encodings.
 java.lang.String getRealPath(java.lang.String path)
          Deprecated. As of Version 2.1 of the Java Servlet API, use ServletContext.getRealPath(java.lang.String)>ServletContext.getRealPath(java.lang.String) 55 instead.
 java.lang.String getRemoteAddr()
          Returns the Internet Protocol (IP) address of the client that sent the request.
 java.lang.String getRemoteHost()
          Returns the fully qualified name of the client that sent the request.
 java.lang.String getRemoteUser()
          Returns the login of the user making this request, if the user has been authenticated, or null if the user has not been authenticated.
 javax.servlet.RequestDispatcher getRequestDispatcher(java.lang.String path)
          Returns a RequestDispatcher object that acts as a wrapper for the resource located at the given path.
 java.lang.String getRequestedSessionId()
          Returns the session ID specified by the client.
 java.lang.String getRequestURI()
          Returns the part of this request's URL from the protocol name up to the query string in the first line of the HTTP request.
 java.lang.StringBuffer getRequestURL()
          Reconstructs the URL the client used to make the request.
 java.lang.String getScheme()
          Returns the name of the scheme used to make 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()
          Returns the part of this request's URL that calls the servlet.
private  ServletUnitHttpSession getServletSession()
           
 javax.servlet.http.HttpSession getSession()
          Returns the current session associated with this request, or if the request does not have a session, creates one.
 javax.servlet.http.HttpSession getSession(boolean create)
          Returns the current HttpSession associated with this request or, if there is no current session and create is true, returns a new session.
 java.security.Principal getUserPrincipal()
          Returns a java.security.Principal object containing the name of the current authenticated user.
 boolean isRequestedSessionIdFromCookie()
          Checks whether the requested session ID came in as a cookie.
 boolean isRequestedSessionIdFromUrl()
          Deprecated. use #isRequestedSessionIdFromURL
 boolean isRequestedSessionIdFromURL()
          Checks whether the requested session ID came in as part of the request URL.
 boolean isRequestedSessionIdValid()
          Checks whether the requested session ID is still valid.
 boolean isSecure()
          Returns a boolean indicating whether this request was made using a secure channel, such as HTTPS.
 boolean isUserInRole(java.lang.String role)
          Returns a boolean indicating whether the authenticated user is included in the specified logical "role".
(package private)  void readBasicAuthentication()
           
(package private)  void readFormAuthentication()
           
(package private)  void recordAuthenticationInfo(java.lang.String userName, java.lang.String[] roles)
           
 void removeAttribute(java.lang.String name)
          Removes an attribute from this request.
 void setAttribute(java.lang.String key, java.lang.Object o)
          Stores an attribute in the context of this request.
 void setCharacterEncoding(java.lang.String charset)
          Overrides the name of the character encoding used in the body of this request.
private  void setCookiesFromHeader(java.util.Dictionary clientHeaders)
           
private  void throwNotImplementedYet()
           
(package private) static java.lang.String[] toArray(java.lang.String roleList)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface javax.servlet.ServletRequest
getLocalAddr, getLocalName, getLocalPort, getRemotePort
 

Field Detail

_inputStream

private ServletInputStreamImpl _inputStream

_contentType

private java.lang.String _contentType

_locales

private java.util.Vector _locales

_secure

private boolean _secure

_requestContext

private RequestContext _requestContext

_charset

private java.lang.String _charset

LOOPBACK_ADDRESS

private static final java.lang.String LOOPBACK_ADDRESS
See Also:
Constant Field Values

_request

private com.meterware.httpunit.WebRequest _request

_servletRequest

private ServletMetaData _servletRequest

_headers

private com.meterware.httpunit.WebClient.HeaderDictionary _headers

_context

private ServletUnitContext _context

_session

private ServletUnitHttpSession _session

_attributes

private java.util.Hashtable _attributes

_cookies

private java.util.Vector _cookies

_sessionID

private java.lang.String _sessionID

_messageBody

private byte[] _messageBody

_userName

private java.lang.String _userName

_roles

private java.lang.String[] _roles
Constructor Detail

ServletUnitHttpRequest

ServletUnitHttpRequest(ServletMetaData servletRequest,
                       com.meterware.httpunit.WebRequest request,
                       ServletUnitContext context,
                       java.util.Dictionary clientHeaders,
                       byte[] messageBody)
                 throws java.net.MalformedURLException
Constructs a ServletUnitHttpRequest from a WebRequest object.

Method Detail

getAuthType

public java.lang.String getAuthType()
Returns the name of the authentication scheme used to protect the servlet, for example, "BASIC" or "SSL," or null if the servlet was not protected.

Specified by:
getAuthType in interface javax.servlet.http.HttpServletRequest

getQueryString

public java.lang.String getQueryString()
Returns the query string that is contained in the request URL after the path.

Specified by:
getQueryString in interface javax.servlet.http.HttpServletRequest

getCookies

public javax.servlet.http.Cookie[] getCookies()
Returns an array containing all of the Cookie objects the client sent with this request. This method returns null if no cookies were sent.

Specified by:
getCookies in interface javax.servlet.http.HttpServletRequest

getIntHeader

public int getIntHeader(java.lang.String name)
Returns the value of the specified request header as an int. If the request does not have a header of the specified name, this method returns -1. If the header cannot be converted to an integer, this method throws a NumberFormatException.

Specified by:
getIntHeader in interface javax.servlet.http.HttpServletRequest

getDateHeader

public long getDateHeader(java.lang.String name)
Returns the value of the specified request header as a long value that represents a Date object. Use this method with headers that contain dates, such as If-Modified-Since.
The date is returned as the number of milliseconds since January 1, 1970 GMT. The header name is case insensitive. If the request did not have a header of the specified name, this method returns -1. If the header can't be converted to a date, the method throws an IllegalArgumentException.

Specified by:
getDateHeader in interface javax.servlet.http.HttpServletRequest

getHeader

public java.lang.String getHeader(java.lang.String name)
Returns the value of the specified request header as a String. If the request did not include a header of the specified name, this method returns null. The header name is case insensitive. You can use this method with any request header.

Specified by:
getHeader in interface javax.servlet.http.HttpServletRequest

getHeaderNames

public java.util.Enumeration getHeaderNames()
Returns an enumeration of all the header names this request contains. If the request has no headers, this method returns an empty enumeration. Some servlet containers do not allow do not allow servlets to access headers using this method, in which case this method returns null.

Specified by:
getHeaderNames in interface javax.servlet.http.HttpServletRequest

getServletPath

public java.lang.String getServletPath()
Returns the part of this request's URL that calls the servlet. This includes either the servlet name or a path to the servlet, but does not include any extra path information or a query string.

Specified by:
getServletPath in interface javax.servlet.http.HttpServletRequest

getMethod

public java.lang.String getMethod()
Returns the name of the HTTP method with which this request was made, for example, GET, POST, or PUT.

Specified by:
getMethod in interface javax.servlet.http.HttpServletRequest

getPathInfo

public java.lang.String getPathInfo()
Returns any extra path information associated with the URL the client sent when it made this request. The extra path information follows the servlet path but precedes the query string. This method returns null if there was no extra path information.

Specified by:
getPathInfo in interface javax.servlet.http.HttpServletRequest

getPathTranslated

public java.lang.String getPathTranslated()
Returns any extra path information after the servlet name but before the query string, and translates it to a real path. If the URL does not have any extra path information, this method returns null.

Specified by:
getPathTranslated in interface javax.servlet.http.HttpServletRequest

isRequestedSessionIdFromCookie

public boolean isRequestedSessionIdFromCookie()
Checks whether the requested session ID came in as a cookie.

Specified by:
isRequestedSessionIdFromCookie in interface javax.servlet.http.HttpServletRequest

getRemoteUser

public java.lang.String getRemoteUser()
Returns the login of the user making this request, if the user has been authenticated, or null if the user has not been authenticated. Whether the user name is sent with each subsequent request depends on the browser and type of authentication.

Specified by:
getRemoteUser in interface javax.servlet.http.HttpServletRequest

getRequestedSessionId

public java.lang.String getRequestedSessionId()
Returns the session ID specified by the client. This may not be the same as the ID of the actual session in use. For example, if the request specified an old (expired) session ID and the server has started a new session, this method gets a new session with a new ID. If the request did not specify a session ID, this method returns null.

Specified by:
getRequestedSessionId in interface javax.servlet.http.HttpServletRequest

getRequestURI

public java.lang.String getRequestURI()
Returns the part of this request's URL from the protocol name up to the query string in the first line of the HTTP request.

Specified by:
getRequestURI in interface javax.servlet.http.HttpServletRequest

getSession

public javax.servlet.http.HttpSession getSession(boolean create)
Returns the current HttpSession associated with this request or, if there is no current session and create is true, returns a new session.
If create is false and the request has no valid HttpSession, this method returns null.

Specified by:
getSession in interface javax.servlet.http.HttpServletRequest

getSession

public javax.servlet.http.HttpSession getSession()
Returns the current session associated with this request, or if the request does not have a session, creates one.

Specified by:
getSession in interface javax.servlet.http.HttpServletRequest

isRequestedSessionIdValid

public boolean isRequestedSessionIdValid()
Checks whether the requested session ID is still valid.

Specified by:
isRequestedSessionIdValid in interface javax.servlet.http.HttpServletRequest

isRequestedSessionIdFromURL

public boolean isRequestedSessionIdFromURL()
Checks whether the requested session ID came in as part of the request URL.

Specified by:
isRequestedSessionIdFromURL in interface javax.servlet.http.HttpServletRequest

isRequestedSessionIdFromUrl

public boolean isRequestedSessionIdFromUrl()
Deprecated. use #isRequestedSessionIdFromURL

Specified by:
isRequestedSessionIdFromUrl in interface javax.servlet.http.HttpServletRequest

getContentLength

public int getContentLength()
Returns the length, in bytes, of the content contained in the request and sent by way of the input stream or -1 if the length is not known.

Specified by:
getContentLength in interface javax.servlet.ServletRequest

getAttribute

public java.lang.Object getAttribute(java.lang.String name)
Returns the value of the named attribute as an Object. This method allows the servlet engine to give the servlet custom information about a request. This method returns null if no attribute of the given name exists.

Specified by:
getAttribute in interface javax.servlet.ServletRequest

getAttributeNames

public java.util.Enumeration getAttributeNames()
Returns an Enumeration containing the names of the attributes available to this request. This method returns an empty Enumeration if the request has no attributes available to it.

Specified by:
getAttributeNames in interface javax.servlet.ServletRequest

getInputStream

public javax.servlet.ServletInputStream getInputStream()
                                                throws java.io.IOException
Retrieves binary data from the body of the request as a javax.servlet.ServletInputStream, which gives you the ability to read one line at a time.

Specified by:
getInputStream in interface javax.servlet.ServletRequest

getCharacterEncoding

public java.lang.String getCharacterEncoding()
Returns the name of the character encoding style used in this request. This method returns null if the request does not use character encoding.

Specified by:
getCharacterEncoding in interface javax.servlet.ServletRequest

getParameterNames

public java.util.Enumeration getParameterNames()
Returns an Enumeration of String objects containing the names of the parameters contained in this request. If the request has no parameters or if the input stream is empty, returns an empty Enumeration. The input stream is empty when all the data returned by getInputStream() 55 has been read.

Specified by:
getParameterNames in interface javax.servlet.ServletRequest

getContentType

public java.lang.String getContentType()
Returns the MIME type of the content of the request, or null if the type is not known. Same as the value of the CGI variable CONTENT_TYPE.

Specified by:
getContentType in interface javax.servlet.ServletRequest

getParameter

public java.lang.String getParameter(java.lang.String name)
Returns the value of a request parameter as a String, or null if the parameter does not exist. Request parameters are extra information sent with the request.

Specified by:
getParameter in interface javax.servlet.ServletRequest

getParameterValues

public java.lang.String[] getParameterValues(java.lang.String name)
Returns an array of String objects containing all of the values the given request parameter has, or null if the parameter does not exist. For example, in an HTTP servlet, this method returns an array of String objects containing the values of a query string or posted form.

Specified by:
getParameterValues in interface javax.servlet.ServletRequest

getProtocol

public java.lang.String getProtocol()
Returns the name and version of the protocol the request uses in the form protocol/majorVersion.minorVersion, for example, HTTP/1.1.

Specified by:
getProtocol in interface javax.servlet.ServletRequest

getScheme

public java.lang.String getScheme()
Returns the name of the scheme used to make this request, for example, http, https, or ftp. Different schemes have different rules for constructing URLs, as noted in RFC 1738.

Specified by:
getScheme in interface javax.servlet.ServletRequest

getRemoteHost

public java.lang.String getRemoteHost()
Returns the fully qualified name of the client that sent the request.

Specified by:
getRemoteHost in interface javax.servlet.ServletRequest

getServerName

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

Specified by:
getServerName in interface javax.servlet.ServletRequest

getServerPort

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

Specified by:
getServerPort in interface javax.servlet.ServletRequest

getRealPath

public java.lang.String getRealPath(java.lang.String path)
Deprecated. As of Version 2.1 of the Java Servlet API, use ServletContext.getRealPath(java.lang.String)>ServletContext.getRealPath(java.lang.String) 55 instead.

Specified by:
getRealPath in interface javax.servlet.ServletRequest

getReader

public java.io.BufferedReader getReader()
                                 throws java.io.IOException
Returns the body of the request as a BufferedReader that translates character set encodings.

Specified by:
getReader in interface javax.servlet.ServletRequest

getRemoteAddr

public java.lang.String getRemoteAddr()
Returns the Internet Protocol (IP) address of the client that sent the request.

Specified by:
getRemoteAddr in interface javax.servlet.ServletRequest

setAttribute

public void setAttribute(java.lang.String key,
                         java.lang.Object o)
Stores an attribute in the context of this request. Attributes are reset between requests.

Specified by:
setAttribute in interface javax.servlet.ServletRequest

isSecure

public boolean isSecure()
Returns a boolean indicating whether this request was made using a secure channel, such as HTTPS.

Specified by:
isSecure in interface javax.servlet.ServletRequest

getLocale

public java.util.Locale getLocale()
Returns the preferred Locale that the client will accept content in, based on the Accept-Language header. If the client request doesn't provide an Accept-Language header, this method returns the default locale for the server.

Specified by:
getLocale in interface javax.servlet.ServletRequest

getLocales

public java.util.Enumeration getLocales()
Returns an Enumeration of Locale objects indicating, in decreasing order starting with the preferred locale, the locales that are acceptable to the client based on the Accept-Language header. If the client request doesn't provide an Accept-Language header, this method returns an Enumeration containing one Locale, the default locale for the server.

Specified by:
getLocales in interface javax.servlet.ServletRequest

getPreferredLocales

private java.util.Vector getPreferredLocales()
Parses the accept-language header to obtain a vector of preferred locales


removeAttribute

public void removeAttribute(java.lang.String name)
Removes an attribute from this request. This method is not generally needed as attributes only persist as long as the request is being handled.

Specified by:
removeAttribute in interface javax.servlet.ServletRequest

getRequestDispatcher

public javax.servlet.RequestDispatcher getRequestDispatcher(java.lang.String path)
Returns a RequestDispatcher object that acts as a wrapper for the resource located at the given path. A RequestDispatcher object can be used to forward a request to the resource or to include the resource in a response. The resource can be dynamic or static. The pathname specified may be relative, although it cannot extend outside the current servlet context. If the path begins with a "/" it is interpreted as relative to the current context root. This method returns null if the servlet container cannot return a RequestDispatcher. The difference between this method and ServletContext.getRequestDispatcher(java.lang.String) is that this method can take a relative path.

Specified by:
getRequestDispatcher in interface javax.servlet.ServletRequest

combinedPath

private java.lang.String combinedPath(java.lang.String basePath,
                                      java.lang.String relativePath)

getUserPrincipal

public java.security.Principal getUserPrincipal()
Returns a java.security.Principal object containing the name of the current authenticated user. If the user has not been authenticated, the method returns null.

Specified by:
getUserPrincipal in interface javax.servlet.http.HttpServletRequest

isUserInRole

public boolean isUserInRole(java.lang.String role)
Returns a boolean indicating whether the authenticated user is included in the specified logical "role". Roles and role membership can be defined using deployment descriptors. If the user has not been authenticated, the method returns false.

Specified by:
isUserInRole in interface javax.servlet.http.HttpServletRequest

getHeaders

public java.util.Enumeration getHeaders(java.lang.String name)
Returns all the values of the specified request header as an Enumeration of String objects.

Specified by:
getHeaders in interface javax.servlet.http.HttpServletRequest

getContextPath

public java.lang.String getContextPath()
Returns the portion of the request URI that indicates the context of the request. The context path always comes first in a request URI. The path starts with a "/" character but does not end with a "/" character. For servlets in the default (root) context, this method returns "".

Specified by:
getContextPath in interface javax.servlet.http.HttpServletRequest

getParameterMap

public java.util.Map getParameterMap()
Returns a java.util.Map of the parameters of this request. Request parameters are extra information sent with the request. For HTTP servlets, parameters are contained in the query string or posted form data.

Specified by:
getParameterMap in interface javax.servlet.ServletRequest
Since:
1.3

setCharacterEncoding

public void setCharacterEncoding(java.lang.String charset)
                          throws java.io.UnsupportedEncodingException
Overrides the name of the character encoding used in the body of this request. This method must be called prior to reading request parameters or reading input using getReader().

Specified by:
setCharacterEncoding in interface javax.servlet.ServletRequest
Since:
1.3

getRequestURL

public java.lang.StringBuffer getRequestURL()
Reconstructs the URL the client used to make the request. The returned URL contains a protocol, server name, port number, and server path, but it does not include query string parameters. Because this method returns a StringBuffer, not a string, you can modify the URL easily, for example, to append query parameters. This method is useful for creating redirect messages and for reporting errors.

Specified by:
getRequestURL in interface javax.servlet.http.HttpServletRequest
Since:
1.3

addCookie

private void addCookie(javax.servlet.http.Cookie cookie)

getServletSession

private ServletUnitHttpSession getServletSession()

readFormAuthentication

void readFormAuthentication()

readBasicAuthentication

void readBasicAuthentication()

toArray

static java.lang.String[] toArray(java.lang.String roleList)

recordAuthenticationInfo

void recordAuthenticationInfo(java.lang.String userName,
                              java.lang.String[] roles)

throwNotImplementedYet

private void throwNotImplementedYet()

setCookiesFromHeader

private void setCookiesFromHeader(java.util.Dictionary clientHeaders)

addOneCookie

private void addOneCookie(java.lang.String cookieDefinition)