Class EntityHttpServletRequest
- java.lang.Object
-
- org.sakaiproject.entitybroker.util.http.EntityHttpServletRequest
-
- All Implemented Interfaces:
javax.servlet.http.HttpServletRequest,javax.servlet.ServletRequest
public class EntityHttpServletRequest extends Object implements javax.servlet.http.HttpServletRequest
Makes a copy of the data in a servlet request into a new request object- Author:
- Aaron Zeckoski (azeckoski @ gmail.com)
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classEntityHttpServletRequest.EntityHttpSessionA fake session for testing, from the spring mock sessionstatic classEntityHttpServletRequest.EntityRequestDispatcherA non-functional request dispatcher, based on the spring mock versionstatic classEntityHttpServletRequest.EntityServletContextFor testing, based on the spring Mock version
-
Field Summary
Fields Modifier and Type Field Description javax.servlet.http.HttpServletRequestcopystatic StringDEFAULT_PROTOCOLdefault protocol: HTTP/1.0static StringDEFAULT_REMOTE_ADDRdefault remote address: 127.0.0.1static StringDEFAULT_REMOTE_HOSTThe default remote host: 'localhost'.static StringDEFAULT_SCHEMAdefault schema: httpstatic StringDEFAULT_SERVER_ADDRdefault server address: 127.0.0.1static StringDEFAULT_SERVER_NAMEdefault server name: localhoststatic intDEFAULT_SERVER_PORTdefault server port: 80Map<String,String[]>pathQueryParamsThis stores all the query params found when the request was created
-
Constructor Summary
Constructors Constructor Description EntityHttpServletRequest(String pathString)Create a request using the pathStringEntityHttpServletRequest(String method, String pathString)Create a request using the pathString and setting the methodEntityHttpServletRequest(String method, String pathString, String... params)Create a request using the pathString and setting the method and paramsEntityHttpServletRequest(javax.servlet.http.HttpServletRequest req)Create a new request from a given requestEntityHttpServletRequest(javax.servlet.http.HttpServletRequest req, String pathString)Create a new request from a given request and modify it based on the path stringEntityHttpServletRequest(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
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddCookie(javax.servlet.http.Cookie cookie)Adds a new cookie to the requestvoidaddHeader(String name, String... content)voidaddParameter(String name, String value)Add a single parameter, this will append to an existing onevoidaddParameter(String name, String[] values)Add an array of values for a parameter, these will append to existing onesvoidclearAttributes()Remove all attributesvoidclearCookies()Remove all cookiesvoidclearHeaders()Remove all headersvoidclearParameters()Remove all parametersObjectgetAttribute(String name)EnumerationgetAttributeNames()StringgetAuthType()StringgetCharacterEncoding()javax.servlet.ServletInputStreamgetContent()Gets the content data out of the request, ensures that the data can be retrieved somehowintgetContentLength()StringgetContentType()StringgetContextPath()javax.servlet.http.Cookie[]getCookies()longgetDateHeader(String name)StringgetHeader(String name)EnumerationgetHeaderNames()EnumerationgetHeaders(String name)javax.servlet.ServletInputStreamgetInputStream()intgetIntHeader(String name)StringgetLocalAddr()LocalegetLocale()EnumerationgetLocales()StringgetLocalName()intgetLocalPort()StringgetMethod()StringgetParameter(String name)MapgetParameterMap()EnumerationgetParameterNames()Map<String,String[]>getParameters()String[]getParameterValues(String name)StringgetPathInfo()StringgetPathTranslated()StringgetProtocol()StringgetQueryString()BufferedReadergetReader()StringgetRealPath(String path)StringgetRemoteAddr()StringgetRemoteHost()intgetRemotePort()StringgetRemoteUser()javax.servlet.RequestDispatchergetRequestDispatcher(String path)StringgetRequestedSessionId()StringgetRequestURI()StringBuffergetRequestURL()StringgetScheme()StringgetServerName()intgetServerPort()StringgetServletPath()javax.servlet.http.HttpSessiongetSession()javax.servlet.http.HttpSessiongetSession(boolean create)Map<String,String>getStringParameters()PrincipalgetUserPrincipal()booleanisRequestedSessionIdFromCookie()booleanisRequestedSessionIdFromUrl()booleanisRequestedSessionIdFromURL()booleanisRequestedSessionIdValid()booleanisSecure()booleanisUserInRole(String role)voidremoveAttribute(String name)voidremoveCookie(String name)Removes the cookie with the given name from the requestvoidremoveHeader(String name)voidremoveParameter(String name)Removes a parameter and all values for itvoidsetAttribute(String name, Object o)voidsetCharacterEncoding(String env)voidsetContent(byte[] content)Allows control over the content data which is used in this request, all data should be UTF-8 encodedvoidsetContent(InputStream contentStream, int contentLength)Allows control over the content data which is used in this request, all data should be UTF-8 encodedvoidsetContent(String content)Allows control over the content data which is used in this request, all data should be UTF-8 encodedvoidsetContentType(String contentType)Sets the content type for this request contentvoidsetContextPath(String contextPath)voidsetLocale(Locale locale)voidsetMethod(String method)voidsetParameter(String name, String[] values)Set a new parameter (overwrite an existing one)voidsetParameters(Map<String,String[]> params)Set a large number of params at once, replaces existing paramsvoidsetPathInfo(String pathInfo)URLDatasetPathString(String pathString)This will set the given url/path string values into this request, this will override any values that are currently setvoidsetQueryString(String queryString)voidsetRequestValues(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 fromvoidsetServletPath(String servletPath)voidsetUseRealDispatcher(boolean real)StringtoString()
-
-
-
Field Detail
-
DEFAULT_SCHEMA
public static final String DEFAULT_SCHEMA
default schema: http- See Also:
- Constant Field Values
-
DEFAULT_PROTOCOL
public static final String DEFAULT_PROTOCOL
default protocol: HTTP/1.0- See Also:
- Constant Field Values
-
DEFAULT_SERVER_ADDR
public static final String DEFAULT_SERVER_ADDR
default server address: 127.0.0.1- See Also:
- Constant Field Values
-
DEFAULT_SERVER_NAME
public static final String DEFAULT_SERVER_NAME
default server name: localhost- See Also:
- Constant Field Values
-
DEFAULT_SERVER_PORT
public static final int DEFAULT_SERVER_PORT
default server port: 80- See Also:
- Constant Field Values
-
DEFAULT_REMOTE_ADDR
public static final String DEFAULT_REMOTE_ADDR
default remote address: 127.0.0.1- See Also:
- Constant Field Values
-
DEFAULT_REMOTE_HOST
public static final String DEFAULT_REMOTE_HOST
The default remote host: 'localhost'.- See Also:
- Constant Field Values
-
copy
public javax.servlet.http.HttpServletRequest copy
-
-
Constructor Detail
-
EntityHttpServletRequest
public EntityHttpServletRequest(javax.servlet.http.HttpServletRequest req)
Create a new request from a given request- Parameters:
req- any request
-
EntityHttpServletRequest
public EntityHttpServletRequest(javax.servlet.http.HttpServletRequest req, String pathString)Create a new request from a given request and modify it based on the path string- Parameters:
req- any requestpathString- any full path or URL (/direct/prefix/id.xml)
-
EntityHttpServletRequest
public 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- Parameters:
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)
-
EntityHttpServletRequest
public EntityHttpServletRequest(String pathString)
Create a request using the pathString- Parameters:
pathString- any path or URL
-
EntityHttpServletRequest
public EntityHttpServletRequest(String method, String pathString)
Create a request using the pathString and setting the method- Parameters:
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 unset
-
EntityHttpServletRequest
public EntityHttpServletRequest(String method, String pathString, String... params)
Create a request using the pathString and setting the method and params- Parameters:
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 parameters
-
-
Method Detail
-
setRequestValues
public 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- Parameters:
req- any request
-
setPathString
public 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- Parameters:
pathString- any url or path string- Returns:
- the url data object based on the input object OR null if the string is null or empty
-
setContent
public 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- Parameters:
content- any IS content, UTF-8 encoded, replaces existing content
-
setContent
public void setContent(byte[] content)
Allows control over the content data which is used in this request, all data should be UTF-8 encoded- Parameters:
content- any byte[] content, UTF-8 encoded, replaces existing content
-
setContent
public void setContent(String content)
Allows control over the content data which is used in this request, all data should be UTF-8 encoded- Parameters:
content- any string content, UTF-8 encoded, replaces existing content
-
getContent
public javax.servlet.ServletInputStream getContent() throws IOExceptionGets the content data out of the request, ensures that the data can be retrieved somehow- Returns:
- the content data from the request
- Throws:
IOException- if there is a failure
-
getAttribute
public Object getAttribute(String name)
- Specified by:
getAttributein interfacejavax.servlet.ServletRequest
-
getAttributeNames
public Enumeration getAttributeNames()
- Specified by:
getAttributeNamesin interfacejavax.servlet.ServletRequest
-
removeAttribute
public void removeAttribute(String name)
- Specified by:
removeAttributein interfacejavax.servlet.ServletRequest
-
setAttribute
public void setAttribute(String name, Object o)
- Specified by:
setAttributein interfacejavax.servlet.ServletRequest
-
clearAttributes
public void clearAttributes()
Remove all attributes
-
setCharacterEncoding
public void setCharacterEncoding(String env) throws UnsupportedEncodingException
- Specified by:
setCharacterEncodingin interfacejavax.servlet.ServletRequest- Throws:
UnsupportedEncodingException
-
getCharacterEncoding
public String getCharacterEncoding()
- Specified by:
getCharacterEncodingin interfacejavax.servlet.ServletRequest
-
setContentType
public void setContentType(String contentType)
Sets the content type for this request content- Parameters:
contentType-
-
getContentType
public String getContentType()
- Specified by:
getContentTypein interfacejavax.servlet.ServletRequest
-
getContentLength
public int getContentLength()
- Specified by:
getContentLengthin interfacejavax.servlet.ServletRequest
-
getInputStream
public javax.servlet.ServletInputStream getInputStream() throws IOException- Specified by:
getInputStreamin interfacejavax.servlet.ServletRequest- Throws:
IOException
-
getReader
public BufferedReader getReader() throws IOException
- Specified by:
getReaderin interfacejavax.servlet.ServletRequest- Throws:
IOException
-
setLocale
public void setLocale(Locale locale)
-
getLocale
public Locale getLocale()
- Specified by:
getLocalein interfacejavax.servlet.ServletRequest
-
setMethod
public void setMethod(String method)
-
getMethod
public String getMethod()
- Specified by:
getMethodin interfacejavax.servlet.http.HttpServletRequest
-
setContextPath
public void setContextPath(String contextPath)
-
getContextPath
public String getContextPath()
- Specified by:
getContextPathin interfacejavax.servlet.http.HttpServletRequest
-
setPathInfo
public void setPathInfo(String pathInfo)
-
getPathInfo
public String getPathInfo()
- Specified by:
getPathInfoin interfacejavax.servlet.http.HttpServletRequest
-
getPathTranslated
public String getPathTranslated()
- Specified by:
getPathTranslatedin interfacejavax.servlet.http.HttpServletRequest
-
setQueryString
public void setQueryString(String queryString)
-
getQueryString
public String getQueryString()
- Specified by:
getQueryStringin interfacejavax.servlet.http.HttpServletRequest
-
getRequestURI
public String getRequestURI()
- Specified by:
getRequestURIin interfacejavax.servlet.http.HttpServletRequest
-
getRequestURL
public StringBuffer getRequestURL()
- Specified by:
getRequestURLin interfacejavax.servlet.http.HttpServletRequest
-
setServletPath
public void setServletPath(String servletPath)
-
getServletPath
public String getServletPath()
- Specified by:
getServletPathin interfacejavax.servlet.http.HttpServletRequest
-
addCookie
public void addCookie(javax.servlet.http.Cookie cookie)
Adds a new cookie to the request- Parameters:
cookie- a cookie to add, will displace existing cookies with the same name
-
removeCookie
public void removeCookie(String name)
Removes the cookie with the given name from the request- Parameters:
name- the name of a cookie
-
getCookies
public javax.servlet.http.Cookie[] getCookies()
- Specified by:
getCookiesin interfacejavax.servlet.http.HttpServletRequest
-
clearCookies
public void clearCookies()
Remove all cookies
-
removeHeader
public void removeHeader(String name)
-
getHeader
public String getHeader(String name)
- Specified by:
getHeaderin interfacejavax.servlet.http.HttpServletRequest
-
getHeaderNames
public Enumeration getHeaderNames()
- Specified by:
getHeaderNamesin interfacejavax.servlet.http.HttpServletRequest
-
getHeaders
public Enumeration getHeaders(String name)
- Specified by:
getHeadersin interfacejavax.servlet.http.HttpServletRequest
-
getDateHeader
public long getDateHeader(String name)
- Specified by:
getDateHeaderin interfacejavax.servlet.http.HttpServletRequest
-
getIntHeader
public int getIntHeader(String name)
- Specified by:
getIntHeaderin interfacejavax.servlet.http.HttpServletRequest
-
clearHeaders
public void clearHeaders()
Remove all headers
-
getAuthType
public String getAuthType()
- Specified by:
getAuthTypein interfacejavax.servlet.http.HttpServletRequest
-
getLocalAddr
public String getLocalAddr()
- Specified by:
getLocalAddrin interfacejavax.servlet.ServletRequest
-
getLocales
public Enumeration getLocales()
- Specified by:
getLocalesin interfacejavax.servlet.ServletRequest
-
getLocalName
public String getLocalName()
- Specified by:
getLocalNamein interfacejavax.servlet.ServletRequest
-
getLocalPort
public int getLocalPort()
- Specified by:
getLocalPortin interfacejavax.servlet.ServletRequest
-
getStringParameters
public Map<String,String> getStringParameters()
- Returns:
- all parameters in this request as single strings
-
getParameter
public String getParameter(String name)
- Specified by:
getParameterin interfacejavax.servlet.ServletRequest
-
getParameterMap
public Map getParameterMap()
- Specified by:
getParameterMapin interfacejavax.servlet.ServletRequest
-
getParameterNames
public Enumeration getParameterNames()
- Specified by:
getParameterNamesin interfacejavax.servlet.ServletRequest
-
getParameterValues
public String[] getParameterValues(String name)
- Specified by:
getParameterValuesin interfacejavax.servlet.ServletRequest
-
addParameter
public void addParameter(String name, String value)
Add a single parameter, this will append to an existing one
-
addParameter
public void addParameter(String name, String[] values)
Add an array of values for a parameter, these will append to existing ones
-
setParameter
public void setParameter(String name, String[] values)
Set a new parameter (overwrite an existing one)
-
setParameters
public void setParameters(Map<String,String[]> params)
Set a large number of params at once, replaces existing params- Parameters:
params- map of params
-
removeParameter
public void removeParameter(String name)
Removes a parameter and all values for it- Parameters:
name-
-
clearParameters
public void clearParameters()
Remove all parameters
-
getProtocol
public String getProtocol()
- Specified by:
getProtocolin interfacejavax.servlet.ServletRequest
-
getRealPath
public String getRealPath(String path)
- Specified by:
getRealPathin interfacejavax.servlet.ServletRequest
-
getRemoteAddr
public String getRemoteAddr()
- Specified by:
getRemoteAddrin interfacejavax.servlet.ServletRequest
-
getRemoteHost
public String getRemoteHost()
- Specified by:
getRemoteHostin interfacejavax.servlet.ServletRequest
-
getRemotePort
public int getRemotePort()
- Specified by:
getRemotePortin interfacejavax.servlet.ServletRequest
-
getRemoteUser
public String getRemoteUser()
- Specified by:
getRemoteUserin interfacejavax.servlet.http.HttpServletRequest
-
setUseRealDispatcher
public void setUseRealDispatcher(boolean real)
- Parameters:
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)
-
getRequestDispatcher
public javax.servlet.RequestDispatcher getRequestDispatcher(String path)
- Specified by:
getRequestDispatcherin interfacejavax.servlet.ServletRequest
-
getScheme
public String getScheme()
- Specified by:
getSchemein interfacejavax.servlet.ServletRequest
-
getServerName
public String getServerName()
- Specified by:
getServerNamein interfacejavax.servlet.ServletRequest
-
getServerPort
public int getServerPort()
- Specified by:
getServerPortin interfacejavax.servlet.ServletRequest
-
getRequestedSessionId
public String getRequestedSessionId()
- Specified by:
getRequestedSessionIdin interfacejavax.servlet.http.HttpServletRequest
-
getSession
public javax.servlet.http.HttpSession getSession()
- Specified by:
getSessionin interfacejavax.servlet.http.HttpServletRequest
-
getSession
public javax.servlet.http.HttpSession getSession(boolean create)
- Specified by:
getSessionin interfacejavax.servlet.http.HttpServletRequest
-
getUserPrincipal
public Principal getUserPrincipal()
- Specified by:
getUserPrincipalin interfacejavax.servlet.http.HttpServletRequest
-
isRequestedSessionIdFromCookie
public boolean isRequestedSessionIdFromCookie()
- Specified by:
isRequestedSessionIdFromCookiein interfacejavax.servlet.http.HttpServletRequest
-
isRequestedSessionIdFromUrl
public boolean isRequestedSessionIdFromUrl()
- Specified by:
isRequestedSessionIdFromUrlin interfacejavax.servlet.http.HttpServletRequest
-
isRequestedSessionIdFromURL
public boolean isRequestedSessionIdFromURL()
- Specified by:
isRequestedSessionIdFromURLin interfacejavax.servlet.http.HttpServletRequest
-
isRequestedSessionIdValid
public boolean isRequestedSessionIdValid()
- Specified by:
isRequestedSessionIdValidin interfacejavax.servlet.http.HttpServletRequest
-
isSecure
public boolean isSecure()
- Specified by:
isSecurein interfacejavax.servlet.ServletRequest
-
isUserInRole
public boolean isUserInRole(String role)
- Specified by:
isUserInRolein interfacejavax.servlet.http.HttpServletRequest
-
-