public class MockServletRequest extends Object implements javax.servlet.http.HttpServletRequest, MockHttpRequest
HttpServletRequest
for mocking purposes.
Constructor and Description |
---|
MockServletRequest() |
Modifier and Type | Method and Description |
---|---|
MockServletRequest |
accept(Object value)
Specifies the
Accept header value on the request. |
MockServletRequest |
acceptCharset(Object value)
Specifies the
Accept-Charset header value on the request. |
MockServletRequest |
acceptEncoding(Object value)
Specifies the
Accept-Encoding header value on the request. |
MockServletRequest |
acceptLanguage(Object value)
Specifies the
Accept-Language header value on the request. |
MockServletRequest |
attribute(String name,
Object value)
Fluent setter.
|
boolean |
authenticate(javax.servlet.http.HttpServletResponse response) |
MockServletRequest |
authorization(Object value)
Specifies the
Authorization header value on the request. |
MockServletRequest |
authType(String value)
Fluent setter.
|
MockServletRequest |
body(Object value)
Fluent setter.
|
MockServletRequest |
cacheControl(Object value)
Specifies the
Cache-Control header value on the request. |
String |
changeSessionId() |
MockServletRequest |
characterEncoding(String value)
Fluent setter.
|
MockServletRequest |
clientVersion(Object value)
Specifies the
X-Client-Version header value on the request. |
MockServletRequest |
connection(Object value)
Specifies the
Connection header value on the request. |
MockServletRequest |
contentEncoding(Object value)
Specifies the
Content-Encoding header value on the request. |
MockServletRequest |
contentLength(Object value)
Specifies the
Content-Length header value on the request. |
MockServletRequest |
contentType(Object value)
Specifies the
Content-Type header value on the request. |
MockServletRequest |
contextPath(String value)
Fluent setter.
|
MockServletRequest |
cookies(javax.servlet.http.Cookie[] value)
Fluent setter.
|
static MockServletRequest |
create()
Creates a new servlet request.
|
static MockServletRequest |
create(String method,
String path,
Object... pathArgs)
Creates a new servlet request with the specified method name and request path.
|
MockServletRequest |
date(Object value)
Specifies the
Date header value on the request. |
MockServletRequest |
debug()
Enabled debug mode on this request.
|
MockServletRequest |
dispatcherType(javax.servlet.DispatcherType value)
Fluent setter.
|
MockServletResponse |
execute()
Executes this request and returns the response object.
|
MockServletRequest |
expect(Object value)
Specifies the
Expect header value on the request. |
MockServletRequest |
formData(String key,
Object value)
Adds a form data entry to this request.
|
MockServletRequest |
from(Object value)
Specifies the
From header value on the request. |
javax.servlet.AsyncContext |
getAsyncContext() |
Object |
getAttribute(String name) |
Enumeration<String> |
getAttributeNames() |
String |
getAuthType() |
String |
getCharacterEncoding() |
int |
getContentLength() |
long |
getContentLengthLong() |
String |
getContentType() |
String |
getContextPath() |
javax.servlet.http.Cookie[] |
getCookies() |
long |
getDateHeader(String name) |
javax.servlet.DispatcherType |
getDispatcherType() |
String |
getHeader(String name) |
Enumeration<String> |
getHeaderNames() |
Enumeration<String> |
getHeaders(String name) |
javax.servlet.ServletInputStream |
getInputStream() |
int |
getIntHeader(String name) |
String |
getLocalAddr() |
Locale |
getLocale() |
Enumeration<Locale> |
getLocales() |
String |
getLocalName() |
int |
getLocalPort() |
String |
getMethod() |
String |
getParameter(String name) |
Map<String,String[]> |
getParameterMap() |
Enumeration<String> |
getParameterNames() |
String[] |
getParameterValues(String name) |
javax.servlet.http.Part |
getPart(String name) |
Collection<javax.servlet.http.Part> |
getParts() |
String |
getPathInfo() |
String |
getPathTranslated() |
String |
getProtocol() |
String |
getQueryString() |
BufferedReader |
getReader() |
String |
getRealPath(String path) |
String |
getRemoteAddr() |
String |
getRemoteHost() |
int |
getRemotePort() |
String |
getRemoteUser() |
javax.servlet.RequestDispatcher |
getRequestDispatcher(String path) |
String |
getRequestedSessionId() |
String |
getRequestURI() |
StringBuffer |
getRequestURL() |
String |
getScheme() |
String |
getServerName() |
int |
getServerPort() |
javax.servlet.ServletContext |
getServletContext() |
String |
getServletPath() |
javax.servlet.http.HttpSession |
getSession() |
javax.servlet.http.HttpSession |
getSession(boolean create) |
Principal |
getUserPrincipal() |
MockServletRequest |
header(String name,
Object value)
Fluent setter.
|
MockServletRequest |
host(Object value)
Specifies the
Host header value on the request. |
MockServletRequest |
html()
Convenience method for setting
Accept and Content-Type headers to |
MockServletRequest |
httpSession(javax.servlet.http.HttpSession value)
Fluent setter.
|
MockServletRequest |
ifMatch(Object value)
Specifies the
If-Match header value on the request. |
MockServletRequest |
ifModifiedSince(Object value)
Specifies the
If-Modified-Since header value on the request. |
MockServletRequest |
ifNoneMatch(Object value)
Specifies the
If-None-Match header value on the request. |
MockServletRequest |
ifRange(Object value)
Specifies the
If-Range header value on the request. |
MockServletRequest |
ifUnmodifiedSince(Object value)
Specifies the
If-Unmodified-Since header value on the request. |
boolean |
isAsyncStarted() |
boolean |
isAsyncSupported() |
boolean |
isRequestedSessionIdFromCookie() |
boolean |
isRequestedSessionIdFromUrl() |
boolean |
isRequestedSessionIdFromURL() |
boolean |
isRequestedSessionIdValid() |
boolean |
isSecure() |
boolean |
isUserInRole(String role) |
MockServletRequest |
json()
Convenience method for setting
Accept and Content-Type headers to |
MockServletRequest |
localAddr(String value)
Fluent setter.
|
MockServletRequest |
locale(Locale value)
Fluent setter.
|
MockServletRequest |
localName(String value)
Fluent setter.
|
MockServletRequest |
localPort(int value)
Fluent setter.
|
void |
login(String username,
String password) |
void |
logout() |
MockServletRequest |
maxForwards(Object value)
Specifies the
Max-Forwards header value on the request. |
MockServletRequest |
method(String value)
Fluent setter.
|
MockServletRequest |
msgpack()
Convenience method for setting
Accept and Content-Type headers to |
MockServletRequest |
pathInfo(String value)
Fluent setter.
|
MockServletRequest |
pathTranslated(String value)
Fluent setter.
|
MockServletRequest |
plainText()
Convenience method for setting
Accept and Content-Type headers to |
MockServletRequest |
pragma(Object value)
Specifies the
Pragma header value on the request. |
MockServletRequest |
protocol(String value)
Fluent setter.
|
MockServletRequest |
proxyAuthorization(Object value)
Specifies the
Proxy-Authorization header value on the request. |
MockServletRequest |
query(String key,
Object value)
Adds a query data entry to this request.
|
MockServletRequest |
queryString(String value)
Fluent setter.
|
MockServletRequest |
range(Object value)
Specifies the
Range header value on the request. |
MockServletRequest |
realPath(String value)
Fluent setter.
|
MockServletRequest |
referer(Object value)
Specifies the
Referer header value on the request. |
MockServletRequest |
remoteAddr(String value)
Fluent setter.
|
MockServletRequest |
remoteHost(String value)
Fluent setter.
|
MockServletRequest |
remotePort(int value)
Fluent setter.
|
MockServletRequest |
remoteUser(String value)
Fluent setter.
|
void |
removeAttribute(String name) |
MockServletRequest |
requestDispatcher(javax.servlet.RequestDispatcher value)
Fluent setter.
|
MockServletRequest |
requestedSessionId(String value)
Fluent setter.
|
MockServletRequest |
requestURI(String value)
Fluent setter.
|
MockServletRequest |
restContext(RestContext restContext)
Fluent setter.
|
MockServletRequest |
scheme(String value)
Fluent setter.
|
MockServletRequest |
serverName(String value)
Fluent setter.
|
MockServletRequest |
serverPort(int value)
Fluent setter.
|
MockServletRequest |
servletContext(javax.servlet.ServletContext value)
Fluent setter.
|
MockServletRequest |
servletPath(String value)
Fluent setter.
|
void |
setAttribute(String name,
Object o) |
void |
setCharacterEncoding(String characterEncoding) |
javax.servlet.AsyncContext |
startAsync() |
javax.servlet.AsyncContext |
startAsync(javax.servlet.ServletRequest servletRequest,
javax.servlet.ServletResponse servletResponse) |
MockServletRequest |
te(Object value)
Specifies the
TE header value on the request. |
MockServletRequest |
uon()
Convenience method for setting
Accept and Content-Type headers to |
<T extends javax.servlet.http.HttpUpgradeHandler> |
upgrade(Class<T> handlerClass) |
MockServletRequest |
upgrade(Object value)
Specifies the
Upgrade header value on the request. |
MockServletRequest |
uri(String uri)
Fluent setter.
|
MockServletRequest |
urlEnc()
Convenience method for setting
Accept and Content-Type headers to |
MockServletRequest |
userAgent(Object value)
Specifies the
User-Agent header value on the request. |
MockServletRequest |
userPrincipal(Principal value)
Fluent setter.
|
MockServletRequest |
warning(Object value)
Specifies the
Warning header value on the request. |
MockServletRequest |
xml()
Convenience method for setting
Accept and Content-Type headers to |
MockServletRequest |
yaml()
Convenience method for setting
Accept and Content-Type headers to |
public MockServletRequest()
public static MockServletRequest create()
"Accept: text/json+simple"
"Content-Type: text/json"
public static MockServletRequest create(String method, String path, Object... pathArgs)
"Accept: text/json+simple"
"Content-Type: text/json"
method
- The HTTP method name.path
- The request path.pathArgs
- Optional path arguments.public MockServletRequest json()
Accept
and Content-Type
headers to public MockServletRequest xml()
Accept
and Content-Type
headers to public MockServletRequest html()
Accept
and Content-Type
headers to public MockServletRequest plainText()
Accept
and Content-Type
headers to public MockServletRequest msgpack()
Accept
and Content-Type
headers to public MockServletRequest uon()
Accept
and Content-Type
headers to public MockServletRequest urlEnc()
Accept
and Content-Type
headers to public MockServletRequest yaml()
Accept
and Content-Type
headers to public MockServletRequest uri(String uri)
uri
in interface MockHttpRequest
uri
- The URI of the request.public MockServletRequest restContext(RestContext restContext)
restContext
- The rest context.public MockServletResponse execute() throws Exception
execute
in interface MockHttpRequest
Exception
public MockServletRequest method(String value)
method
in interface MockHttpRequest
value
- The method name for this request.public MockServletRequest characterEncoding(String value)
value
- The character encoding.public MockServletRequest protocol(String value)
value
- The protocol.public MockServletRequest scheme(String value)
value
- The scheme.public MockServletRequest serverName(String value)
value
- The server name.public MockServletRequest serverPort(int value)
value
- The server port.public MockServletRequest remoteAddr(String value)
value
- The remote address.public MockServletRequest remoteHost(String value)
value
- The remote port.public MockServletRequest locale(Locale value)
value
- The locale.public MockServletRequest realPath(String value)
value
- The real path.public MockServletRequest remotePort(int value)
value
- The remote port.public MockServletRequest localName(String value)
value
- The local name.public MockServletRequest localAddr(String value)
value
- The local address.public MockServletRequest localPort(int value)
value
- The local port.public MockServletRequest requestDispatcher(javax.servlet.RequestDispatcher value)
value
- The request dispatcher.public MockServletRequest servletContext(javax.servlet.ServletContext value)
value
- The servlet context.public MockServletRequest dispatcherType(javax.servlet.DispatcherType value)
value
- The dispatcher type.public MockServletRequest authType(String value)
value
- The auth type.public MockServletRequest cookies(javax.servlet.http.Cookie[] value)
value
- The cookies.public MockServletRequest pathInfo(String value)
value
- The path info.public MockServletRequest pathTranslated(String value)
value
- The path translated.public MockServletRequest contextPath(String value)
value
- The context path.public MockServletRequest queryString(String value)
value
- The query string.public MockServletRequest remoteUser(String value)
value
- The remote user.public MockServletRequest userPrincipal(Principal value)
value
- The user principal.public MockServletRequest requestedSessionId(String value)
value
- The requested session ID.public MockServletRequest requestURI(String value)
value
- The request URI.public MockServletRequest servletPath(String value)
value
- The servlet path.public MockServletRequest httpSession(javax.servlet.http.HttpSession value)
value
- The HTTP session.public Object getAttribute(String name)
getAttribute
in interface javax.servlet.ServletRequest
public Enumeration<String> getAttributeNames()
getAttributeNames
in interface javax.servlet.ServletRequest
public String getCharacterEncoding()
getCharacterEncoding
in interface javax.servlet.ServletRequest
public void setCharacterEncoding(String characterEncoding) throws UnsupportedEncodingException
setCharacterEncoding
in interface javax.servlet.ServletRequest
UnsupportedEncodingException
public int getContentLength()
getContentLength
in interface javax.servlet.ServletRequest
public long getContentLengthLong()
getContentLengthLong
in interface javax.servlet.ServletRequest
public String getContentType()
getContentType
in interface javax.servlet.ServletRequest
public javax.servlet.ServletInputStream getInputStream() throws IOException
getInputStream
in interface javax.servlet.ServletRequest
IOException
public String getParameter(String name)
getParameter
in interface javax.servlet.ServletRequest
public Enumeration<String> getParameterNames()
getParameterNames
in interface javax.servlet.ServletRequest
public String[] getParameterValues(String name)
getParameterValues
in interface javax.servlet.ServletRequest
public Map<String,String[]> getParameterMap()
getParameterMap
in interface javax.servlet.ServletRequest
public String getProtocol()
getProtocol
in interface javax.servlet.ServletRequest
public String getScheme()
getScheme
in interface javax.servlet.ServletRequest
public String getServerName()
getServerName
in interface javax.servlet.ServletRequest
public int getServerPort()
getServerPort
in interface javax.servlet.ServletRequest
public BufferedReader getReader() throws IOException
getReader
in interface javax.servlet.ServletRequest
IOException
public String getRemoteAddr()
getRemoteAddr
in interface javax.servlet.ServletRequest
public String getRemoteHost()
getRemoteHost
in interface javax.servlet.ServletRequest
public void setAttribute(String name, Object o)
setAttribute
in interface javax.servlet.ServletRequest
public void removeAttribute(String name)
removeAttribute
in interface javax.servlet.ServletRequest
public Locale getLocale()
getLocale
in interface javax.servlet.ServletRequest
public Enumeration<Locale> getLocales()
getLocales
in interface javax.servlet.ServletRequest
public boolean isSecure()
isSecure
in interface javax.servlet.ServletRequest
public javax.servlet.RequestDispatcher getRequestDispatcher(String path)
getRequestDispatcher
in interface javax.servlet.ServletRequest
public String getRealPath(String path)
getRealPath
in interface javax.servlet.ServletRequest
public int getRemotePort()
getRemotePort
in interface javax.servlet.ServletRequest
public String getLocalName()
getLocalName
in interface javax.servlet.ServletRequest
public String getLocalAddr()
getLocalAddr
in interface javax.servlet.ServletRequest
public int getLocalPort()
getLocalPort
in interface javax.servlet.ServletRequest
public javax.servlet.ServletContext getServletContext()
getServletContext
in interface javax.servlet.ServletRequest
public javax.servlet.AsyncContext startAsync() throws IllegalStateException
startAsync
in interface javax.servlet.ServletRequest
IllegalStateException
public javax.servlet.AsyncContext startAsync(javax.servlet.ServletRequest servletRequest, javax.servlet.ServletResponse servletResponse) throws IllegalStateException
startAsync
in interface javax.servlet.ServletRequest
IllegalStateException
public boolean isAsyncStarted()
isAsyncStarted
in interface javax.servlet.ServletRequest
public boolean isAsyncSupported()
isAsyncSupported
in interface javax.servlet.ServletRequest
public javax.servlet.AsyncContext getAsyncContext()
getAsyncContext
in interface javax.servlet.ServletRequest
public javax.servlet.DispatcherType getDispatcherType()
getDispatcherType
in interface javax.servlet.ServletRequest
public String getAuthType()
getAuthType
in interface javax.servlet.http.HttpServletRequest
public javax.servlet.http.Cookie[] getCookies()
getCookies
in interface javax.servlet.http.HttpServletRequest
public long getDateHeader(String name)
getDateHeader
in interface javax.servlet.http.HttpServletRequest
public String getHeader(String name)
getHeader
in interface javax.servlet.http.HttpServletRequest
public Enumeration<String> getHeaders(String name)
getHeaders
in interface javax.servlet.http.HttpServletRequest
public Enumeration<String> getHeaderNames()
getHeaderNames
in interface javax.servlet.http.HttpServletRequest
public int getIntHeader(String name)
getIntHeader
in interface javax.servlet.http.HttpServletRequest
public String getMethod()
getMethod
in interface javax.servlet.http.HttpServletRequest
public String getPathInfo()
getPathInfo
in interface javax.servlet.http.HttpServletRequest
public String getPathTranslated()
getPathTranslated
in interface javax.servlet.http.HttpServletRequest
public String getContextPath()
getContextPath
in interface javax.servlet.http.HttpServletRequest
public String getQueryString()
getQueryString
in interface javax.servlet.http.HttpServletRequest
public String getRemoteUser()
getRemoteUser
in interface javax.servlet.http.HttpServletRequest
public boolean isUserInRole(String role)
isUserInRole
in interface javax.servlet.http.HttpServletRequest
public Principal getUserPrincipal()
getUserPrincipal
in interface javax.servlet.http.HttpServletRequest
public String getRequestedSessionId()
getRequestedSessionId
in interface javax.servlet.http.HttpServletRequest
public String getRequestURI()
getRequestURI
in interface javax.servlet.http.HttpServletRequest
public StringBuffer getRequestURL()
getRequestURL
in interface javax.servlet.http.HttpServletRequest
public String getServletPath()
getServletPath
in interface javax.servlet.http.HttpServletRequest
public javax.servlet.http.HttpSession getSession(boolean create)
getSession
in interface javax.servlet.http.HttpServletRequest
public javax.servlet.http.HttpSession getSession()
getSession
in interface javax.servlet.http.HttpServletRequest
public String changeSessionId()
changeSessionId
in interface javax.servlet.http.HttpServletRequest
public boolean isRequestedSessionIdValid()
isRequestedSessionIdValid
in interface javax.servlet.http.HttpServletRequest
public boolean isRequestedSessionIdFromCookie()
isRequestedSessionIdFromCookie
in interface javax.servlet.http.HttpServletRequest
public boolean isRequestedSessionIdFromURL()
isRequestedSessionIdFromURL
in interface javax.servlet.http.HttpServletRequest
public boolean isRequestedSessionIdFromUrl()
isRequestedSessionIdFromUrl
in interface javax.servlet.http.HttpServletRequest
public boolean authenticate(javax.servlet.http.HttpServletResponse response) throws IOException, javax.servlet.ServletException
authenticate
in interface javax.servlet.http.HttpServletRequest
IOException
javax.servlet.ServletException
public void login(String username, String password) throws javax.servlet.ServletException
login
in interface javax.servlet.http.HttpServletRequest
javax.servlet.ServletException
public void logout() throws javax.servlet.ServletException
logout
in interface javax.servlet.http.HttpServletRequest
javax.servlet.ServletException
public Collection<javax.servlet.http.Part> getParts() throws IOException, javax.servlet.ServletException
getParts
in interface javax.servlet.http.HttpServletRequest
IOException
javax.servlet.ServletException
public javax.servlet.http.Part getPart(String name) throws IOException, javax.servlet.ServletException
getPart
in interface javax.servlet.http.HttpServletRequest
IOException
javax.servlet.ServletException
public <T extends javax.servlet.http.HttpUpgradeHandler> T upgrade(Class<T> handlerClass) throws IOException, javax.servlet.ServletException
upgrade
in interface javax.servlet.http.HttpServletRequest
IOException
javax.servlet.ServletException
public MockServletRequest header(String name, Object value)
header
in interface MockHttpRequest
name
- Header name.value
- Header value.
Object.toString()
.public MockServletRequest attribute(String name, Object value)
name
- Request attribute name.value
- Request attribute value.public MockServletRequest body(Object value)
body
in interface MockHttpRequest
value
- The body of the request.
byte []
Reader
InputStream
CharSequence
public MockServletRequest formData(String key, Object value)
key
- The form data key.value
- The form data value.
Object.toString()
.public MockServletRequest query(String key, Object value)
key
- The query key.value
- The query value.
Object.toString()
.public MockServletRequest accept(Object value)
Accept
header value on the request.value
- The new value.public MockServletRequest acceptCharset(Object value)
Accept-Charset
header value on the request.value
- The new value.public MockServletRequest acceptEncoding(Object value)
Accept-Encoding
header value on the request.value
- The new value.public MockServletRequest acceptLanguage(Object value)
Accept-Language
header value on the request.value
- The new value.public MockServletRequest authorization(Object value)
Authorization
header value on the request.value
- The new value for the header.public MockServletRequest cacheControl(Object value)
Cache-Control
header value on the request.value
- The new value for the header.public MockServletRequest clientVersion(Object value)
X-Client-Version
header value on the request.value
- The new value.public MockServletRequest connection(Object value)
Connection
header value on the request.value
- The new value for the header.public MockServletRequest contentEncoding(Object value)
Content-Encoding
header value on the request.value
- The new value.public MockServletRequest contentLength(Object value)
Content-Length
header value on the request.value
- The new value for the header.public MockServletRequest contentType(Object value)
Content-Type
header value on the request.value
- The new value.public MockServletRequest date(Object value)
Date
header value on the request.value
- The new value for the header.public MockServletRequest expect(Object value)
Expect
header value on the request.value
- The new value for the header.public MockServletRequest from(Object value)
From
header value on the request.value
- The new value for the header.public MockServletRequest host(Object value)
Host
header value on the request.value
- The new value for the header.public MockServletRequest ifMatch(Object value)
If-Match
header value on the request.value
- The new value for the header.public MockServletRequest ifModifiedSince(Object value)
If-Modified-Since
header value on the request.value
- The new value for the header.public MockServletRequest ifNoneMatch(Object value)
If-None-Match
header value on the request.value
- The new value for the header.public MockServletRequest ifRange(Object value)
If-Range
header value on the request.value
- The new value for the header.public MockServletRequest ifUnmodifiedSince(Object value)
If-Unmodified-Since
header value on the request.value
- The new value for the header.public MockServletRequest maxForwards(Object value)
Max-Forwards
header value on the request.value
- The new value for the header.public MockServletRequest pragma(Object value)
Pragma
header value on the request.value
- The new value for the header.public MockServletRequest proxyAuthorization(Object value)
Proxy-Authorization
header value on the request.value
- The new value for the header.public MockServletRequest range(Object value)
Range
header value on the request.value
- The new value for the header.public MockServletRequest referer(Object value)
Referer
header value on the request.value
- The new value for the header.public MockServletRequest te(Object value)
TE
header value on the request.value
- The new value for the header.public MockServletRequest upgrade(Object value)
Upgrade
header value on the request.value
- The new value for the header.public MockServletRequest userAgent(Object value)
User-Agent
header value on the request.value
- The new value for the header.public MockServletRequest warning(Object value)
Warning
header value on the request.value
- The new value for the header.public MockServletRequest debug()
Causes information about the request execution to be sent to STDERR.
Copyright © 2018 Apache. All rights reserved.