public class ExternalContextImpl extends ExternalContext
This implementation of ExternalContext
is specific to the
servlet implementation.
BASIC_AUTH, CLIENT_CERT_AUTH, DIGEST_AUTH, FORM_AUTH
Constructor and Description |
---|
ExternalContextImpl(javax.servlet.ServletContext sc,
javax.servlet.ServletRequest request,
javax.servlet.ServletResponse response) |
Modifier and Type | Method and Description |
---|---|
void |
addResponseCookie(String name,
String value,
Map<String,Object> properties)
Adds the cookie represented by the arguments to the response. |
void |
addResponseHeader(String name,
String value)
Add the given name and value to the response header. |
void |
dispatch(String requestURI)
Dispatch a request to the specified resource to create output
for this response.
|
String |
encodeActionURL(String url)
Return the input URL, after performing any rewriting needed to
ensure that it will correctly identify an addressable action in the
current application.
|
String |
encodeBookmarkableURL(String baseUrl,
Map<String,List<String>> parameters)
The purpose of this method is to generate a query string from the collection of Parameter objects provided by the parameters argument and append that query string to the baseUrl. |
String |
encodeNamespace(String name)
Return the specified
name, after prefixing it with a namespace that ensures that it
will be unique within the context of a particular page.
|
String |
encodePartialActionURL(String url)
Return the input URL, after performing any rewriting needed to ensure that it can be used in a partial page submission (ajax request) to correctly identify an addressable action in the current application. |
String |
encodeRedirectURL(String baseUrl,
Map<String,List<String>> parameters)
The purpose of this method is to generate a query string from the collection of Parameter
objects provided by the parameters argument and append that query string to the baseUrl.
|
String |
encodeResourceURL(String url)
Return the input URL, after performing any rewriting needed to
ensure that it will correctly identify an addressable resource in the
current application.
|
String |
encodeWebsocketURL(String url)
Return the websocket URL, after performing any rewriting needed to
ensure that it will correctly identify an addressable websocket in the
current application.
|
String |
getApplicationContextPath()
Return the name of the container context for this application. |
Map<String,Object> |
getApplicationMap()
Return a mutable
Map representing the application scope attributes
for the current application. |
String |
getAuthType()
Return the name of the authentication scheme used to authenticate
the current user, if any; otherwise, return
null . |
ClientWindow |
getClientWindow()
Return the |
Object |
getContext()
Return the
application environment object instance for the current
appication.
|
String |
getContextName()
Return the name of the container context for this application. |
String |
getFallbackMimeType(String file) |
Flash |
getFlash()
Return the threadsafe |
String |
getInitParameter(String name)
Return the value of
the specified application initialization parameter (if any).
|
Map<String,String> |
getInitParameterMap()
Return an
immutable
Map whose keys are the set of application
initialization parameter names configured for this application,
and whose values are the corresponding parameter values. |
String |
getMimeType(String file)
Returns the MIME type of the
specified file or |
String |
getRealPath(String path)
Returns a String containing the real path for a given virtual path. |
String |
getRemoteUser()
Return the login name of the user making the current request
if any; otherwise, return
null . |
Object |
getRequest()
Return the environment-specific object instance for the current
request.
|
String |
getRequestCharacterEncoding()
Return the character encoding currently being used
to interpret this request.
|
int |
getRequestContentLength()
Return the result
of calling |
String |
getRequestContentType()
Return the MIME Content-Type for this request.
|
String |
getRequestContextPath()
Return the portion of the request URI that identifies the web
application context for this request.
|
Map<String,Object> |
getRequestCookieMap()
Return an immutable
Map whose keys are the set of
cookie names included in the current request, and whose
values (of type javax.servlet.http.Cookie )
are the first (or only) cookie for each cookie name
returned by the underlying request. |
Map<String,String> |
getRequestHeaderMap()
Return an immutable
Map whose keys are the set of
request header names included in the current request, and whose
values (of type String) are the first (or only) value for each
header name returned by the underlying request. |
Map<String,String[]> |
getRequestHeaderValuesMap()
Return an immutable
Map whose keys are the set of
request header names included in the current request, and whose
values (of type String[]) are all of the value for each
header name returned by the underlying request. |
Locale |
getRequestLocale()
Return the preferred
Locale in which the client
will accept content. |
Iterator<Locale> |
getRequestLocales()
Return an
Iterator over the preferred
Locale s specified in the request, in decreasing
order of preference. |
Map<String,Object> |
getRequestMap()
Return a mutable
Map representing the request
scope attributes for the current application. |
Map<String,String> |
getRequestParameterMap()
Return an immutable
Map whose keys are the set of
request parameters names included in the current request, and whose
values (of type String) are the first (or only) value for each
parameter name returned by the underlying request. |
Iterator<String> |
getRequestParameterNames()
Return an
Iterator over the names of all request
parameters included in the current request. |
Map<String,String[]> |
getRequestParameterValuesMap()
Return an immutable
Map whose keys are the set of
request parameters names included in the current request, and whose
values (of type String[]) are all of the values for each
parameter name returned by the underlying request. |
String |
getRequestPathInfo()
Return the extra path information (if any) included in the
request URI; otherwise, return
null . |
String |
getRequestScheme()
Returns the name of the scheme used to make this request, for example, http, https, or ftp. |
String |
getRequestServerName()
Returns the host name of the server to which the request was sent. |
int |
getRequestServerPort()
Returns the port number to which the request was sent. |
String |
getRequestServletPath()
Return the Jakarta Servlet path information (if any) included in the
request URI; otherwise, return
null . |
URL |
getResource(String path)
Return a
URL for the application resource mapped to the
specified path, if it exists; otherwise, return
null . |
InputStream |
getResourceAsStream(String path)
Return an
InputStream for an application resource mapped to
the specified path, if it exists; otherwise, return
null . |
Set<String> |
getResourcePaths(String path)
Return the
Set of resource paths for all application resources
whose resource path starts with the specified argument. |
Object |
getResponse()
Return the environment-specific object instance for the current
response.
|
int |
getResponseBufferSize()
Return the buffer size for the current response. |
String |
getResponseCharacterEncoding()
Returns the name of
the character encoding (MIME charset) used for the body sent in
this response.
|
String |
getResponseContentType()
Return the MIME Content-Type for this response.
|
OutputStream |
getResponseOutputStream()
Returns an |
Writer |
getResponseOutputWriter()
Returns a |
Object |
getSession(boolean create)
If the
create parameter is true ,
create (if necessary) and return a session instance associated
with the current request. |
String |
getSessionId(boolean create)
Return the id of the current session
or the empty string if no session has been created and the
|
Map<String,Object> |
getSessionMap()
Return a mutable
Map representing the session
scope attributes for the current application. |
int |
getSessionMaxInactiveInterval()
Returns the maximum time interval, in seconds, that the Jakarta Servlet container will keep this session open between client accesses. |
Principal |
getUserPrincipal()
Return the
Principal object containing the name of
the current authenticated user, if any; otherwise, return
null . |
void |
invalidateSession()
Invalidates this session then unbinds any objects bound to it. |
boolean |
isResponseCommitted()
Check if the current response has been committed. |
boolean |
isSecure()
Returns a boolean indicating whether this request was made using a secure channel, such as HTTPS. |
boolean |
isUserInRole(String role)
Return
true if the currently authenticated user is
included in the specified role. |
void |
log(String message)
Log the specified
message to the application object.
|
void |
log(String message,
Throwable throwable)
Log the specified
message and exception to the application object.
|
void |
redirect(String requestURI)
Redirect a request
to the specified URL, and cause the
responseComplete() method to be called on the
FacesContext instance for the current request. |
void |
responseFlushBuffer()
Flushes the buffered response content to the client. |
void |
responseReset()
Resets the current response. |
void |
responseSendError(int statusCode,
String message)
Sends an HTTP status code with message. |
void |
setClientWindow(ClientWindow window)
Associate this instance with a |
void |
setRequest(Object request)
Set the environment-specific request to be returned by
subsequent calls to
ExternalContext.getRequest() . |
void |
setRequestCharacterEncoding(String encoding)
Overrides the name of the character
encoding used in the body of this request.
|
void |
setResponse(Object response)
Set the environment-specific response to be returned by
subsequent calls to
ExternalContext.getResponse() . |
void |
setResponseBufferSize(int size)
Set the buffer size for the current response. |
void |
setResponseCharacterEncoding(String encoding)
Sets the character encoding (MIME charset) of the response being sent
to the client, for example, to UTF-8.
|
void |
setResponseContentLength(int length)
Set the content length of the response. |
void |
setResponseContentType(String contentType)
Sets the content type of the response being sent to the client, if the response has not been committed yet. |
void |
setResponseHeader(String name,
String value)
Set the response header with the given name and value. |
void |
setResponseStatus(int statusCode)
Sets the HTTP status code for the response. |
void |
setSessionMaxInactiveInterval(int interval)
Specifies the time, in seconds, between client requests before the Jakarta Servlet container will invalidate this session. |
public ExternalContextImpl(javax.servlet.ServletContext sc, javax.servlet.ServletRequest request, javax.servlet.ServletResponse response)
public Object getSession(boolean create)
ExternalContext
If the create
parameter is true
,
create (if necessary) and return a session instance associated
with the current request. If the create
parameter
is false
return any existing session instance
associated with the current request, or return null
if
there is no such session.
Jakarta Servlet: This must return the result of calling
getSession(create)
on the underlying
javax.servlet.http.HttpServletRequest
instance.
getSession
in class ExternalContext
create
- Flag indicating whether or not a new session should be
created if there is no session associated with the current requestExternalContext.getSession(boolean)
public String getSessionId(boolean create)
ExternalContext
Return the id of the current session
or the empty string if no session has been created and the
create
parameter is false
.
Jakarta Servlet: If create
is true, obtain
a reference to the HttpSession
for the current request
(creating the session if necessary) and return its id. If
create
is false
, obtain a reference to the
current session, if one exists, and return its id. If no session exists,
return the empty string.
getSessionId
in class ExternalContext
create
- Flag indicating whether or not a new session should be
created if there is no session associated with the current requestpublic Object getContext()
ExternalContext
Return the application environment object instance for the current appication.
It is valid to call this method
during application startup or shutdown. If called during application
startup or shutdown, this returns the same container context instance
(ServletContext
or PortletContext
) as
the one returned when calling getContext()
on the
ExternalContext
returned by the
FacesContext
during an actual request.
Jakarta Servlet: This must be the current application's
javax.servlet.ServletContext
instance.
getContext
in class ExternalContext
ServletContext
.ExternalContext.getContext()
public String getContextName()
ExternalContext
Return the name of the container context for this application.
Return the result of calling
getServletContextName()
on the
ServletContext
instance for this application. It is
valid to call this method during application startup or shutdown.
The default implementation throws
UnsupportedOperationException
and is provided for
the sole purpose of not breaking existing applications that
extend this class.
getContextName
in class ExternalContext
ServletContext
.ExternalContext.getContextName()
public Object getRequest()
ExternalContext
Return the environment-specific object instance for the current request.
Jakarta Servlet: This must be the current request's
javax.servlet.http.HttpServletRequest
instance.
getRequest
in class ExternalContext
ExternalContext.getRequest()
public void setRequest(Object request)
ExternalContext
Set the environment-specific request to be returned by
subsequent calls to ExternalContext.getRequest()
. This may be used to
install a wrapper for the request.
The default implementation throws
UnsupportedOperationException
and is provided
for the sole purpose of not breaking existing applications that extend
this class.
setRequest
in class ExternalContext
request
- the request object to be set.ExternalContext.setRequest(Object)
public void setRequestCharacterEncoding(String encoding) throws UnsupportedEncodingException
ExternalContext
Overrides the name of the character encoding used in the body of this request.
Calling this method after the request has been accessed will have no
no effect, unless a Reader
or Stream
has been
obtained from the request, in which case an IllegalStateException
is thrown.
Jakarta Servlet: This must call through to the
javax.servlet.ServletRequest
method
setCharacterEncoding()
.
The default implementation throws
UnsupportedOperationException
and is provided
for the sole purpose of not breaking existing applications that extend
this class.
setRequestCharacterEncoding
in class ExternalContext
encoding
- the encoding name to be set.UnsupportedEncodingException
- if this is not a valid
encodingExternalContext.setRequestCharacterEncoding(String)
public Object getResponse()
ExternalContext
Return the environment-specific object instance for the current response.
Jakarta Servlet: This is the current request's
javax.servlet.http.HttpServletResponse
instance.
getResponse
in class ExternalContext
javax.servlet.http.HttpServletResponse
.ExternalContext.getResponse()
public void setResponse(Object response)
ExternalContext
Set the environment-specific response to be returned by
subsequent calls to ExternalContext.getResponse()
. This may be used to
install a wrapper for the response.
The default implementation throws
UnsupportedOperationException
and is provided
for the sole purpose of not breaking existing applications that extend
this class.
setResponse
in class ExternalContext
response
- the response instance to be set.ExternalContext.setResponse(Object)
public ClientWindow getClientWindow()
ExternalContext
Return the ClientWindow
set in a preceding
call to ExternalContext.setClientWindow(javax.faces.lifecycle.ClientWindow)
, or null
if no such call has
been made.
getClientWindow
in class ExternalContext
ClientWindow
.public void setClientWindow(ClientWindow window)
ExternalContext
Associate this instance with a ClientWindow
.
setClientWindow
in class ExternalContext
window
- the window with which this instance is associated.public void setResponseCharacterEncoding(String encoding)
ExternalContext
Sets the character encoding (MIME charset) of the response being sent to the client, for example, to UTF-8.
Jakarta Servlet: This must call through to the
javax.servlet.ServletResponse
method
setCharacterEncoding()
.
The default implementation throws
UnsupportedOperationException
and is provided
for the sole purpose of not breaking existing applications that extend
this class.
setResponseCharacterEncoding
in class ExternalContext
encoding
- the character encoding to be sent by the current response.ExternalContext.setResponseCharacterEncoding(String)
public Map<String,Object> getApplicationMap()
ExternalContext
Return a mutable
Map
representing the application scope attributes
for the current application. The returned Map
must
implement the entire contract for a modifiable map as described
in the JavaDocs for java.util.Map
. Modifications
made in the Map
must cause the corresponding changes
in the set of application scope attributes. Particularly the
clear()
, remove()
, put()
,
putAll()
, and get()
operations must
take the appropriate action on the underlying data structure.
For any of the Map
methods that cause an element
to be removed from the underlying data structure, the following
action regarding managed-beans must be taken. If the element to
be removed is a managed-bean, and it has one or more public
no-argument void return methods annotated with
javax.annotation.PreDestroy
, each such method must
be called before the element is removed from the underlying data
structure. Elements that are not managed-beans, but do happen to
have methods with that annotation must not have those methods
called on removal. Any exception thrown by the
PreDestroy
annotated methods must by caught and not
rethrown. The exception may be logged.
It is valid to call this method
during application startup or shutdown. If called at startup or shutdown time, this
method returns a Map
that is backed by the same
container context instance (ServletContext
or
PortletContext
) as the one returned by calling
getApplicationMap()
on the
ExternalContext
returned by the
FacesContext
during an actual request.
Jakarta Servlet: This must be the set of attributes available via
the javax.servlet.ServletContext
methods
getAttribute()
, getAttributeNames()
,
removeAttribute()
, and setAttribute()
.
getApplicationMap
in class ExternalContext
ServletContext
.ExternalContext.getApplicationMap()
public String getApplicationContextPath()
ExternalContext
Return the name of the container context for this application.
Jakarta Servlet:
Return the result of calling
getContextPath()
on the
ServletContext
instance for this application.
It is valid to call this method during application startup or shutdown.
The default implementation throws
UnsupportedOperationException
and is provided for
the sole purpose of not breaking existing applications that
extend this class.
getApplicationContextPath
in class ExternalContext
public Map<String,Object> getSessionMap()
ExternalContext
Return a mutable Map
representing the session
scope attributes for the current application. The returned
Map
must implement the entire contract for a
modifiable map as described in the JavaDocs for
java.util.Map
. Modifications made in the
Map
must cause the corresponding changes in the set
of session scope attributes. Particularly the
clear()
, remove()
, put()
,
and get()
operations must take the appropriate
action on the underlying data structure. Accessing attributes
via this Map
must cause the creation of a session
associated with the current request, if such a session does not
already exist.
For any of the Map
methods that cause an element
to be removed from the underlying data structure, the following
action regarding managed-beans must be taken. If the element to
be removed is a managed-bean, and it has one or more public
no-argument void return methods annotated with
javax.annotation.PreDestroy
, each such method must
be called before the element is removed from the underlying data
structure. Elements that are not managed-beans, but do happen to
have methods with that annotation must not have those methods
called on removal. Any exception thrown by the
PreDestroy
annotated methods must by caught and not
rethrown. The exception may be logged.
Jakarta Servlet: This must be the set of attributes available via
the javax.servlet.http.HttpSession
methods
getAttribute()
, getAttributeNames()
,
removeAttribute()
, and setAttribute()
.
getSessionMap
in class ExternalContext
ExternalContext.getSessionMap()
public Map<String,Object> getRequestMap()
ExternalContext
Return a mutable Map
representing the request
scope attributes for the current application. The returned
Map
must implement the entire contract for a
modifiable map as described in the JavaDocs for
java.util.Map
. Modifications made in the
Map
must cause the corresponding changes in the set
of request scope attributes. Particularly the
clear()
, remove()
, put()
,
putAll()
, and get()
operations must
take the appropriate action on the underlying data structure.
For any of the Map
methods that cause an element
to be removed from the underlying data structure, the following
action regarding managed-beans must be taken. If the element to
be removed is a managed-bean, and it has one or more public
no-argument void return methods annotated with
javax.annotation.PreDestroy
, each such method must
be called before the element is removed from the underlying data
structure. Elements that are not managed-beans, but do happen to
have methods with that annotation must not have those methods
called on removal. Any exception thrown by the
PreDestroy
annotated methods must by caught and not
rethrown. The exception may be logged.
Jakarta Servlet: This must be the set of attributes available via
the javax.servlet.ServletRequest
methods
getAttribute()
, getAttributeNames()
,
removeAttribute()
, and setAttribute()
.
getRequestMap
in class ExternalContext
ExternalContext.getRequestMap()
public Map<String,String> getRequestHeaderMap()
ExternalContext
Return an immutable Map
whose keys are the set of
request header names included in the current request, and whose
values (of type String) are the first (or only) value for each
header name returned by the underlying request. The returned
Map
must implement the entire contract for an unmodifiable
map as described in the JavaDocs for java.util.Map
. In
addition, key comparisons must be performed in a case insensitive
manner.
Jakarta Servlet: This must be the set of headers available via
the javax.servlet.http.HttpServletRequest
methods
getHeader()
and getHeaderNames()
.
getRequestHeaderMap
in class ExternalContext
ExternalContext.getRequestHeaderMap()
public Map<String,String[]> getRequestHeaderValuesMap()
ExternalContext
Return an immutable Map
whose keys are the set of
request header names included in the current request, and whose
values (of type String[]) are all of the value for each
header name returned by the underlying request. The returned
Map
must implement the entire contract for an unmodifiable
map as described in the JavaDocs for java.util.Map
. In
addition, key comparisons must be performed in a case insensitive
manner.
Jakarta Servlet: This must be the set of headers available via
the javax.servlet.http.HttpServletRequest
methods
getHeaders()
and getHeaderNames()
.
getRequestHeaderValuesMap
in class ExternalContext
ExternalContext.getRequestHeaderValuesMap()
public Map<String,Object> getRequestCookieMap()
ExternalContext
Return an immutable Map
whose keys are the set of
cookie names included in the current request, and whose
values (of type javax.servlet.http.Cookie
)
are the first (or only) cookie for each cookie name
returned by the underlying request. The returned
Map
must implement the entire contract for an unmodifiable
map as described in the JavaDocs for java.util.Map
.
Jakarta Servlet: This must be the value returned by the
javax.servlet.http.HttpServletRequest
method
getCookies()
, unless null
was returned,
in which case this must be a zero-length array.
getRequestCookieMap
in class ExternalContext
ExternalContext.getRequestCookieMap()
public Map<String,String> getInitParameterMap()
ExternalContext
Return an
immutable Map
whose keys are the set of application
initialization parameter names configured for this application,
and whose values are the corresponding parameter values. The
returned Map
must implement the entire contract for
an unmodifiable map as described in the JavaDocs for
java.util.Map
.
It is valid to call this method
during application startup or shutdown. If called during application
startup or shutdown, this method returns a Map
that is backed by
the same container context instance (ServletContext
or PortletContext
) as the one returned by calling
getInitParameterMap()
on the
ExternalContext
returned by the
FacesContext
during an actual request.
Jakarta Servlet: This result must be as if it were synthesized
by calling the javax.servlet.ServletContext
method getInitParameterNames
, and putting
each configured parameter name/value pair into the result.
getInitParameterMap
in class ExternalContext
ExternalContext.getInitParameterMap()
public Map<String,String> getRequestParameterMap()
ExternalContext
Return an immutable Map
whose keys are the set of
request parameters names included in the current request, and whose
values (of type String) are the first (or only) value for each
parameter name returned by the underlying request. The returned
Map
must implement the entire contract for an unmodifiable
map as described in the JavaDocs for java.util.Map
.
Jakarta Servlet: This must be the set of parameters available via
the javax.servlet.ServletRequest
methods
getParameter()
and getParameterNames()
.
getRequestParameterMap
in class ExternalContext
ExternalContext.getRequestParameterMap()
public Map<String,String[]> getRequestParameterValuesMap()
ExternalContext
Return an immutable Map
whose keys are the set of
request parameters names included in the current request, and whose
values (of type String[]) are all of the values for each
parameter name returned by the underlying request. The returned
Map
must implement the entire contract for an unmodifiable
map as described in the JavaDocs for java.util.Map
.
Jakarta Servlet: This must be the set of parameters available via
the javax.servlet.ServletRequest
methods
getParameterValues()
and
getParameterNames()
.
getRequestParameterValuesMap
in class ExternalContext
ExternalContext.getRequestParameterValuesMap()
public Iterator<String> getRequestParameterNames()
ExternalContext
Return an Iterator
over the names of all request
parameters included in the current request.
Jakarta Servlet: This must be an Iterator
over the
values returned by the javax.servlet.ServletRequest
method getParameterNames()
.
getRequestParameterNames
in class ExternalContext
Iterator
for the names of the current request parameters.ExternalContext.getRequestParameterNames()
public Locale getRequestLocale()
ExternalContext
Return the preferred Locale
in which the client
will accept content.
Jakarta Servlet: This must be the value returned by the
javax.servlet.ServletRequest
method
getLocale()
.
getRequestLocale
in class ExternalContext
Locale
of the current request.ExternalContext.getRequestLocale()
public Iterator<Locale> getRequestLocales()
ExternalContext
Return an Iterator
over the preferred
Locale
s specified in the request, in decreasing
order of preference.
Jakarta Servlet: This must be an Iterator
over the values returned by the javax.servlet.ServletRequest
method getLocales()
.
getRequestLocales
in class ExternalContext
Iterator
of Locale
s of the current request.ExternalContext.getRequestLocales()
public String getRequestPathInfo()
ExternalContext
Return the extra path information (if any) included in the
request URI; otherwise, return null
.
Jakarta Servlet: This must be the value returned by the
javax.servlet.http.HttpServletRequest
method
getPathInfo()
.
getRequestPathInfo
in class ExternalContext
ExternalContext.getRequestPathInfo()
public String getRealPath(String path)
ExternalContext
Returns a String containing the real path for a given virtual path.
It is valid to call this method
during application startup or shutdown. If called during application
startup or shutdown, this method calls through to the
getRealPath()
method on the same container
context instance (ServletContext
or
PortletContext
) as the one used when calling
getRealPath()
on the
ExternalContext
returned by the
FacesContext
during an actual request.
Jakarta Servlet: This must be the value returned by the
javax.servlet.ServletContext
method
getRealPath()
.
The default implementation throws
UnsupportedOperationException
and is provided
for the sole purpose of not breaking existing applications that extend
this class.
getRealPath
in class ExternalContext
path
- The context of the requested initialization parameterExternalContext.getRealPath(String)
public String getRequestContextPath()
ExternalContext
Return the portion of the request URI that identifies the web application context for this request.
Jakarta Servlet: This must be the value returned by the
javax.servlet.http.HttpServletRequest
method
getContextPath()
.
getRequestContextPath
in class ExternalContext
ExternalContext.getRequestContextPath()
public String getRequestServletPath()
ExternalContext
Return the Jakarta Servlet path information (if any) included in the
request URI; otherwise, return null
.
Jakarta Servlet: This must be the value returned by the
javax.servlet.http.HttpServletRequest
method
getServletPath()
.
getRequestServletPath
in class ExternalContext
ExternalContext.getRequestServletPath()
public String getRequestCharacterEncoding()
ExternalContext
Return the character encoding currently being used to interpret this request.
Jakarta Servlet: This must return the value returned by the
javax.servlet.ServletRequest
method
getCharacterEncoding()
.
The default implementation throws
UnsupportedOperationException
and is provided
for the sole purpose of not breaking existing applications that extend
this class.
getRequestCharacterEncoding
in class ExternalContext
ExternalContext.getRequestCharacterEncoding()
public String getRequestContentType()
ExternalContext
Return the MIME Content-Type for this request. If not
available, return null
.
Jakarta Servlet: This must return the value returned by the
javax.servlet.ServletRequest
method
getContentType()
.
The default implementation throws
UnsupportedOperationException
and is provided
for the sole purpose of not breaking existing applications that extend
this class.
getRequestContentType
in class ExternalContext
ExternalContext.getRequestContentType()
public int getRequestContentLength()
ExternalContext
Return the result
of calling getContentLenth()
on the
ServletRequest
instance for this request.
The default implementation throws
UnsupportedOperationException
and is provided for
the sole purpose of not breaking existing applications that
extend this class.
getRequestContentLength
in class ExternalContext
ExternalContext.getRequestContentLength()
public String getResponseCharacterEncoding()
ExternalContext
Returns the name of the character encoding (MIME charset) used for the body sent in this response.
Jakarta Servlet: This must return the value returned by the
javax.servlet.ServletResponse
method
getCharacterEncoding()
.
Portlet: if this method is called
during a lifecycle phase other than RENDER_RESPONSE, this must
return null
. If called during RENDER_RESPONSE,
return the response encoding of the portlet response.
The default implementation throws
UnsupportedOperationException
and is provided
for the sole purpose of not breaking existing applications that extend
this class.
getResponseCharacterEncoding
in class ExternalContext
ExternalContext.getResponseCharacterEncoding()
public String getResponseContentType()
ExternalContext
Return the MIME Content-Type for this response. If not
available, return null
.
Jakarta Servlet: This must return the value returned by the
javax.servlet.ServletResponse
method
getContentType()
.
The default implementation throws
UnsupportedOperationException
and is provided
for the sole purpose of not breaking existing applications that extend
this class.
getResponseContentType
in class ExternalContext
ExternalContext.getResponseContentType()
public String getInitParameter(String name)
ExternalContext
Return the value of the specified application initialization parameter (if any).
Jakarta Servlet: This must be the result of the
javax.servlet.ServletContext
method
getInitParameter(name)
.
It is valid to call this method during application startup or shutdown. If called during application startup or shutdown, this method calls through to the actual container context to return the init parameter value.
getInitParameter
in class ExternalContext
name
- Name of the requested initialization parameterExternalContext.getInitParameter(String)
public Set<String> getResourcePaths(String path)
ExternalContext
Return the
Set
of resource paths for all application resources
whose resource path starts with the specified argument.
It is valid to call this method
during application startup or shutdown. If called during application
startup or shutdown, this method calls through to the
getResourcePaths()
method on the same container
context instance (ServletContext
or
PortletContext
) as the one used when calling
getResourcePaths()
on the
ExternalContext
returned by the
FacesContext
during an actual request.
Jakarta Servlet: This must be the value returned by the
javax.servlet.ServletContext
method
getResourcePaths(path).
getResourcePaths
in class ExternalContext
path
- Partial path used to match resources, which must
start with a slash ("/") characterSet
of resource paths for the application resources.ExternalContext.getResourcePaths(String)
public InputStream getResourceAsStream(String path)
ExternalContext
Return an
InputStream
for an application resource mapped to
the specified path, if it exists; otherwise, return
null
.
It is valid to call this method
during application startup or shutdown. If called during application
startup or shutdown, this method calls through to the
getResourceAsStream()
method on the same container
context instance (ServletContext
or
PortletContext
) as the one used when calling
getResourceAsStream()
on the
ExternalContext
returned by the
FacesContext
during an actual request.
Jakarta Servlet: This must be the value returned by the
javax.servlet.ServletContext
method
getResourceAsStream(path)
.
getResourceAsStream
in class ExternalContext
path
- The path to the requested resource, which must
start with a slash ("/" characterInputStream
for the application resource.ExternalContext.getResourceAsStream(String)
public URL getResource(String path)
ExternalContext
Return a
URL
for the application resource mapped to the
specified path, if it exists; otherwise, return
null
.
It is valid to call this method
during application startup or shutdown. If called during application
startup or shutdown, this method calls through to the
getResource()
method on the same container
context instance (ServletContext
or
PortletContext
) as the one used when calling
getResource()
on the
ExternalContext
returned by the
FacesContext
during an actual request.
Jakarta Servlet: This must be the value returned by the
javax.servlet.ServletContext
method
getResource(path)
.
getResource
in class ExternalContext
path
- The path to the requested resource, which must
start with a slash ("/" characterExternalContext.getResource(String)
public String encodeActionURL(String url)
ExternalContext
Return the input URL, after performing any rewriting needed to ensure that it will correctly identify an addressable action in the current application.
Encoding the ClientWindow
Call
ClientWindow.isClientWindowRenderModeEnabled(javax.faces.context.FacesContext)
. If the result isfalse
take no further action and return the rewritten URL. If the result istrue
, callExternalContext.getClientWindow()
. If the result is non-null
, callClientWindow.getId()
and append the id to the query string of the URL, making the necessary allowances for a pre-existing query string or no query-string.Call
ClientWindow.getQueryURLParameters(javax.faces.context.FacesContext)
. If the result is non-null
, for each parameter in the map, unconditionally add that parameter to the URL.The name of the query string parameter is given by the value of the constant
ResponseStateManager.CLIENT_WINDOW_URL_PARAM
.
Jakarta Servlet: This must be the value returned by the
javax.servlet.http.HttpServletResponse
method
encodeURL(url)
.
encodeActionURL
in class ExternalContext
url
- The input URL to be encodedExternalContext.encodeActionURL(String)
public String encodeResourceURL(String url)
ExternalContext
Return the input URL, after performing any rewriting needed to ensure that it will correctly identify an addressable resource in the current application.
Jakarta Servlet: This must be the value returned by the
javax.servlet.http.HttpServletResponse
method
encodeURL(url)
.
encodeResourceURL
in class ExternalContext
url
- The input URL to be encodedExternalContext.encodeResourceURL(String)
public String encodeWebsocketURL(String url)
ExternalContext
Return the websocket URL, after performing any rewriting needed to ensure that it will correctly identify an addressable websocket in the current application.
Jakarta Servlet: This must ensure that the input URL is prefixed
with the correct websocket scheme, domain and port and then
encoded by ExternalContext.encodeResourceURL(String)
.
encodeWebsocketURL
in class ExternalContext
url
- The input URL to be encoded.ExternalContext.encodeWebsocketURL(String)
public String encodeNamespace(String name)
ExternalContext
Return the specified name, after prefixing it with a namespace that ensures that it will be unique within the context of a particular page.
Jakarta Servlet: The input value must be returned unchanged.
encodeNamespace
in class ExternalContext
name
- Name to be encodedExternalContext.encodeNamespace(String)
public void dispatch(String requestURI) throws IOException, FacesException
ExternalContext
Dispatch a request to the specified resource to create output for this response.
Jakarta Servlet: This must be accomplished by calling the
javax.servlet.ServletContext
method
getRequestDispatcher(path)
, and calling the
forward()
method on the resulting object.
If the call to getRequestDisatcher(path)
returns null
, send aServletResponse SC_NOT_FOUND
error code.
dispatch
in class ExternalContext
requestURI
- Context relative path to the specified resource,
which must start with a slash ("/") characterIOException
- if an input/output error occursFacesException
- thrown if a ServletException
occursExternalContext.dispatch(String)
public void redirect(String requestURI) throws IOException
ExternalContext
Redirect a request
to the specified URL, and cause the
responseComplete()
method to be called on the
FacesContext
instance for the current request.
The implementation must determine if
the request is an Ajax
request by obtaining a
PartialViewContext
instance from the FacesContext
and
calling PartialViewContext.isAjaxRequest()
.
Jakarta Servlet: For
non Ajax
requests, this must be accomplished by calling
the javax.servlet.http.HttpServletResponse
method
sendRedirect()
.
PartialResponseWriter
instance from the
FacesContext
.ExternalContext.setResponseContentType(java.lang.String)
with text/xml
ExternalContext.setResponseCharacterEncoding(java.lang.String)
with UTF-8
ExternalContext.addResponseHeader(java.lang.String, java.lang.String)
with Cache-Control
,
no-cache
PartialResponseWriter.startDocument()
PartialResponseWriter.redirect(java.lang.String)
with the url
argument.PartialResponseWriter.endDocument()
redirect
in class ExternalContext
requestURI
- Absolute URL to which the client should be redirectedIOException
- if an input/output error occursExternalContext.redirect(String)
public void log(String message)
ExternalContext
Log the specified message to the application object.
It is valid to call this method
during application startup or shutdown. If called during application
startup or shutdown, this calls the log()
method on the same
container context instance (ServletContext
or
PortletContext
) as the one used during a call to
log()
on the ExternalContext
returned
by the FacesContext
during an actual request.
Jakarta Servlet: This must be performed by calling the
javax.servlet.ServletContext
method
log(String)
.
log
in class ExternalContext
message
- Message to be loggedExternalContext.log(String)
public void log(String message, Throwable throwable)
ExternalContext
Log the specified message and exception to the application object.
It is valid to call this method
during application startup or shutdown. If called during application
startup or shutdown, this calls the log()
method on the same
container context instance (ServletContext
or
PortletContext
) as the one used when calling
log()
on the ExternalContext
returned
by the FacesContext
during an actual request.
Jakarta Servlet: This must be performed by calling the
javax.servlet.ServletContext
method
log(String,Throwable)
.
log
in class ExternalContext
message
- Message to be loggedthrowable
- Exception to be loggedExternalContext.log(String, Throwable)
public String getAuthType()
ExternalContext
Return the name of the authentication scheme used to authenticate
the current user, if any; otherwise, return null
.
For standard authentication schemes, the returned value will match
one of the following constants:
BASIC_AUTH
, CLIENT_CERT_AUTH
,
DIGEST_AUTH
, or FORM_AUTH
.
Jakarta Servlet: This must be the value returned by the
javax.servlet.http.HttpServletRequest
method
getAuthType()
.
getAuthType
in class ExternalContext
ExternalContext.getAuthType()
public String getMimeType(String file)
ExternalContext
Returns the MIME type of the
specified file or null
if the MIME type is not
known. The MIME type is determined by the container.
It is valid to call this method
during application startup or shutdown. If called during application
startup or shutdown, this method calls through to the
getMimeType()
method on the same container
context instance (ServletContext
or
PortletContext
) as the one used when calling
getMimeType()
on the
ExternalContext
returned by the
FacesContext
during an actual request.
Jakarta Servlet: This must be the value returned by the
javax.servlet.ServletContext
method
getMimeType()
.
getMimeType
in class ExternalContext
file
- The file for which the mime type should be obtained.ExternalContext.getMimeType(String)
public String getRemoteUser()
ExternalContext
Return the login name of the user making the current request
if any; otherwise, return null
.
Jakarta Servlet: This must be the value returned by the
javax.servlet.http.HttpServletRequest
method
getRemoteUser()
.
getRemoteUser
in class ExternalContext
ExternalContext.getRemoteUser()
public Principal getUserPrincipal()
ExternalContext
Return the Principal
object containing the name of
the current authenticated user, if any; otherwise, return
null
.
Jakarta Servlet: This must be the value returned by the
javax.servlet.http.HttpServletRequest
method
getUserPrincipal()
.
getUserPrincipal
in class ExternalContext
Principal
object.ExternalContext.getUserPrincipal()
public boolean isUserInRole(String role)
ExternalContext
Return true
if the currently authenticated user is
included in the specified role. Otherwise, return false
.
Jakarta Servlet: This must be the value returned by the
javax.servlet.http.HttpServletRequest
method
isUserInRole(role)
.
isUserInRole
in class ExternalContext
role
- Logical role name to be checkedExternalContext.isUserInRole(String)
public void invalidateSession()
ExternalContext
Invalidates this session then unbinds any objects bound to it.
Jakarta Servlet: This must be the value returned by the
javax.servlet.http.HttpSession
method
invalidate()
.
The default implementation throws
UnsupportedOperationException
and is provided for
the sole purpose of not breaking existing applications that
extend this class.
invalidateSession
in class ExternalContext
ExternalContext.invalidateSession()
public void addResponseCookie(String name, String value, Map<String,Object> properties)
ExternalContext
Adds the cookie represented by the arguments to the response.
Jakarta Servlet: This must be accomplished by calling the
javax.servlet.http.HttpServletResponse
method
addCookie()
. The Cookie
argument must
be constructed by passing the name
and
value
parameters. If the properties
arugument is non-null
and not empty, the
Cookie
instance must be initialized as described
below.
Key in "values" Map |
Expected type of value. | Name of setter method on Cookie instance to be
set with the value from the Map . |
---|---|---|
comment | String | setComment |
domain | String | setDomain |
maxAge | Integer | setMaxAge |
secure | Boolean | setSecure |
path | String | setPath |
httpOnly | Boolean | setHttpOnly |
The default implementation throws
UnsupportedOperationException
and is provided for
the sole purpose of not breaking existing applications that
extend this class.
addResponseCookie
in class ExternalContext
name
- value
- properties
- ExternalContext.addResponseCookie(String, String, java.util.Map)
public OutputStream getResponseOutputStream() throws IOException
ExternalContext
Returns an OutputStream
suitable for writing binary data to the user-agent.
Jakarta Servlet: This must return the value returned by the
javax.servlet.ServletResponse
method
getOutputStream()
.
The default implementation throws
UnsupportedOperationException
and is provided for
the sole purpose of not breaking existing applications that
extend this class.
getResponseOutputStream
in class ExternalContext
OutputStream
for the current response.IOException
- any IO related exception.ExternalContext.getResponseOutputStream()
public Writer getResponseOutputWriter() throws IOException
ExternalContext
Returns a Writer
suitable for writing character data to the user-agent.
Jakarta Servlet: This must return the value returned by the
ServletResponse.getWriter()
.
The default implementation throws
UnsupportedOperationException
and is provided for
the sole purpose of not breaking existing applications that
extend this class.
getResponseOutputWriter
in class ExternalContext
Writer
for the current response.IOException
- any IO related exception.ExternalContext.getResponseOutputWriter()
public String getRequestScheme()
ExternalContext
Returns the name of the scheme used to make this request, for example, http, https, or ftp.
Jakarta Servlet: This must be the value returned by the
javax.servlet.ServletRequest
method
getScheme()
.
The default implementation throws
UnsupportedOperationException
and is provided for
the sole purpose of not breaking existing applications that
extend this class.
getRequestScheme
in class ExternalContext
ExternalContext.getRequestScheme()
public String getRequestServerName()
ExternalContext
Returns the host name of the server to which the request was sent.
Jakarta Servlet: This must be the value returned by the
javax.servlet.ServletRequest
method
getServerName()
.
The default implementation throws
UnsupportedOperationException
and is provided for
the sole purpose of not breaking existing applications that
extend this class.
getRequestServerName
in class ExternalContext
ExternalContext.getRequestServerName()
public int getRequestServerPort()
ExternalContext
Returns the port number to which the request was sent.
Jakarta Servlet: This must be the value returned by the
javax.servlet.ServletRequest
method
getServerPort()
.
The default implementation throws
UnsupportedOperationException
and is provided for
the sole purpose of not breaking existing applications that
extend this class.
getRequestServerPort
in class ExternalContext
ExternalContext.getRequestServerPort()
public void setResponseContentType(String contentType)
ExternalContext
Sets the content type of the response being sent to the client, if the response has not been committed yet.
Jakarta Servlet: This must call
setContentType()
on the underlying
javax.servlet.ServletResponse
instance.
The default implementation throws
UnsupportedOperationException
and is provided for
the sole purpose of not breaking existing applications that
extend this class.
setResponseContentType
in class ExternalContext
contentType
- The content type to be set as the contentType
of the response.ExternalContext.setResponseContentType(String)
public void setResponseHeader(String name, String value)
ExternalContext
Set the response header with the given name and value.
Jakarta Servlet:This must be performed by calling the
javax.servlet.http.HttpServletResponse
setHeader
method.
The default implementation throws
UnsupportedOperationException
and is provided for
the sole purpose of not breaking existing applications that
extend this class.
setResponseHeader
in class ExternalContext
name
- The name of the response header.value
- The value of the response header.ExternalContext.setResponseHeader(String, String)
public void addResponseHeader(String name, String value)
ExternalContext
Add the given name and value to the response header.
Jakarta Servlet:This must be performed by calling the
javax.servlet.http.HttpServletResponse
addHeader
method.
The default implementation throws
UnsupportedOperationException
and is provided for
the sole purpose of not breaking existing applications that
extend this class.
addResponseHeader
in class ExternalContext
name
- The name of the response header.value
- The value of the response header.ExternalContext.addResponseHeader(String, String)
public void setResponseBufferSize(int size)
ExternalContext
Set the buffer size for the current response.
Jakarta Servlet: This must be performed by calling the
javax.servlet.http.HttpServletResponse
setBufferSize
method.
The default implementation throws
UnsupportedOperationException
and is provided for
the sole purpose of not breaking existing applications that
extend this class.
setResponseBufferSize
in class ExternalContext
size
- the new buffer sizeExternalContext.setResponseBufferSize(int)
public boolean isResponseCommitted()
ExternalContext
Check if the current response has been committed.
Jakarta Servlet: This must be performed by calling the
javax.servlet.http.HttpServletResponse
isCommitted
method.
The default implementation throws
UnsupportedOperationException
and is provided for
the sole purpose of not breaking existing applications that
extend this class.
isResponseCommitted
in class ExternalContext
ExternalContext.isResponseCommitted()
public void responseReset()
ExternalContext
Resets the current response.
Jakarta Servlet: This must be performed by calling the
javax.servlet.http.HttpServletResponse
reset
method.
The default implementation throws
UnsupportedOperationException
and is provided for
the sole purpose of not breaking existing applications that
extend this class.
responseReset
in class ExternalContext
ExternalContext.responseReset()
public void responseSendError(int statusCode, String message) throws IOException
ExternalContext
Sends an HTTP status code with message.
Jakarta Servlet: This must be performed by calling the
javax.servlet.http.HttpServletResponse
sendError
method.
The default implementation throws
UnsupportedOperationException
and is provided for
the sole purpose of not breaking existing applications that
extend this class.
responseSendError
in class ExternalContext
statusCode
- an HTTP status codemessage
- an option message to detail the cause of the codeIOException
- any IO related exceptions.ExternalContext.responseSendError(int, String)
public void setResponseStatus(int statusCode)
ExternalContext
Sets the HTTP status code for the response.
Jakarta Servlet: This must be performed by calling the
javax.servlet.http.HttpServletResponse
setStatus
method.
The default implementation throws
UnsupportedOperationException
and is provided for
the sole purpose of not breaking existing applications that
extend this class.
setResponseStatus
in class ExternalContext
statusCode
- an HTTP status codeExternalContext.setResponseStatus(int)
public void responseFlushBuffer() throws IOException
ExternalContext
Flushes the buffered response content to the client.
Jakarta Servlet: This must be performed by calling the
javax.servlet.http.HttpServletResponse
flushBuffer
method.
The default implementation throws
UnsupportedOperationException
and is provided for
the sole purpose of not breaking existing applications that
extend this class.
responseFlushBuffer
in class ExternalContext
IOException
- any IO related exception.ExternalContext.responseFlushBuffer()
public void setResponseContentLength(int length)
ExternalContext
Set the content length of the response.
Jakarta Servlet: This must be performed by calling the
javax.servlet.http.HttpServletResponse
setContentLength
method.
The default implementation throws
UnsupportedOperationException
and is provided for
the sole purpose of not breaking existing applications that
extend this class.
setResponseContentLength
in class ExternalContext
length
- the value to be set.ExternalContext.setResponseContentLength(int)
public void setSessionMaxInactiveInterval(int interval)
ExternalContext
Specifies the time, in seconds, between client requests before the Jakarta Servlet container will invalidate this session.
An interval value of zero or less indicates that the session should never timeout.
Jakarta Servlet: This must call
setMaxInactiveInterval
on the underlying
javax.servlet.http.HttpServletRequest
instance.
The default implementation throws
UnsupportedOperationException
and is provided
for the sole purpose of not breaking existing applications that extend
this class.
setSessionMaxInactiveInterval
in class ExternalContext
interval
- the value to be set.ExternalContext.setSessionMaxInactiveInterval(int)
public int getResponseBufferSize()
ExternalContext
Return the buffer size for the current response.
Jakarta Servlet: This must be performed by calling the
javax.servlet.http.HttpServletResponse
getBufferSize
method.
The default implementation throws
UnsupportedOperationException
and is provided for
the sole purpose of not breaking existing applications that
extend this class.
getResponseBufferSize
in class ExternalContext
ExternalContext.getResponseBufferSize()
public int getSessionMaxInactiveInterval()
ExternalContext
Returns the maximum time interval, in seconds, that
the Jakarta Servlet container will keep this session open between client accesses.
After this interval, the Jakarta Servlet container will invalidate the session.
The maximum time interval can be set with the
ExternalContext.setSessionMaxInactiveInterval(int)
method.
A return value of zero or less indicates that the session will never timeout.
Jakarta Servlet: This must return the result of calling
getMaxInactiveInterval
on the underlying
javax.servlet.http.HttpSession
instance.
The default implementation throws
UnsupportedOperationException
and is provided
for the sole purpose of not breaking existing applications that extend
this class.
getSessionMaxInactiveInterval
in class ExternalContext
\
public boolean isSecure()
ExternalContext
Returns a boolean indicating whether this request was made using a secure channel, such as HTTPS.
Jakarta Servlet: This must return the result of calling
isSecure
on the underlying
javax.servlet.http.HttpServletRequest
instance.
The default implementation throws
UnsupportedOperationException
and is provided
for the sole purpose of not breaking existing applications that extend
this class.
isSecure
in class ExternalContext
ExternalContext.isSecure()
public String encodeBookmarkableURL(String baseUrl, Map<String,List<String>> parameters)
ExternalContext
The purpose of this method is to generate a query string from the collection of Parameter objects provided by the parameters argument and append that query string to the baseUrl. This method must be able to encode the parameters to a baseUrl that may or may not have existing query parameters. The parameter values should be encoded appropriately for the environment so that the resulting URL can be used as the target of a link (e.g., in an href attribute) in a Jakarta Server Faces response. It's possible for an ExternalContext implementation to override this method in any way that would make the URL bookmarkable in that environment.
See ExternalContext.encodeActionURL(java.lang.String)
for the required specification of how to encode the ClientWindow
.
The default implementation throws
UnsupportedOperationException
and is provided for
the sole purpose of not breaking existing applications that
extend this class.
encodeBookmarkableURL
in class ExternalContext
baseUrl
- The base URL onto which the query string generated by this method will be appended. The URL may contain query parameters.parameters
- The collection of Parameter objects, representing name=value pairs that are used to produce a query stringpublic String encodeRedirectURL(String baseUrl, Map<String,List<String>> parameters)
ExternalContext
See ExternalContext.encodeActionURL(java.lang.String)
for the required specification of how to encode the ClientWindow
.
encodeRedirectURL
in class ExternalContext
baseUrl
- The base URL onto which the query string generated by this method will be appended. The URL may contain query parameters.parameters
- The collection of Parameter objects, representing name=value pairs that are used to produce a query stringpublic String encodePartialActionURL(String url)
ExternalContext
Return the input URL, after performing any rewriting needed to ensure that it can be used in a partial page submission (ajax request) to correctly identify an addressable action in the current application.
See ExternalContext.encodeActionURL(java.lang.String)
for the required specification of how to encode the ClientWindow
.
Jakarta Servlet:Returns the same encoded URL as the
ExternalContext.encodeActionURL(String url)
method.
Portlet:Returns an encoded URL that, upon HTTP POST, will invoke the RESOURCE_PHASE of the portlet lifecycle.
encodePartialActionURL
in class ExternalContext
url
- The input URL to be encodedExternalContext.encodePartialActionURL(String)
public Flash getFlash()
ExternalContext
Return the threadsafe Flash
for this application. The default implementation will throw
UnsupportedOperationException
. Compliant Jakarta Server Faces
runtimes must provide an implementation of this method.
getFlash
in class ExternalContext
Flash
for this application.Comments to: faces-dev@eclipse.org.
Copyright © 2019 Eclipse Foundation. All rights reserved.
Use is subject to license terms.