{
// If someone didn't release the RequestContext on an earlier request,
// then it'd still be around, and trying to create a new one
// would trigger an exception. We don't want to take down
// this thread for all eternity, so clean up after poorly-behaved code.
RequestContext context = RequestContext.getCurrentInstance();
if (context != null)
{
if (_LOG.isWarning())
{
_LOG.warning("RequestContext had not been properly released on earlier " + "request.");
}
context.release();
}
// See if we've got a cached RequestContext instance; if so,
// reattach it
final Object cachedRequestContext = externalContext.getRequestMap().get(
_REQUEST_CONTEXT);
// Catch both the null scenario and the
// RequestContext-from-a-different-classloader scenario
if (cachedRequestContext instanceof RequestContext)
{
context = (RequestContext) cachedRequestContext;
context.attach();
}
else
{
final RequestContextFactory factory = RequestContextFactory.getFactory();
assert factory != null;