class GrailsMockHttpServletRequest extends org.springframework.mock.web.MockHttpServletRequest implements org.springframework.web.multipart.MultipartHttpServletRequest
A custom mock HTTP servlet request that provides the extra properties and methods normally injected by the "servlets" plugin.
Modifiers | Name | Description |
---|---|---|
private javax.servlet.AsyncContext |
asyncContext |
|
private javax.servlet.ServletInputStream |
cachedInputStream |
|
private java.lang.Object |
cachedJson |
|
private java.lang.Object |
cachedXml |
|
private javax.servlet.DispatcherType |
dispatcherType |
|
private org.springframework.http.HttpHeaders |
httpHeaders |
|
private boolean |
invalidToken |
|
private java.util.Map<java.lang.String, java.lang.String> |
multipartContentTypes |
|
private org.springframework.util.MultiValueMap |
multipartFiles |
|
private java.util.Map<java.lang.String, org.springframework.http.HttpHeaders> |
multipartHeaders |
|
private org.springframework.http.HttpHeaders |
requestHeaders |
|
private org.springframework.http.HttpMethod |
requestMethod |
Fields inherited from class | Fields |
---|---|
class org.springframework.mock.web.MockHttpServletRequest |
DEFAULT_PROTOCOL, DEFAULT_SCHEME, DEFAULT_SERVER_ADDR, DEFAULT_SERVER_NAME, DEFAULT_SERVER_PORT, DEFAULT_REMOTE_ADDR, DEFAULT_REMOTE_HOST, BASIC_AUTH, FORM_AUTH, CLIENT_CERT_AUTH, DIGEST_AUTH |
Type | Name and description |
---|---|
javax.servlet.AsyncContext |
asyncContext |
javax.servlet.DispatcherType |
dispatcherType |
java.lang.String |
forwardURI |
boolean |
invalidToken |
java.lang.Object |
jSON |
java.lang.String |
multipartContentType |
org.springframework.util.MultiValueMap |
multipartFiles |
org.springframework.http.HttpHeaders |
multipartHeaders |
java.lang.Object |
property |
org.springframework.http.HttpHeaders |
requestHeaders |
org.springframework.http.HttpMethod |
requestMethod |
java.lang.Object |
xML |
Constructor and description |
---|
GrailsMockHttpServletRequest
() |
GrailsMockHttpServletRequest
(javax.servlet.ServletContext servletContext) |
Type Params | Return Type | Name and description |
---|---|---|
|
void |
addFile(org.springframework.web.multipart.MultipartFile file) Add a file to this request. |
|
void |
addFile(java.lang.String location, byte[] contents) Add a file for the given location and bytes |
|
void |
clearAttributes() |
|
java.lang.Object |
each(groovy.lang.Closure c) Iterates over the request attributes. |
|
java.lang.Object |
find(groovy.lang.Closure c) Adds a "find()" method to the request that searches the request's attributes. |
|
java.lang.Object |
findAll(groovy.lang.Closure c) Like the find(Closure) method, this searches the request attributes. |
|
java.lang.Object |
getAt(java.lang.String key) Map-like access to request attributes, e.g. request["count"]. |
|
org.springframework.web.multipart.MultipartFile |
getFile(java.lang.String name) {
|
|
java.util.Map<java.lang.String, org.springframework.web.multipart.MultipartFile> |
getFileMap() {
|
|
java.util.Iterator<java.lang.String> |
getFileNames() {
|
|
java.util.List<org.springframework.web.multipart.MultipartFile> |
getFiles(java.lang.String name) {
|
|
java.lang.String |
getForwardURI() Implementation of the dynamic "forwardURI" property. |
|
javax.servlet.ServletInputStream |
getInputStream() |
|
java.lang.Object |
getJSON() Parses the request content as JSON using the JSON converter. |
|
org.springframework.util.MultiValueMap<java.lang.String, org.springframework.web.multipart.MultipartFile> |
getMultiFileMap() {
|
|
java.lang.String |
getMultipartContentType(java.lang.String paramOrFileName) |
|
org.springframework.http.HttpHeaders |
getMultipartHeaders(java.lang.String paramOrFileName) |
|
javax.servlet.http.Part |
getPart(java.lang.String name) |
|
java.util.Collection<javax.servlet.http.Part> |
getParts() |
|
java.lang.Object |
getProperty(java.lang.String name) Property access for request attributes. |
|
java.lang.Object |
getXML() Parses the request content as XML using XmlSlurper and returns the GPath result object. |
|
boolean |
isAsyncStarted() |
|
boolean |
isAsyncSupported() |
|
boolean |
isGet() |
|
boolean |
isPost() |
|
boolean |
isXhr() Indicates whether this is an AJAX request or not (as far as Grails is concerned). |
|
void |
makeAjaxRequest() Makes this request an AJAX request as Grails understands it. |
|
void |
putAt(java.lang.String key, java.lang.Object val) Map-like setting of request attributes, e.g. request["count"] = 10. |
|
void |
setContentType(java.lang.String newContentType) |
|
void |
setFormat(java.lang.String format) Sets the request format to use |
|
void |
setForwardURI(java.lang.String uri) Sets the "forwardURI" property for the request. |
|
void |
setJSON(java.lang.Object sourceJson) |
|
void |
setJson(java.lang.Object sourceJson) Sets the body of the request to be a json packet |
|
java.lang.String |
setMultipartContentType(java.lang.String paramOrFileName, java.lang.String contentType) |
|
org.springframework.http.HttpHeaders |
setMultipartHeaders(java.lang.String paramOrFileName, org.springframework.http.HttpHeaders headers) |
|
void |
setProperty(java.lang.String name, java.lang.Object value) Property setting of request attributes. |
|
void |
setXML(java.lang.Object sourceXml) |
|
void |
setXml(java.lang.Object sourceXml) Sets the body of the request to be an XML packet |
|
javax.servlet.AsyncContext |
startAsync() |
|
javax.servlet.AsyncContext |
startAsync(javax.servlet.ServletRequest servletRequest, javax.servlet.ServletResponse servletResponse) |
Methods inherited from class | Name |
---|---|
class org.springframework.mock.web.MockHttpServletRequest |
org.springframework.mock.web.MockHttpServletRequest#getServletContext(), org.springframework.mock.web.MockHttpServletRequest#getParameterNames(), org.springframework.mock.web.MockHttpServletRequest#removeHeader(java.lang.String), org.springframework.mock.web.MockHttpServletRequest#removeAttribute(java.lang.String), org.springframework.mock.web.MockHttpServletRequest#getSession(boolean), org.springframework.mock.web.MockHttpServletRequest#getSession(), org.springframework.mock.web.MockHttpServletRequest#getParts(), org.springframework.mock.web.MockHttpServletRequest#setProtocol(java.lang.String), org.springframework.mock.web.MockHttpServletRequest#getParameter(java.lang.String), org.springframework.mock.web.MockHttpServletRequest#getReader(), org.springframework.mock.web.MockHttpServletRequest#getAttributeNames(), org.springframework.mock.web.MockHttpServletRequest#setParameter(java.lang.String, [Ljava.lang.String;), org.springframework.mock.web.MockHttpServletRequest#setParameter(java.lang.String, java.lang.String), org.springframework.mock.web.MockHttpServletRequest#removeParameter(java.lang.String), org.springframework.mock.web.MockHttpServletRequest#setScheme(java.lang.String), org.springframework.mock.web.MockHttpServletRequest#addParameters(java.util.Map), org.springframework.mock.web.MockHttpServletRequest#addParameter(java.lang.String, java.lang.String), org.springframework.mock.web.MockHttpServletRequest#addParameter(java.lang.String, [Ljava.lang.String;), org.springframework.mock.web.MockHttpServletRequest#upgrade(java.lang.Class), org.springframework.mock.web.MockHttpServletRequest#getCookies(), org.springframework.mock.web.MockHttpServletRequest#authenticate(javax.servlet.http.HttpServletResponse), org.springframework.mock.web.MockHttpServletRequest#getUserPrincipal(), org.springframework.mock.web.MockHttpServletRequest#login(java.lang.String, java.lang.String), org.springframework.mock.web.MockHttpServletRequest#logout(), org.springframework.mock.web.MockHttpServletRequest#getRemotePort(), org.springframework.mock.web.MockHttpServletRequest#setContent([B), org.springframework.mock.web.MockHttpServletRequest#isSecure(), org.springframework.mock.web.MockHttpServletRequest#setSecure(boolean), org.springframework.mock.web.MockHttpServletRequest#setQueryString(java.lang.String), org.springframework.mock.web.MockHttpServletRequest#getQueryString(), org.springframework.mock.web.MockHttpServletRequest#getLocalName(), org.springframework.mock.web.MockHttpServletRequest#setLocalName(java.lang.String), org.springframework.mock.web.MockHttpServletRequest#getMethod(), org.springframework.mock.web.MockHttpServletRequest#close(), org.springframework.mock.web.MockHttpServletRequest#getScheme(), org.springframework.mock.web.MockHttpServletRequest#getInputStream(), org.springframework.mock.web.MockHttpServletRequest#getProtocol(), org.springframework.mock.web.MockHttpServletRequest#isActive(), org.springframework.mock.web.MockHttpServletRequest#setAttribute(java.lang.String, java.lang.Object), org.springframework.mock.web.MockHttpServletRequest#getAttribute(java.lang.String), org.springframework.mock.web.MockHttpServletRequest#getLocale(), org.springframework.mock.web.MockHttpServletRequest#setMethod(java.lang.String), org.springframework.mock.web.MockHttpServletRequest#setParameters(java.util.Map), org.springframework.mock.web.MockHttpServletRequest#getHeader(java.lang.String), org.springframework.mock.web.MockHttpServletRequest#getContentLength(), org.springframework.mock.web.MockHttpServletRequest#getCharacterEncoding(), org.springframework.mock.web.MockHttpServletRequest#setCharacterEncoding(java.lang.String), org.springframework.mock.web.MockHttpServletRequest#getContextPath(), org.springframework.mock.web.MockHttpServletRequest#getRequestDispatcher(java.lang.String), org.springframework.mock.web.MockHttpServletRequest#getRealPath(java.lang.String), org.springframework.mock.web.MockHttpServletRequest#getParameterValues(java.lang.String), org.springframework.mock.web.MockHttpServletRequest#getParameterMap(), org.springframework.mock.web.MockHttpServletRequest#getServerName(), org.springframework.mock.web.MockHttpServletRequest#getServerPort(), org.springframework.mock.web.MockHttpServletRequest#getRemoteAddr(), org.springframework.mock.web.MockHttpServletRequest#getRemoteHost(), org.springframework.mock.web.MockHttpServletRequest#getLocales(), org.springframework.mock.web.MockHttpServletRequest#getLocalAddr(), org.springframework.mock.web.MockHttpServletRequest#startAsync(), org.springframework.mock.web.MockHttpServletRequest#startAsync(javax.servlet.ServletRequest, javax.servlet.ServletResponse), org.springframework.mock.web.MockHttpServletRequest#isAsyncStarted(), org.springframework.mock.web.MockHttpServletRequest#isAsyncSupported(), org.springframework.mock.web.MockHttpServletRequest#getAsyncContext(), org.springframework.mock.web.MockHttpServletRequest#getDispatcherType(), org.springframework.mock.web.MockHttpServletRequest#setAsyncSupported(boolean), org.springframework.mock.web.MockHttpServletRequest#getContentAsByteArray(), org.springframework.mock.web.MockHttpServletRequest#getContentAsString(), org.springframework.mock.web.MockHttpServletRequest#clearAttributes(), org.springframework.mock.web.MockHttpServletRequest#setServerPort(int), org.springframework.mock.web.MockHttpServletRequest#setRemoteAddr(java.lang.String), org.springframework.mock.web.MockHttpServletRequest#setRemoteHost(java.lang.String), org.springframework.mock.web.MockHttpServletRequest#addPreferredLocale(java.util.Locale), org.springframework.mock.web.MockHttpServletRequest#setPreferredLocales(java.util.List), org.springframework.mock.web.MockHttpServletRequest#setRemotePort(int), org.springframework.mock.web.MockHttpServletRequest#setLocalAddr(java.lang.String), org.springframework.mock.web.MockHttpServletRequest#setLocalPort(int), org.springframework.mock.web.MockHttpServletRequest#setAsyncStarted(boolean), org.springframework.mock.web.MockHttpServletRequest#setAsyncContext(org.springframework.mock.web.MockAsyncContext), org.springframework.mock.web.MockHttpServletRequest#setDispatcherType(javax.servlet.DispatcherType), org.springframework.mock.web.MockHttpServletRequest#setAuthType(java.lang.String), org.springframework.mock.web.MockHttpServletRequest#setCookies([Ljavax.servlet.http.Cookie;), org.springframework.mock.web.MockHttpServletRequest#setPathInfo(java.lang.String), org.springframework.mock.web.MockHttpServletRequest#setContextPath(java.lang.String), org.springframework.mock.web.MockHttpServletRequest#setRemoteUser(java.lang.String), org.springframework.mock.web.MockHttpServletRequest#addUserRole(java.lang.String), org.springframework.mock.web.MockHttpServletRequest#setUserPrincipal(java.security.Principal), org.springframework.mock.web.MockHttpServletRequest#setRequestedSessionId(java.lang.String), org.springframework.mock.web.MockHttpServletRequest#setRequestURI(java.lang.String), org.springframework.mock.web.MockHttpServletRequest#setServletPath(java.lang.String), org.springframework.mock.web.MockHttpServletRequest#setSession(javax.servlet.http.HttpSession), org.springframework.mock.web.MockHttpServletRequest#removeAllParameters(), org.springframework.mock.web.MockHttpServletRequest#setServerName(java.lang.String), org.springframework.mock.web.MockHttpServletRequest#setRequestedSessionIdValid(boolean), org.springframework.mock.web.MockHttpServletRequest#setRequestedSessionIdFromCookie(boolean), org.springframework.mock.web.MockHttpServletRequest#setRequestedSessionIdFromURL(boolean), org.springframework.mock.web.MockHttpServletRequest#addPart(javax.servlet.http.Part), org.springframework.mock.web.MockHttpServletRequest#addHeader(java.lang.String, java.lang.Object), org.springframework.mock.web.MockHttpServletRequest#getLocalPort(), org.springframework.mock.web.MockHttpServletRequest#getAuthType(), org.springframework.mock.web.MockHttpServletRequest#getDateHeader(java.lang.String), org.springframework.mock.web.MockHttpServletRequest#getHeaderNames(), org.springframework.mock.web.MockHttpServletRequest#getIntHeader(java.lang.String), org.springframework.mock.web.MockHttpServletRequest#getPathInfo(), org.springframework.mock.web.MockHttpServletRequest#getPathTranslated(), org.springframework.mock.web.MockHttpServletRequest#getRemoteUser(), org.springframework.mock.web.MockHttpServletRequest#isUserInRole(java.lang.String), org.springframework.mock.web.MockHttpServletRequest#getRequestedSessionId(), org.springframework.mock.web.MockHttpServletRequest#getRequestURI(), org.springframework.mock.web.MockHttpServletRequest#getRequestURL(), org.springframework.mock.web.MockHttpServletRequest#getServletPath(), org.springframework.mock.web.MockHttpServletRequest#changeSessionId(), org.springframework.mock.web.MockHttpServletRequest#isRequestedSessionIdValid(), org.springframework.mock.web.MockHttpServletRequest#isRequestedSessionIdFromCookie(), org.springframework.mock.web.MockHttpServletRequest#isRequestedSessionIdFromURL(), org.springframework.mock.web.MockHttpServletRequest#isRequestedSessionIdFromUrl(), org.springframework.mock.web.MockHttpServletRequest#getPart(java.lang.String), org.springframework.mock.web.MockHttpServletRequest#getContentLengthLong(), org.springframework.mock.web.MockHttpServletRequest#getHeaders(java.lang.String), org.springframework.mock.web.MockHttpServletRequest#setContentType(java.lang.String), org.springframework.mock.web.MockHttpServletRequest#getContentType(), org.springframework.mock.web.MockHttpServletRequest#invalidate(), org.springframework.mock.web.MockHttpServletRequest#wait(long, int), org.springframework.mock.web.MockHttpServletRequest#wait(), org.springframework.mock.web.MockHttpServletRequest#wait(long), org.springframework.mock.web.MockHttpServletRequest#equals(java.lang.Object), org.springframework.mock.web.MockHttpServletRequest#toString(), org.springframework.mock.web.MockHttpServletRequest#hashCode(), org.springframework.mock.web.MockHttpServletRequest#getClass(), org.springframework.mock.web.MockHttpServletRequest#notify(), org.springframework.mock.web.MockHttpServletRequest#notifyAll(), org.springframework.mock.web.MockHttpServletRequest#isTrailerFieldsReady(), org.springframework.mock.web.MockHttpServletRequest#getHttpServletMapping(), org.springframework.mock.web.MockHttpServletRequest#newPushBuilder(), org.springframework.mock.web.MockHttpServletRequest#getTrailerFields() |
Add a file to this request. The parameter name from the multipart form is taken from the org.springframework.web.multipart.MultipartFile#getName().
file
- multipart file to be addedAdd a file for the given location and bytes
location
- The locationcontents
- The bytesIterates over the request attributes.
Adds a "find()" method to the request that searches the request's
attributes. Returns the first attribute for which the closure
returns true
, just like the normal Groovy find() method.
Like the find(Closure) method, this searches the request attributes. Returns all the attributes that match the closure conditions.
Map-like access to request attributes, e.g. request["count"].
{
{
{
{
Implementation of the dynamic "forwardURI" property.
Parses the request content as JSON using the JSON converter. Throws an exception if there is no content or the content is not valid JSON.
{
Property access for request attributes.
Parses the request content as XML using XmlSlurper and returns the GPath result object. Throws an exception if there is no content or the content is not valid XML.
Indicates whether this is an AJAX request or not (as far as
Grails is concerned). Returns true
if it is an
AJAX request, otherwise false
.
Makes this request an AJAX request as Grails understands it. This cannot be undone, so if you need a non-AJAX request you will have to create a new instance.
Map-like setting of request attributes, e.g. request["count"] = 10.
Sets the request format to use
format
- The request formatSets the "forwardURI" property for the request.
Sets the body of the request to be a json packet
sourceJson
- The source jsonProperty setting of request attributes.
Sets the body of the request to be an XML packet
Groovy Documentation