Package org.apache.juneau.rest.mock
Class MockServletRequest
java.lang.Object
org.apache.juneau.rest.mock.MockServletRequest
- All Implemented Interfaces:
jakarta.servlet.http.HttpServletRequest
,jakarta.servlet.ServletRequest
-
Field Summary
Fields inherited from interface jakarta.servlet.http.HttpServletRequest
BASIC_AUTH, CLIENT_CERT_AUTH, DIGEST_AUTH, FORM_AUTH
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionIf the specified request is aMockRestRequest
, applies any of the override values to this servlet request.Fluent setter.boolean
authenticate
(jakarta.servlet.http.HttpServletResponse response) Fluent setter.characterEncoding
(String value) Fluent setter.Fluent setter.contextPath
(String value) Fluent setter.cookies
(jakarta.servlet.http.Cookie[] value) Fluent setter.static MockServletRequest
create()
Creates a new servlet request.static MockServletRequest
Creates a new servlet request with the specified method name and request path.protected MockServletRequest
debug
(boolean value) Enabled debug mode on this request.dispatcherType
(jakarta.servlet.DispatcherType value) Fluent setter.jakarta.servlet.AsyncContext
getAttribute
(String name) int
long
jakarta.servlet.http.Cookie[]
long
getDateHeader
(String name) jakarta.servlet.DispatcherType
getHeaders
(String name) jakarta.servlet.ServletInputStream
int
getIntHeader
(String name) int
getParameter
(String name) String[]
getParameterValues
(String name) jakarta.servlet.http.Part
Collection<jakarta.servlet.http.Part>
getParts()
int
jakarta.servlet.RequestDispatcher
getRequestDispatcher
(String path) int
jakarta.servlet.ServletConnection
jakarta.servlet.ServletContext
jakarta.servlet.http.HttpSession
jakarta.servlet.http.HttpSession
getSession
(boolean create) Fluent setter.httpSession
(jakarta.servlet.http.HttpSession value) Fluent setter.boolean
boolean
boolean
boolean
boolean
boolean
isSecure()
boolean
isUserInRole
(String role) Fluent setter.Fluent setter.Fluent setter.localPort
(int value) Fluent setter.void
void
logout()
Fluent setter.noTrace
(boolean value) Enabled debug mode on this request.Fluent setter.pathTranslated
(String value) Fluent setter.Add resolved path variables to this client.Adds the specified parent path variables to this servlet request.Fluent setter.queryString
(String value) Fluent setter.remoteAddr
(String value) Fluent setter.remoteHost
(String value) Fluent setter.remotePort
(int value) Fluent setter.remoteUser
(String value) Fluent setter.void
removeAttribute
(String name) requestDispatcher
(String name, jakarta.servlet.RequestDispatcher value) Fluent setter.requestedSessionId
(String value) Fluent setter.requestURI
(String value) Fluent setter.Adds the specified role on this request.Adds the specified roles on this request.Fluent setter.serverName
(String value) Fluent setter.serverPort
(int value) Fluent setter.servletContext
(jakarta.servlet.ServletContext value) Fluent setter.servletPath
(String value) Fluent setter.void
setAttribute
(String name, Object o) void
setCharacterEncoding
(String characterEncoding) jakarta.servlet.AsyncContext
jakarta.servlet.AsyncContext
startAsync
(jakarta.servlet.ServletRequest servletRequest, jakarta.servlet.ServletResponse servletResponse) <T extends jakarta.servlet.http.HttpUpgradeHandler>
TFluent setter.userPrincipal
(Principal value) Fluent setter.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface jakarta.servlet.http.HttpServletRequest
getHttpServletMapping, getTrailerFields, isTrailerFieldsReady, newPushBuilder
-
Constructor Details
-
MockServletRequest
public MockServletRequest()
-
-
Method Details
-
create
Creates a new servlet request. Initialized with the following:"Accept: text/json5" "Content-Type: text/json"
- Returns:
- A new request.
-
create
Creates a new servlet request with the specified method name and request path. Initialized with the following:"Accept: text/json5" "Content-Type: text/json"
- Parameters:
method
- The HTTP method name.uri
- The request path.pathArgs
- Optional path arguments.- Returns:
- A new request.
-
uri
Fluent setter.- Parameters:
uri
- The URI of the request.- Returns:
- This object.
-
roles
Adds the specified roles on this request.- Parameters:
roles
- The roles to add to this request (e.g."ROLE_ADMIN" ).- Returns:
- This object.
-
pathVars
Adds the specified parent path variables to this servlet request.See
MockRestClient.Builder.pathVars(Map)
for an example.- Parameters:
pathVars
- The- Returns:
- This object.
- See Also:
-
pathVars
Add resolved path variables to this client.Identical to
pathVars(Map)
but allows you to specify as a list of key/value pairs.- Parameters:
pairs
- The key/value pairs. Must be an even number of parameters.- Returns:
- This object.
-
role
Adds the specified role on this request.- Parameters:
role
- The role to add to this request (e.g."ROLE_ADMIN" ).- Returns:
- This object.
-
method
Fluent setter.- Parameters:
value
- The method name for this request.- Returns:
- This object.
-
characterEncoding
Fluent setter.- Parameters:
value
- The character encoding.- Returns:
- This object.
-
protocol
Fluent setter.- Parameters:
value
- The protocol.- Returns:
- This object.
-
scheme
Fluent setter.- Parameters:
value
- The scheme.- Returns:
- This object.
-
serverName
Fluent setter.- Parameters:
value
- The server name.- Returns:
- This object.
-
serverPort
Fluent setter.- Parameters:
value
- The server port.- Returns:
- This object.
-
remoteAddr
Fluent setter.- Parameters:
value
- The remote address.- Returns:
- This object.
-
remoteHost
Fluent setter.- Parameters:
value
- The remote port.- Returns:
- This object.
-
locale
Fluent setter.- Parameters:
value
- The locale.- Returns:
- This object.
-
remotePort
Fluent setter.- Parameters:
value
- The remote port.- Returns:
- This object.
-
localName
Fluent setter.- Parameters:
value
- The local name.- Returns:
- This object.
-
localAddr
Fluent setter.- Parameters:
value
- The local address.- Returns:
- This object.
-
localPort
Fluent setter.- Parameters:
value
- The local port.- Returns:
- This object.
-
requestDispatcher
Fluent setter.- Parameters:
name
- The path to resolve.value
- The request dispatcher.- Returns:
- This object.
-
servletContext
Fluent setter.- Parameters:
value
- The servlet context.- Returns:
- This object.
-
dispatcherType
Fluent setter.- Parameters:
value
- The dispatcher type.- Returns:
- This object.
-
authType
Fluent setter.- Parameters:
value
- The auth type.- Returns:
- This object.
-
cookies
Fluent setter.- Parameters:
value
- The cookies.- Returns:
- This object.
-
pathInfo
Fluent setter.- Parameters:
value
- The path info.- Returns:
- This object.
-
pathTranslated
Fluent setter.- Parameters:
value
- The path translated.- Returns:
- This object.
-
contextPath
Fluent setter.- Parameters:
value
- The context path.- Returns:
- This object.
-
queryString
Fluent setter.- Parameters:
value
- The query string.- Returns:
- This object.
-
remoteUser
Fluent setter.- Parameters:
value
- The remote user.- Returns:
- This object.
-
userPrincipal
Fluent setter.- Parameters:
value
- The user principal.- Returns:
- This object.
-
requestedSessionId
Fluent setter.- Parameters:
value
- The requested session ID.- Returns:
- This object.
-
requestURI
Fluent setter.- Parameters:
value
- The request URI.- Returns:
- This object.
-
servletPath
Fluent setter.- Parameters:
value
- The servlet path.- Returns:
- This object.
-
httpSession
Fluent setter.- Parameters:
value
- The HTTP session.- Returns:
- This object.
-
getAttribute
- Specified by:
getAttribute
in interfacejakarta.servlet.ServletRequest
-
getAttributeNames
- Specified by:
getAttributeNames
in interfacejakarta.servlet.ServletRequest
-
getCharacterEncoding
- Specified by:
getCharacterEncoding
in interfacejakarta.servlet.ServletRequest
-
setCharacterEncoding
- Specified by:
setCharacterEncoding
in interfacejakarta.servlet.ServletRequest
- Throws:
UnsupportedEncodingException
-
getContentLength
- Specified by:
getContentLength
in interfacejakarta.servlet.ServletRequest
-
getContentLengthLong
- Specified by:
getContentLengthLong
in interfacejakarta.servlet.ServletRequest
-
getContentType
- Specified by:
getContentType
in interfacejakarta.servlet.ServletRequest
-
getInputStream
- Specified by:
getInputStream
in interfacejakarta.servlet.ServletRequest
- Throws:
IOException
-
getParameter
- Specified by:
getParameter
in interfacejakarta.servlet.ServletRequest
-
getParameterNames
- Specified by:
getParameterNames
in interfacejakarta.servlet.ServletRequest
-
getParameterValues
- Specified by:
getParameterValues
in interfacejakarta.servlet.ServletRequest
-
getParameterMap
- Specified by:
getParameterMap
in interfacejakarta.servlet.ServletRequest
-
getProtocol
- Specified by:
getProtocol
in interfacejakarta.servlet.ServletRequest
-
getScheme
- Specified by:
getScheme
in interfacejakarta.servlet.ServletRequest
-
getServerName
- Specified by:
getServerName
in interfacejakarta.servlet.ServletRequest
-
getServerPort
- Specified by:
getServerPort
in interfacejakarta.servlet.ServletRequest
-
getReader
- Specified by:
getReader
in interfacejakarta.servlet.ServletRequest
- Throws:
IOException
-
getRemoteAddr
- Specified by:
getRemoteAddr
in interfacejakarta.servlet.ServletRequest
-
getRemoteHost
- Specified by:
getRemoteHost
in interfacejakarta.servlet.ServletRequest
-
setAttribute
- Specified by:
setAttribute
in interfacejakarta.servlet.ServletRequest
-
removeAttribute
- Specified by:
removeAttribute
in interfacejakarta.servlet.ServletRequest
-
getLocale
- Specified by:
getLocale
in interfacejakarta.servlet.ServletRequest
-
getLocales
- Specified by:
getLocales
in interfacejakarta.servlet.ServletRequest
-
isSecure
- Specified by:
isSecure
in interfacejakarta.servlet.ServletRequest
-
getRequestDispatcher
- Specified by:
getRequestDispatcher
in interfacejakarta.servlet.ServletRequest
-
getRemotePort
- Specified by:
getRemotePort
in interfacejakarta.servlet.ServletRequest
-
getLocalName
- Specified by:
getLocalName
in interfacejakarta.servlet.ServletRequest
-
getLocalAddr
- Specified by:
getLocalAddr
in interfacejakarta.servlet.ServletRequest
-
getLocalPort
- Specified by:
getLocalPort
in interfacejakarta.servlet.ServletRequest
-
getServletContext
- Specified by:
getServletContext
in interfacejakarta.servlet.ServletRequest
-
startAsync
- Specified by:
startAsync
in interfacejakarta.servlet.ServletRequest
- Throws:
IllegalStateException
-
startAsync
public jakarta.servlet.AsyncContext startAsync(jakarta.servlet.ServletRequest servletRequest, jakarta.servlet.ServletResponse servletResponse) throws IllegalStateException - Specified by:
startAsync
in interfacejakarta.servlet.ServletRequest
- Throws:
IllegalStateException
-
isAsyncStarted
- Specified by:
isAsyncStarted
in interfacejakarta.servlet.ServletRequest
-
isAsyncSupported
- Specified by:
isAsyncSupported
in interfacejakarta.servlet.ServletRequest
-
getAsyncContext
- Specified by:
getAsyncContext
in interfacejakarta.servlet.ServletRequest
-
getDispatcherType
- Specified by:
getDispatcherType
in interfacejakarta.servlet.ServletRequest
-
getAuthType
- Specified by:
getAuthType
in interfacejakarta.servlet.http.HttpServletRequest
-
getCookies
- Specified by:
getCookies
in interfacejakarta.servlet.http.HttpServletRequest
-
getDateHeader
- Specified by:
getDateHeader
in interfacejakarta.servlet.http.HttpServletRequest
-
getHeader
- Specified by:
getHeader
in interfacejakarta.servlet.http.HttpServletRequest
-
getHeaders
- Specified by:
getHeaders
in interfacejakarta.servlet.http.HttpServletRequest
-
getHeaderNames
- Specified by:
getHeaderNames
in interfacejakarta.servlet.http.HttpServletRequest
-
getIntHeader
- Specified by:
getIntHeader
in interfacejakarta.servlet.http.HttpServletRequest
-
getMethod
- Specified by:
getMethod
in interfacejakarta.servlet.http.HttpServletRequest
-
getPathInfo
- Specified by:
getPathInfo
in interfacejakarta.servlet.http.HttpServletRequest
-
getPathTranslated
- Specified by:
getPathTranslated
in interfacejakarta.servlet.http.HttpServletRequest
-
getContextPath
- Specified by:
getContextPath
in interfacejakarta.servlet.http.HttpServletRequest
-
getQueryString
- Specified by:
getQueryString
in interfacejakarta.servlet.http.HttpServletRequest
-
getRemoteUser
- Specified by:
getRemoteUser
in interfacejakarta.servlet.http.HttpServletRequest
-
isUserInRole
- Specified by:
isUserInRole
in interfacejakarta.servlet.http.HttpServletRequest
-
getUserPrincipal
- Specified by:
getUserPrincipal
in interfacejakarta.servlet.http.HttpServletRequest
-
getRequestedSessionId
- Specified by:
getRequestedSessionId
in interfacejakarta.servlet.http.HttpServletRequest
-
getRequestURI
- Specified by:
getRequestURI
in interfacejakarta.servlet.http.HttpServletRequest
-
getRequestURL
- Specified by:
getRequestURL
in interfacejakarta.servlet.http.HttpServletRequest
-
getServletPath
- Specified by:
getServletPath
in interfacejakarta.servlet.http.HttpServletRequest
-
getSession
- Specified by:
getSession
in interfacejakarta.servlet.http.HttpServletRequest
-
getSession
- Specified by:
getSession
in interfacejakarta.servlet.http.HttpServletRequest
-
changeSessionId
- Specified by:
changeSessionId
in interfacejakarta.servlet.http.HttpServletRequest
-
isRequestedSessionIdValid
- Specified by:
isRequestedSessionIdValid
in interfacejakarta.servlet.http.HttpServletRequest
-
isRequestedSessionIdFromCookie
- Specified by:
isRequestedSessionIdFromCookie
in interfacejakarta.servlet.http.HttpServletRequest
-
isRequestedSessionIdFromURL
- Specified by:
isRequestedSessionIdFromURL
in interfacejakarta.servlet.http.HttpServletRequest
-
authenticate
public boolean authenticate(jakarta.servlet.http.HttpServletResponse response) throws IOException, jakarta.servlet.ServletException - Specified by:
authenticate
in interfacejakarta.servlet.http.HttpServletRequest
- Throws:
IOException
jakarta.servlet.ServletException
-
login
- Specified by:
login
in interfacejakarta.servlet.http.HttpServletRequest
- Throws:
jakarta.servlet.ServletException
-
logout
- Specified by:
logout
in interfacejakarta.servlet.http.HttpServletRequest
- Throws:
jakarta.servlet.ServletException
-
getParts
public Collection<jakarta.servlet.http.Part> getParts() throws IOException, jakarta.servlet.ServletException- Specified by:
getParts
in interfacejakarta.servlet.http.HttpServletRequest
- Throws:
IOException
jakarta.servlet.ServletException
-
getPart
public jakarta.servlet.http.Part getPart(String name) throws IOException, jakarta.servlet.ServletException - Specified by:
getPart
in interfacejakarta.servlet.http.HttpServletRequest
- Throws:
IOException
jakarta.servlet.ServletException
-
upgrade
public <T extends jakarta.servlet.http.HttpUpgradeHandler> T upgrade(Class<T> handlerClass) throws IOException, jakarta.servlet.ServletException - Specified by:
upgrade
in interfacejakarta.servlet.http.HttpServletRequest
- Throws:
IOException
jakarta.servlet.ServletException
-
header
Fluent setter.- Parameters:
name
- Header name.value
- Header value.
The value is converted to a simple string usingObject.toString()
.- Returns:
- This object.
-
attribute
Fluent setter.- Parameters:
name
- Request attribute name.value
- Request attribute value.- Returns:
- This object.
-
content
Fluent setter.- Parameters:
value
- The body of the request.
Can be any of the following data types:byte []Reader
InputStream
CharSequence
toString() method.- Returns:
- This object.
-
debug
Enabled debug mode on this request.Causes information about the request execution to be sent to STDERR.
- Parameters:
value
- The enable flag value.- Returns:
- This object.
-
noTrace
Enabled debug mode on this request.Prevents errors from being logged on the server side if no-trace per-request is enabled.
- Parameters:
value
- The enable flag value.- Returns:
- This object.
-
applyOverrides
If the specified request is aMockRestRequest
, applies any of the override values to this servlet request.- Parameters:
req
- The request to copy overrides from.- Returns:
- This object.
-
getRequestId
- Specified by:
getRequestId
in interfacejakarta.servlet.ServletRequest
-
getProtocolRequestId
- Specified by:
getProtocolRequestId
in interfacejakarta.servlet.ServletRequest
-
getServletConnection
- Specified by:
getServletConnection
in interfacejakarta.servlet.ServletRequest
-