Class ExternalContext
- Direct Known Subclasses:
- ExternalContextWrapper
This class allows the Faces API to be unaware of the nature of its containing application environment. In particular, this class allows Jakarta Faces based applications to run in either a Jakarta Servlet or a Portlet environment.
 The documentation for this class only specifies the behavior for the Jakarta Servlet implementation of
 ExternalContext. The Portlet implementation of ExternalContext is specified under
 the revision of the Portlet Bridge Specification for JavaServer
 Faces JSR that corresponds to this version of the Jakarta Faces Specification. 
 See the Preface of the Jakarta Faces Specification Document, for a reference.
 
 If a reference to an ExternalContext is obtained during application startup or shutdown time, any method
 documented as "valid to call this method during application startup or shutdown" must be supported during application
 startup or shutdown time. The result of calling a method during application startup or shutdown time that does not
 have this designation is undefined.
 
 An ExternalContext can be injected into a CDI managed bean using
 @Inject ExternalContext externalContext;
 
- 
Field SummaryFields
- 
Constructor SummaryConstructors
- 
Method SummaryModifier and TypeMethodDescriptionvoidAdds the cookie represented by the arguments to the response.voidaddResponseHeader(String name, String value) Add the given name and value to the response header.abstract voidDispatch a request to the specified resource to create output for this response.abstract StringencodeActionURL(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.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.abstract StringencodeNamespace(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.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.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.abstract StringencodeResourceURL(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.abstract StringencodeWebsocketURL(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.Return the name of the container context for this application.Return a mutableMaprepresenting the application scope attributes for the current application.abstract StringReturn the name of the authentication scheme used to authenticate the current user, if any; otherwise, returnnull.Return theClientWindowset in a preceding call tosetClientWindow(jakarta.faces.lifecycle.ClientWindow), ornullif no such call has been made.abstract ObjectReturn the application environment object instance for the current appication.Return the name of the container context for this application.getFlash()Return the threadsafeFlashfor this application.abstract StringgetInitParameter(String name) Return the value of the specified application initialization parameter (if any).Return an immutableMapwhose keys are the set of application initialization parameter names configured for this application, and whose values are the corresponding parameter values.getMimeType(String file) Returns the MIME type of the specified file ornullif the MIME type is not known.getRealPath(String path) Returns a String containing the real path for a given virtual path.abstract StringReturn the login name of the user making the current request if any; otherwise, returnnull.abstract ObjectReturn the environment-specific object instance for the current request.Return the character encoding currently being used to interpret this request.intReturn the result of callinggetContentLenth()on theServletRequestinstance for this request.Return the MIME Content-Type for this request.abstract StringReturn the portion of the request URI that identifies the web application context for this request.Return an immutableMapwhose keys are the set of cookie names included in the current request, and whose values (of typejakarta.servlet.http.Cookie) are the first (or only) cookie for each cookie name returned by the underlying request.Return an immutableMapwhose 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.Return an immutableMapwhose 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.abstract LocaleReturn the preferredLocalein which the client will accept content.Return anIteratorover the preferredLocales specified in the request, in decreasing order of preference.Return a mutableMaprepresenting the request scope attributes for the current application.Return an immutableMapwhose 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.Return anIteratorover the names of all request parameters included in the current request.Return an immutableMapwhose 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.abstract StringReturn the extra path information (if any) included in the request URI; otherwise, returnnull.Returns the name of the scheme used to make this request, for example, http, https, or ftp.Returns the host name of the server to which the request was sent.intReturns the port number to which the request was sent.abstract StringReturn the Jakarta Servlet path information (if any) included in the request URI; otherwise, returnnull.abstract URLgetResource(String path) Return aURLfor the application resource mapped to the specified path, if it exists; otherwise, returnnull.abstract InputStreamgetResourceAsStream(String path) Return anInputStreamfor an application resource mapped to the specified path, if it exists; otherwise, returnnull.getResourcePaths(String path) Return theSetof resource paths for all application resources whose resource path starts with the specified argument.abstract ObjectReturn the environment-specific object instance for the current response.intReturn the buffer size for the current response.Returns the name of the character encoding (MIME charset) used for the body sent in this response.Return the MIME Content-Type for this response.Returns anOutputStreamsuitable for writing binary data to the user-agent.Returns aWritersuitable for writing character data to the user-agent.abstract ObjectgetSession(boolean create) If thecreateparameter istrue, create (if necessary) and return a session instance associated with the current request.getSessionId(boolean create) Return the id of the current session or the empty string if no session has been created and thecreateparameter isfalse.Return a mutableMaprepresenting the session scope attributes for the current application.intReturns the maximum time interval, in seconds, that the Jakarta Servlet container will keep this session open between client accesses.abstract PrincipalReturn thePrincipalobject containing the name of the current authenticated user, if any; otherwise, returnnull.voidInvalidates this session then unbinds any objects bound to it.booleanCheck if the current response has been committed.booleanisSecure()Returns a boolean indicating whether this request was made using a secure channel, such as HTTPS.abstract booleanisUserInRole(String role) Returntrueif the currently authenticated user is included in the specified role.abstract voidLog the specified message to the application object.abstract voidLog the specified message and exception to the application object.abstract voidRedirect a request to the specified URL, and cause theresponseComplete()method to be called on theFacesContextinstance for the current request.abstract voidrelease()Release any resources associated with thisExternalContextinstance.voidFlushes the buffered response content to the client.voidResets the current response.voidresponseSendError(int statusCode, String message) Sends an HTTP status code with message.voidsetClientWindow(ClientWindow window) Associate this instance with aClientWindow.voidsetRequest(Object request) Set the environment-specific request to be returned by subsequent calls togetRequest().voidsetRequestCharacterEncoding(String encoding) Overrides the name of the character encoding used in the body of this request.voidsetResponse(Object response) Set the environment-specific response to be returned by subsequent calls togetResponse().voidsetResponseBufferSize(int size) Set the buffer size for the current response.voidsetResponseCharacterEncoding(String encoding) Sets the character encoding (MIME charset) of the response being sent to the client, for example, to UTF-8.voidsetResponseContentLength(int length) Set the content length of the response as an intvoidsetResponseContentLengthLong(long length) Set the content length of the response as a long.voidsetResponseContentType(String contentType) Sets the content type of the response being sent to the client, if the response has not been committed yet.voidsetResponseHeader(String name, String value) Set the response header with the given name and value.voidsetResponseStatus(int statusCode) Sets the HTTP status code for the response.voidsetSessionMaxInactiveInterval(int interval) Specifies the time, in seconds, between client requests before the Jakarta Servlet container will invalidate this session.
- 
Field Details- 
BASIC_AUTHString identifier for BASIC authentication. - See Also:
 
- 
CLIENT_CERT_AUTHString identifier for CLIENT_CERT authentication. - See Also:
 
- 
DIGEST_AUTHString identifier for DIGEST authentication. - See Also:
 
- 
FORM_AUTHString identifier for FORM authentication. - See Also:
 
 
- 
- 
Constructor Details- 
ExternalContextpublic ExternalContext()
 
- 
- 
Method Details- 
addResponseCookieAdds the cookie represented by the arguments to the response. Jakarta Servlet: This must be accomplished by calling the jakarta.servlet.http.HttpServletResponsemethodaddCookie(). TheCookieargument must be constructed by passing thenameandvalueparameters. If thepropertiesarugument is non-nulland not empty, theCookieinstance must be initialized as described below.Cookie handling table Key in "values" Map(case sensitive)Expected type of value. Name of setter method on Cookieinstance to be set with the value from theMap.comment String setComment domain String setDomain maxAge Integer setMaxAge secure Boolean setSecure path String setPath httpOnly Boolean setHttpOnly any other attribute (e.g. SameSite) String setAttribute The default implementation throws UnsupportedOperationExceptionand is provided for the sole purpose of not breaking existing applications that extend this class.- Parameters:
- name- To be passed as the first argument to the- Cookieconstructor.
- value- To be passed as the second argument to the- Cookieconstructor.
- properties- A- Mapcontaing key/value pairs to be passed as arguments to the setter methods as described above.
- Since:
- 2.0
 
- 
dispatchDispatch a request to the specified resource to create output for this response. Jakarta Servlet: This must be accomplished by calling the jakarta.servlet.ServletContextmethodgetRequestDispatcher(path), and calling theforward()method on the resulting object.If the call to getRequestDisatcher(path)returnsnull, send aServletResponse SC_NOT_FOUNDerror code.- Parameters:
- path- Context relative path to the specified resource, which must start with a slash ("/") character
- Throws:
- FacesException- thrown if a- ServletExceptionoccurs
- IOException- if an input/output error occurs
 
- 
encodeActionURLReturn the input URL, after performing any rewriting needed to ensure that it will correctly identify an addressable action in the current application. Encoding the ClientWindowCall ClientWindow.isClientWindowRenderModeEnabled(jakarta.faces.context.FacesContext). If the result isfalsetake no further action and return the rewritten URL. If the result istrue, callgetClientWindow(). 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(jakarta.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 jakarta.servlet.http.HttpServletResponsemethodencodeURL(url).- Parameters:
- url- The input URL to be encoded
- Returns:
- the encoded URL.
- Throws:
- NullPointerException- if- urlis- null
 
- 
encodeNamespaceReturn 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. - Parameters:
- name- Name to be encoded
- Returns:
- the unique name prefixed with namespace.
 
- 
encodeResourceURLReturn 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 jakarta.servlet.http.HttpServletResponsemethodencodeURL(url).- Parameters:
- url- The input URL to be encoded
- Returns:
- the encoded resource URL.
- Throws:
- NullPointerException- if- urlis- null
 
- 
encodeWebsocketURLReturn 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 encodeResourceURL(String).- Parameters:
- url- The input URL to be encoded.
- Returns:
- the encoded websocket URL.
- Throws:
- NullPointerException- if- urlis- null.
- Since:
- 2.3
 
- 
getApplicationMapReturn a mutable Maprepresenting the application scope attributes for the current application. The returnedMapmust implement the entire contract for a modifiable map as described in the JavaDocs forjava.util.Map. Modifications made in theMapmust cause the corresponding changes in the set of application scope attributes. Particularly theclear(),remove(),put(),putAll(), andget()operations must take the appropriate action on the underlying data structure.It is valid to call this method during application startup or shutdown. If called at startup or shutdown time, this method returns a Mapthat is backed by the same container context instance (ServletContextorPortletContext) as the one returned by callinggetApplicationMap()on theExternalContextreturned by theFacesContextduring an actual request.Jakarta Servlet: This must be the set of attributes available via the jakarta.servlet.ServletContextmethodsgetAttribute(),getAttributeNames(),removeAttribute(), andsetAttribute().- Returns:
- the map associated with the backed ServletContext.
 
- 
getAuthTypeReturn 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, orFORM_AUTH.Jakarta Servlet: This must be the value returned by the jakarta.servlet.http.HttpServletRequestmethodgetAuthType().- Returns:
- the authentication type.
 
- 
getFlashReturn the threadsafe Flashfor this application. The default implementation will throwUnsupportedOperationException. Compliant Jakarta Faces runtimes must provide an implementation of this method.- Returns:
- the Flashfor this application.
- Since:
- 2.0
 
- 
getMimeTypeReturns the MIME type of the specified file or nullif 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 (ServletContextorPortletContext) as the one used when callinggetMimeType()on theExternalContextreturned by theFacesContextduring an actual request.Jakarta Servlet: This must be the value returned by the jakarta.servlet.ServletContextmethodgetMimeType().- Parameters:
- file- The file for which the mime type should be obtained.
- Returns:
- the MIME type of the file.
- Since:
- 2.0
 
- 
getContextReturn 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 ( ServletContextorPortletContext) as the one returned when callinggetContext()on theExternalContextreturned by theFacesContextduring an actual request.Jakarta Servlet: This must be the current application's jakarta.servlet.ServletContextinstance.- Returns:
- the object of the ServletContext.
 
- 
getContextNameReturn the name of the container context for this application. Return the result of calling getServletContextName()on theServletContextinstance for this application. It is valid to call this method during application startup or shutdown.The default implementation throws UnsupportedOperationExceptionand is provided for the sole purpose of not breaking existing applications that extend this class.- Returns:
- the name the ServletContext.
 
- 
getApplicationContextPathReturn the name of the container context for this application. Jakarta Servlet: Return the result of calling getContextPath()on theServletContextinstance for this application.It is valid to call this method during application startup or shutdown. The default implementation throws UnsupportedOperationExceptionand is provided for the sole purpose of not breaking existing applications that extend this class.- Returns:
- the context path of this application.
- Since:
- 2.2
 
- 
getInitParameterReturn the value of the specified application initialization parameter (if any). Jakarta Servlet: This must be the result of the jakarta.servlet.ServletContextmethodgetInitParameter(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. - Parameters:
- name- Name of the requested initialization parameter
- Returns:
- the value of the specified parameter.
- Throws:
- NullPointerException- if- nameis- null
 
- 
getInitParameterMapReturn an immutable Mapwhose keys are the set of application initialization parameter names configured for this application, and whose values are the corresponding parameter values. The returnedMapmust implement the entire contract for an unmodifiable map as described in the JavaDocs forjava.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 Mapthat is backed by the same container context instance (ServletContextorPortletContext) as the one returned by callinggetInitParameterMap()on theExternalContextreturned by theFacesContextduring an actual request.Jakarta Servlet: This result must be as if it were synthesized by calling the jakarta.servlet.ServletContextmethodgetInitParameterNames, and putting each configured parameter name/value pair into the result.- Returns:
- the init parameter map for this application.
 
- 
getRemoteUserReturn 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 jakarta.servlet.http.HttpServletRequestmethodgetRemoteUser().- Returns:
- the user name of the current request.
 
- 
getRequestReturn the environment-specific object instance for the current request. Jakarta Servlet: This must be the current request's jakarta.servlet.http.HttpServletRequestinstance.- Returns:
- the instance of the current request.
 
- 
setRequestSet the environment-specific request to be returned by subsequent calls to getRequest(). This may be used to install a wrapper for the request.The default implementation throws UnsupportedOperationExceptionand is provided for the sole purpose of not breaking existing applications that extend this class.- Parameters:
- request- the request object to be set.
- Since:
- 1.2
 
- 
getRequestSchemeReturns 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 jakarta.servlet.ServletRequestmethodgetScheme().The default implementation throws UnsupportedOperationExceptionand is provided for the sole purpose of not breaking existing applications that extend this class.- Returns:
- the name of the scheme.
- Since:
- 2.0
 
- 
getRequestServerNameReturns the host name of the server to which the request was sent. Jakarta Servlet: This must be the value returned by the jakarta.servlet.ServletRequestmethodgetServerName().The default implementation throws UnsupportedOperationExceptionand is provided for the sole purpose of not breaking existing applications that extend this class.- Returns:
- the host name of the server.
- Since:
- 2.0
 
- 
getRequestServerPortpublic int getRequestServerPort()Returns the port number to which the request was sent. Jakarta Servlet: This must be the value returned by the jakarta.servlet.ServletRequestmethodgetServerPort().The default implementation throws UnsupportedOperationExceptionand is provided for the sole purpose of not breaking existing applications that extend this class.- Returns:
- the port number to which the request was sent.
- Since:
- 2.0
 
- 
setRequestCharacterEncodingOverrides 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 ReaderorStreamhas been obtained from the request, in which case anIllegalStateExceptionis thrown.Jakarta Servlet: This must call through to the jakarta.servlet.ServletRequestmethodsetCharacterEncoding().The default implementation throws UnsupportedOperationExceptionand is provided for the sole purpose of not breaking existing applications that extend this class.- Parameters:
- encoding- the encoding name to be set.
- Throws:
- UnsupportedEncodingException- if this is not a valid encoding
- Since:
- 1.2
 
- 
getRealPathReturns 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 (ServletContextorPortletContext) as the one used when callinggetRealPath()on theExternalContextreturned by theFacesContextduring an actual request.Jakarta Servlet: This must be the value returned by the jakarta.servlet.ServletContextmethodgetRealPath().The default implementation throws UnsupportedOperationExceptionand is provided for the sole purpose of not breaking existing applications that extend this class.- Parameters:
- path- The context of the requested initialization parameter
- Returns:
- the real path for the specified virtual path.
- Since:
- 2.0
 
- 
getRequestContextPathReturn 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 jakarta.servlet.http.HttpServletRequestmethodgetContextPath().- Returns:
- the context path for this request.
 
- 
getRequestCookieMapReturn an immutable Mapwhose keys are the set of cookie names included in the current request, and whose values (of typejakarta.servlet.http.Cookie) are the first (or only) cookie for each cookie name returned by the underlying request. The returnedMapmust implement the entire contract for an unmodifiable map as described in the JavaDocs forjava.util.Map.Jakarta Servlet: This must be the value returned by the jakarta.servlet.http.HttpServletRequestmethodgetCookies(), unlessnullwas returned, in which case this must be a zero-length array.- Returns:
- the cookie map in the current request.
 
- 
getRequestHeaderMapReturn an immutable Mapwhose 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 returnedMapmust implement the entire contract for an unmodifiable map as described in the JavaDocs forjava.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 jakarta.servlet.http.HttpServletRequestmethodsgetHeader()andgetHeaderNames().- Returns:
- the header map in the current request.
 
- 
getRequestHeaderValuesMapReturn an immutable Mapwhose 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 returnedMapmust implement the entire contract for an unmodifiable map as described in the JavaDocs forjava.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 jakarta.servlet.http.HttpServletRequestmethodsgetHeaders()andgetHeaderNames().- Returns:
- the header values map in the current request.
 
- 
getRequestLocaleReturn the preferred Localein which the client will accept content.Jakarta Servlet: This must be the value returned by the jakarta.servlet.ServletRequestmethodgetLocale().- Returns:
- the Localeof the current request.
 
- 
getRequestLocalesReturn an Iteratorover the preferredLocales specified in the request, in decreasing order of preference.Jakarta Servlet: This must be an Iteratorover the values returned by thejakarta.servlet.ServletRequestmethodgetLocales().- Returns:
- the IteratorofLocales of the current request.
 
- 
getRequestMapReturn a mutable Maprepresenting the request scope attributes for the current application. The returnedMapmust implement the entire contract for a modifiable map as described in the JavaDocs forjava.util.Map. Modifications made in theMapmust cause the corresponding changes in the set of request scope attributes. Particularly theclear(),remove(),put(),putAll(), andget()operations must take the appropriate action on the underlying data structure.Jakarta Servlet: This must be the set of attributes available via the jakarta.servlet.ServletRequestmethodsgetAttribute(),getAttributeNames(),removeAttribute(), andsetAttribute().- Returns:
- the map including the attributes of the current request.
 
- 
getRequestParameterMapReturn an immutable Mapwhose 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 returnedMapmust implement the entire contract for an unmodifiable map as described in the JavaDocs forjava.util.Map.Jakarta Servlet: This must be the set of parameters available via the jakarta.servlet.ServletRequestmethodsgetParameter()andgetParameterNames().- Returns:
- the map for the current request parameters.
 
- 
getRequestParameterNamesReturn an Iteratorover the names of all request parameters included in the current request.Jakarta Servlet: This must be an Iteratorover the values returned by thejakarta.servlet.ServletRequestmethodgetParameterNames().- Returns:
- the Iteratorfor the names of the current request parameters.
 
- 
getRequestParameterValuesMapReturn an immutable Mapwhose 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 returnedMapmust implement the entire contract for an unmodifiable map as described in the JavaDocs forjava.util.Map.Jakarta Servlet: This must be the set of parameters available via the jakarta.servlet.ServletRequestmethodsgetParameterValues()andgetParameterNames().- Returns:
- the map for the parameter values of the current request.
 
- 
getRequestPathInfoReturn the extra path information (if any) included in the request URI; otherwise, return null.Jakarta Servlet: This must be the value returned by the jakarta.servlet.http.HttpServletRequestmethodgetPathInfo().- Returns:
- the path information of the current request.
 
- 
getRequestServletPathReturn 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 jakarta.servlet.http.HttpServletRequestmethodgetServletPath().- Returns:
- the Jakarta Servlet path information of the current request.
 
- 
getRequestCharacterEncodingReturn the character encoding currently being used to interpret this request. Jakarta Servlet: This must return the value returned by the jakarta.servlet.ServletRequestmethodgetCharacterEncoding().The default implementation throws UnsupportedOperationExceptionand is provided for the sole purpose of not breaking existing applications that extend this class.- Returns:
- the character encoding currently being used.
- Since:
- 1.2
 
- 
getRequestContentTypeReturn the MIME Content-Type for this request. If not available, return null.Jakarta Servlet: This must return the value returned by the jakarta.servlet.ServletRequestmethodgetContentType().The default implementation throws UnsupportedOperationExceptionand is provided for the sole purpose of not breaking existing applications that extend this class.- Returns:
- the Content-Type for this request.
- Since:
- 1.2
 
- 
getRequestContentLengthpublic int getRequestContentLength()Return the result of calling getContentLenth()on theServletRequestinstance for this request.The default implementation throws UnsupportedOperationExceptionand is provided for the sole purpose of not breaking existing applications that extend this class.- Returns:
- the content length of the current request.
- Since:
- 2.0
 
- 
getResponseCharacterEncodingReturns 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 jakarta.servlet.ServletResponsemethodgetCharacterEncoding().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 UnsupportedOperationExceptionand is provided for the sole purpose of not breaking existing applications that extend this class.- Returns:
- the name of the character encoding.
- Since:
- 1.2
 
- 
getResponseContentTypeReturn the MIME Content-Type for this response. If not available, return null.Jakarta Servlet: This must return the value returned by the jakarta.servlet.ServletResponsemethodgetContentType().The default implementation throws UnsupportedOperationExceptionand is provided for the sole purpose of not breaking existing applications that extend this class.- Returns:
- the MIME Content-Type for this response.
- Since:
- 1.2
 
- 
getResourceReturn a URLfor the application resource mapped to the specified path, if it exists; otherwise, returnnull.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 (ServletContextorPortletContext) as the one used when callinggetResource()on theExternalContextreturned by theFacesContextduring an actual request.Jakarta Servlet: This must be the value returned by the jakarta.servlet.ServletContextmethodgetResource(path).- Parameters:
- path- The path to the requested resource, which must start with a slash ("/" character
- Returns:
- the URL of the resource.
- Throws:
- MalformedURLException- if the specified path is not in the correct form
- NullPointerException- if- pathis- null
 
- 
getResourceAsStreamReturn an InputStreamfor an application resource mapped to the specified path, if it exists; otherwise, returnnull.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 (ServletContextorPortletContext) as the one used when callinggetResourceAsStream()on theExternalContextreturned by theFacesContextduring an actual request.Jakarta Servlet: This must be the value returned by the jakarta.servlet.ServletContextmethodgetResourceAsStream(path).- Parameters:
- path- The path to the requested resource, which must start with a slash ("/" character
- Returns:
- the InputStreamfor the application resource.
- Throws:
- NullPointerException- if- pathis- null
 
- 
getResourcePathsReturn the Setof 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 (ServletContextorPortletContext) as the one used when callinggetResourcePaths()on theExternalContextreturned by theFacesContextduring an actual request.Jakarta Servlet: This must be the value returned by the jakarta.servlet.ServletContextmethodgetResourcePaths(path).- Parameters:
- path- Partial path used to match resources, which must start with a slash ("/") character
- Returns:
- the Setof resource paths for the application resources.
- Throws:
- NullPointerException- if- pathis- null
 
- 
getResponseReturn the environment-specific object instance for the current response. Jakarta Servlet: This is the current request's jakarta.servlet.http.HttpServletResponseinstance.- Returns:
- the instance of the current jakarta.servlet.http.HttpServletResponse.
 
- 
setResponseSet the environment-specific response to be returned by subsequent calls to getResponse(). This may be used to install a wrapper for the response.The default implementation throws UnsupportedOperationExceptionand is provided for the sole purpose of not breaking existing applications that extend this class.- Parameters:
- response- the response instance to be set.
- Since:
- 1.2
 
- 
getResponseOutputStreamReturns an OutputStreamsuitable for writing binary data to the user-agent.Jakarta Servlet: This must return the value returned by the jakarta.servlet.ServletResponsemethodgetOutputStream().The default implementation throws UnsupportedOperationExceptionand is provided for the sole purpose of not breaking existing applications that extend this class.- Returns:
- the OutputStreamfor the current response.
- Throws:
- IOException- any IO related exception.
- Since:
- 2.0
 
- 
getResponseOutputWriterReturns a Writersuitable for writing character data to the user-agent.Jakarta Servlet: This must return the value returned by the ServletResponse.getWriter().The default implementation throws UnsupportedOperationExceptionand is provided for the sole purpose of not breaking existing applications that extend this class.- Returns:
- the Writerfor the current response.
- Throws:
- IOException- any IO related exception.
- Since:
- 2.0
 
- 
setResponseCharacterEncodingSets 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 jakarta.servlet.ServletResponsemethodsetCharacterEncoding().The default implementation throws UnsupportedOperationExceptionand is provided for the sole purpose of not breaking existing applications that extend this class.- Parameters:
- encoding- the character encoding to be sent by the current response.
- Since:
- 1.2
 
- 
setResponseContentTypeSets 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 underlyingjakarta.servlet.ServletResponseinstance.The default implementation throws UnsupportedOperationExceptionand is provided for the sole purpose of not breaking existing applications that extend this class.- Parameters:
- contentType- The content type to be set as the contentType of the response.
- Since:
- 2.0
 
- 
getSessionIf the createparameter istrue, create (if necessary) and return a session instance associated with the current request. If thecreateparameter isfalsereturn any existing session instance associated with the current request, or returnnullif there is no such session.Jakarta Servlet: This must return the result of calling getSession(create)on the underlyingjakarta.servlet.http.HttpServletRequestinstance.- Parameters:
- create- Flag indicating whether or not a new session should be created if there is no session associated with the current request
- Returns:
- the session object of the current request.
 
- 
getSessionIdReturn the id of the current session or the empty string if no session has been created and the createparameter isfalse.Jakarta Servlet: If createis true, obtain a reference to theHttpSessionfor the current request (creating the session if necessary) and return its id. Ifcreateisfalse, obtain a reference to the current session, if one exists, and return its id. If no session exists, return the empty string.- Parameters:
- create- Flag indicating whether or not a new session should be created if there is no session associated with the current request
- Returns:
- the session id for the current request.
- Since:
- 2.2
 
- 
getSessionMaxInactiveIntervalpublic int getSessionMaxInactiveInterval()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 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 getMaxInactiveIntervalon the underlyingjakarta.servlet.http.HttpSessioninstance.The default implementation throws UnsupportedOperationExceptionand is provided for the sole purpose of not breaking existing applications that extend this class.- Returns:
- the session maximum inactive interval.
- Since:
- 2.1
 
- 
getSessionMapReturn a mutable Maprepresenting the session scope attributes for the current application. The returnedMapmust implement the entire contract for a modifiable map as described in the JavaDocs forjava.util.Map. Modifications made in theMapmust cause the corresponding changes in the set of session scope attributes. Particularly theclear(),remove(),put(), andget()operations must take the appropriate action on the underlying data structure. Accessing attributes via thisMapmust cause the creation of a session associated with the current request, if such a session does not already exist.Jakarta Servlet: This must be the set of attributes available via the jakarta.servlet.http.HttpSessionmethodsgetAttribute(),getAttributeNames(),removeAttribute(), andsetAttribute().- Returns:
- the session map for the current application.
 
- 
getUserPrincipalReturn the Principalobject containing the name of the current authenticated user, if any; otherwise, returnnull.Jakarta Servlet: This must be the value returned by the jakarta.servlet.http.HttpServletRequestmethodgetUserPrincipal().- Returns:
- the Principalobject.
 
- 
getClientWindowReturn the ClientWindowset in a preceding call tosetClientWindow(jakarta.faces.lifecycle.ClientWindow), ornullif no such call has been made.- Returns:
- the instance of the ClientWindow.
- Since:
- 2.2
 
- 
invalidateSessionpublic void invalidateSession()Invalidates this session then unbinds any objects bound to it. Jakarta Servlet: This must be the value returned by the jakarta.servlet.http.HttpSessionmethodinvalidate().The default implementation throws UnsupportedOperationExceptionand is provided for the sole purpose of not breaking existing applications that extend this class.- Since:
- 2.0
 
- 
isUserInRoleReturn trueif the currently authenticated user is included in the specified role. Otherwise, returnfalse.Jakarta Servlet: This must be the value returned by the jakarta.servlet.http.HttpServletRequestmethodisUserInRole(role).- Parameters:
- role- Logical role name to be checked
- Returns:
- the flag indicating whether the current user is in the specified role.
- Throws:
- NullPointerException- if- roleis- null
 
- 
logLog 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 (ServletContextorPortletContext) as the one used during a call tolog()on theExternalContextreturned by theFacesContextduring an actual request.Jakarta Servlet: This must be performed by calling the jakarta.servlet.ServletContextmethodlog(String).- Parameters:
- message- Message to be logged
- Throws:
- NullPointerException- if- messageis- null
 
- 
logLog 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 (ServletContextorPortletContext) as the one used when callinglog()on theExternalContextreturned by theFacesContextduring an actual request.Jakarta Servlet: This must be performed by calling the jakarta.servlet.ServletContextmethodlog(String,Throwable).- Parameters:
- message- Message to be logged
- exception- Exception to be logged
- Throws:
- NullPointerException- if- messageor- exceptionis- null
 
- 
redirectRedirect a request to the specified URL, and cause the responseComplete()method to be called on theFacesContextinstance for the current request.The implementation must determine if the request is an Ajaxrequest by obtaining aPartialViewContextinstance from theFacesContextand callingPartialViewContext.isAjaxRequest().Jakarta Servlet: For non Ajaxrequests, this must be accomplished by calling thejakarta.servlet.http.HttpServletResponsemethodsendRedirect().For Ajax requests, the implementation must:- Get a PartialResponseWriterinstance from theFacesContext.
- Call setResponseContentType(java.lang.String)withtext/xml
- Call setResponseCharacterEncoding(java.lang.String)withUTF-8
- Call addResponseHeader(java.lang.String, java.lang.String)withCache-Control,no-cache
- Call PartialResponseWriter.startDocument()
- Call PartialResponseWriter.redirect(java.lang.String)with theurlargument.
- Call PartialResponseWriter.endDocument()
 - Parameters:
- url- Absolute URL to which the client should be redirected
- Throws:
- IllegalArgumentException- if the specified url is relative
- IllegalStateException- if, in a portlet environment, the current response object is a- RenderResponseinstead of an- ActionResponse
- IllegalStateException- if, in a Jakarta Servlet environment, the current response has already been committed
- IOException- if an input/output error occurs
 
- Get a 
- 
setResponseHeaderSet the response header with the given name and value. Jakarta Servlet:This must be performed by calling the jakarta.servlet.http.HttpServletResponsesetHeadermethod.The default implementation throws UnsupportedOperationExceptionand is provided for the sole purpose of not breaking existing applications that extend this class.- Parameters:
- name- The name of the response header.
- value- The value of the response header.
- Since:
- 2.0
 
- 
addResponseHeaderAdd the given name and value to the response header. Jakarta Servlet:This must be performed by calling the jakarta.servlet.http.HttpServletResponseaddHeadermethod.The default implementation throws UnsupportedOperationExceptionand is provided for the sole purpose of not breaking existing applications that extend this class.- Parameters:
- name- The name of the response header.
- value- The value of the response header.
- Since:
- 2.0
 
- 
setResponseBufferSizepublic void setResponseBufferSize(int size) Set the buffer size for the current response. Jakarta Servlet: This must be performed by calling the jakarta.servlet.http.HttpServletResponsesetBufferSizemethod.The default implementation throws UnsupportedOperationExceptionand is provided for the sole purpose of not breaking existing applications that extend this class.- Parameters:
- size- the new buffer size
- Since:
- 2.0
 
- 
getResponseBufferSizepublic int getResponseBufferSize()Return the buffer size for the current response. Jakarta Servlet: This must be performed by calling the jakarta.servlet.http.HttpServletResponsegetBufferSizemethod.The default implementation throws UnsupportedOperationExceptionand is provided for the sole purpose of not breaking existing applications that extend this class.- Returns:
- the buffer size of the response.
- Since:
- 2.0
 
- 
isResponseCommittedpublic boolean isResponseCommitted()Check if the current response has been committed. Jakarta Servlet: This must be performed by calling the jakarta.servlet.http.HttpServletResponseisCommittedmethod.The default implementation throws UnsupportedOperationExceptionand is provided for the sole purpose of not breaking existing applications that extend this class.- Returns:
- the flag indicating whether the current response has been committed.
- Since:
- 2.0
 
- 
responseResetpublic void responseReset()Resets the current response. Jakarta Servlet: This must be performed by calling the jakarta.servlet.http.HttpServletResponseresetmethod.The default implementation throws UnsupportedOperationExceptionand is provided for the sole purpose of not breaking existing applications that extend this class.- Since:
- 2.0
 
- 
responseSendErrorSends an HTTP status code with message. Jakarta Servlet: This must be performed by calling the jakarta.servlet.http.HttpServletResponsesendErrormethod.The default implementation throws UnsupportedOperationExceptionand is provided for the sole purpose of not breaking existing applications that extend this class.- Parameters:
- statusCode- an HTTP status code
- message- an option message to detail the cause of the code
- Throws:
- IOException- any IO related exceptions.
- Since:
- 2.0
 
- 
setResponseStatuspublic void setResponseStatus(int statusCode) Sets the HTTP status code for the response. Jakarta Servlet: This must be performed by calling the jakarta.servlet.http.HttpServletResponsesetStatusmethod.The default implementation throws UnsupportedOperationExceptionand is provided for the sole purpose of not breaking existing applications that extend this class.- Parameters:
- statusCode- an HTTP status code
- Since:
- 2.0
 
- 
setSessionMaxInactiveIntervalpublic void setSessionMaxInactiveInterval(int interval) 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 setMaxInactiveIntervalon the underlyingjakarta.servlet.http.HttpServletRequestinstance.The default implementation throws UnsupportedOperationExceptionand is provided for the sole purpose of not breaking existing applications that extend this class.- Parameters:
- interval- the value to be set.
- Since:
- 2.1
 
- 
setClientWindowAssociate this instance with a ClientWindow.- Parameters:
- window- the window with which this instance is associated.
- Since:
- 2.2
 
- 
responseFlushBufferFlushes the buffered response content to the client. Jakarta Servlet: This must be performed by calling the jakarta.servlet.http.HttpServletResponseflushBuffermethod.The default implementation throws UnsupportedOperationExceptionand is provided for the sole purpose of not breaking existing applications that extend this class.- Throws:
- IOException- any IO related exception.
- Since:
- 2.0
 
- 
setResponseContentLengthpublic void setResponseContentLength(int length) Set the content length of the response as an int Jakarta Servlet: This must be performed by calling the jakarta.servlet.http.HttpServletResponsesetContentLengthmethod.The default implementation throws UnsupportedOperationExceptionand is provided for the sole purpose of not breaking existing applications that extend this class.- Parameters:
- length- the value to be set.
- Since:
- 2.0
 
- 
setResponseContentLengthLongpublic void setResponseContentLengthLong(long length) Set the content length of the response as a long. Jakarta Servlet: This must be performed by calling the jakarta.servlet.http.HttpServletResponsesetContentLengthLongmethod.The default implementation throws UnsupportedOperationExceptionand is provided for the sole purpose of not breaking existing applications that extend this class.- Parameters:
- length- the value to be set.
- Since:
- 4.1
 
- 
encodeBookmarkableURLThe 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 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 encodeActionURL(java.lang.String)for the required specification of how to encode theClientWindow.The default implementation throws UnsupportedOperationExceptionand is provided for the sole purpose of not breaking existing applications that extend this class.- Parameters:
- 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 string
- Returns:
- the result of encoding.
- Since:
- 2.0
 
- 
encodeRedirectURLThe 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 redirect. It's possible for an ExternalContext implementation to override this method to accomodate the definition of redirect for that environment.See encodeActionURL(java.lang.String)for the required specification of how to encode theClientWindow.- Parameters:
- 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 string
- Returns:
- the result of encoding.
- Since:
- 2.0
 
- 
encodePartialActionURLReturn 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 encodeActionURL(java.lang.String)for the required specification of how to encode theClientWindow.Jakarta Servlet:Returns the same encoded URL as the encodeActionURL(String url)method.Portlet:Returns an encoded URL that, upon HTTP POST, will invoke the RESOURCE_PHASE of the portlet lifecycle. - Parameters:
- url- The input URL to be encoded
- Returns:
- the encoded URL.
- Throws:
- NullPointerException- if- urlis- null
- Since:
- 2.0
 
- 
isSecurepublic boolean isSecure()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 isSecureon the underlyingjakarta.servlet.http.HttpServletRequestinstance.The default implementation throws UnsupportedOperationExceptionand is provided for the sole purpose of not breaking existing applications that extend this class.- Returns:
- the boolean indicating whether this request is secured.
- Since:
- 2.1
 
- 
releasepublic abstract void release()Release any resources associated with this ExternalContextinstance. This method is called during during destruction of the associatedFacesContext.- Since:
- 4.0
 
 
-