Package org.pac4j.core.context
Class JEEContext
- java.lang.Object
-
- org.pac4j.core.context.JEEContext
-
- All Implemented Interfaces:
WebContext
public class JEEContext extends java.lang.Object implements WebContext
This implementation uses the JEEHttpServletRequest
andHttpServletResponse
.- Since:
- 1.4.0
- Author:
- Jerome Leleu
-
-
Constructor Summary
Constructors Constructor Description JEEContext(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response)
Build a JEE context from the current HTTP request and response.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addResponseCookie(Cookie cookie)
Adds cookies to the responsejava.lang.String
getFullRequestURL()
Return the full URL (with query string) the client used to request the server.javax.servlet.http.HttpServletRequest
getNativeRequest()
Return the native HTTP request.javax.servlet.http.HttpServletResponse
getNativeResponse()
Return the native HTTP response.java.lang.String
getPath()
This is not implemented usingHttpServletRequest.getServletPath()
orHttpServletRequest.getPathInfo()
because they both have strange behaviours in different contexts (inside servlets, inside filters, various container implementation, etc)java.lang.String
getProtocol()
Get the protocol version.java.lang.String
getRemoteAddr()
Return the remote address.java.util.Optional
getRequestAttribute(java.lang.String name)
Return a request attribute.java.lang.String
getRequestContent()
Gets content body of the original request.java.util.Collection<Cookie>
getRequestCookies()
Retrieves request cookies.java.util.Optional<java.lang.String>
getRequestHeader(java.lang.String name)
Return a request header.java.lang.String
getRequestMethod()
Return the request method.java.util.Optional<java.lang.String>
getRequestParameter(java.lang.String name)
Return a request parameter.java.util.Map<java.lang.String,java.lang.String[]>
getRequestParameters()
Return all request parameters.java.lang.String
getRequestURL()
Return the full URL (without the query string) the client used to request the server.java.util.Optional<java.lang.String>
getResponseHeader(java.lang.String name)
Get a header from the response.java.lang.String
getScheme()
Return the scheme.java.lang.String
getServerName()
Return the server name.int
getServerPort()
Return the server port.boolean
isSecure()
Return whether the request is secure.void
setRequestAttribute(java.lang.String name, java.lang.Object value)
Save a request attribute.void
setResponseContentType(java.lang.String content)
Sets the response content type.void
setResponseHeader(java.lang.String name, java.lang.String value)
Add a header to the response.
-
-
-
Method Detail
-
getRequestParameter
public java.util.Optional<java.lang.String> getRequestParameter(java.lang.String name)
Description copied from interface:WebContext
Return a request parameter.- Specified by:
getRequestParameter
in interfaceWebContext
- Parameters:
name
- name of the parameter- Returns:
- the request parameter
-
getRequestAttribute
public java.util.Optional getRequestAttribute(java.lang.String name)
Description copied from interface:WebContext
Return a request attribute.- Specified by:
getRequestAttribute
in interfaceWebContext
- Parameters:
name
- the name of the attribute- Returns:
- the attribute
-
setRequestAttribute
public void setRequestAttribute(java.lang.String name, java.lang.Object value)
Description copied from interface:WebContext
Save a request attribute.- Specified by:
setRequestAttribute
in interfaceWebContext
- Parameters:
name
- the name of the attributevalue
- the attribute
-
getRequestParameters
public java.util.Map<java.lang.String,java.lang.String[]> getRequestParameters()
Description copied from interface:WebContext
Return all request parameters.- Specified by:
getRequestParameters
in interfaceWebContext
- Returns:
- all request parameters
-
getRequestHeader
public java.util.Optional<java.lang.String> getRequestHeader(java.lang.String name)
Description copied from interface:WebContext
Return a request header.- Specified by:
getRequestHeader
in interfaceWebContext
- Parameters:
name
- name of the header- Returns:
- the request header
-
getRequestMethod
public java.lang.String getRequestMethod()
Description copied from interface:WebContext
Return the request method.- Specified by:
getRequestMethod
in interfaceWebContext
- Returns:
- the request method
-
getRemoteAddr
public java.lang.String getRemoteAddr()
Description copied from interface:WebContext
Return the remote address.- Specified by:
getRemoteAddr
in interfaceWebContext
- Returns:
- the remote address.
-
getNativeRequest
public javax.servlet.http.HttpServletRequest getNativeRequest()
Return the native HTTP request.- Returns:
- the native HTTP request
-
getNativeResponse
public javax.servlet.http.HttpServletResponse getNativeResponse()
Return the native HTTP response.- Returns:
- the native HTTP response
-
setResponseHeader
public void setResponseHeader(java.lang.String name, java.lang.String value)
Description copied from interface:WebContext
Add a header to the response.- Specified by:
setResponseHeader
in interfaceWebContext
- Parameters:
name
- name of the headervalue
- value of the header
-
getResponseHeader
public java.util.Optional<java.lang.String> getResponseHeader(java.lang.String name)
Description copied from interface:WebContext
Get a header from the response.- Specified by:
getResponseHeader
in interfaceWebContext
- Parameters:
name
- name of the header- Returns:
- the value of the header
-
setResponseContentType
public void setResponseContentType(java.lang.String content)
Description copied from interface:WebContext
Sets the response content type.- Specified by:
setResponseContentType
in interfaceWebContext
- Parameters:
content
- the content type
-
getServerName
public java.lang.String getServerName()
Description copied from interface:WebContext
Return the server name.- Specified by:
getServerName
in interfaceWebContext
- Returns:
- the server name
-
getServerPort
public int getServerPort()
Description copied from interface:WebContext
Return the server port.- Specified by:
getServerPort
in interfaceWebContext
- Returns:
- the server port
-
getScheme
public java.lang.String getScheme()
Description copied from interface:WebContext
Return the scheme.- Specified by:
getScheme
in interfaceWebContext
- Returns:
- the scheme
-
isSecure
public boolean isSecure()
Description copied from interface:WebContext
Return whether the request is secure.- Specified by:
isSecure
in interfaceWebContext
- Returns:
- whether the request is secure
-
getRequestURL
public java.lang.String getRequestURL()
Description copied from interface:WebContext
Return the full URL (without the query string) the client used to request the server.- Specified by:
getRequestURL
in interfaceWebContext
- Returns:
- the URL
-
getFullRequestURL
public java.lang.String getFullRequestURL()
Description copied from interface:WebContext
Return the full URL (with query string) the client used to request the server.- Specified by:
getFullRequestURL
in interfaceWebContext
- Returns:
- the URL
-
getRequestCookies
public java.util.Collection<Cookie> getRequestCookies()
Description copied from interface:WebContext
Retrieves request cookies.- Specified by:
getRequestCookies
in interfaceWebContext
- Returns:
- the request cookies
-
addResponseCookie
public void addResponseCookie(Cookie cookie)
Description copied from interface:WebContext
Adds cookies to the response- Specified by:
addResponseCookie
in interfaceWebContext
- Parameters:
cookie
- a cookie to add to the response
-
getPath
public java.lang.String getPath()
This is not implemented usingHttpServletRequest.getServletPath()
orHttpServletRequest.getPathInfo()
because they both have strange behaviours in different contexts (inside servlets, inside filters, various container implementation, etc)- Specified by:
getPath
in interfaceWebContext
- Returns:
- the "servlet path"
-
getRequestContent
public java.lang.String getRequestContent()
Description copied from interface:WebContext
Gets content body of the original request.- Specified by:
getRequestContent
in interfaceWebContext
- Returns:
- the request content
-
getProtocol
public java.lang.String getProtocol()
Description copied from interface:WebContext
Get the protocol version.- Specified by:
getProtocol
in interfaceWebContext
- Returns:
- the protocol version
-
-