|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectorg.apache.wicket.protocol.http.mock.MockHttpServletRequest
public class MockHttpServletRequest
Mock servlet request. Implements all of the methods from the standard HttpServletRequest class plus helper methods to aid setting up a request.
| Field Summary |
|---|
| Fields inherited from interface javax.servlet.http.HttpServletRequest |
|---|
BASIC_AUTH, CLIENT_CERT_AUTH, DIGEST_AUTH, FORM_AUTH |
| Constructor Summary | |
|---|---|
MockHttpServletRequest(Application application,
javax.servlet.http.HttpSession session,
javax.servlet.ServletContext context)
Create the request using the supplied session object. |
|
| Method Summary | |
|---|---|
void |
addCookie(javax.servlet.http.Cookie cookie)
Add a new cookie. |
void |
addCookies(Iterable<javax.servlet.http.Cookie> cookies)
|
void |
addDateHeader(String name,
long date)
|
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. |
void |
addParameter(String name,
String value)
|
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. |
Charset |
getCharset()
Get the current character set. |
int |
getContentLength()
Return the length of the content. |
String |
getContentType()
If useMultiPartContentType set as true return the correct content-type. |
String |
getContextPath()
Get the context path. |
javax.servlet.http.Cookie |
getCookie(String name)
|
javax.servlet.http.Cookie[] |
getCookies()
Get all of the cookies for this request. |
long |
getDateHeader(String name)
Get the given header as a date. |
String |
getFilterPrefix()
|
String |
getHeader(String name)
Get the given header value. |
Enumeration<String> |
getHeaderNames()
Get the names of all of the headers. |
Enumeration<String> |
getHeaders(String name)
Get enumeration of all header values with the given name. |
javax.servlet.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()
|
Locale |
getLocale()
Get the locale of the request. |
Enumeration<Locale> |
getLocales()
Return all the accepted locales. |
String |
getLocalName()
|
int |
getLocalPort()
|
String |
getMethod()
Get the method. |
String |
getParameter(String name)
Get the request parameter with the given name. |
Map<String,String[]> |
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. |
MockRequestParameters |
getPostParameters()
|
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()
|
String |
getRemoteHost()
Get the remote host. |
int |
getRemotePort()
|
String |
getRemoteUser()
Get the name of the remote user from the REMOTE_USER header. |
javax.servlet.RequestDispatcher |
getRequestDispatcher(String name)
Return a dummy dispatcher that just records that dispatch has occurred without actually doing anything. |
String |
getRequestedSessionId()
Get the requested session id. |
String |
getRequestURI()
Returns context path and servlet path concatenated, typically /applicationClassName/applicationClassName |
StringBuffer |
getRequestURL()
Try to build a rough URL. |
String |
getScheme()
Get the scheme. |
String |
getServerName()
Get the server name. |
int |
getServerPort()
|
javax.servlet.ServletContext |
getServletContext()
|
String |
getServletPath()
The servlet path may either be the application name or /. |
javax.servlet.http.HttpSession |
getSession()
Get the sessions. |
javax.servlet.http.HttpSession |
getSession(boolean b)
Get the session. |
Url |
getUrl()
|
Principal |
getUserPrincipal()
Get the user principal. |
boolean |
hasUploadedFiles()
|
void |
initialize()
Reset the request back to a default state. |
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()
|
boolean |
isUserInRole(String name)
NOT IMPLEMENTED. |
void |
removeAttribute(String name)
Remove the given attribute. |
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 |
setCookies(javax.servlet.http.Cookie[] theCookies)
Set the cookies. |
void |
setHeader(String name,
String value)
Sets a header to the request. |
void |
setMethod(String method)
Set the method. |
void |
setParameter(String name,
String value)
Set a parameter. |
void |
setParameters(Map<String,String[]> parameters)
Sets a map of parameters. |
void |
setPath(String path)
Set the path that this request is supposed to be serving. |
void |
setRemoteAddr(String addr)
|
void |
setScheme(String scheme)
Sets the scheme of this request set the secure flag accordingly
(true for 'https', false otherwise) |
void |
setSecure(boolean secure)
|
void |
setServerName(String serverName)
Set the server name. |
void |
setServerPort(int port)
Sets the server port for this request |
void |
setURL(String url)
Set the complete url for this request. |
void |
setUrl(Url url)
|
void |
setUseMultiPartContentType(boolean useMultiPartContentType)
true will force Request generate multiPart ContentType and ContentLength |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Constructor Detail |
|---|
public MockHttpServletRequest(Application application,
javax.servlet.http.HttpSession session,
javax.servlet.ServletContext context)
MockHttpSession
application - The application that this request is forsession - The session objectcontext - The current servlet context| Method Detail |
|---|
public void addCookie(javax.servlet.http.Cookie cookie)
cookie - The cookiepublic void addCookies(Iterable<javax.servlet.http.Cookie> cookies)
cookies -
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 addvalue - The valueaddHeader(String, String)
public void addDateHeader(String name,
long date)
name - date - public Object getAttribute(String name)
getAttribute in interface javax.servlet.ServletRequestname - The attribute name
public Enumeration<String> getAttributeNames()
getAttributeNames in interface javax.servlet.ServletRequestpublic String getAuthType()
getAuthType in interface javax.servlet.http.HttpServletRequestpublic String getCharacterEncoding()
getCharacterEncoding in interface javax.servlet.ServletRequestpublic Charset getCharset()
public void setUseMultiPartContentType(boolean useMultiPartContentType)
useMultiPartContentType - public int getContentLength()
getContentLength in interface javax.servlet.ServletRequestpublic String getContentType()
getContentType in interface javax.servlet.ServletRequestpublic String getContextPath()
getContextPath in interface javax.servlet.http.HttpServletRequestpublic javax.servlet.http.Cookie getCookie(String name)
name -
public javax.servlet.http.Cookie[] getCookies()
getCookies in interface javax.servlet.http.HttpServletRequest
public long getDateHeader(String name)
throws IllegalArgumentException
getDateHeader in interface javax.servlet.http.HttpServletRequestname - The header name
IllegalArgumentException - If the header cannot be convertedpublic String getHeader(String name)
getHeader in interface javax.servlet.http.HttpServletRequestname - The header name
public Enumeration<String> getHeaderNames()
getHeaderNames in interface javax.servlet.http.HttpServletRequestpublic Enumeration<String> getHeaders(String name)
getHeaders in interface javax.servlet.http.HttpServletRequestname - The name
public javax.servlet.ServletInputStream getInputStream()
throws IOException
addFile(String, File, String) to add some uploaded files.
getInputStream in interface javax.servlet.ServletRequestIOException - If an I/O related problem occurspublic int getIntHeader(String name)
getIntHeader in interface javax.servlet.http.HttpServletRequestname - The header name
NumberFormatException - If the header is not formatted correctlypublic Locale getLocale()
getLocale in interface javax.servlet.ServletRequestpublic Enumeration<Locale> getLocales()
getLocales in interface javax.servlet.ServletRequestpublic String getMethod()
getMethod in interface javax.servlet.http.HttpServletRequestpublic String getParameter(String name)
getParameter in interface javax.servlet.ServletRequestname - The parameter name
public Map<String,String[]> getParameterMap()
getParameterMap in interface javax.servlet.ServletRequestpublic Enumeration<String> getParameterNames()
getParameterNames in interface javax.servlet.ServletRequestpublic String[] getParameterValues(String name)
getParameterValues in interface javax.servlet.ServletRequestname - The name of the parameter
public String getPathInfo()
getPathInfo in interface javax.servlet.http.HttpServletRequestpublic String getPathTranslated()
getPathTranslated in interface javax.servlet.http.HttpServletRequestpublic String getProtocol()
getProtocol in interface javax.servlet.ServletRequestpublic String getQueryString()
getQueryString in interface javax.servlet.http.HttpServletRequest
public BufferedReader getReader()
throws IOException
getReader in interface javax.servlet.ServletRequestIOException - If an I/O related problem occurs@Deprecated public String getRealPath(String name)
getRealPath in interface javax.servlet.ServletRequestname - The name
public String getRemoteAddr()
getRemoteAddr in interface javax.servlet.ServletRequestpublic void setRemoteAddr(String addr)
addr - Format: "aaa.bbb.ccc.ddd"public String getRemoteHost()
getRemoteHost in interface javax.servlet.ServletRequestpublic String getRemoteUser()
getRemoteUser in interface javax.servlet.http.HttpServletRequestpublic javax.servlet.RequestDispatcher getRequestDispatcher(String name)
getRequestDispatcher in interface javax.servlet.ServletRequestname - The name to dispatch to
public String getRequestedSessionId()
getRequestedSessionId in interface javax.servlet.http.HttpServletRequestpublic String getRequestURI()
getRequestURI in interface javax.servlet.http.HttpServletRequestHttpServletRequest.getRequestURI()public StringBuffer getRequestURL()
getRequestURL in interface javax.servlet.http.HttpServletRequestHttpServletRequest.getRequestURL()public String getScheme()
getScheme in interface javax.servlet.ServletRequestpublic void setScheme(String scheme)
secure flag accordingly
(true for 'https', false otherwise)
scheme - protocol scheme (e.g. https, http, ftp)isSecure()public String getServerName()
getServerName in interface javax.servlet.ServletRequestpublic void setServerName(String serverName)
serverName - content of 'Host' headerpublic int getServerPort()
getServerPort in interface javax.servlet.ServletRequestpublic void setServerPort(int port)
port - public String getServletPath()
getServletPath in interface javax.servlet.http.HttpServletRequestpublic javax.servlet.http.HttpSession getSession()
getSession in interface javax.servlet.http.HttpServletRequestpublic javax.servlet.http.HttpSession getSession(boolean b)
getSession in interface javax.servlet.http.HttpServletRequestb - Ignored, there is always a session
public Principal getUserPrincipal()
getUserPrincipal in interface javax.servlet.http.HttpServletRequestpublic boolean hasUploadedFiles()
addFile(String, File, String)public void initialize()
public boolean isRequestedSessionIdFromCookie()
isRequestedSessionIdFromCookie in interface javax.servlet.http.HttpServletRequestpublic boolean isRequestedSessionIdFromUrl()
isRequestedSessionIdFromUrl in interface javax.servlet.http.HttpServletRequestpublic boolean isRequestedSessionIdFromURL()
isRequestedSessionIdFromURL in interface javax.servlet.http.HttpServletRequestpublic boolean isRequestedSessionIdValid()
isRequestedSessionIdValid in interface javax.servlet.http.HttpServletRequestpublic boolean isSecure()
isSecure in interface javax.servlet.ServletRequesttrue if this request's scheme is 'https', false - otherwisepublic void setSecure(boolean secure)
secure - public boolean isUserInRole(String name)
isUserInRole in interface javax.servlet.http.HttpServletRequestname - The role name
public void removeAttribute(String name)
removeAttribute in interface javax.servlet.ServletRequestname - The name of the attribute
public void setAttribute(String name,
Object o)
setAttribute in interface javax.servlet.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 javax.servlet.ServletRequestencoding - The character encoding
UnsupportedEncodingException - If encoding not supportedpublic void setCookies(javax.servlet.http.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 addParameter(String name,
String value)
name - value - public void setParameters(Map<String,String[]> parameters)
parameters - the parameters to setpublic void setPath(String path)
path - public void setURL(String url)
url - public String getLocalAddr()
getLocalAddr in interface javax.servlet.ServletRequestpublic String getLocalName()
getLocalName in interface javax.servlet.ServletRequestpublic int getLocalPort()
getLocalPort in interface javax.servlet.ServletRequestpublic int getRemotePort()
getRemotePort in interface javax.servlet.ServletRequestpublic void setUrl(Url url)
url - public Url getUrl()
public MockRequestParameters getPostParameters()
public String getFilterPrefix()
public javax.servlet.ServletContext getServletContext()
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||