public class MockServletRequest extends Object implements HttpServletRequest
HttpServletRequest
for mocking purposes.
BASIC_AUTH, CLIENT_CERT_AUTH, DIGEST_AUTH, FORM_AUTH
Constructor and Description |
---|
MockServletRequest() |
public MockServletRequest()
public static MockServletRequest create()
public static MockServletRequest create(String method, String uri, Object... pathArgs)
method
- The HTTP method name.uri
- The request path.pathArgs
- Optional path arguments.public MockServletRequest uri(String uri)
uri
- The URI of the request.public MockServletRequest roles(String... roles)
roles
- The roles to add to this request (e.g. public MockServletRequest pathVars(Map<String,String> pathVars)
See MockRestClientBuilder.pathVars(Map)
for an example.
pathVars
- TheMockRestClientBuilder.pathVars(Map)
public MockServletRequest pathVars(String... pairs)
Identical to pathVars(Map)
but allows you to specify as a list of key/value pairs.
pairs
- The key/value pairs. Must be an even number of parameters.public MockServletRequest role(String role)
role
- The role to add to this request (e.g. public MockServletRequest method(String value)
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 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(String name, RequestDispatcher value)
name
- The path to resolve.value
- The request dispatcher.public MockServletRequest servletContext(ServletContext value)
value
- The servlet context.public MockServletRequest dispatcherType(DispatcherType value)
value
- The dispatcher type.public MockServletRequest authType(String value)
value
- The auth type.public MockServletRequest cookies(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(HttpSession value)
value
- The HTTP session.public Object getAttribute(String name)
getAttribute
in interface ServletRequest
public Enumeration<String> getAttributeNames()
getAttributeNames
in interface ServletRequest
public String getCharacterEncoding()
getCharacterEncoding
in interface ServletRequest
public void setCharacterEncoding(String characterEncoding) throws UnsupportedEncodingException
setCharacterEncoding
in interface ServletRequest
UnsupportedEncodingException
public int getContentLength()
getContentLength
in interface ServletRequest
public long getContentLengthLong()
getContentLengthLong
in interface ServletRequest
public String getContentType()
getContentType
in interface ServletRequest
public ServletInputStream getInputStream() throws IOException
getInputStream
in interface ServletRequest
IOException
public String getParameter(String name)
getParameter
in interface ServletRequest
public Enumeration<String> getParameterNames()
getParameterNames
in interface ServletRequest
public String[] getParameterValues(String name)
getParameterValues
in interface ServletRequest
public Map<String,String[]> getParameterMap()
getParameterMap
in interface ServletRequest
public String getProtocol()
getProtocol
in interface ServletRequest
public String getScheme()
getScheme
in interface ServletRequest
public String getServerName()
getServerName
in interface ServletRequest
public int getServerPort()
getServerPort
in interface ServletRequest
public BufferedReader getReader() throws IOException
getReader
in interface ServletRequest
IOException
public String getRemoteAddr()
getRemoteAddr
in interface ServletRequest
public String getRemoteHost()
getRemoteHost
in interface ServletRequest
public void setAttribute(String name, Object o)
setAttribute
in interface ServletRequest
public void removeAttribute(String name)
removeAttribute
in interface ServletRequest
public Locale getLocale()
getLocale
in interface ServletRequest
public Enumeration<Locale> getLocales()
getLocales
in interface ServletRequest
public boolean isSecure()
isSecure
in interface ServletRequest
public RequestDispatcher getRequestDispatcher(String path)
getRequestDispatcher
in interface ServletRequest
public String getRealPath(String path)
getRealPath
in interface ServletRequest
public int getRemotePort()
getRemotePort
in interface ServletRequest
public String getLocalName()
getLocalName
in interface ServletRequest
public String getLocalAddr()
getLocalAddr
in interface ServletRequest
public int getLocalPort()
getLocalPort
in interface ServletRequest
public ServletContext getServletContext()
getServletContext
in interface ServletRequest
public AsyncContext startAsync() throws IllegalStateException
startAsync
in interface ServletRequest
IllegalStateException
public AsyncContext startAsync(ServletRequest servletRequest, ServletResponse servletResponse) throws IllegalStateException
startAsync
in interface ServletRequest
IllegalStateException
public boolean isAsyncStarted()
isAsyncStarted
in interface ServletRequest
public boolean isAsyncSupported()
isAsyncSupported
in interface ServletRequest
public AsyncContext getAsyncContext()
getAsyncContext
in interface ServletRequest
public DispatcherType getDispatcherType()
getDispatcherType
in interface ServletRequest
public String getAuthType()
getAuthType
in interface HttpServletRequest
public Cookie[] getCookies()
getCookies
in interface HttpServletRequest
public long getDateHeader(String name)
getDateHeader
in interface HttpServletRequest
public String getHeader(String name)
getHeader
in interface HttpServletRequest
public Enumeration<String> getHeaders(String name)
getHeaders
in interface HttpServletRequest
public Enumeration<String> getHeaderNames()
getHeaderNames
in interface HttpServletRequest
public int getIntHeader(String name)
getIntHeader
in interface HttpServletRequest
public String getMethod()
getMethod
in interface HttpServletRequest
public String getPathInfo()
getPathInfo
in interface HttpServletRequest
public String getPathTranslated()
getPathTranslated
in interface HttpServletRequest
public String getContextPath()
getContextPath
in interface HttpServletRequest
public String getQueryString()
getQueryString
in interface HttpServletRequest
public String getRemoteUser()
getRemoteUser
in interface HttpServletRequest
public boolean isUserInRole(String role)
isUserInRole
in interface HttpServletRequest
public Principal getUserPrincipal()
getUserPrincipal
in interface HttpServletRequest
public String getRequestedSessionId()
getRequestedSessionId
in interface HttpServletRequest
public String getRequestURI()
getRequestURI
in interface HttpServletRequest
public StringBuffer getRequestURL()
getRequestURL
in interface HttpServletRequest
public String getServletPath()
getServletPath
in interface HttpServletRequest
public HttpSession getSession(boolean create)
getSession
in interface HttpServletRequest
public HttpSession getSession()
getSession
in interface HttpServletRequest
public String changeSessionId()
changeSessionId
in interface HttpServletRequest
public boolean isRequestedSessionIdValid()
isRequestedSessionIdValid
in interface HttpServletRequest
public boolean isRequestedSessionIdFromCookie()
isRequestedSessionIdFromCookie
in interface HttpServletRequest
public boolean isRequestedSessionIdFromURL()
isRequestedSessionIdFromURL
in interface HttpServletRequest
public boolean isRequestedSessionIdFromUrl()
isRequestedSessionIdFromUrl
in interface HttpServletRequest
public boolean authenticate(HttpServletResponse response) throws IOException, ServletException
authenticate
in interface HttpServletRequest
IOException
ServletException
public void login(String username, String password) throws ServletException
login
in interface HttpServletRequest
ServletException
public void logout() throws ServletException
logout
in interface HttpServletRequest
ServletException
public Collection<Part> getParts() throws IOException, ServletException
getParts
in interface HttpServletRequest
IOException
ServletException
public Part getPart(String name) throws IOException, ServletException
getPart
in interface HttpServletRequest
IOException
ServletException
public <T extends HttpUpgradeHandler> T upgrade(Class<T> handlerClass) throws IOException, ServletException
upgrade
in interface HttpServletRequest
IOException
ServletException
public MockServletRequest header(String name, Object value)
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)
value
- The body of the request.
byte []
Reader
InputStream
CharSequence
protected MockServletRequest debug(boolean value)
Causes information about the request execution to be sent to STDERR.
value
- The enable flag value.public MockServletRequest noTrace(boolean value)
Prevents errors from being logged on the server side if no-trace per-request is enabled.
value
- The enable flag value.public MockServletRequest applyOverrides(HttpRequest req)
MockRestRequest
, applies any of the override values to this servlet request.req
- The request to copy overrides from.Copyright © 2016–2020 The Apache Software Foundation. All rights reserved.