|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.resteasy.mock.MockHttpServletRequest
public class MockHttpServletRequest
Mock implementation of the HttpServletRequest
interface. Supports the Servlet 2.4 API level.
Used for testing the web framework; also useful for testing application controllers.
Field Summary | |
---|---|
static java.lang.String |
DEFAULT_PROTOCOL
The default protocol: 'http'. |
static java.lang.String |
DEFAULT_REMOTE_ADDR
The default remote address: '127.0.0.1'. |
static java.lang.String |
DEFAULT_REMOTE_HOST
The default remote host: 'localhost'. |
static java.lang.String |
DEFAULT_SERVER_ADDR
The default server address: '127.0.0.1'. |
static java.lang.String |
DEFAULT_SERVER_NAME
The default server name: 'localhost'. |
static int |
DEFAULT_SERVER_PORT
The default server port: '80'. |
Fields inherited from interface javax.servlet.http.HttpServletRequest |
---|
BASIC_AUTH, CLIENT_CERT_AUTH, DIGEST_AUTH, FORM_AUTH |
Constructor Summary | |
---|---|
MockHttpServletRequest()
Create a new MockHttpServletRequest with a default MockServletContext . |
|
MockHttpServletRequest(javax.servlet.ServletContext servletContext)
Create a new MockHttpServletRequest. |
|
MockHttpServletRequest(javax.servlet.ServletContext servletContext,
java.lang.String method,
java.lang.String requestURI)
Create a new MockHttpServletRequest. |
|
MockHttpServletRequest(java.lang.String method,
java.lang.String requestURI)
Create a new MockHttpServletRequest with a default MockServletContext . |
Method Summary | |
---|---|
void |
addHeader(java.lang.String name,
java.lang.Object value)
Add a header entry for the given name. |
void |
addParameter(java.lang.String name,
java.lang.String value)
Add a single value for the specified HTTP parameter. |
void |
addParameter(java.lang.String name,
java.lang.String[] values)
Add an array of values for the specified HTTP parameter. |
void |
addPreferredLocale(java.util.Locale locale)
Add a new preferred locale, before any existing locales. |
void |
addRole(java.lang.String role)
Deprecated. in favor of addUserRole |
void |
addUserRole(java.lang.String role)
|
protected void |
checkActive()
Check whether this request is still active (that is, not completed yet), throwing an IllegalStateException if not active anymore. |
void |
clearAttributes()
Clear all of this request's attributes. |
void |
close()
Mark this request as completed, keeping its state. |
java.lang.Object |
getAttribute(java.lang.String name)
|
java.util.Enumeration |
getAttributeNames()
|
java.lang.String |
getAuthType()
|
java.lang.String |
getCharacterEncoding()
|
int |
getContentLength()
|
java.lang.String |
getContentType()
|
java.lang.String |
getContextPath()
|
javax.servlet.http.Cookie[] |
getCookies()
|
long |
getDateHeader(java.lang.String name)
|
java.lang.String |
getHeader(java.lang.String name)
|
java.util.Enumeration |
getHeaderNames()
|
java.util.Enumeration |
getHeaders(java.lang.String name)
|
javax.servlet.ServletInputStream |
getInputStream()
|
int |
getIntHeader(java.lang.String name)
|
java.lang.String |
getLocalAddr()
|
java.util.Locale |
getLocale()
|
java.util.Enumeration |
getLocales()
|
java.lang.String |
getLocalName()
|
int |
getLocalPort()
|
java.lang.String |
getMethod()
|
java.lang.String |
getParameter(java.lang.String name)
|
java.util.Map |
getParameterMap()
|
java.util.Enumeration |
getParameterNames()
|
java.lang.String[] |
getParameterValues(java.lang.String name)
|
java.lang.String |
getPathInfo()
|
java.lang.String |
getPathTranslated()
|
java.lang.String |
getProtocol()
|
java.lang.String |
getQueryString()
|
java.io.BufferedReader |
getReader()
|
java.lang.String |
getRealPath(java.lang.String path)
|
java.lang.String |
getRemoteAddr()
|
java.lang.String |
getRemoteHost()
|
int |
getRemotePort()
|
java.lang.String |
getRemoteUser()
|
javax.servlet.RequestDispatcher |
getRequestDispatcher(java.lang.String path)
|
java.lang.String |
getRequestedSessionId()
|
java.lang.String |
getRequestURI()
|
java.lang.StringBuffer |
getRequestURL()
|
java.lang.String |
getScheme()
|
java.lang.String |
getServerName()
|
int |
getServerPort()
|
java.lang.String |
getServletPath()
|
javax.servlet.http.HttpSession |
getSession()
|
javax.servlet.http.HttpSession |
getSession(boolean create)
|
java.security.Principal |
getUserPrincipal()
|
void |
invalidate()
Invalidate this request, clearing its state. |
boolean |
isActive()
Return whether this request is still active (that is, not completed yet). |
boolean |
isRequestedSessionIdFromCookie()
|
boolean |
isRequestedSessionIdFromUrl()
|
boolean |
isRequestedSessionIdFromURL()
|
boolean |
isRequestedSessionIdValid()
|
boolean |
isSecure()
|
boolean |
isUserInRole(java.lang.String role)
|
void |
removeAttribute(java.lang.String name)
|
void |
removeParameter(java.lang.String name)
Remove already registered values for the specified HTTP parameter, if any. |
void |
setAttribute(java.lang.String name,
java.lang.Object value)
|
void |
setAuthType(java.lang.String authType)
|
void |
setCharacterEncoding(java.lang.String characterEncoding)
|
void |
setContent(byte[] content)
|
void |
setContentType(java.lang.String contentType)
|
void |
setContextPath(java.lang.String contextPath)
|
void |
setCookies(javax.servlet.http.Cookie[] cookies)
|
void |
setLocalAddr(java.lang.String localAddr)
|
void |
setLocalName(java.lang.String localName)
|
void |
setLocalPort(int localPort)
|
void |
setMethod(java.lang.String method)
|
void |
setParameter(java.lang.String name,
java.lang.String value)
Set a single value for the specified HTTP parameter. |
void |
setParameter(java.lang.String name,
java.lang.String[] values)
Set an array of values for the specified HTTP parameter. |
void |
setPathInfo(java.lang.String pathInfo)
|
void |
setProtocol(java.lang.String protocol)
|
void |
setQueryString(java.lang.String queryString)
|
void |
setRemoteAddr(java.lang.String remoteAddr)
|
void |
setRemoteHost(java.lang.String remoteHost)
|
void |
setRemotePort(int remotePort)
|
void |
setRemoteUser(java.lang.String remoteUser)
|
void |
setRequestedSessionIdFromCookie(boolean requestedSessionIdFromCookie)
|
void |
setRequestedSessionIdFromURL(boolean requestedSessionIdFromURL)
|
void |
setRequestedSessionIdValid(boolean requestedSessionIdValid)
|
void |
setRequestURI(java.lang.String requestURI)
|
void |
setScheme(java.lang.String scheme)
|
void |
setSecure(boolean secure)
|
void |
setServerName(java.lang.String serverName)
|
void |
setServerPort(int serverPort)
|
void |
setServletPath(java.lang.String servletPath)
|
void |
setSession(javax.servlet.http.HttpSession session)
|
void |
setUserPrincipal(java.security.Principal userPrincipal)
|
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static final java.lang.String DEFAULT_PROTOCOL
public static final java.lang.String DEFAULT_SERVER_ADDR
public static final java.lang.String DEFAULT_SERVER_NAME
public static final int DEFAULT_SERVER_PORT
public static final java.lang.String DEFAULT_REMOTE_ADDR
public static final java.lang.String DEFAULT_REMOTE_HOST
Constructor Detail |
---|
public MockHttpServletRequest()
MockServletContext
.
MockServletContext
public MockHttpServletRequest(java.lang.String method, java.lang.String requestURI)
MockServletContext
.
method
- the request method (may be null
)requestURI
- the request URI (may be null
)setMethod(java.lang.String)
,
setRequestURI(java.lang.String)
,
MockServletContext
public MockHttpServletRequest(javax.servlet.ServletContext servletContext)
servletContext
- the ServletContext that the request runs in
(may be null
to use a default MockServletContext)MockServletContext
public MockHttpServletRequest(javax.servlet.ServletContext servletContext, java.lang.String method, java.lang.String requestURI)
servletContext
- the ServletContext that the request runs in
(may be null
to use a default MockServletContext)method
- the request method (may be null
)requestURI
- the request URI (may be null
)setMethod(java.lang.String)
,
setRequestURI(java.lang.String)
,
MockServletContext
Method Detail |
---|
public boolean isActive()
public void close()
public void invalidate()
protected void checkActive() throws java.lang.IllegalStateException
java.lang.IllegalStateException
public java.lang.Object getAttribute(java.lang.String name)
getAttribute
in interface javax.servlet.ServletRequest
public java.util.Enumeration getAttributeNames()
getAttributeNames
in interface javax.servlet.ServletRequest
public java.lang.String getCharacterEncoding()
getCharacterEncoding
in interface javax.servlet.ServletRequest
public void setCharacterEncoding(java.lang.String characterEncoding)
setCharacterEncoding
in interface javax.servlet.ServletRequest
public void setContent(byte[] content)
public int getContentLength()
getContentLength
in interface javax.servlet.ServletRequest
public void setContentType(java.lang.String contentType)
public java.lang.String getContentType()
getContentType
in interface javax.servlet.ServletRequest
public javax.servlet.ServletInputStream getInputStream()
getInputStream
in interface javax.servlet.ServletRequest
public void setParameter(java.lang.String name, java.lang.String value)
If there are already one or more values registered for the given parameter name, they will be replaced.
public void setParameter(java.lang.String name, java.lang.String[] values)
If there are already one or more values registered for the given parameter name, they will be replaced.
public void addParameter(java.lang.String name, java.lang.String value)
If there are already one or more values registered for the given parameter name, the given value will be added to the end of the list.
public void addParameter(java.lang.String name, java.lang.String[] values)
If there are already one or more values registered for the given parameter name, the given values will be added to the end of the list.
public void removeParameter(java.lang.String name)
public java.lang.String getParameter(java.lang.String name)
getParameter
in interface javax.servlet.ServletRequest
public java.util.Enumeration getParameterNames()
getParameterNames
in interface javax.servlet.ServletRequest
public java.lang.String[] getParameterValues(java.lang.String name)
getParameterValues
in interface javax.servlet.ServletRequest
public java.util.Map getParameterMap()
getParameterMap
in interface javax.servlet.ServletRequest
public void setProtocol(java.lang.String protocol)
public java.lang.String getProtocol()
getProtocol
in interface javax.servlet.ServletRequest
public void setScheme(java.lang.String scheme)
public java.lang.String getScheme()
getScheme
in interface javax.servlet.ServletRequest
public void setServerName(java.lang.String serverName)
public java.lang.String getServerName()
getServerName
in interface javax.servlet.ServletRequest
public void setServerPort(int serverPort)
public int getServerPort()
getServerPort
in interface javax.servlet.ServletRequest
public java.io.BufferedReader getReader() throws java.io.UnsupportedEncodingException
getReader
in interface javax.servlet.ServletRequest
java.io.UnsupportedEncodingException
public void setRemoteAddr(java.lang.String remoteAddr)
public java.lang.String getRemoteAddr()
getRemoteAddr
in interface javax.servlet.ServletRequest
public void setRemoteHost(java.lang.String remoteHost)
public java.lang.String getRemoteHost()
getRemoteHost
in interface javax.servlet.ServletRequest
public void setAttribute(java.lang.String name, java.lang.Object value)
setAttribute
in interface javax.servlet.ServletRequest
public void removeAttribute(java.lang.String name)
removeAttribute
in interface javax.servlet.ServletRequest
public void clearAttributes()
public void addPreferredLocale(java.util.Locale locale)
public java.util.Locale getLocale()
getLocale
in interface javax.servlet.ServletRequest
public java.util.Enumeration getLocales()
getLocales
in interface javax.servlet.ServletRequest
public void setSecure(boolean secure)
public boolean isSecure()
isSecure
in interface javax.servlet.ServletRequest
public javax.servlet.RequestDispatcher getRequestDispatcher(java.lang.String path)
getRequestDispatcher
in interface javax.servlet.ServletRequest
public java.lang.String getRealPath(java.lang.String path)
getRealPath
in interface javax.servlet.ServletRequest
public void setRemotePort(int remotePort)
public int getRemotePort()
getRemotePort
in interface javax.servlet.ServletRequest
public void setLocalName(java.lang.String localName)
public java.lang.String getLocalName()
getLocalName
in interface javax.servlet.ServletRequest
public void setLocalAddr(java.lang.String localAddr)
public java.lang.String getLocalAddr()
getLocalAddr
in interface javax.servlet.ServletRequest
public void setLocalPort(int localPort)
public int getLocalPort()
getLocalPort
in interface javax.servlet.ServletRequest
public void setAuthType(java.lang.String authType)
public java.lang.String getAuthType()
getAuthType
in interface javax.servlet.http.HttpServletRequest
public void setCookies(javax.servlet.http.Cookie[] cookies)
public javax.servlet.http.Cookie[] getCookies()
getCookies
in interface javax.servlet.http.HttpServletRequest
public void addHeader(java.lang.String name, java.lang.Object value)
If there was no entry for that header name before, the value will be used as-is. In case of an existing entry, a String array will be created, adding the given value (more specifically, its toString representation) as further element.
Multiple values can only be stored as list of Strings,
following the Servlet spec (see getHeaders
accessor).
As alternative to repeated addHeader
calls for
individual elements, you can use a single call with an entire
array or Collection of values as parameter.
getHeaderNames()
,
getHeader(java.lang.String)
,
getHeaders(java.lang.String)
,
getDateHeader(java.lang.String)
,
getIntHeader(java.lang.String)
public long getDateHeader(java.lang.String name)
getDateHeader
in interface javax.servlet.http.HttpServletRequest
public java.lang.String getHeader(java.lang.String name)
getHeader
in interface javax.servlet.http.HttpServletRequest
public java.util.Enumeration getHeaders(java.lang.String name)
getHeaders
in interface javax.servlet.http.HttpServletRequest
public java.util.Enumeration getHeaderNames()
getHeaderNames
in interface javax.servlet.http.HttpServletRequest
public int getIntHeader(java.lang.String name)
getIntHeader
in interface javax.servlet.http.HttpServletRequest
public void setMethod(java.lang.String method)
public java.lang.String getMethod()
getMethod
in interface javax.servlet.http.HttpServletRequest
public void setPathInfo(java.lang.String pathInfo)
public java.lang.String getPathInfo()
getPathInfo
in interface javax.servlet.http.HttpServletRequest
public java.lang.String getPathTranslated()
getPathTranslated
in interface javax.servlet.http.HttpServletRequest
public void setContextPath(java.lang.String contextPath)
public java.lang.String getContextPath()
getContextPath
in interface javax.servlet.http.HttpServletRequest
public void setQueryString(java.lang.String queryString)
public java.lang.String getQueryString()
getQueryString
in interface javax.servlet.http.HttpServletRequest
public void setRemoteUser(java.lang.String remoteUser)
public java.lang.String getRemoteUser()
getRemoteUser
in interface javax.servlet.http.HttpServletRequest
public void addRole(java.lang.String role)
addUserRole(java.lang.String)
public void addUserRole(java.lang.String role)
public boolean isUserInRole(java.lang.String role)
isUserInRole
in interface javax.servlet.http.HttpServletRequest
public void setUserPrincipal(java.security.Principal userPrincipal)
public java.security.Principal getUserPrincipal()
getUserPrincipal
in interface javax.servlet.http.HttpServletRequest
public java.lang.String getRequestedSessionId()
getRequestedSessionId
in interface javax.servlet.http.HttpServletRequest
public void setRequestURI(java.lang.String requestURI)
public java.lang.String getRequestURI()
getRequestURI
in interface javax.servlet.http.HttpServletRequest
public java.lang.StringBuffer getRequestURL()
getRequestURL
in interface javax.servlet.http.HttpServletRequest
public void setServletPath(java.lang.String servletPath)
public java.lang.String getServletPath()
getServletPath
in interface javax.servlet.http.HttpServletRequest
public void setSession(javax.servlet.http.HttpSession session)
public javax.servlet.http.HttpSession getSession(boolean create)
getSession
in interface javax.servlet.http.HttpServletRequest
public javax.servlet.http.HttpSession getSession()
getSession
in interface javax.servlet.http.HttpServletRequest
public void setRequestedSessionIdValid(boolean requestedSessionIdValid)
public boolean isRequestedSessionIdValid()
isRequestedSessionIdValid
in interface javax.servlet.http.HttpServletRequest
public void setRequestedSessionIdFromCookie(boolean requestedSessionIdFromCookie)
public boolean isRequestedSessionIdFromCookie()
isRequestedSessionIdFromCookie
in interface javax.servlet.http.HttpServletRequest
public void setRequestedSessionIdFromURL(boolean requestedSessionIdFromURL)
public boolean isRequestedSessionIdFromURL()
isRequestedSessionIdFromURL
in interface javax.servlet.http.HttpServletRequest
public boolean isRequestedSessionIdFromUrl()
isRequestedSessionIdFromUrl
in interface javax.servlet.http.HttpServletRequest
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |