[seam-commits] Seam SVN: r9495 - trunk/src/main/org/jboss/seam/web.
seam-commits at lists.jboss.org
seam-commits at lists.jboss.org
Tue Nov 4 07:39:11 EST 2008
Author: pete.muir at jboss.org
Date: 2008-11-04 07:39:11 -0500 (Tue, 04 Nov 2008)
New Revision: 9495
Modified:
trunk/src/main/org/jboss/seam/web/WicketFilter.java
Log:
JBSEAM-3621, thanks to Clint Popetz
Modified: trunk/src/main/org/jboss/seam/web/WicketFilter.java
===================================================================
--- trunk/src/main/org/jboss/seam/web/WicketFilter.java 2008-11-04 01:18:15 UTC (rev 9494)
+++ trunk/src/main/org/jboss/seam/web/WicketFilter.java 2008-11-04 12:39:11 UTC (rev 9495)
@@ -19,15 +19,19 @@
import org.jboss.seam.ScopeType;
import org.jboss.seam.annotations.Install;
import org.jboss.seam.annotations.Name;
+import org.jboss.seam.annotations.Observer;
import org.jboss.seam.annotations.Scope;
import org.jboss.seam.annotations.intercept.BypassInterceptors;
+import org.jboss.seam.contexts.Contexts;
+import org.jboss.seam.core.Init;
+import org.jboss.seam.deployment.HotDeploymentStrategy;
import org.jboss.seam.servlet.ContextualHttpServletRequest;
@Scope(APPLICATION)
@Name("org.jboss.seam.web.wicketFilter")
@Install(precedence = BUILT_IN, dependencies="org.jboss.seam.wicket.web.wicketFilterInstantiator")
@BypassInterceptors
- at org.jboss.seam.annotations.web.Filter
+ at org.jboss.seam.annotations.web.Filter(within="org.jboss.seam.debug.hotDeployFilter")
public class WicketFilter extends AbstractFilter
{
@@ -39,8 +43,26 @@
private boolean detectPortletContext;
+ private long lastInitTime = 0;
+ private FilterConfig savedConfig;
+ private ClassLoader hotDeployClassLoader;
+
+ @Observer(value= { "org.jboss.seam.postInitialization","org.jboss.seam.postReInitialization"} )
+ public void postReInitialization()
+ {
+ HotDeploymentStrategy strategy = (HotDeploymentStrategy)Contexts.getEventContext().get(HotDeploymentStrategy.NAME);
+ if (strategy != null)
+ {
+ hotDeployClassLoader = strategy.getClassLoader();
+ }
+ else
+ {
+ hotDeployClassLoader = null;
+ }
+ }
+
public void doFilter(final ServletRequest servletRequest, final ServletResponse servletResponse, final FilterChain chain) throws IOException, ServletException
{
if (delegate==null)
@@ -54,6 +76,55 @@
@Override
public void process() throws Exception
{
+ /*
+ * 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 (lastInitTime != Init.instance().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", "/*");
+ }
+ 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.instance().getTimestamp();
+ }
delegate.doFilter(servletRequest, servletResponse, chain);
}
@@ -67,32 +138,7 @@
super.init(filterConfig);
delegate = (javax.servlet.Filter) Component.getInstance("org.jboss.seam.wicket.web.wicketFilterInstantiator", ScopeType.STATELESS);
-
- if (delegate!=null)
- {
- 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", "/*");
- }
- if (getApplicationFactoryClass() != null)
- {
- parameters.put("applicationFactoryClassName", getApplicationFactoryClass());
- }
- if (isDetectPortletContext())
- {
- parameters.put("detectPortletContext", "true");
- }
- delegate.init( new FilterConfigWrapper(filterConfig, parameters) );
- }
+ savedConfig = filterConfig;
}
public String getApplicationClass()
More information about the seam-commits
mailing list