public class MockHttpServletRequest extends Object implements javax.servlet.http.HttpServletRequest
Mock implementation of HttpServletContext
.
Constructor and Description |
---|
MockHttpServletRequest() |
MockHttpServletRequest(javax.servlet.http.HttpSession session) |
MockHttpServletRequest(String contextPath,
String servletPath,
String pathInfo,
String queryString) |
MockHttpServletRequest(String contextPath,
String servletPath,
String pathInfo,
String queryString,
javax.servlet.http.HttpSession session) |
Modifier and Type | Method and Description |
---|---|
void |
addAttributeListener(javax.servlet.ServletRequestAttributeListener listener)
Add a new listener instance that should be notified about
attribute changes.
|
void |
addDateHeader(String name,
long value)
Add a date-valued header for this request.
|
void |
addHeader(String name,
String value)
Add a String-valued header for this request.
|
void |
addIntHeader(String name,
int value)
Add an integer-valued header for this request.
|
void |
addParameter(String name,
String value)
Add a request parameter for this request.
|
Object |
getAttribute(String name) |
Enumeration |
getAttributeNames() |
String |
getAuthType() |
String |
getCharacterEncoding() |
int |
getContentLength() |
String |
getContentType() |
String |
getContextPath() |
javax.servlet.http.Cookie[] |
getCookies() |
long |
getDateHeader(String name) |
String |
getHeader(String name) |
Enumeration |
getHeaderNames() |
Enumeration |
getHeaders(String name) |
javax.servlet.ServletInputStream |
getInputStream() |
int |
getIntHeader(String name) |
String |
getLocalAddr() |
Locale |
getLocale() |
Enumeration |
getLocales() |
String |
getLocalName() |
int |
getLocalPort() |
String |
getMethod() |
String |
getParameter(String name) |
Map |
getParameterMap() |
Enumeration |
getParameterNames() |
String[] |
getParameterValues(String name) |
String |
getPathInfo() |
String |
getPathTranslated() |
String |
getProtocol() |
String |
getQueryString() |
BufferedReader |
getReader() |
String |
getRealPath(String path) |
String |
getRemoteAddr() |
String |
getRemoteHost() |
int |
getRemotePort() |
String |
getRemoteUser() |
javax.servlet.RequestDispatcher |
getRequestDispatcher(String path) |
String |
getRequestedSessionId() |
String |
getRequestURI() |
StringBuffer |
getRequestURL() |
String |
getScheme() |
String |
getServerName() |
int |
getServerPort() |
javax.servlet.ServletContext |
getServletContext()
Return the
ServletContext associated with
this request. |
String |
getServletPath() |
javax.servlet.http.HttpSession |
getSession() |
javax.servlet.http.HttpSession |
getSession(boolean create) |
Principal |
getUserPrincipal() |
boolean |
isRequestedSessionIdFromCookie() |
boolean |
isRequestedSessionIdFromUrl() |
boolean |
isRequestedSessionIdFromURL() |
boolean |
isRequestedSessionIdValid() |
boolean |
isSecure() |
boolean |
isUserInRole(String role) |
void |
removeAttribute(String name) |
void |
setAttribute(String name,
Object value) |
void |
setCharacterEncoding(String name) |
void |
setHttpSession(javax.servlet.http.HttpSession session)
Set the
HttpSession associated with this request. |
void |
setLocale(Locale locale)
Set the
Locale associated with this request. |
void |
setPathElements(String contextPath,
String servletPath,
String pathInfo,
String queryString)
Set the parsed path elements associated with this request.
|
void |
setServletContext(javax.servlet.ServletContext servletContext)
Set the
ServletContext associated with this request. |
void |
setUserPrincipal(Principal principal)
Set the
Principal associated with this request. |
public MockHttpServletRequest()
public MockHttpServletRequest(javax.servlet.http.HttpSession session)
public MockHttpServletRequest(String contextPath, String servletPath, String pathInfo, String queryString)
public void addAttributeListener(javax.servlet.ServletRequestAttributeListener listener)
Add a new listener instance that should be notified about attribute changes.
listener
- The new listener to registerpublic void addDateHeader(String name, long value)
Add a date-valued header for this request.
name
- Header namevalue
- Header valuepublic void addHeader(String name, String value)
Add a String-valued header for this request.
name
- Header namevalue
- Header valuepublic void addIntHeader(String name, int value)
Add an integer-valued header for this request.
name
- Header namevalue
- Header valuepublic void addParameter(String name, String value)
Add a request parameter for this request.
name
- Parameter namevalue
- Parameter valuepublic javax.servlet.ServletContext getServletContext()
Return the ServletContext
associated with
this request.
public void setHttpSession(javax.servlet.http.HttpSession session)
Set the HttpSession
associated with this request.
session
- The new sessionpublic void setLocale(Locale locale)
Set the Locale
associated with this request.
locale
- The new localepublic void setPathElements(String contextPath, String servletPath, String pathInfo, String queryString)
Set the parsed path elements associated with this request.
contextPath
- The context pathservletPath
- The servlet pathpathInfo
- The extra path informationqueryString
- The query stringpublic void setServletContext(javax.servlet.ServletContext servletContext)
Set the ServletContext
associated with this request.
servletContext
- The new servlet contextpublic void setUserPrincipal(Principal principal)
Set the Principal
associated with this request.
principal
- The new Principalpublic String getAuthType()
getAuthType
in interface javax.servlet.http.HttpServletRequest
public String getContextPath()
getContextPath
in interface javax.servlet.http.HttpServletRequest
public javax.servlet.http.Cookie[] getCookies()
getCookies
in interface javax.servlet.http.HttpServletRequest
public long getDateHeader(String name)
getDateHeader
in interface javax.servlet.http.HttpServletRequest
public String getHeader(String name)
getHeader
in interface javax.servlet.http.HttpServletRequest
public Enumeration getHeaderNames()
getHeaderNames
in interface javax.servlet.http.HttpServletRequest
public Enumeration getHeaders(String name)
getHeaders
in interface javax.servlet.http.HttpServletRequest
public int getIntHeader(String name)
getIntHeader
in interface javax.servlet.http.HttpServletRequest
public String getMethod()
getMethod
in interface javax.servlet.http.HttpServletRequest
public String getPathInfo()
getPathInfo
in interface javax.servlet.http.HttpServletRequest
public String getPathTranslated()
getPathTranslated
in interface javax.servlet.http.HttpServletRequest
public String getQueryString()
getQueryString
in interface javax.servlet.http.HttpServletRequest
public String getRemoteUser()
getRemoteUser
in interface javax.servlet.http.HttpServletRequest
public String getRequestedSessionId()
getRequestedSessionId
in interface javax.servlet.http.HttpServletRequest
public String getRequestURI()
getRequestURI
in interface javax.servlet.http.HttpServletRequest
public StringBuffer getRequestURL()
getRequestURL
in interface javax.servlet.http.HttpServletRequest
public String getServletPath()
getServletPath
in interface javax.servlet.http.HttpServletRequest
public javax.servlet.http.HttpSession getSession()
getSession
in interface javax.servlet.http.HttpServletRequest
public javax.servlet.http.HttpSession getSession(boolean create)
getSession
in interface javax.servlet.http.HttpServletRequest
public Principal getUserPrincipal()
getUserPrincipal
in interface javax.servlet.http.HttpServletRequest
public boolean isRequestedSessionIdFromCookie()
isRequestedSessionIdFromCookie
in interface javax.servlet.http.HttpServletRequest
public boolean isRequestedSessionIdFromUrl()
isRequestedSessionIdFromUrl
in interface javax.servlet.http.HttpServletRequest
public boolean isRequestedSessionIdFromURL()
isRequestedSessionIdFromURL
in interface javax.servlet.http.HttpServletRequest
public boolean isRequestedSessionIdValid()
isRequestedSessionIdValid
in interface javax.servlet.http.HttpServletRequest
public boolean isUserInRole(String role)
isUserInRole
in interface javax.servlet.http.HttpServletRequest
public Object getAttribute(String name)
getAttribute
in interface javax.servlet.ServletRequest
public Enumeration getAttributeNames()
getAttributeNames
in interface javax.servlet.ServletRequest
public String getCharacterEncoding()
getCharacterEncoding
in interface javax.servlet.ServletRequest
public int getContentLength()
getContentLength
in interface javax.servlet.ServletRequest
public String getContentType()
getContentType
in interface javax.servlet.ServletRequest
public javax.servlet.ServletInputStream getInputStream()
getInputStream
in interface javax.servlet.ServletRequest
public Locale getLocale()
getLocale
in interface javax.servlet.ServletRequest
public Enumeration getLocales()
getLocales
in interface javax.servlet.ServletRequest
public String getLocalAddr()
getLocalAddr
in interface javax.servlet.ServletRequest
public String getLocalName()
getLocalName
in interface javax.servlet.ServletRequest
public int getLocalPort()
getLocalPort
in interface javax.servlet.ServletRequest
public String getParameter(String name)
getParameter
in interface javax.servlet.ServletRequest
public Map getParameterMap()
getParameterMap
in interface javax.servlet.ServletRequest
public Enumeration getParameterNames()
getParameterNames
in interface javax.servlet.ServletRequest
public String[] getParameterValues(String name)
getParameterValues
in interface javax.servlet.ServletRequest
public String getProtocol()
getProtocol
in interface javax.servlet.ServletRequest
public BufferedReader getReader()
getReader
in interface javax.servlet.ServletRequest
public String getRealPath(String path)
getRealPath
in interface javax.servlet.ServletRequest
public String getRemoteAddr()
getRemoteAddr
in interface javax.servlet.ServletRequest
public String getRemoteHost()
getRemoteHost
in interface javax.servlet.ServletRequest
public int getRemotePort()
getRemotePort
in interface javax.servlet.ServletRequest
public javax.servlet.RequestDispatcher getRequestDispatcher(String path)
getRequestDispatcher
in interface javax.servlet.ServletRequest
public String getScheme()
getScheme
in interface javax.servlet.ServletRequest
public String getServerName()
getServerName
in interface javax.servlet.ServletRequest
public int getServerPort()
getServerPort
in interface javax.servlet.ServletRequest
public boolean isSecure()
isSecure
in interface javax.servlet.ServletRequest
public void removeAttribute(String name)
removeAttribute
in interface javax.servlet.ServletRequest
public void setAttribute(String name, Object value)
setAttribute
in interface javax.servlet.ServletRequest
public void setCharacterEncoding(String name)
setCharacterEncoding
in interface javax.servlet.ServletRequest
Copyright © 2004-2013 Apache Software Foundation. All Rights Reserved.