users@javaserverfaces-spec-public.java.net

[jsr344-experts mirror] [jsr344-experts] Re: 1012 ExternalContext.getApplicationContextPath()

From: Neil Griffin <neil.griffin_at_portletfaces.org>
Date: Thu, 20 Dec 2012 11:32:00 -0500

On Dec 19, 2012, at 4:39 PM, Edward Burns <edward.burns_at_oracle.com> wrote:

>>>>>> On Tue, 18 Dec 2012 14:48:23 -0500, Neil Griffin <neil.griffin_at_portletfaces.org> said:
>
> NG> Hi Ed,
> NG> Regarding issue 1012 [1], the JSF 2.2 JavaDocs expose a new method on ExternalContext named getApplicationContextPath() which has the following requirements:
>
> NG> * <p class="changed_added_2_2"><em>Servlet:</em>
> NG> * Return the result of calling
> NG> * <code>getContextPath()</code> on the
> NG> * <code>ServletContext</code> instance for this application. It is
> NG> * valid to call this method during application startup or shutdown.</p>
>
> NG> Since FacesContext.getCurrentInstance() is a ThreadLocal singleton
> NG> bound to the request thread, it is not possible to call
> NG> FacesContext.getCurrentInstance().getExternalContext() during
> NG> application startup or shutdown.
>
> Ooooooh, wait a minute here. The ability to do that is reeally
> important. FacesContext.getCurrentInstance() says:
>
> Return the FacesContext instance for the request that is being
> processed by the current thread. If called during application
> initialization or shutdown, 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.

My bad, thanks for pointing out the requirement.

>
> NG> Also, the Portlet API does not provide access to the underlying
> NG> ServletContext. I suppose that the best we could do in a portlet
> NG> environment would be to register a ServletContextListener and
> NG> remember the ServletContext instance for later reference.
>
> NG> When you get a chance, could you elaborate on what made it necessary
> NG> to add the getApplicationContextPath() feature?
>
> JIRA is down at the moment, but I recall it was just a feature request
> from a user, similar to yours or anyone else's. Mojarra also happens to
> use it in implementing 869-CSRF protection.

Gotcha, thanks.

>
> Ed
>
> --
> | edward.burns_at_oracle.com | office: +1 407 458 0017
> | homepage: | http://ridingthecrest.com/