| java.lang.Object servletunit.HttpServletRequestSimulator
Method Summary | |
public void | addCookie(Cookie cookie) Adds a cookie that can be retrieved from this request via the
getCookies() method. | public void | addParameter(String key, String value) | public void | addParameter(String name, String[] values) | public Object | getAttribute(String s) Returns the value of the named attribute as an Object ,
or null if no attribute of the given name exists.
Attributes can be set two ways. | public Enumeration | getAttributeNames() Returns an Enumeration containing the
names of the attributes available to this request. | public String | getAuthType() Returns the name of the authentication scheme used to protect
the servlet. | public String | getCharacterEncoding() Returns the name of the character encoding used in the body of this
request. | public int | getContentLength() Returns the length, in bytes, of the request body
and made available by the input stream, or -1 if the
length is not known. | public String | getContentType() Returns the MIME type of the body of the request, or
null if the type is not known. | public String | getContextPath() Returns the portion of the request URI that indicates the context
of the request. | public Cookie[] | getCookies() Returns an array containing all of the Cookie
objects the client sent with this request. | public long | getDateHeader(String name) Returns the value of the specified request header as a long value that represents a Date object. | public String | getHeader(String s) Returns the value of the specified request header
as a String . | public Enumeration | getHeaderNames() Returns an enumeration of all the header names
this request contains. | public Enumeration | getHeaders(String s) This operation is not supported. | public ServletInputStream | getInputStream() This operation is not supported. | public int | getIntHeader(String s) Returns the value of the specified request header
as an int . | public String | getLocalAddr() | public String | getLocalName() | public int | getLocalPort() | public Locale | getLocale() Returns the preferred Locale that the client will
accept content in, based on the Accept-Language header. | public 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. | public String | getMethod() Returns the name of the HTTP method with which this
request was made, for example, GET, POST, or PUT. | public String | getParameter(String s) Returns the value of a request parameter as a String ,
or null if the parameter does not exist. | public Map | getParameterMap() Returns a java.util.Map of the parameters of this request.
Request parameters
are extra information sent with the request. | public Enumeration | getParameterNames() Returns an Enumeration of String
objects containing the names of the parameters contained
in this request. | public String[] | getParameterValues(String s) Returns an array of String objects containing
all of the values the given request parameter has, or
null if the parameter does not exist. | public String | getPathInfo() Returns any extra path information associated with
the URL the client sent when it made this request. | public String | getPathTranslated() This operation is not supported. | public String | getProtocol() Returns the name and version of the protocol the request uses
in the form protocol/majorVersion.minorVersion, for
example, HTTP/1.1. | public String | getQueryString() Returns the query string that is contained in the request
URL after the path. | public BufferedReader | getReader() This operation is not supported. | public String | getRealPath(String path) | public String | getRemoteAddr() Returns the Internet Protocol (IP) address of the client
that sent the request. | public String | getRemoteHost() Returns the fully qualified name of the client that sent the
request. | public int | getRemotePort() | public String | getRemoteUser() Returns the fully qualified name of the client that sent the
request. | public RequestDispatcher | getRequestDispatcher(String url) 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. | public 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. | public StringBuffer | getRequestURL() Reconstructs the URL the client used to make the request. | public String | getRequestedSessionId() Returns the session ID specified by the client. | public String | getScheme() Returns the name of the scheme used to make this request,
for example,
http , https , or ftp . | public String | getServerName() Returns the host name of the server that received
the request. | public int | getServerPort() Returns the port number on which this request was received. | public String | getServletPath() Returns the part of this request's URL that calls
the servlet. | public HttpSession | getSession() Returns the current session associated with this request,
or if the request does not have a session, creates one. | public HttpSession | getSession(boolean b) Returns the current HttpSession
associated with this request or, if 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 .
To make sure the session is properly maintained,
you must call this method before
the response is committed. | public Principal | getUserPrincipal() Returns a java.security.Principal object containing
the name of the current authenticated user. | public boolean | isRequestedSessionIdFromCookie() Checks whether the requested session ID came in as a cookie. | public boolean | isRequestedSessionIdFromURL() Checks whether the requested session ID came in as part of the
request URL. | public boolean | isRequestedSessionIdFromUrl() | public boolean | isRequestedSessionIdValid() Checks whether the requested session ID is still valid. | public boolean | isSecure() Returns a boolean indicating whether this request was made using a
secure channel, such as HTTPS. | public boolean | isUserInRole(String s) Returns a boolean indicating whether the authenticated user is included
in the specified logical "role". | public void | removeAttribute(String s) Removes an attribute from this request. | public void | setAttribute(String name, Object o) Stores an attribute in this request.
Attributes are reset between requests. | public void | setAuthType(String s) Sets authentication scheme to be used in
HttpServletRequestSimulator.getAuthType . | public void | setCharacterEncoding(String s) Sets character encoding to be used in
HttpServletRequestSimulator.getCharacterEncoding . | public void | setContentType(String s) Sets content type to be used in
HttpServletRequestSimulator.getContentType . | public void | setContextPath(String s) Sets the context path to be used by
HttpServletRequestSimulator.getContextPath . | public void | setCookies(Cookie[] cookies) Adds a set of cookies that can be retrieved from this request via the
getCookies() method. | public void | setDateHeader(String name, long millis) Sets a header with the appropriate date string given the time in milliseconds. | public void | setHeader(String key, String value) Sets a header to be used in
HttpServletRequestSimulator.getHeader . | public void | setLocalAddr(String localAddr) | public void | setLocalName(String localName) | public void | setLocalPort(int localPort) | public void | setLocale(Locale locale) Sets the locale to be used by
HttpServletRequestSimulator.getLocale . | public void | setMethod(int methodType) Sets the name of the HTTP method with which this request
was made. | public void | setParameterValue(String key, String[] value) Sets parameter value to be used by
HttpServletRequestSimulator.getParameter . | public void | setPathInfo(String s) Sets path information to be used by
HttpServletRequestSimulator.getPathInfo . | public void | setQueryString(String s) Sets query string to be used by
HttpServletRequestSimulator.getQueryString . | public void | setRemoteAddr(String remoteAddr) Sets remote address to be used by
HttpServletRequestSimulator.getRemoteAddr . | public void | setRemoteHost(String remoteHost) Sets remote host to be used by
HttpServletRequestSimulator.getRemoteHost . | public void | setRemotePort(int remotePort) | public void | setRemoteUser(String remoteUser) Sets remote user to be used by
HttpServletRequestSimulator.getRemoteUser . | public void | setRequestURI(String requestURI) Sets request URI to be used by
HttpServletRequestSimulator.getRequestURI . | public void | setRequestURL(String url) Sets the request URL to be used in this test. | public void | setRequestedSessionId(String s) Sets requested session ID to be used by
HttpServletRequestSimulator.getRequestedSessionId . | public void | setScheme(String s) Sets scheme to be used by
HttpServletRequestSimulator.getScheme . | public void | setServerName(String s) Sets server name to be used by
HttpServletRequestSimulator.getServerName . | public void | setServerPort(int port) Sets the server port to be used with
HttpServletRequestSimulator.getServerPort . | public void | setServletPath(String s) Sets servlet path to be used by
HttpServletRequestSimulator.getServletPath . | public void | setUserPrincipal(Principal principal) Sets the Principal used by
HttpServletRequestSimulator.getUserPrincipal . | public void | setUserRole(String role) |
remotePort | int remotePort(Code) | | |
addCookie | public void addCookie(Cookie cookie)(Code) | | Adds a cookie that can be retrieved from this request via the
getCookies() method.
Parameters: cookie - a Cookie object to be retrieved from thisrequest. See Also: HttpServletRequestSimulator.getCookies |
addParameter | public void addParameter(String key, String value)(Code) | | Adds a parameter to this object's list of parameters
Parameters: key - The name of the parameter Parameters: value - The value of the parameter |
addParameter | public void addParameter(String name, String[] values)(Code) | | Adds a parameter as a String array to this object's list of parameters
|
getAttribute | public Object getAttribute(String s)(Code) | | Returns the value of the named attribute as an Object ,
or null if no attribute of the given name exists.
Attributes can be set two ways. The servlet container may set
attributes to make available custom information about a request.
For example, for requests made using HTTPS, the attribute
javax.servlet.request.X509Certificate can be used to
retrieve information on the certificate of the client. Attributes
can also be set programatically using
ServletRequest.setAttribute . This allows information to be
embedded into a request before a
RequestDispatcher call.
Attribute names should follow the same conventions as package
names. This specification reserves names matching java.* ,
javax.* , and sun.* .
Parameters: s - a String specifying the name ofthe attribute an Object containing the valueof the attribute, or null ifthe attribute does not exist |
getAttributeNames | public Enumeration getAttributeNames()(Code) | | 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.
an Enumeration of stringscontaining the namesof the request's attributes |
getAuthType | public String getAuthType()(Code) | | Returns the name of the authentication scheme used to protect
the servlet. All servlet containers support basic, form and client
certificate authentication, and may additionally support digest
authentication.
If the servlet is not authenticated null is returned.
Same as the value of the CGI variable AUTH_TYPE.
one of the static members BASIC_AUTH,FORM_AUTH, CLIENT_CERT_AUTH, DIGEST_AUTH(suitable for == comparison)indicating the authentication scheme, ornull if the request wasnot authenticated. |
getCharacterEncoding | public String getCharacterEncoding()(Code) | | Returns the name of the character encoding used in the body of this
request. This method returns null if the request
does not specify a character encoding
a String containing the name ofthe chararacter encoding, or null if the request does not specify a character encoding |
getContentLength | public int getContentLength()(Code) | | Returns the length, in bytes, of the request body
and made available by the input stream, or -1 if the
length is not known. For HTTP servlets, same as the value
of the CGI variable CONTENT_LENGTH.
-1, since this is a mock container |
getContentType | public String getContentType()(Code) | | Returns the MIME type of the body of the request, or
null if the type is not known. For HTTP servlets,
same as the value of the CGI variable CONTENT_TYPE.
a String containing the nameof the MIME type ofthe request, or null if the type is not known |
getContextPath | public String getContextPath()(Code) | | 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 "". The container does not decode this string.
a String specifying theportion of the request URI that indicates the contextof the request |
getCookies | public Cookie[] getCookies()(Code) | | Returns an array containing all of the Cookie
objects the client sent with this request.
This method returns null if no cookies were sent.
an array of all the Cookies included with this request, or null if the request has no cookies |
getDateHeader | public long getDateHeader(String name)(Code) | | 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.
Parameters: name - a String specifying the name of the header a long value representing the date specified in the header expressed as the number of milliseconds since January 1, 1970 GMT, or -1 if the named header was not included with the reqest. |
getHeader | public String getHeader(String s)(Code) | | 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.
Parameters: s - a String specifying theheader name a String containing thevalue of the requestedheader, or null if the request does nothave a header of that name |
getHeaderNames | public Enumeration getHeaderNames()(Code) | | 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
an enumeration of all theheader names sent with thisrequest; if the request hasno headers, an empty enumeration;if the servlet container does notallow servlets to use this method,null |
getIntHeader | public int getIntHeader(String s)(Code) | | 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 .
The header name is case insensitive.
Parameters: s - a String specifying the nameof a request header an integer expressing the valueof the request header or -1if the request doesn't have aheader of this name exception: NumberFormatException - If the header valuecan't be convertedto an int |
getLocalPort | public int getLocalPort()(Code) | | |
getLocale | public Locale getLocale()(Code) | | 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.
the preferred Locale for the client,defaults to Locale.US if HttpServletRequestSimulator.setLocale hasnot been called. |
getLocales | public Enumeration getLocales()(Code) | | 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.
an Enumeration of preferred Locale objects for the client |
getMethod | public String getMethod()(Code) | | Returns the name of the HTTP method with which this
request was made, for example, GET, POST, or PUT.
Same as the value of the CGI variable REQUEST_METHOD.
a String specifying the nameof the method with whichthis request was made |
getParameter | public String getParameter(String s)(Code) | | 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. For HTTP servlets,
parameters are contained in the query string or posted form data.
You should only use this method when you are sure the
parameter has only one value. If the parameter might have
more than one value, use
HttpServletRequestSimulator.getParameterValues .
If you use this method with a multivalued
parameter, the value returned is equal to the first value
in the array returned by getParameterValues .
If the parameter data was sent in the request body, such as occurs
with an HTTP POST request, then reading the body directly via
HttpServletRequestSimulator.getInputStream or
HttpServletRequestSimulator.getReader can interfere
with the execution of this method.
Parameters: s - a String specifying thename of the parameter a String representing thesingle value of the parameter See Also: HttpServletRequestSimulator.getParameterValues |
getParameterMap | public Map getParameterMap()(Code) | | 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.
an immutable java.util.Map containing parameter names askeys and parameter values as map values. The keys in the parametermap are of type String. The values in the parameter map are of typeString array. |
getParameterNames | public Enumeration getParameterNames()(Code) | | Returns an Enumeration of String
objects containing the names of the parameters contained
in this request. If the request has
no parameters, the method returns an
empty Enumeration .
an Enumeration of String objects, each String containingthe name of a request parameter; or anempty Enumeration if therequest has no parameters |
getParameterValues | public String[] getParameterValues(String s)(Code) | | Returns an array of String objects containing
all of the values the given request parameter has, or
null if the parameter does not exist.
If the parameter has a single value, the array has a length
of 1.
Parameters: s - a String containing the name ofthe parameter whose value is requested an array of String objectscontaining the parameter's values See Also: HttpServletRequestSimulator.getParameter |
getPathInfo | public String getPathInfo()(Code) | | 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.
Same as the value of the CGI variable PATH_INFO.
a String , decoded by theweb container, specifyingextra path information that comesafter the servlet path but beforethe query string in the request URL;or null if the URL does not haveany extra path information |
getPathTranslated | public String getPathTranslated()(Code) | | This operation is not supported.
|
getProtocol | public String getProtocol()(Code) | | Returns the name and version of the protocol the request uses
in the form protocol/majorVersion.minorVersion, for
example, HTTP/1.1. For HTTP servlets, the value
returned is the same as the value of the CGI variable
SERVER_PROTOCOL .
a String containing the protocolname and version number |
getQueryString | public String getQueryString()(Code) | | Returns the query string that is contained in the request
URL after the path. This method returns null
if the URL does not have a query string. Same as the value
of the CGI variable QUERY_STRING.
a String containing the querystring or null if the URLcontains no query string. The value is notdecoded by the container. |
getRemoteAddr | public String getRemoteAddr()(Code) | | Returns the Internet Protocol (IP) address of the client
that sent the request. For HTTP servlets, same as the value of the
CGI variable REMOTE_ADDR .
a String containing theIP address of the client that sent the request |
getRemoteHost | public String getRemoteHost()(Code) | | Returns the fully qualified name of the client that sent the
request. If the engine cannot or chooses not to resolve the hostname
(to improve performance), this method returns the dotted-string form of
the IP address. For HTTP servlets, same as the value of the CGI variable
REMOTE_HOST .
a String containing the fullyqualified name of the client |
getRemotePort | public int getRemotePort()(Code) | | |
getRemoteUser | public String getRemoteUser()(Code) | | Returns the fully qualified name of the client that sent the
request. If the engine cannot or chooses not to resolve the hostname
(to improve performance), this method returns the dotted-string form of
the IP address. For HTTP servlets, same as the value of the CGI variable
REMOTE_HOST .
a String containing the fullyqualified name of the client |
getRequestDispatcher | public RequestDispatcher getRequestDispatcher(String url)(Code) | | 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 is that this method can take a
relative path.
Parameters: url - a String specifying the pathnameto the resource a RequestDispatcher objectthat acts as a wrapper for the resourceat the specified path See Also: RequestDispatcherSimulator See Also: ServletContextSimulator.getRequestDispatcher |
getRequestURI | public String getRequestURI()(Code) | | 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.
The web container does not decode this String.
For example:
First line of HTTP request |
Returned Value |
---|
POST /some/path.html HTTP/1.1 | | /some/path.html
| GET http://foo.bar/a.html HTTP/1.0
| | /a.html
| HEAD /xyz?a=b HTTP/1.1 | | /xyz
|
a String containingthe part of the URL from theprotocol name up to the query string |
getRequestURL | public StringBuffer getRequestURL()(Code) | | 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.
a StringBuffer object containing the reconstructed URL |
getRequestedSessionId | public String getRequestedSessionId()(Code) | | 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 .
a String specifying the sessionID, or null if the request didnot specify a session ID See Also: HttpServletRequestSimulator.isRequestedSessionIdValid |
getScheme | public String getScheme()(Code) | | 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.
a String containing the nameof the scheme used to make this request |
getServerName | public String getServerName()(Code) | | Returns the host name of the server that received
the request. For HTTP servlets, same as the value of
the CGI variable SERVER_NAME.
the name of the server to which the request was sent |
getServerPort | public int getServerPort()(Code) | | Returns the port number on which this request was received. For HTTP servlets, same as the value of the CGI variable SERVER_PORT.
an integer specifying the port number |
getServletPath | public String getServletPath()(Code) | | 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. Same as the value
of the CGI variable SCRIPT_NAME.
a String containingthe name or path of the servlet beingcalled, as specified in the request URL,decoded. |
getSession | public HttpSession getSession(boolean b)(Code) | | Returns the current HttpSession
associated with this request or, if 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 .
To make sure the session is properly maintained,
you must call this method before
the response is committed. If the container is using cookies
to maintain session integrity and is asked to create a new session
when the response is committed, an IllegalStateException is thrown.
Parameters: b - true to createa new session for this request if necessary;false to return null if there's no current session the HttpSession associatedwith this request or null ifcreate is false and the request has no valid session See Also: HttpServletRequestSimulator.getSession() |
getUserPrincipal | public Principal getUserPrincipal()(Code) | | 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 .
a java.security.Principal containingthe name of the user making this request;null if the user has not beenauthenticated |
isRequestedSessionIdFromURL | public boolean isRequestedSessionIdFromURL()(Code) | | Checks whether the requested session ID came in as part of the
request URL.
false in all cases. See Also: HttpServletRequestSimulator.getSession |
isSecure | public boolean isSecure()(Code) | | Returns a boolean indicating whether this request was made using a
secure channel, such as HTTPS.
true if scheme has been set to HTTPS (ignoring case) |
isUserInRole | public boolean isUserInRole(String s)(Code) | | 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 .
Parameters: s - a String specifying the nameof the role false in all cases |
removeAttribute | public void removeAttribute(String s)(Code) | | Removes an attribute from this request. This method is not
generally needed as attributes only persist as long as the request
is being handled.
Attribute names should follow the same conventions as
package names. Names beginning with java.* ,
javax.* , and com.sun.* , are
reserved for use by Sun Microsystems.
Parameters: s - a String specifyingthe name of the attribute to remove |
setAttribute | public void setAttribute(String name, Object o)(Code) | | Stores an attribute in this request.
Attributes are reset between requests. This method is most
often used in conjunction with
RequestDispatcher .
Attribute names should follow the same conventions as
package names. Names beginning with java.* ,
javax.* , and com.sun.* , are
reserved for use by Sun Microsystems.
If the value passed in is null, the effect is the same as
calling
HttpServletRequestSimulator.removeAttribute .
Parameters: name - a String specifyingthe name of the attribute Parameters: o - the Object to be stored |
setCookies | public void setCookies(Cookie[] cookies)(Code) | | Adds a set of cookies that can be retrieved from this request via the
getCookies() method.
Parameters: cookies - an array of Cookie object to be retrieved from thisrequest. See Also: HttpServletRequestSimulator.getCookies |
setDateHeader | public void setDateHeader(String name, long millis)(Code) | | Sets a header with the appropriate date string given the time in milliseconds.
Parameters: name - the name of the header Parameters: millis - the time in milliseconds |
setLocalAddr | public void setLocalAddr(String localAddr)(Code) | | |
setLocalName | public void setLocalName(String localName)(Code) | | |
setLocalPort | public void setLocalPort(int localPort)(Code) | | |
setRemotePort | public void setRemotePort(int remotePort)(Code) | | |
setRequestURL | public void setRequestURL(String url)(Code) | | Sets the request URL to be used in this test. This method uses
the given request URL to also set the scheme, server name, server
port, request URI, and query string.
|
|
|