public class MockHttpServletRequest extends Object implements javax.servlet.http.HttpServletRequest
| Constructor and Description |
|---|
MockHttpServletRequest(Application application,
javax.servlet.http.HttpSession session,
javax.servlet.ServletContext context)
Create the request using the supplied session object.
|
| Modifier and Type | Method and Description |
|---|---|
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) |
boolean |
authenticate(javax.servlet.http.HttpServletResponse response) |
javax.servlet.AsyncContext |
getAsyncContext() |
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.
|
javax.servlet.DispatcherType |
getDispatcherType() |
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.
|
javax.servlet.http.Part |
getPart(String name) |
Collection<javax.servlet.http.Part> |
getParts() |
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 |
isAsyncStarted() |
boolean |
isAsyncSupported() |
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 |
login(String username,
String password) |
void |
logout() |
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 |
setLocale(Locale locale) |
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.
|
MockHttpServletRequest |
setPart(String name,
javax.servlet.http.Part part) |
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
|
javax.servlet.AsyncContext |
startAsync() |
javax.servlet.AsyncContext |
startAsync(javax.servlet.ServletRequest servletRequest,
javax.servlet.ServletResponse servletResponse) |
public MockHttpServletRequest(Application application, javax.servlet.http.HttpSession session, javax.servlet.ServletContext context)
MockHttpSessionapplication - The application that this request is forsession - The session objectcontext - The current servlet contextpublic 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 valuepublic 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 namepublic 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.HttpServletRequestpublic long getDateHeader(String name) throws IllegalArgumentException
getDateHeader in interface javax.servlet.http.HttpServletRequestname - The header nameIllegalArgumentException - If the header cannot be convertedpublic String getHeader(String name)
getHeader in interface javax.servlet.http.HttpServletRequestname - The header namepublic Enumeration<String> getHeaderNames()
getHeaderNames in interface javax.servlet.http.HttpServletRequestpublic Enumeration<String> getHeaders(String name)
getHeaders in interface javax.servlet.http.HttpServletRequestname - The namepublic 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 nameNumberFormatException - If the header is not formatted correctlypublic Locale getLocale()
getLocale in interface javax.servlet.ServletRequestpublic void setLocale(Locale locale)
public 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 namepublic 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 parameterpublic 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.HttpServletRequestpublic 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 namepublic 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 topublic 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 sessionpublic 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 authenticate(javax.servlet.http.HttpServletResponse response)
throws IOException,
javax.servlet.ServletException
authenticate in interface javax.servlet.http.HttpServletRequestIOExceptionjavax.servlet.ServletExceptionpublic void login(String username, String password) throws javax.servlet.ServletException
login in interface javax.servlet.http.HttpServletRequestjavax.servlet.ServletExceptionpublic void logout()
throws javax.servlet.ServletException
logout in interface javax.servlet.http.HttpServletRequestjavax.servlet.ServletExceptionpublic Collection<javax.servlet.http.Part> getParts() throws IOException, javax.servlet.ServletException
getParts in interface javax.servlet.http.HttpServletRequestIOExceptionjavax.servlet.ServletExceptionpublic javax.servlet.http.Part getPart(String name) throws IOException, javax.servlet.ServletException
getPart in interface javax.servlet.http.HttpServletRequestIOExceptionjavax.servlet.ServletExceptionpublic MockHttpServletRequest setPart(String name, javax.servlet.http.Part part)
public 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 namepublic void removeAttribute(String name)
removeAttribute in interface javax.servlet.ServletRequestname - The name of the attributepublic 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 typepublic void setCharacterEncoding(String encoding) throws UnsupportedEncodingException
setCharacterEncoding in interface javax.servlet.ServletRequestencoding - The character encodingUnsupportedEncodingException - If encoding not supportedpublic void setCookies(javax.servlet.http.Cookie[] theCookies)
theCookies - The cookiespublic void setMethod(String method)
method - The methodpublic void setParameter(String name, String value)
name - The namevalue - The valuepublic 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()
getServletContext in interface javax.servlet.ServletRequestpublic javax.servlet.AsyncContext startAsync()
throws IllegalStateException
startAsync in interface javax.servlet.ServletRequestIllegalStateExceptionpublic javax.servlet.AsyncContext startAsync(javax.servlet.ServletRequest servletRequest,
javax.servlet.ServletResponse servletResponse)
throws IllegalStateException
startAsync in interface javax.servlet.ServletRequestIllegalStateExceptionpublic boolean isAsyncStarted()
isAsyncStarted in interface javax.servlet.ServletRequestpublic boolean isAsyncSupported()
isAsyncSupported in interface javax.servlet.ServletRequestpublic javax.servlet.AsyncContext getAsyncContext()
getAsyncContext in interface javax.servlet.ServletRequestpublic javax.servlet.DispatcherType getDispatcherType()
getDispatcherType in interface javax.servlet.ServletRequestCopyright © 2006–2021 Apache Software Foundation. All rights reserved.