|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectorg.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 request
public MockRequest(Locale locale,
ServletContext servletContext)
locale - locale for this requestservletContext - the servletContext for this request
public MockRequest(Locale locale,
ServletContext servletContext,
HttpSession session)
locale - The request locale, or null to use the default localesession - The session objectservletContext - The current servlet context
public 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 session| Method 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 cookie
public 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 value
public void setHeader(String name,
String value)
name - the name of the header to setvalue - the header value
public void setHeader(String name,
String... values)
name - the name of the header to setvalues - the header valuespublic Object getAttribute(String name)
getAttribute in interface ServletRequestname - The attribute name
public Enumeration<String> getAttributeNames()
getAttributeNames in interface ServletRequestpublic String getAuthType()
getAuthType in interface HttpServletRequestpublic String getCharacterEncoding()
getCharacterEncoding in interface ServletRequestpublic void setUseMultiPartContentType(boolean useMultiPartContentType)
useMultiPartContentType - true if the request is multi-part, false
otherwisepublic int getContentLength()
getContentLength in interface ServletRequestpublic String getContentType()
getContentType in interface ServletRequestpublic Cookie[] getCookies()
getCookies in interface HttpServletRequest
public long getDateHeader(String name)
throws IllegalArgumentException
getDateHeader in interface HttpServletRequestname - The header name
IllegalArgumentException - If the header cannot be convertedpublic String getHeader(String name)
getHeader in interface HttpServletRequestname - The header name
public Enumeration<String> getHeaderNames()
getHeaderNames in interface HttpServletRequestpublic Enumeration<String> getHeaders(String name)
getHeaders in interface HttpServletRequestname - 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 ServletRequestIOException - If an I/O related problem occurspublic int getIntHeader(String name)
getIntHeader in interface HttpServletRequestname - The header name
NumberFormatException - If the header is not formatted correctlypublic Locale getLocale()
getLocale in interface ServletRequestpublic Enumeration<Locale> getLocales()
getLocales in interface ServletRequestpublic String getMethod()
getMethod in interface HttpServletRequestpublic String getParameter(String name)
getParameter in interface ServletRequestname - The parameter name
public Map<String,Object> getParameterMap()
getParameterMap in interface ServletRequestpublic Enumeration<String> getParameterNames()
getParameterNames in interface ServletRequestpublic String[] getParameterValues(String name)
getParameterValues in interface ServletRequestname - The name of the parameter
public String getPathInfo()
getPathInfo in interface HttpServletRequestpublic String getPathTranslated()
getPathTranslated in interface HttpServletRequestpublic String getProtocol()
getProtocol in interface ServletRequestpublic String getQueryString()
getQueryString in interface HttpServletRequest
public BufferedReader getReader()
throws IOException
getReader in interface ServletRequestIOException - If an I/O related problem occurspublic String getRealPath(String name)
getRealPath in interface ServletRequestname - The name
public String getRemoteAddr()
getRemoteAddr in interface ServletRequestpublic String getRemoteHost()
getRemoteHost in interface ServletRequestpublic 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 HttpServletRequestpublic String getLocalAddr()
public String getLocalName()
public int getLocalPort()
public int getRemotePort()
public RequestDispatcher getRequestDispatcher(String path)
getRequestDispatcher in interface ServletRequestpath - a String specifying the pathname to the resource
public String getRequestedSessionId()
getRequestedSessionId in interface HttpServletRequestpublic String getRequestURI()
getRequestURI in interface HttpServletRequestHttpServletRequest.getRequestURI()public StringBuffer getRequestURL()
getRequestURL in interface HttpServletRequestpublic boolean isPost()
public String getScheme()
getScheme in interface ServletRequestpublic void setScheme(String scheme)
scheme - the request's schemepublic String getServerName()
getServerName in interface ServletRequestpublic void setServerName(String serverName)
serverName - the server name the request was sent topublic int getServerPort()
getServerPort in interface ServletRequestpublic void setServerPort(int serverPort)
serverPort - the port number to which the request was sentpublic String getContextPath()
getContextPath in interface HttpServletRequestpublic void setContextPath(String contextPath)
contextPath - the portion of the request URI that indicates the
context of the request.public String getServletPath()
getServletPath in interface HttpServletRequestpublic void setServletPath(String servletPath)
servletPath - a String containing the name or path of the servlet
being calledpublic HttpSession getSession()
getSession in interface HttpServletRequestpublic void setSession(HttpSession session)
session - the HttpSession to associate with this requestpublic HttpSession getSession(boolean create)
getSession in interface HttpServletRequestcreate - if true creates a new session if one does not exist
public Principal getUserPrincipal()
getRemoteUser().
getUserPrincipal in interface HttpServletRequestpublic 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 HttpServletRequestpublic boolean isRequestedSessionIdFromUrl()
isRequestedSessionIdFromUrl in interface HttpServletRequestpublic boolean isRequestedSessionIdFromURL()
isRequestedSessionIdFromURL in interface HttpServletRequestpublic boolean isRequestedSessionIdValid()
isRequestedSessionIdValid in interface HttpServletRequestpublic boolean isSecure()
isSecure in interface ServletRequestpublic 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 HttpServletRequestrole - the role name
public void removeAttribute(String name)
removeAttribute in interface ServletRequestname - The name of the attribute
public void setAttribute(String name,
Object o)
setAttribute in interface ServletRequestname - The attribute nameo - The value to setpublic void setAuthType(String authType)
authType - The auth type
public void setCharacterEncoding(String encoding)
throws UnsupportedEncodingException
setCharacterEncoding in interface ServletRequestencoding - The character encoding
UnsupportedEncodingException - If encoding not supportedpublic void setCookies(Cookie[] theCookies)
theCookies - The cookiespublic void setMethod(String method)
method - The method
public void setParameter(String name,
String value)
name - The namevalue - The value
public 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 | ||||||||