public class FakeHttpServletRequest extends Object implements javax.servlet.http.HttpServletRequest
To use this class, you specify the request info (URL, parameters) in the constructors.
Lots of stuff are still not implemented here. Feel free to implement them.
| Modifier and Type | Field and Description |
|---|---|
protected Map<String,Object> |
attributes |
protected String |
characterEncoding |
protected String |
contentType |
protected String |
contextPath |
protected Map<String,javax.servlet.http.Cookie> |
cookies |
protected static String |
DEFAULT_HOST |
protected static int |
DEFAULT_PORT |
protected boolean |
getInputStreamCalled |
protected boolean |
getReaderCalled |
protected Hashtable<String,String> |
headers |
protected String |
host |
protected String |
ip |
protected Locale |
locale |
protected List<Locale> |
locales |
protected String |
method |
protected Map<String,String[]> |
parameters |
protected String |
pathInfo |
protected int |
port |
protected byte[] |
postData |
protected Set<String> |
postParameters |
protected String |
protocol |
protected String |
queryString |
protected String |
scheme |
protected boolean |
secure |
protected String |
servletPath |
| Constructor and Description |
|---|
FakeHttpServletRequest() |
FakeHttpServletRequest(String urlStr) |
FakeHttpServletRequest(String host,
int port,
String contextPath,
String servletPath,
String queryString)
Example: http://www.example.com:1234/foo/bar?abc=xyz "www.example.com" is
the host 1234 is the port "/foo" is the contextPath "/bar" is the
servletPath "abc=xyz" is the queryString
|
FakeHttpServletRequest(String contextPath,
String servletPath,
String queryString) |
FakeHttpServletRequest(String host,
String port,
String contextPath,
String servletPath,
String queryString) |
protected static final String DEFAULT_HOST
protected static final int DEFAULT_PORT
protected String scheme
protected String host
protected int port
protected boolean secure
protected String method
protected String protocol
protected String contextPath
protected String servletPath
protected String pathInfo
protected String queryString
protected String ip
protected String contentType
protected Locale locale
protected byte[] postData
protected String characterEncoding
protected boolean getReaderCalled
protected boolean getInputStreamCalled
public FakeHttpServletRequest(String host, int port, String contextPath, String servletPath, String queryString)
public FakeHttpServletRequest(String host, String port, String contextPath, String servletPath, String queryString)
public FakeHttpServletRequest(String contextPath, String servletPath, String queryString)
public FakeHttpServletRequest()
public FakeHttpServletRequest(String urlStr) throws MalformedURLException
MalformedURLExceptionpublic FakeHttpServletRequest setLocale(Locale locale)
public FakeHttpServletRequest setLocales(List<Locale> locales)
public FakeHttpServletRequest setProtocol(String prot)
public FakeHttpServletRequest setSecure(boolean secure)
public FakeHttpServletRequest setHeader(String name, String value)
public FakeHttpServletRequest setCookies(javax.servlet.http.Cookie... cookies)
cookies - the cookies associated with this request.public FakeHttpServletRequest setCookie(javax.servlet.http.Cookie c)
c - the cookie to associate with this request.public FakeHttpServletRequest setParameter(String name, boolean isPost, String... values)
name - the string keyvalues - the string array valueisPost - if the paramenter comes in the post body.public FakeHttpServletRequest setParameter(String name, String... values)
name - the string keyvalues - the string array valuepublic FakeHttpServletRequest setPathInfo(String path)
public FakeHttpServletRequest setPostData(String postString, String encoding) throws UnsupportedEncodingException
postString - the mock post dataencoding - format with which to encode mock post dataUnsupportedEncodingExceptionpublic FakeHttpServletRequest setPostData(byte[] data)
data - the mock post data; this is owned by the caller, so
modifications made after this call will show up when the post data
is readpublic FakeHttpServletRequest setQueryString(String queryString)
queryString - representing the new value. i.e.: "bug=1&id=23"public FakeHttpServletRequest setSession(javax.servlet.http.HttpSession session)
session - the new sessionpublic FakeHttpServletRequest setContentType(String contentType)
contentType - of the request.public String getAuthType()
getAuthType in interface javax.servlet.http.HttpServletRequestpublic String getContextPath()
getContextPath in interface javax.servlet.http.HttpServletRequestpublic javax.servlet.http.Cookie[] getCookies()
getCookies in interface javax.servlet.http.HttpServletRequestpublic long getDateHeader(String name)
getDateHeader in interface javax.servlet.http.HttpServletRequestpublic FakeHttpServletRequest setDateHeader(String name, long value)
public String getHeader(String name)
getHeader in interface javax.servlet.http.HttpServletRequestpublic Enumeration<String> getHeaderNames()
getHeaderNames in interface javax.servlet.http.HttpServletRequestpublic Enumeration<?> getHeaders(String name)
getHeaders in interface javax.servlet.http.HttpServletRequestpublic int getIntHeader(String name)
getIntHeader in interface javax.servlet.http.HttpServletRequestpublic String getMethod()
getMethod in interface javax.servlet.http.HttpServletRequestpublic FakeHttpServletRequest setMethod(String method)
public String getPathInfo()
getPathInfo in interface javax.servlet.http.HttpServletRequestpublic String getPathTranslated()
getPathTranslated in interface javax.servlet.http.HttpServletRequestpublic String getQueryString()
getQueryString in interface javax.servlet.http.HttpServletRequestpublic String getRemoteUser()
getRemoteUser in interface javax.servlet.http.HttpServletRequestpublic String getRequestedSessionId()
getRequestedSessionId in interface javax.servlet.http.HttpServletRequestpublic String getRequestURI()
getRequestURI in interface javax.servlet.http.HttpServletRequestpublic StringBuffer getRequestURL()
getRequestURL in interface javax.servlet.http.HttpServletRequestpublic String getServletPath()
getServletPath in interface javax.servlet.http.HttpServletRequestpublic FakeHttpServletRequest setServletPath(String servletPath)
public javax.servlet.http.HttpSession getSession()
getSession in interface javax.servlet.http.HttpServletRequestpublic javax.servlet.http.HttpSession getSession(boolean create)
getSession in interface javax.servlet.http.HttpServletRequestpublic Principal getUserPrincipal()
getUserPrincipal in interface javax.servlet.http.HttpServletRequestpublic boolean isRequestedSessionIdFromCookie()
isRequestedSessionIdFromCookie in interface javax.servlet.http.HttpServletRequest@Deprecated public boolean isRequestedSessionIdFromUrl()
isRequestedSessionIdFromUrl in interface javax.servlet.http.HttpServletRequestpublic boolean isRequestedSessionIdFromURL()
isRequestedSessionIdFromURL in interface javax.servlet.http.HttpServletRequestpublic boolean isRequestedSessionIdValid()
isRequestedSessionIdValid in interface javax.servlet.http.HttpServletRequestpublic boolean isUserInRole(String role)
isUserInRole in interface javax.servlet.http.HttpServletRequestpublic Object getAttribute(String name)
getAttribute in interface javax.servlet.ServletRequestpublic Enumeration<?> getAttributeNames()
getAttributeNames in interface javax.servlet.ServletRequestpublic String getCharacterEncoding()
getCharacterEncoding in interface javax.servlet.ServletRequestpublic int getContentLength()
getContentLength in interface javax.servlet.ServletRequestpublic String getContentType()
getContentType in interface javax.servlet.ServletRequestpublic javax.servlet.ServletInputStream getInputStream()
getInputStream in interface javax.servlet.ServletRequestpublic Locale getLocale()
getLocale in interface javax.servlet.ServletRequestpublic Enumeration<?> getLocales()
getLocales in interface javax.servlet.ServletRequestpublic String getParameter(String name)
getParameter in interface javax.servlet.ServletRequestpublic Map<String,String[]> getParameterMap()
getParameterMap in interface javax.servlet.ServletRequestpublic Enumeration<String> getParameterNames()
getParameterNames in interface javax.servlet.ServletRequestpublic String[] getParameterValues(String name)
getParameterValues in interface javax.servlet.ServletRequestpublic String getProtocol()
getProtocol in interface javax.servlet.ServletRequestpublic BufferedReader getReader() throws IOException
getReader in interface javax.servlet.ServletRequestIOException@Deprecated public String getRealPath(String path)
getRealPath in interface javax.servlet.ServletRequestpublic String getRemoteAddr()
getRemoteAddr in interface javax.servlet.ServletRequestpublic FakeHttpServletRequest setRemoteAddr(String ip)
FakeHttpServletRequest.ip - the IP to setFakeHttpServletRequest objectpublic String getRemoteHost()
getRemoteHost in interface javax.servlet.ServletRequestpublic int getLocalPort()
getLocalPort in interface javax.servlet.ServletRequestpublic String getLocalAddr()
getLocalAddr in interface javax.servlet.ServletRequestpublic String getLocalName()
getLocalName in interface javax.servlet.ServletRequestpublic int getRemotePort()
getRemotePort in interface javax.servlet.ServletRequestpublic javax.servlet.RequestDispatcher getRequestDispatcher(String path)
getRequestDispatcher in interface javax.servlet.ServletRequestpublic String getScheme()
getScheme in interface javax.servlet.ServletRequestpublic String getServerName()
getServerName in interface javax.servlet.ServletRequestpublic int getServerPort()
getServerPort in interface javax.servlet.ServletRequestpublic boolean isSecure()
isSecure in interface javax.servlet.ServletRequestpublic void removeAttribute(String name)
removeAttribute in interface javax.servlet.ServletRequestpublic void setAttribute(String name, Object value)
setAttribute in interface javax.servlet.ServletRequestpublic void setCharacterEncoding(String env)
setCharacterEncoding in interface javax.servlet.ServletRequestprotected void constructor(String host, int port, String contextPath, String servletPath, String queryString)
public FakeHttpServletRequest(String foo) {
// Do something here
this(foo, bar); // calling another constructor here is not allowed
}
protected void decodeQueryString(String queryString, Map<String,String[]> parameters)
Copyright © 2007-2014 The Apache Software Foundation. All Rights Reserved.