{
chain.doFilter(servletRequest, servletResponse);
}
else
{
Init init = (Init) getServletContext().getAttribute( Seam.getComponentName(Init.class) );
/*
* We initialize the delegate on the first actual request and any time the
* init timestamp changes, so that the WicketFilter gets reinitialized whenever the
* hot deployment classloader detects changes, enabling wicket components to be hot deployed.
*/
if (init != null && lastInitTime != init.getTimestamp())
{
delegate.destroy();
Map<String, String> parameters = new HashMap<String, String>();
if ( getApplicationClass() != null )
{
parameters.put( "applicationClassName", getApplicationClass() );
}
if ( getUrlPattern() != null )
{
parameters.put("filterMappingUrlPattern", getUrlPattern());
}
else
{
parameters.put("filterMappingUrlPattern", "/*");
}
/* Let the seam debug flag control the wicket configuration flag (deployment vs. development) */
parameters.put("configuration",init.isDebug() ? "development" : "deployment");
if (getApplicationFactoryClass() != null)
{
parameters.put("applicationFactoryClassName", getApplicationFactoryClass());
}
if (isDetectPortletContext())
{
parameters.put("detectPortletContext", "true");
}
//We have no way of passing the hot deploy classLoader to the delegate filter created by
//WicketFilterInstantiator, because it is unwrapped as a plain filter, which only takes string
//pairs as configuration. In addition, it is a STATELESS component, so it can't listen for the
//reinitialization events and store the classloader itself. So we set it as the thread's contextClassLoader,
//and reset that afterwards
ClassLoader previousClassLoader = Thread.currentThread().getContextClassLoader();
if (hotDeployClassLoader != null)
Thread.currentThread().setContextClassLoader(hotDeployClassLoader);
try {
delegate.init(new FilterConfigWrapper(savedConfig, parameters));
}
finally {
if (hotDeployClassLoader != null)
Thread.currentThread().setContextClassLoader(previousClassLoader);
}
lastInitTime = init.getTimestamp();
}
delegate.doFilter(servletRequest, servletResponse, chain);
}
}