public class EntityHttpServletRequest extends Object implements javax.servlet.http.HttpServletRequest
| Modifier and Type | Class and Description |
|---|---|
static class |
EntityHttpServletRequest.EntityHttpSession
A fake session for testing, from the spring mock session
|
static class |
EntityHttpServletRequest.EntityRequestDispatcher
A non-functional request dispatcher, based on the spring mock version
|
static class |
EntityHttpServletRequest.EntityServletContext
For testing, based on the spring Mock version
|
| Modifier and Type | Field and Description |
|---|---|
javax.servlet.http.HttpServletRequest |
copy |
static String |
DEFAULT_PROTOCOL
default protocol: HTTP/1.0
|
static String |
DEFAULT_REMOTE_ADDR
default remote address: 127.0.0.1
|
static String |
DEFAULT_REMOTE_HOST
The default remote host: 'localhost'.
|
static String |
DEFAULT_SCHEMA
default schema: http
|
static String |
DEFAULT_SERVER_ADDR
default server address: 127.0.0.1
|
static String |
DEFAULT_SERVER_NAME
default server name: localhost
|
static int |
DEFAULT_SERVER_PORT
default server port: 80
|
Map<String,String[]> |
pathQueryParams
This stores all the query params found when the request was created
|
| Constructor and Description |
|---|
EntityHttpServletRequest(javax.servlet.http.HttpServletRequest req)
Create a new request from a given request
|
EntityHttpServletRequest(javax.servlet.http.HttpServletRequest req,
String pathString)
Create a new request from a given request and modify it based on the path string
|
EntityHttpServletRequest(javax.servlet.http.HttpServletRequest req,
String method,
String pathString)
Create a new request from a given request and modify it based on the path string and method
|
EntityHttpServletRequest(String pathString)
Create a request using the pathString
|
EntityHttpServletRequest(String method,
String pathString)
Create a request using the pathString and setting the method
|
EntityHttpServletRequest(String method,
String pathString,
String... params)
Create a request using the pathString and setting the method and params
|
| Modifier and Type | Method and Description |
|---|---|
void |
addCookie(javax.servlet.http.Cookie cookie)
Adds a new cookie to the request
|
void |
addHeader(String name,
String... content) |
void |
addParameter(String name,
String value)
Add a single parameter,
this will append to an existing one
|
void |
addParameter(String name,
String[] values)
Add an array of values for a parameter,
these will append to existing ones
|
void |
clearAttributes()
Remove all attributes
|
void |
clearCookies()
Remove all cookies
|
void |
clearHeaders()
Remove all headers
|
void |
clearParameters()
Remove all parameters
|
Object |
getAttribute(String name) |
Enumeration |
getAttributeNames() |
String |
getAuthType() |
String |
getCharacterEncoding() |
javax.servlet.ServletInputStream |
getContent()
Gets the content data out of the request, ensures that the data can be retrieved somehow
|
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() |
Map<String,String[]> |
getParameters() |
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() |
String |
getServletPath() |
javax.servlet.http.HttpSession |
getSession() |
javax.servlet.http.HttpSession |
getSession(boolean create) |
Map<String,String> |
getStringParameters() |
Principal |
getUserPrincipal() |
boolean |
isRequestedSessionIdFromCookie() |
boolean |
isRequestedSessionIdFromUrl() |
boolean |
isRequestedSessionIdFromURL() |
boolean |
isRequestedSessionIdValid() |
boolean |
isSecure() |
boolean |
isUserInRole(String role) |
void |
removeAttribute(String name) |
void |
removeCookie(String name)
Removes the cookie with the given name from the request
|
void |
removeHeader(String name) |
void |
removeParameter(String name)
Removes a parameter and all values for it
|
void |
setAttribute(String name,
Object o) |
void |
setCharacterEncoding(String env) |
void |
setContent(byte[] content)
Allows control over the content data which is used in this request,
all data should be UTF-8 encoded
|
void |
setContent(InputStream contentStream,
int contentLength)
Allows control over the content data which is used in this request,
all data should be UTF-8 encoded
|
void |
setContent(String content)
Allows control over the content data which is used in this request,
all data should be UTF-8 encoded
|
void |
setContentType(String contentType)
Sets the content type for this request content
|
void |
setContextPath(String contextPath) |
void |
setLocale(Locale locale) |
void |
setMethod(String method) |
void |
setParameter(String name,
String[] values)
Set a new parameter (overwrite an existing one)
|
void |
setParameters(Map<String,String[]> params)
Set a large number of params at once,
replaces existing params
|
void |
setPathInfo(String pathInfo) |
URLData |
setPathString(String pathString)
This will set the given url/path string values into this request,
this will override any values that are currently set
|
void |
setQueryString(String queryString) |
void |
setRequestValues(javax.servlet.http.HttpServletRequest req)
Set all the values from a request on this request object and set this request
as the one which the values were copied from
|
void |
setServletPath(String servletPath) |
void |
setUseRealDispatcher(boolean real) |
String |
toString() |
public static final String DEFAULT_SCHEMA
public static final String DEFAULT_PROTOCOL
public static final String DEFAULT_SERVER_ADDR
public static final String DEFAULT_SERVER_NAME
public static final int DEFAULT_SERVER_PORT
public static final String DEFAULT_REMOTE_ADDR
public static final String DEFAULT_REMOTE_HOST
public javax.servlet.http.HttpServletRequest copy
public EntityHttpServletRequest(javax.servlet.http.HttpServletRequest req)
req - any requestpublic EntityHttpServletRequest(javax.servlet.http.HttpServletRequest req,
String pathString)
req - any requestpathString - any full path or URL (/direct/prefix/id.xml)public EntityHttpServletRequest(javax.servlet.http.HttpServletRequest req,
String method,
String pathString)
req - any requestmethod - GET, POST, PUT, DELETE (PUT and DELETE not supported by browsers),
this will be set to POST if null or unsetpathString - any full path or URL (/direct/prefix/id.xml)public EntityHttpServletRequest(String pathString)
pathString - any path or URLpublic EntityHttpServletRequest(String method, String pathString)
pathString - any path or URLmethod - GET, POST, PUT, DELETE (PUT and DELETE not supported by browsers),
this will be set to POST if null or unsetpublic EntityHttpServletRequest(String method, String pathString, String... params)
method - GET, POST, PUT, DELETE (PUT and DELETE not supported by browsers),
this will be set to POST if null or unsetpathString - any path or URLparams - alternating keys and values (starting with keys) to place into the request parameterspublic void setRequestValues(javax.servlet.http.HttpServletRequest req)
req - any requestpublic URLData setPathString(String pathString)
pathString - any url or path stringpublic void setContent(InputStream contentStream, int contentLength)
content - any IS content, UTF-8 encoded, replaces existing contentpublic void setContent(byte[] content)
content - any byte[] content, UTF-8 encoded, replaces existing contentpublic void setContent(String content)
content - any string content, UTF-8 encoded, replaces existing contentpublic javax.servlet.ServletInputStream getContent()
throws IOException
IOException - if there is a failurepublic Object getAttribute(String name)
getAttribute in interface javax.servlet.ServletRequestpublic Enumeration getAttributeNames()
getAttributeNames in interface javax.servlet.ServletRequestpublic void removeAttribute(String name)
removeAttribute in interface javax.servlet.ServletRequestpublic void setAttribute(String name, Object o)
setAttribute in interface javax.servlet.ServletRequestpublic void clearAttributes()
public void setCharacterEncoding(String env) throws UnsupportedEncodingException
setCharacterEncoding in interface javax.servlet.ServletRequestUnsupportedEncodingExceptionpublic String getCharacterEncoding()
getCharacterEncoding in interface javax.servlet.ServletRequestpublic void setContentType(String contentType)
contentType - public String getContentType()
getContentType in interface javax.servlet.ServletRequestpublic int getContentLength()
getContentLength in interface javax.servlet.ServletRequestpublic javax.servlet.ServletInputStream getInputStream()
throws IOException
getInputStream in interface javax.servlet.ServletRequestIOExceptionpublic BufferedReader getReader() throws IOException
getReader in interface javax.servlet.ServletRequestIOExceptionpublic void setLocale(Locale locale)
public Locale getLocale()
getLocale in interface javax.servlet.ServletRequestpublic void setMethod(String method)
public String getMethod()
getMethod in interface javax.servlet.http.HttpServletRequestpublic void setContextPath(String contextPath)
public String getContextPath()
getContextPath in interface javax.servlet.http.HttpServletRequestpublic void setPathInfo(String pathInfo)
public String getPathInfo()
getPathInfo in interface javax.servlet.http.HttpServletRequestpublic String getPathTranslated()
getPathTranslated in interface javax.servlet.http.HttpServletRequestpublic void setQueryString(String queryString)
public String getQueryString()
getQueryString in interface javax.servlet.http.HttpServletRequestpublic String getRequestURI()
getRequestURI in interface javax.servlet.http.HttpServletRequestpublic StringBuffer getRequestURL()
getRequestURL in interface javax.servlet.http.HttpServletRequestpublic void setServletPath(String servletPath)
public String getServletPath()
getServletPath in interface javax.servlet.http.HttpServletRequestpublic void addCookie(javax.servlet.http.Cookie cookie)
cookie - a cookie to add, will displace existing cookies with the same namepublic void removeCookie(String name)
name - the name of a cookiepublic javax.servlet.http.Cookie[] getCookies()
getCookies in interface javax.servlet.http.HttpServletRequestpublic void clearCookies()
public void removeHeader(String name)
public String getHeader(String name)
getHeader in interface javax.servlet.http.HttpServletRequestpublic Enumeration getHeaderNames()
getHeaderNames in interface javax.servlet.http.HttpServletRequestpublic Enumeration getHeaders(String name)
getHeaders in interface javax.servlet.http.HttpServletRequestpublic long getDateHeader(String name)
getDateHeader in interface javax.servlet.http.HttpServletRequestpublic int getIntHeader(String name)
getIntHeader in interface javax.servlet.http.HttpServletRequestpublic void clearHeaders()
public String getAuthType()
getAuthType in interface javax.servlet.http.HttpServletRequestpublic String getLocalAddr()
getLocalAddr in interface javax.servlet.ServletRequestpublic Enumeration getLocales()
getLocales in interface javax.servlet.ServletRequestpublic String getLocalName()
getLocalName in interface javax.servlet.ServletRequestpublic int getLocalPort()
getLocalPort in interface javax.servlet.ServletRequestpublic Map<String,String> getStringParameters()
public String getParameter(String name)
getParameter in interface javax.servlet.ServletRequestpublic Map getParameterMap()
getParameterMap in interface javax.servlet.ServletRequestpublic Enumeration getParameterNames()
getParameterNames in interface javax.servlet.ServletRequestpublic String[] getParameterValues(String name)
getParameterValues in interface javax.servlet.ServletRequestpublic void addParameter(String name, String value)
public void addParameter(String name, String[] values)
public void setParameter(String name, String[] values)
public void setParameters(Map<String,String[]> params)
params - map of paramspublic void removeParameter(String name)
name - public void clearParameters()
public String getProtocol()
getProtocol in interface javax.servlet.ServletRequestpublic String getRealPath(String path)
getRealPath in interface javax.servlet.ServletRequestpublic String getRemoteAddr()
getRemoteAddr in interface javax.servlet.ServletRequestpublic String getRemoteHost()
getRemoteHost in interface javax.servlet.ServletRequestpublic int getRemotePort()
getRemotePort in interface javax.servlet.ServletRequestpublic String getRemoteUser()
getRemoteUser in interface javax.servlet.http.HttpServletRequestpublic void setUseRealDispatcher(boolean real)
real - if true and there is a real RequestDispatcher available then use it,
otherwise just emulate a forward/include call using the fake one
(will always use the fake one if no real one is found)public 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 String getRequestedSessionId()
getRequestedSessionId in interface javax.servlet.http.HttpServletRequestpublic 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.HttpServletRequestpublic 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 isSecure()
isSecure in interface javax.servlet.ServletRequestpublic boolean isUserInRole(String role)
isUserInRole in interface javax.servlet.http.HttpServletRequestCopyright © 2007–2018 CARET, University of Cambridge. All rights reserved.