|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.apache.click.servlet.MockRequest
public class MockRequest
Mock implementation of HttpServletRequest
.
Field Summary | |
---|---|
static String |
REMOTE_USER
The REMOTE_USER header. |
Fields inherited from interface javax.servlet.http.HttpServletRequest |
---|
BASIC_AUTH, CLIENT_CERT_AUTH, DIGEST_AUTH, FORM_AUTH |
Constructor Summary | |
---|---|
MockRequest()
Create new MockRequest. |
|
MockRequest(Locale locale)
Create new MockRequest for the specified local. |
|
MockRequest(Locale locale,
ServletContext servletContext)
Create a new MockRequest for the specified locale and servletContext. |
|
MockRequest(Locale locale,
ServletContext servletContext,
HttpSession session)
Create a new MockRequest for the specified arguments. |
|
MockRequest(Locale locale,
String contextPath,
String servletPath,
ServletContext servletContext,
HttpSession session)
Create a new MockRequest for the specified arguments. |
|
MockRequest(ServletContext servletContext)
Create a new MockRequest for the specified context. |
Method Summary | |
---|---|
void |
addCookie(Cookie cookie)
Add a new cookie. |
void |
addFile(String fieldName,
File file,
String contentType)
Add an uploaded file to the request. |
void |
addHeader(String name,
String value)
Add a header to the request. |
Object |
getAttribute(String name)
Get an attribute. |
Enumeration<String> |
getAttributeNames()
Get the names of all of the values. |
String |
getAuthType()
Get the auth type. |
String |
getCharacterEncoding()
Get the current character encoding. |
int |
getContentLength()
Return the length of the content. |
String |
getContentType()
If useMultiPartContentType set as true return the correct content-type. |
String |
getContextPath()
Returns the portion of the request URI that indicates the context of the request. |
Cookie[] |
getCookies()
Get all of the cookies for this request. |
long |
getDateHeader(String name)
Get the given header as a date. |
String |
getForward()
Returns the url that was forwarded to, otherwise return null. |
String |
getHeader(String name)
Get the given header value. |
Enumeration<String> |
getHeaderNames()
Get the names of all of the headers. |
Map<String,List<String>> |
getHeaders()
Return the map of headers for this request. |
Enumeration<String> |
getHeaders(String name)
Get enumeration of all header values with the given name. |
List<String> |
getIncludes()
Returns the list of server side included url's. |
ServletInputStream |
getInputStream()
Returns an input stream if there has been added some uploaded files. |
int |
getIntHeader(String name)
Get the given header as an int. |
String |
getLocalAddr()
Return the local address, "127.0.0.1". |
Locale |
getLocale()
Get the locale of the request. |
Enumeration<Locale> |
getLocales()
Return all the accepted locales. |
String |
getLocalName()
Return the local name, "127.0.0.1". |
int |
getLocalPort()
Return the local port, 80. |
String |
getMethod()
Get the method. |
String |
getParameter(String name)
Get the request parameter with the given name. |
Map<String,Object> |
getParameterMap()
Get the map of all of the parameters. |
Enumeration<String> |
getParameterNames()
Get the names of all of the parameters. |
String[] |
getParameterValues(String name)
Get the values for the given parameter. |
String |
getPathInfo()
Get the path info. |
String |
getPathTranslated()
Always returns null. |
String |
getProtocol()
Get the protocol. |
String |
getQueryString()
Get the query string part of the request. |
BufferedReader |
getReader()
This feature is not implemented at this time as we are not supporting binary servlet input. |
String |
getRealPath(String name)
Deprecated. Use ServletContext.getRealPath(String) instead. |
String |
getRemoteAddr()
Get the remote address of the client. |
String |
getRemoteHost()
Get the remote host. |
int |
getRemotePort()
Return the remote port, 80. |
String |
getRemoteUser()
Return the name of the userPrincipal if set, otherwise
the value of the "REMOTE_USER" header. |
RequestDispatcher |
getRequestDispatcher(String path)
Returns a RequestDispatcher for the specified path. |
String |
getRequestedSessionId()
Get the requested session id. |
String |
getRequestURI()
Returns context path and servlet path concatenated, typically /applicationClassName/applicationClassName. |
StringBuffer |
getRequestURL()
Returns (an attempt at) a reconstructed URL based on it's constituent parts. |
String |
getScheme()
Get the scheme http, https, or ftp. |
String |
getServerName()
Get the host server name to which the request was sent. |
int |
getServerPort()
Returns the port number to which the request was sent. |
String |
getServletPath()
Return a String containing the name or path of the servlet being called. |
HttpSession |
getSession()
Returns the current HttpSession associated with this request. |
HttpSession |
getSession(boolean create)
Returns the current HttpSession associated with this request. |
Principal |
getUserPrincipal()
Get the user principal. |
boolean |
hasUploadedFiles()
|
void |
initialize()
Reset the request back to a default state. |
boolean |
isPost()
Return whether the request is a post or not. |
boolean |
isRequestedSessionIdFromCookie()
Check whether session id is from a cookie. |
boolean |
isRequestedSessionIdFromUrl()
Check whether session id is from a url rewrite. |
boolean |
isRequestedSessionIdFromURL()
Check whether session id is from a url rewrite. |
boolean |
isRequestedSessionIdValid()
Check whether the session id is valid. |
boolean |
isSecure()
Always returns false. |
boolean |
isUserInRole(String role)
Returns true if the authenticated user is
included in the given role, false otherwise. |
void |
removeAttribute(String name)
Remove the given attribute. |
void |
removeParameter(String name)
Remove the specified parameter. |
void |
reset()
Delegate to initialize method. |
void |
setAttribute(String name,
Object o)
Set the given attribute. |
void |
setAuthType(String authType)
Set the auth type. |
void |
setCharacterEncoding(String encoding)
Set the character encoding. |
void |
setContextPath(String contextPath)
Set the portion of the request URI that indicates the context of the request. |
void |
setCookies(Cookie[] theCookies)
Set the cookies. |
void |
setHeader(String name,
String... values)
Set request header values. |
void |
setHeader(String name,
String value)
Set request header value. |
void |
setHttpSession(HttpSession session)
Set the request's session instance. |
void |
setMethod(String method)
Set the method. |
void |
setParameter(String name,
String value)
Set a parameter. |
void |
setParameter(String name,
String[] values)
Set the specified parameter name to the array of strings. |
void |
setParameters(Map<String,Object> parameters)
Sets a map of parameters. |
void |
setPathInfo(String path)
Set the path that this request is supposed to be serving. |
void |
setScheme(String scheme)
Set the request's scheme, for example http, https, or ftp. |
void |
setServerName(String serverName)
Sets the host server name to which the request was sent. |
void |
setServerPort(int serverPort)
Set the port number to which the request was sent. |
void |
setServletContext(ServletContext servletContext)
Set the request's servletContext instance. |
void |
setServletPath(String servletPath)
Set the string containing the name or path of the servlet being called. |
void |
setSession(HttpSession session)
Set the current HttpSession associated with this request. |
void |
setUseMultiPartContentType(boolean useMultiPartContentType)
True will force Request to generate multiPart ContentType and ContentLength. |
void |
setUserPrincipal(Principal userPrincipal)
Set the user principal. |
String |
toString()
Returns the String representation of the mock request. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Field Detail |
---|
public static final String REMOTE_USER
Constructor Detail |
---|
public MockRequest()
public MockRequest(Locale locale)
locale
- locale for this requestpublic MockRequest(ServletContext servletContext)
servletContext
- the servletContext for this requestpublic MockRequest(Locale locale, ServletContext servletContext)
locale
- locale for this requestservletContext
- the servletContext for this requestpublic MockRequest(Locale locale, ServletContext servletContext, HttpSession session)
locale
- The request locale, or null to use the default localesession
- The session objectservletContext
- The current servlet contextpublic MockRequest(Locale locale, String contextPath, String servletPath, ServletContext servletContext, HttpSession session)
locale
- The request locale, or null to use the default localecontextPath
- the request context pathservletPath
- the request servlet pathservletContext
- The current servlet contextsession
- the request sessionMethod Detail |
---|
public void setServletContext(ServletContext servletContext)
servletContext
- the new ServletContext instancepublic void setHttpSession(HttpSession session)
session
- the new HttpSession instancepublic void addCookie(Cookie cookie)
cookie
- The cookiepublic void addFile(String fieldName, File file, String contentType)
fieldName
- The fieldname of the upload field.file
- The file to upload.contentType
- The content type of the file. Must be a correct
mimetype.public void addHeader(String name, String value)
name
- the name of the header to addvalue
- the valuepublic void setHeader(String name, String value)
name
- the name of the header to setvalue
- the header valuepublic void setHeader(String name, String... values)
name
- the name of the header to setvalues
- the header valuespublic Object getAttribute(String name)
getAttribute
in interface ServletRequest
name
- The attribute name
public Enumeration<String> getAttributeNames()
getAttributeNames
in interface ServletRequest
public String getAuthType()
getAuthType
in interface HttpServletRequest
public String getCharacterEncoding()
getCharacterEncoding
in interface ServletRequest
public void setUseMultiPartContentType(boolean useMultiPartContentType)
useMultiPartContentType
- true if the request is multi-part, false
otherwisepublic int getContentLength()
getContentLength
in interface ServletRequest
public String getContentType()
getContentType
in interface ServletRequest
public Cookie[] getCookies()
getCookies
in interface HttpServletRequest
public long getDateHeader(String name) throws IllegalArgumentException
getDateHeader
in interface HttpServletRequest
name
- The header name
IllegalArgumentException
- If the header cannot be convertedpublic String getHeader(String name)
getHeader
in interface HttpServletRequest
name
- The header name
public Enumeration<String> getHeaderNames()
getHeaderNames
in interface HttpServletRequest
public Enumeration<String> getHeaders(String name)
getHeaders
in interface HttpServletRequest
name
- The name
public Map<String,List<String>> getHeaders()
public ServletInputStream getInputStream() throws IOException
addFile(String, File, String)
to add some uploaded files.
getInputStream
in interface ServletRequest
IOException
- If an I/O related problem occurspublic int getIntHeader(String name)
getIntHeader
in interface HttpServletRequest
name
- The header name
NumberFormatException
- If the header is not formatted correctlypublic Locale getLocale()
getLocale
in interface ServletRequest
public Enumeration<Locale> getLocales()
getLocales
in interface ServletRequest
public String getMethod()
getMethod
in interface HttpServletRequest
public String getParameter(String name)
getParameter
in interface ServletRequest
name
- The parameter name
public Map<String,Object> getParameterMap()
getParameterMap
in interface ServletRequest
public Enumeration<String> getParameterNames()
getParameterNames
in interface ServletRequest
public String[] getParameterValues(String name)
getParameterValues
in interface ServletRequest
name
- The name of the parameter
public String getPathInfo()
getPathInfo
in interface HttpServletRequest
public String getPathTranslated()
getPathTranslated
in interface HttpServletRequest
public String getProtocol()
getProtocol
in interface ServletRequest
public String getQueryString()
getQueryString
in interface HttpServletRequest
public BufferedReader getReader() throws IOException
getReader
in interface ServletRequest
IOException
- If an I/O related problem occurspublic String getRealPath(String name)
getRealPath
in interface ServletRequest
name
- The name
public String getRemoteAddr()
getRemoteAddr
in interface ServletRequest
public String getRemoteHost()
getRemoteHost
in interface ServletRequest
public String getRemoteUser()
userPrincipal
if set, otherwise
the value of the "REMOTE_USER" header.
To set the remote user, create an instance of a MockPrincipal
and set it on the request through the method
setUserPrincipal(java.security.Principal)
.
getRemoteUser
in interface HttpServletRequest
public String getLocalAddr()
public String getLocalName()
public int getLocalPort()
public int getRemotePort()
public RequestDispatcher getRequestDispatcher(String path)
getRequestDispatcher
in interface ServletRequest
path
- a String specifying the pathname to the resource
public String getRequestedSessionId()
getRequestedSessionId
in interface HttpServletRequest
public String getRequestURI()
getRequestURI
in interface HttpServletRequest
HttpServletRequest.getRequestURI()
public StringBuffer getRequestURL()
getRequestURL
in interface HttpServletRequest
public boolean isPost()
public String getScheme()
getScheme
in interface ServletRequest
public void setScheme(String scheme)
scheme
- the request's schemepublic String getServerName()
getServerName
in interface ServletRequest
public void setServerName(String serverName)
serverName
- the server name the request was sent topublic int getServerPort()
getServerPort
in interface ServletRequest
public void setServerPort(int serverPort)
serverPort
- the port number to which the request was sentpublic String getContextPath()
getContextPath
in interface HttpServletRequest
public void setContextPath(String contextPath)
contextPath
- the portion of the request URI that indicates the
context of the request.public String getServletPath()
getServletPath
in interface HttpServletRequest
public void setServletPath(String servletPath)
servletPath
- a String containing the name or path of the servlet
being calledpublic HttpSession getSession()
getSession
in interface HttpServletRequest
public void setSession(HttpSession session)
session
- the HttpSession to associate with this requestpublic HttpSession getSession(boolean create)
getSession
in interface HttpServletRequest
create
- if true creates a new session if one does not exist
public Principal getUserPrincipal()
getRemoteUser()
.
getUserPrincipal
in interface HttpServletRequest
public void setUserPrincipal(Principal userPrincipal)
userPrincipal
- the user principalpublic boolean hasUploadedFiles()
addFile(String, File, String)
.public final void initialize()
public void reset()
public boolean isRequestedSessionIdFromCookie()
isRequestedSessionIdFromCookie
in interface HttpServletRequest
public boolean isRequestedSessionIdFromUrl()
isRequestedSessionIdFromUrl
in interface HttpServletRequest
public boolean isRequestedSessionIdFromURL()
isRequestedSessionIdFromURL
in interface HttpServletRequest
public boolean isRequestedSessionIdValid()
isRequestedSessionIdValid
in interface HttpServletRequest
public boolean isSecure()
isSecure
in interface ServletRequest
public boolean isUserInRole(String role)
authenticated user
is
included in the given role, false otherwise.
To mock up roles for a user, create a user principal
and set the necessary roles. See MockPrincipal
for an example.
isUserInRole
in interface HttpServletRequest
role
- the role name
public void removeAttribute(String name)
removeAttribute
in interface ServletRequest
name
- The name of the attributepublic void setAttribute(String name, Object o)
setAttribute
in interface ServletRequest
name
- The attribute nameo
- The value to setpublic void setAuthType(String authType)
authType
- The auth typepublic void setCharacterEncoding(String encoding) throws UnsupportedEncodingException
setCharacterEncoding
in interface ServletRequest
encoding
- The character encoding
UnsupportedEncodingException
- If encoding not supportedpublic void setCookies(Cookie[] theCookies)
theCookies
- The cookiespublic void setMethod(String method)
method
- The methodpublic void setParameter(String name, String value)
name
- The namevalue
- The valuepublic void setParameter(String name, String[] values)
name
- name of the parametervalues
- the parameter valuespublic void removeParameter(String name)
name
- the parameter name to removepublic void setParameters(Map<String,Object> parameters)
parameters
- the parameters to setpublic void setPathInfo(String path)
path
- specifies the request path to servepublic String getForward()
MockRequestDispatcher.forward(javax.servlet.ServletRequest,
javax.servlet.ServletResponse)
public List<String> getIncludes()
MockRequestDispatcher.include(javax.servlet.ServletRequest,
javax.servlet.ServletResponse)
public String toString()
toString
in class Object
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |