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
A mutable implementation of 
HttpServletRequest for mocking purposes.
 See Also:
- 
Field SummaryFields inherited from interface jakarta.servlet.http.HttpServletRequestBASIC_AUTH, CLIENT_CERT_AUTH, DIGEST_AUTH, FORM_AUTH
- 
Constructor SummaryConstructors
- 
Method SummaryModifier and TypeMethodDescriptionIf the specified request is aMockRestRequest, applies any of the override values to this servlet request.Fluent setter.booleanauthenticate(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 MockServletRequestcreate()Creates a new servlet request.static MockServletRequestCreates a new servlet request with the specified method name and request path.protected MockServletRequestdebug(boolean value) Enabled debug mode on this request.dispatcherType(jakarta.servlet.DispatcherType value) Fluent setter.jakarta.servlet.AsyncContextgetAttribute(String name) intlongjakarta.servlet.http.Cookie[]longgetDateHeader(String name) jakarta.servlet.DispatcherTypegetHeaders(String name) jakarta.servlet.ServletInputStreamintgetIntHeader(String name) intgetParameter(String name) String[]getParameterValues(String name) jakarta.servlet.http.PartCollection<jakarta.servlet.http.Part>getParts()intjakarta.servlet.RequestDispatchergetRequestDispatcher(String path) intjakarta.servlet.ServletConnectionjakarta.servlet.ServletContextjakarta.servlet.http.HttpSessionjakarta.servlet.http.HttpSessiongetSession(boolean create) Fluent setter.httpSession(jakarta.servlet.http.HttpSession value) Fluent setter.booleanbooleanbooleanbooleanbooleanbooleanisSecure()booleanisUserInRole(String role) Fluent setter.Fluent setter.Fluent setter.localPort(int value) Fluent setter.voidvoidlogout()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.voidremoveAttribute(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.voidsetAttribute(String name, Object o) voidsetCharacterEncoding(String characterEncoding) jakarta.servlet.AsyncContextjakarta.servlet.AsyncContextstartAsync(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.Objectclone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface jakarta.servlet.http.HttpServletRequestgetHttpServletMapping, getTrailerFields, isTrailerFieldsReady, newPushBuilderMethods inherited from interface jakarta.servlet.ServletRequestsetCharacterEncoding
- 
Constructor Details- 
MockServletRequestpublic MockServletRequest()
 
- 
- 
Method Details- 
createCreates a new servlet request. Initialized with the following:- "Accept: text/json5" 
- "Content-Type: text/json" 
 - Returns:
- A new request.
 
- 
createCreates 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.
 
- 
uriFluent setter.- Parameters:
- uri- The URI of the request.
- Returns:
- This object.
 
- 
rolesAdds the specified roles on this request.- Parameters:
- roles- The roles to add to this request (e.g.- "ROLE_ADMIN" ).
- Returns:
- This object.
 
- 
pathVarsAdds 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:
 
- 
pathVarsAdd 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.
 
- 
roleAdds the specified role on this request.- Parameters:
- role- The role to add to this request (e.g.- "ROLE_ADMIN" ).
- Returns:
- This object.
 
- 
methodFluent setter.- Parameters:
- value- The method name for this request.
- Returns:
- This object.
 
- 
characterEncodingFluent setter.- Parameters:
- value- The character encoding.
- Returns:
- This object.
 
- 
protocolFluent setter.- Parameters:
- value- The protocol.
- Returns:
- This object.
 
- 
schemeFluent setter.- Parameters:
- value- The scheme.
- Returns:
- This object.
 
- 
serverNameFluent setter.- Parameters:
- value- The server name.
- Returns:
- This object.
 
- 
serverPortFluent setter.- Parameters:
- value- The server port.
- Returns:
- This object.
 
- 
remoteAddrFluent setter.- Parameters:
- value- The remote address.
- Returns:
- This object.
 
- 
remoteHostFluent setter.- Parameters:
- value- The remote port.
- Returns:
- This object.
 
- 
localeFluent setter.- Parameters:
- value- The locale.
- Returns:
- This object.
 
- 
remotePortFluent setter.- Parameters:
- value- The remote port.
- Returns:
- This object.
 
- 
localNameFluent setter.- Parameters:
- value- The local name.
- Returns:
- This object.
 
- 
localAddrFluent setter.- Parameters:
- value- The local address.
- Returns:
- This object.
 
- 
localPortFluent setter.- Parameters:
- value- The local port.
- Returns:
- This object.
 
- 
requestDispatcherFluent setter.- Parameters:
- name- The path to resolve.
- value- The request dispatcher.
- Returns:
- This object.
 
- 
servletContextFluent setter.- Parameters:
- value- The servlet context.
- Returns:
- This object.
 
- 
dispatcherTypeFluent setter.- Parameters:
- value- The dispatcher type.
- Returns:
- This object.
 
- 
authTypeFluent setter.- Parameters:
- value- The auth type.
- Returns:
- This object.
 
- 
cookiesFluent setter.- Parameters:
- value- The cookies.
- Returns:
- This object.
 
- 
pathInfoFluent setter.- Parameters:
- value- The path info.
- Returns:
- This object.
 
- 
pathTranslatedFluent setter.- Parameters:
- value- The path translated.
- Returns:
- This object.
 
- 
contextPathFluent setter.- Parameters:
- value- The context path.
- Returns:
- This object.
 
- 
queryStringFluent setter.- Parameters:
- value- The query string.
- Returns:
- This object.
 
- 
remoteUserFluent setter.- Parameters:
- value- The remote user.
- Returns:
- This object.
 
- 
userPrincipalFluent setter.- Parameters:
- value- The user principal.
- Returns:
- This object.
 
- 
requestedSessionIdFluent setter.- Parameters:
- value- The requested session ID.
- Returns:
- This object.
 
- 
requestURIFluent setter.- Parameters:
- value- The request URI.
- Returns:
- This object.
 
- 
servletPathFluent setter.- Parameters:
- value- The servlet path.
- Returns:
- This object.
 
- 
httpSessionFluent setter.- Parameters:
- value- The HTTP session.
- Returns:
- This object.
 
- 
getAttribute- Specified by:
- getAttributein interface- jakarta.servlet.ServletRequest
 
- 
getAttributeNames- Specified by:
- getAttributeNamesin interface- jakarta.servlet.ServletRequest
 
- 
getCharacterEncoding- Specified by:
- getCharacterEncodingin interface- jakarta.servlet.ServletRequest
 
- 
setCharacterEncoding- Specified by:
- setCharacterEncodingin interface- jakarta.servlet.ServletRequest
- Throws:
- UnsupportedEncodingException
 
- 
getContentLength- Specified by:
- getContentLengthin interface- jakarta.servlet.ServletRequest
 
- 
getContentLengthLong- Specified by:
- getContentLengthLongin interface- jakarta.servlet.ServletRequest
 
- 
getContentType- Specified by:
- getContentTypein interface- jakarta.servlet.ServletRequest
 
- 
getInputStream- Specified by:
- getInputStreamin interface- jakarta.servlet.ServletRequest
- Throws:
- IOException
 
- 
getParameter- Specified by:
- getParameterin interface- jakarta.servlet.ServletRequest
 
- 
getParameterNames- Specified by:
- getParameterNamesin interface- jakarta.servlet.ServletRequest
 
- 
getParameterValues- Specified by:
- getParameterValuesin interface- jakarta.servlet.ServletRequest
 
- 
getParameterMap- Specified by:
- getParameterMapin interface- jakarta.servlet.ServletRequest
 
- 
getProtocol- Specified by:
- getProtocolin interface- jakarta.servlet.ServletRequest
 
- 
getScheme- Specified by:
- getSchemein interface- jakarta.servlet.ServletRequest
 
- 
getServerName- Specified by:
- getServerNamein interface- jakarta.servlet.ServletRequest
 
- 
getServerPort- Specified by:
- getServerPortin interface- jakarta.servlet.ServletRequest
 
- 
getReader- Specified by:
- getReaderin interface- jakarta.servlet.ServletRequest
- Throws:
- IOException
 
- 
getRemoteAddr- Specified by:
- getRemoteAddrin interface- jakarta.servlet.ServletRequest
 
- 
getRemoteHost- Specified by:
- getRemoteHostin interface- jakarta.servlet.ServletRequest
 
- 
setAttribute- Specified by:
- setAttributein interface- jakarta.servlet.ServletRequest
 
- 
removeAttribute- Specified by:
- removeAttributein interface- jakarta.servlet.ServletRequest
 
- 
getLocale- Specified by:
- getLocalein interface- jakarta.servlet.ServletRequest
 
- 
getLocales- Specified by:
- getLocalesin interface- jakarta.servlet.ServletRequest
 
- 
isSecure- Specified by:
- isSecurein interface- jakarta.servlet.ServletRequest
 
- 
getRequestDispatcher- Specified by:
- getRequestDispatcherin interface- jakarta.servlet.ServletRequest
 
- 
getRemotePort- Specified by:
- getRemotePortin interface- jakarta.servlet.ServletRequest
 
- 
getLocalName- Specified by:
- getLocalNamein interface- jakarta.servlet.ServletRequest
 
- 
getLocalAddr- Specified by:
- getLocalAddrin interface- jakarta.servlet.ServletRequest
 
- 
getLocalPort- Specified by:
- getLocalPortin interface- jakarta.servlet.ServletRequest
 
- 
getServletContext- Specified by:
- getServletContextin interface- jakarta.servlet.ServletRequest
 
- 
startAsync- Specified by:
- startAsyncin interface- jakarta.servlet.ServletRequest
- Throws:
- IllegalStateException
 
- 
startAsyncpublic jakarta.servlet.AsyncContext startAsync(jakarta.servlet.ServletRequest servletRequest, jakarta.servlet.ServletResponse servletResponse) throws IllegalStateException - Specified by:
- startAsyncin interface- jakarta.servlet.ServletRequest
- Throws:
- IllegalStateException
 
- 
isAsyncStarted- Specified by:
- isAsyncStartedin interface- jakarta.servlet.ServletRequest
 
- 
isAsyncSupported- Specified by:
- isAsyncSupportedin interface- jakarta.servlet.ServletRequest
 
- 
getAsyncContext- Specified by:
- getAsyncContextin interface- jakarta.servlet.ServletRequest
 
- 
getDispatcherType- Specified by:
- getDispatcherTypein interface- jakarta.servlet.ServletRequest
 
- 
getAuthType- Specified by:
- getAuthTypein interface- jakarta.servlet.http.HttpServletRequest
 
- 
getCookies- Specified by:
- getCookiesin interface- jakarta.servlet.http.HttpServletRequest
 
- 
getDateHeader- Specified by:
- getDateHeaderin interface- jakarta.servlet.http.HttpServletRequest
 
- 
getHeader- Specified by:
- getHeaderin interface- jakarta.servlet.http.HttpServletRequest
 
- 
getHeaders- Specified by:
- getHeadersin interface- jakarta.servlet.http.HttpServletRequest
 
- 
getHeaderNames- Specified by:
- getHeaderNamesin interface- jakarta.servlet.http.HttpServletRequest
 
- 
getIntHeader- Specified by:
- getIntHeaderin interface- jakarta.servlet.http.HttpServletRequest
 
- 
getMethod- Specified by:
- getMethodin interface- jakarta.servlet.http.HttpServletRequest
 
- 
getPathInfo- Specified by:
- getPathInfoin interface- jakarta.servlet.http.HttpServletRequest
 
- 
getPathTranslated- Specified by:
- getPathTranslatedin interface- jakarta.servlet.http.HttpServletRequest
 
- 
getContextPath- Specified by:
- getContextPathin interface- jakarta.servlet.http.HttpServletRequest
 
- 
getQueryString- Specified by:
- getQueryStringin interface- jakarta.servlet.http.HttpServletRequest
 
- 
getRemoteUser- Specified by:
- getRemoteUserin interface- jakarta.servlet.http.HttpServletRequest
 
- 
isUserInRole- Specified by:
- isUserInRolein interface- jakarta.servlet.http.HttpServletRequest
 
- 
getUserPrincipal- Specified by:
- getUserPrincipalin interface- jakarta.servlet.http.HttpServletRequest
 
- 
getRequestedSessionId- Specified by:
- getRequestedSessionIdin interface- jakarta.servlet.http.HttpServletRequest
 
- 
getRequestURI- Specified by:
- getRequestURIin interface- jakarta.servlet.http.HttpServletRequest
 
- 
getRequestURL- Specified by:
- getRequestURLin interface- jakarta.servlet.http.HttpServletRequest
 
- 
getServletPath- Specified by:
- getServletPathin interface- jakarta.servlet.http.HttpServletRequest
 
- 
getSession- Specified by:
- getSessionin interface- jakarta.servlet.http.HttpServletRequest
 
- 
getSession- Specified by:
- getSessionin interface- jakarta.servlet.http.HttpServletRequest
 
- 
changeSessionId- Specified by:
- changeSessionIdin interface- jakarta.servlet.http.HttpServletRequest
 
- 
isRequestedSessionIdValid- Specified by:
- isRequestedSessionIdValidin interface- jakarta.servlet.http.HttpServletRequest
 
- 
isRequestedSessionIdFromCookie- Specified by:
- isRequestedSessionIdFromCookiein interface- jakarta.servlet.http.HttpServletRequest
 
- 
isRequestedSessionIdFromURL- Specified by:
- isRequestedSessionIdFromURLin interface- jakarta.servlet.http.HttpServletRequest
 
- 
authenticatepublic boolean authenticate(jakarta.servlet.http.HttpServletResponse response) throws IOException, jakarta.servlet.ServletException - Specified by:
- authenticatein interface- jakarta.servlet.http.HttpServletRequest
- Throws:
- IOException
- jakarta.servlet.ServletException
 
- 
login- Specified by:
- loginin interface- jakarta.servlet.http.HttpServletRequest
- Throws:
- jakarta.servlet.ServletException
 
- 
logout- Specified by:
- logoutin interface- jakarta.servlet.http.HttpServletRequest
- Throws:
- jakarta.servlet.ServletException
 
- 
getPartspublic Collection<jakarta.servlet.http.Part> getParts() throws IOException, jakarta.servlet.ServletException- Specified by:
- getPartsin interface- jakarta.servlet.http.HttpServletRequest
- Throws:
- IOException
- jakarta.servlet.ServletException
 
- 
getPartpublic jakarta.servlet.http.Part getPart(String name) throws IOException, jakarta.servlet.ServletException - Specified by:
- getPartin interface- jakarta.servlet.http.HttpServletRequest
- Throws:
- IOException
- jakarta.servlet.ServletException
 
- 
upgradepublic <T extends jakarta.servlet.http.HttpUpgradeHandler> T upgrade(Class<T> handlerClass) throws IOException, jakarta.servlet.ServletException - Specified by:
- upgradein interface- jakarta.servlet.http.HttpServletRequest
- Throws:
- IOException
- jakarta.servlet.ServletException
 
- 
headerFluent setter.- Parameters:
- name- Header name.
- value- Header value.
 The value is converted to a simple string using- Object.toString().
- Returns:
- This object.
 
- 
attributeFluent setter.- Parameters:
- name- Request attribute name.
- value- Request attribute value.
- Returns:
- This object.
 
- 
contentFluent 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.
 
- 
debugEnabled 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.
 
- 
noTraceEnabled 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.
 
- 
applyOverridesIf 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:
- getRequestIdin interface- jakarta.servlet.ServletRequest
 
- 
getProtocolRequestId- Specified by:
- getProtocolRequestIdin interface- jakarta.servlet.ServletRequest
 
- 
getServletConnection- Specified by:
- getServletConnectionin interface- jakarta.servlet.ServletRequest
 
 
-