class MockHttpServletRequest extends HttpServletRequest
A Mock ServletRequest. Change its state to create the request you are interested in. At the very least, you will need to change method and path.
There are several things that aren't supported:
- getRequestDispatcher - returns null always
- getRequestedSessionId - always returns null. The related isRequestedSessionId... methods similarly all return false
- getRealPath - simply returns the input string
- Alphabetic
- By Inheritance
- MockHttpServletRequest
- HttpServletRequest
- ServletRequest
- AnyRef
- Any
- Hide All
- Show All
- Public
- All
Instance Constructors
-
new
MockHttpServletRequest(url: URL, contextPath: String)
Construct a new mock request for the given URL.
Construct a new mock request for the given URL. See processUrl for limitations.
- url
The URL to extract from
- contextPath
The servlet context of the request.
-
new
MockHttpServletRequest(url: URL)
Construct a new mock request for the given URL.
Construct a new mock request for the given URL. See processUrl for limitations.
- url
The URL to extract from
-
new
MockHttpServletRequest(url: String = null, contextPath: String = "")
- url
The URL to extract from
- contextPath
The context path for this request. Defaults to "" per the Servlet API.
Value Members
-
final
def
!=(arg0: Any): Boolean
- Definition Classes
- AnyRef → Any
-
final
def
##(): Int
- Definition Classes
- AnyRef → Any
-
final
def
==(arg0: Any): Boolean
- Definition Classes
- AnyRef → Any
-
def
addBasicAuth(user: String, pass: String): Unit
Adds an "Authorization" header, per RFC1945.
-
final
def
asInstanceOf[T0]: T0
- Definition Classes
- Any
- var attributes: Map[String, AnyRef]
- var authType: String
-
def
authenticate(resp: HttpServletResponse): Boolean
- Definition Classes
- MockHttpServletRequest → HttpServletRequest
-
var
body: Array[Byte]
The raw body of the request.
-
def
body_=(jval: JValue, contentType: String): Unit
Sets the body to the given json value and content type.
-
def
body_=(jval: JValue): Unit
Sets the body to the given json value.
Sets the body to the given json value. Also sets the contentType to "application/json"
-
def
body_=(nodes: NodeSeq, contentType: String): Unit
Sets the body to the given elements and content type.
Sets the body to the given elements and content type.
Note that the elements will be converted to bytes based on the current setting of charEncoding.
-
def
body_=(nodes: NodeSeq): Unit
Sets the body to the given elements.
Sets the body to the given elements. Also sets the contentType to "text/xml"
Note that the elements will be converted to bytes based on the current setting of charEncoding.
-
def
body_=(s: String, contentType: String): Unit
Sets the body to the given string and content type.
Sets the body to the given string and content type.
Note that the String will be converted to bytes based on the current setting of charEncoding.
-
def
body_=(s: String): Unit
Sets the body to the given string.
Sets the body to the given string. The content type is set to "text/plain".
Note that the String will be converted to bytes based on the current setting of charEncoding.
-
def
changeSessionId(): String
- Definition Classes
- MockHttpServletRequest → HttpServletRequest
-
var
charEncoding: String
The character encoding of the request.
The character encoding of the request.
Defaults to UTF-8. Note that this differs from the default encoding per the HTTP spec (ISO-8859-1), so you will need to change this if you need something other than UTF-8.
-
def
clone(): AnyRef
- Attributes
- protected[java.lang]
- Definition Classes
- AnyRef
- Annotations
- @throws( ... )
-
def
computeRealPath(path: String): String
Compute the path portion after the contextPath
- var contentType: String
- var contextPath: String
- var cookies: List[Cookie]
-
final
def
eq(arg0: AnyRef): Boolean
- Definition Classes
- AnyRef
-
def
equals(arg0: Any): Boolean
- Definition Classes
- AnyRef → Any
-
def
finalize(): Unit
- Attributes
- protected[java.lang]
- Definition Classes
- AnyRef
- Annotations
- @throws( classOf[java.lang.Throwable] )
-
def
getAsyncContext(): AsyncContext
- Definition Classes
- MockHttpServletRequest → ServletRequest
-
def
getAttribute(key: String): AnyRef
- Definition Classes
- MockHttpServletRequest → ServletRequest
-
def
getAttributeNames(): Enumeration[String]
- Definition Classes
- MockHttpServletRequest → ServletRequest
-
def
getAuthType(): String
- Definition Classes
- MockHttpServletRequest → HttpServletRequest
-
def
getCharacterEncoding(): String
- Definition Classes
- MockHttpServletRequest → ServletRequest
-
final
def
getClass(): Class[_]
- Definition Classes
- AnyRef → Any
-
def
getContentLength(): Int
- Definition Classes
- MockHttpServletRequest → ServletRequest
-
def
getContentLengthLong(): Long
- Definition Classes
- MockHttpServletRequest → ServletRequest
-
def
getContentType(): String
- Definition Classes
- MockHttpServletRequest → ServletRequest
-
def
getContextPath(): String
- Definition Classes
- MockHttpServletRequest → HttpServletRequest
-
def
getCookies(): Array[Cookie]
- Definition Classes
- MockHttpServletRequest → HttpServletRequest
-
def
getDateHeader(h: String): Long
- Definition Classes
- MockHttpServletRequest → HttpServletRequest
-
def
getDispatcherType(): DispatcherType
- Definition Classes
- MockHttpServletRequest → ServletRequest
-
def
getHeader(h: String): String
- Definition Classes
- MockHttpServletRequest → HttpServletRequest
-
def
getHeaderNames(): Enumeration[String]
- Definition Classes
- MockHttpServletRequest → HttpServletRequest
-
def
getHeaders(s: String): Enumeration[String]
- Definition Classes
- MockHttpServletRequest → HttpServletRequest
-
def
getInputStream(): ServletInputStream
- Definition Classes
- MockHttpServletRequest → ServletRequest
-
def
getIntHeader(h: String): Int
- Definition Classes
- MockHttpServletRequest → HttpServletRequest
-
def
getLocalAddr(): String
- Definition Classes
- MockHttpServletRequest → ServletRequest
-
def
getLocalName(): String
- Definition Classes
- MockHttpServletRequest → ServletRequest
-
def
getLocalPort(): Int
- Definition Classes
- MockHttpServletRequest → ServletRequest
-
def
getLocale(): Locale
- Definition Classes
- MockHttpServletRequest → ServletRequest
-
def
getLocales(): Enumeration[Locale]
- Definition Classes
- MockHttpServletRequest → ServletRequest
-
def
getMethod(): String
- Definition Classes
- MockHttpServletRequest → HttpServletRequest
-
def
getParameter(key: String): String
- Definition Classes
- MockHttpServletRequest → ServletRequest
-
def
getParameterMap(): Map[String, Array[String]]
- Definition Classes
- MockHttpServletRequest → ServletRequest
-
def
getParameterNames(): Enumeration[String]
- Definition Classes
- MockHttpServletRequest → ServletRequest
-
def
getParameterValues(key: String): Array[String]
- Definition Classes
- MockHttpServletRequest → ServletRequest
-
def
getPart(partName: String): Part
- Definition Classes
- MockHttpServletRequest → HttpServletRequest
-
def
getParts(): Collection[Part]
- Definition Classes
- MockHttpServletRequest → HttpServletRequest
-
def
getPathInfo(): String
- Definition Classes
- MockHttpServletRequest → HttpServletRequest
-
def
getPathTranslated(): String
- Definition Classes
- MockHttpServletRequest → HttpServletRequest
-
def
getProtocol(): String
- Definition Classes
- MockHttpServletRequest → ServletRequest
-
def
getQueryString(): String
- Definition Classes
- MockHttpServletRequest → HttpServletRequest
-
def
getReader(): BufferedReader
- Definition Classes
- MockHttpServletRequest → ServletRequest
-
def
getRealPath(s: String): String
- Definition Classes
- MockHttpServletRequest → ServletRequest
-
def
getRemoteAddr(): String
- Definition Classes
- MockHttpServletRequest → ServletRequest
-
def
getRemoteHost(): String
- Definition Classes
- MockHttpServletRequest → ServletRequest
-
def
getRemotePort(): Int
- Definition Classes
- MockHttpServletRequest → ServletRequest
-
def
getRemoteUser(): String
- Definition Classes
- MockHttpServletRequest → HttpServletRequest
-
def
getRequestDispatcher(s: String): RequestDispatcher
- Definition Classes
- MockHttpServletRequest → ServletRequest
-
def
getRequestURI(): String
- Definition Classes
- MockHttpServletRequest → HttpServletRequest
-
def
getRequestURL(): StringBuffer
- Definition Classes
- MockHttpServletRequest → HttpServletRequest
-
def
getRequestedSessionId(): String
- Definition Classes
- MockHttpServletRequest → HttpServletRequest
-
def
getScheme(): String
- Definition Classes
- MockHttpServletRequest → ServletRequest
-
def
getServerName(): String
- Definition Classes
- MockHttpServletRequest → ServletRequest
-
def
getServerPort(): Int
- Definition Classes
- MockHttpServletRequest → ServletRequest
-
def
getServletContext(): ServletContext
- Definition Classes
- MockHttpServletRequest → ServletRequest
-
def
getServletPath(): String
- Definition Classes
- MockHttpServletRequest → HttpServletRequest
-
def
getSession(create: Boolean): HttpSession
- Definition Classes
- MockHttpServletRequest → HttpServletRequest
-
def
getSession(): HttpSession
- Definition Classes
- MockHttpServletRequest → HttpServletRequest
-
def
getUserPrincipal(): Principal
- Definition Classes
- MockHttpServletRequest → HttpServletRequest
-
def
hashCode(): Int
- Definition Classes
- AnyRef → Any
- var headers: Map[String, List[String]]
-
def
isAsyncStarted(): Boolean
- Definition Classes
- MockHttpServletRequest → ServletRequest
-
def
isAsyncSupported(): Boolean
- Definition Classes
- MockHttpServletRequest → ServletRequest
-
final
def
isInstanceOf[T0]: Boolean
- Definition Classes
- Any
-
def
isRequestedSessionIdFromCookie(): Boolean
- Definition Classes
- MockHttpServletRequest → HttpServletRequest
-
def
isRequestedSessionIdFromURL(): Boolean
- Definition Classes
- MockHttpServletRequest → HttpServletRequest
-
def
isRequestedSessionIdFromUrl(): Boolean
- Definition Classes
- MockHttpServletRequest → HttpServletRequest
-
def
isRequestedSessionIdValid(): Boolean
- Definition Classes
- MockHttpServletRequest → HttpServletRequest
-
def
isSecure(): Boolean
- Definition Classes
- MockHttpServletRequest → ServletRequest
-
def
isUserInRole(user: String): Boolean
- Definition Classes
- MockHttpServletRequest → HttpServletRequest
-
var
localAddr: String
The local address that the request was received on.
The local address that the request was received on.
If you change this you should probably change localName and serverName as well.
-
var
localName: String
The local hostname that the request was received on.
The local hostname that the request was received on.
If you change this you should probably change localAddr and serverName as well.
-
var
localPort: Int
The port that this request was received on.
The port that this request was received on. You should probably change serverPort as well if you change this.
-
var
locales: List[Locale]
The preferred locales for the client, in decreasing order of preference.
The preferred locales for the client, in decreasing order of preference. If not set, the default locale will be used.
-
def
login(username: String, password: String): Unit
- Definition Classes
- MockHttpServletRequest → HttpServletRequest
-
def
logout(): Unit
- Definition Classes
- MockHttpServletRequest → HttpServletRequest
- var method: String
-
final
def
ne(arg0: AnyRef): Boolean
- Definition Classes
- AnyRef
-
final
def
notify(): Unit
- Definition Classes
- AnyRef
-
final
def
notifyAll(): Unit
- Definition Classes
- AnyRef
-
var
parameters: List[(String, String)]
The query parameters for the request.
The query parameters for the request. There are two main ways to set this List, either by modifying the parameters var directly, or by assigning to queryString, which will parse the provided string into GET parameters.
- var path: String
- var pathInfo: String
-
def
processUrl(url: URL): Unit
Set fields based on the given URL.
Set fields based on the given URL. There are several limitations:
- The host portion is used to set localAddr, localHost and serverName. You will need to manually set these if you want different behavior.
- The userinfo field isn't processed. If you want to mock BASIC authentication, use the addBasicAuth method
- url
The URL to extract from
-
def
processUrl(url: String): Unit
Set fields based on the given url string.
Set fields based on the given url string. If the url begins with "http" it is assumed to be a full URL, and is processed with processUrl(URL). If the url begins with "/" then it's assumed to be only the path and query string.
- url
The URL to extract from
- var protocol: String
- def queryString: String
- def queryString_=(q: String): Unit
-
var
remoteAddr: String
The address of the client that sent the request.
The address of the client that sent the request.
If you change this you should probably change remoteHost as well.
-
var
remoteHost: String
The hostname of the client that sent the request.
The hostname of the client that sent the request.
If you change this you should probably change remoteAddr as well.
- var remotePort: Int
-
def
removeAttribute(key: String): Unit
- Definition Classes
- MockHttpServletRequest → ServletRequest
- var requestUri: String
- var scheme: String
-
var
secure: Boolean
Indicates whether the request is being handled by a secure protocol (e.g.
Indicates whether the request is being handled by a secure protocol (e.g. HTTPS). If you set the scheme to https you should set this to true.
- var serverName: String
-
var
serverPort: Int
The port that this request was received on.
The port that this request was received on. You should probably change localPort as well if you change this.
- var servletPath: String
- var session: HttpSession
-
def
setAttribute(key: String, value: AnyRef): Unit
- Definition Classes
- MockHttpServletRequest → ServletRequest
-
def
setCharacterEncoding(enc: String): Unit
- Definition Classes
- MockHttpServletRequest → ServletRequest
-
def
setDateHeader(s: String, l: Long): Unit
A utility method to set the given header to an RFC1123 date based on the given long value (epoch seconds).
-
def
startAsync(): AsyncContext
- Definition Classes
- MockHttpServletRequest → ServletRequest
-
def
startAsync(request: ServletRequest, response: ServletResponse): AsyncContext
- Definition Classes
- MockHttpServletRequest → ServletRequest
-
final
def
synchronized[T0](arg0: ⇒ T0): T0
- Definition Classes
- AnyRef
-
def
toString(): String
- Definition Classes
- AnyRef → Any
-
def
upgrade[T <: HttpUpgradeHandler](arg0: Class[T]): T
- Definition Classes
- MockHttpServletRequest → HttpServletRequest
- val url: String
- var user: String
- var userPrincipal: Principal
- var userRoles: Set[String]
-
final
def
wait(): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws( ... )
-
final
def
wait(arg0: Long, arg1: Int): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws( ... )
-
final
def
wait(arg0: Long): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws( ... )