Weld SVN: r6084 - in extensions/trunk: src/main/java/org/jboss/weld/extensions and 4 other directories.
by weld-commits@lists.jboss.org
Author: swd847
Date: 2010-04-09 09:07:07 -0400 (Fri, 09 Apr 2010)
New Revision: 6084
Added:
extensions/trunk/src/main/java/org/jboss/weld/extensions/ResourceListener.java
extensions/trunk/src/main/java/org/jboss/weld/extensions/resources/servlet/
extensions/trunk/src/main/java/org/jboss/weld/extensions/resources/servlet/ServletContextDestroyedEvent.java
extensions/trunk/src/main/java/org/jboss/weld/extensions/resources/servlet/ServletContextInitializedEvent.java
extensions/trunk/src/main/java/org/jboss/weld/extensions/resources/servlet/ServletResourceExtension.java
Modified:
extensions/trunk/pom.xml
extensions/trunk/src/main/java/org/jboss/weld/extensions/resources/spi/ResourceLoader.java
extensions/trunk/src/main/java/org/jboss/weld/extensions/resources/spi/ResourceLoaderImpl.java
extensions/trunk/src/main/resources/META-INF/services/javax.enterprise.inject.spi.Extension
Log:
added loading resources from the ServletContext
Modified: extensions/trunk/pom.xml
===================================================================
--- extensions/trunk/pom.xml 2010-04-09 11:28:53 UTC (rev 6083)
+++ extensions/trunk/pom.xml 2010-04-09 13:07:07 UTC (rev 6084)
@@ -154,6 +154,12 @@
</exclusion>
</exclusions>
</dependency>
+
+ <dependency>
+ <groupId>javax.servlet</groupId>
+ <artifactId>servlet-api</artifactId>
+ <optional>true</optional>
+ </dependency>
<dependency>
<groupId>javax.enterprise</groupId>
Added: extensions/trunk/src/main/java/org/jboss/weld/extensions/ResourceListener.java
===================================================================
--- extensions/trunk/src/main/java/org/jboss/weld/extensions/ResourceListener.java (rev 0)
+++ extensions/trunk/src/main/java/org/jboss/weld/extensions/ResourceListener.java 2010-04-09 13:07:07 UTC (rev 6084)
@@ -0,0 +1,81 @@
+package org.jboss.weld.extensions;
+
+import java.lang.annotation.Annotation;
+import java.util.ArrayList;
+import java.util.List;
+
+import javax.enterprise.inject.spi.BeanManager;
+import javax.naming.InitialContext;
+import javax.naming.NamingException;
+import javax.servlet.ServletContextEvent;
+import javax.servlet.ServletContextListener;
+
+import org.jboss.weld.extensions.resources.servlet.ServletContextDestroyedEvent;
+import org.jboss.weld.extensions.resources.servlet.ServletContextInitializedEvent;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * ServletContextListener that fires a CDI event when the ServletContext is
+ * created or destroyed
+ *
+ * @author Stuart Douglas
+ *
+ */
+//@WebListener
+public class ResourceListener implements ServletContextListener
+{
+ private BeanManager beanManager;
+
+ private Logger log = LoggerFactory.getLogger(ResourceListener.class);
+ // FIXME: hack to work around invalid binding in JBoss AS 6 M2
+ private static final List<String> beanManagerLocations = new ArrayList<String>()
+ {
+ private static final long serialVersionUID = 1L;
+ {
+ add("java:comp/BeanManager");
+ add("java:app/BeanManager");
+ }
+ };
+
+ public ResourceListener()
+ {
+ beanManager = lookupBeanManager();
+ }
+
+ private BeanManager lookupBeanManager()
+ {
+ for (String location : beanManagerLocations)
+ {
+ try
+ {
+ log.trace("Looking for Bean Manager at JNDI location #0", location);
+ return (BeanManager) new InitialContext().lookup(location);
+ }
+ catch (NamingException e)
+ {
+ // No panic, keep trying
+ log.debug("Bean Manager not found at JNDI location #0", location);
+ }
+ }
+ // OK, panic
+ throw new IllegalArgumentException("Could not find BeanManager in " + beanManagerLocations);
+ }
+
+ private void fireEvent(Object payload, Annotation... qualifiers)
+ {
+ log.trace("Firing event #0 with qualifiers #1", payload, qualifiers);
+ beanManager.fireEvent(payload, qualifiers);
+ }
+
+ public void contextDestroyed(ServletContextEvent sce)
+ {
+ fireEvent(new ServletContextDestroyedEvent(sce.getServletContext()));
+ }
+
+ public void contextInitialized(ServletContextEvent sce)
+ {
+ fireEvent(new ServletContextInitializedEvent(sce.getServletContext()));
+ }
+
+}
Added: extensions/trunk/src/main/java/org/jboss/weld/extensions/resources/servlet/ServletContextDestroyedEvent.java
===================================================================
--- extensions/trunk/src/main/java/org/jboss/weld/extensions/resources/servlet/ServletContextDestroyedEvent.java (rev 0)
+++ extensions/trunk/src/main/java/org/jboss/weld/extensions/resources/servlet/ServletContextDestroyedEvent.java 2010-04-09 13:07:07 UTC (rev 6084)
@@ -0,0 +1,25 @@
+package org.jboss.weld.extensions.resources.servlet;
+
+import javax.servlet.ServletContext;
+
+/**
+ * Event class that is fired from a ServletContextListener
+ *
+ * @author Stuart Douglas
+ *
+ */
+public class ServletContextDestroyedEvent
+{
+ ServletContext servletContext;
+
+ public ServletContextDestroyedEvent(ServletContext servletContext)
+ {
+ this.servletContext = servletContext;
+ }
+
+ public ServletContext getServletContext()
+ {
+ return servletContext;
+ }
+
+}
Added: extensions/trunk/src/main/java/org/jboss/weld/extensions/resources/servlet/ServletContextInitializedEvent.java
===================================================================
--- extensions/trunk/src/main/java/org/jboss/weld/extensions/resources/servlet/ServletContextInitializedEvent.java (rev 0)
+++ extensions/trunk/src/main/java/org/jboss/weld/extensions/resources/servlet/ServletContextInitializedEvent.java 2010-04-09 13:07:07 UTC (rev 6084)
@@ -0,0 +1,25 @@
+package org.jboss.weld.extensions.resources.servlet;
+
+import javax.servlet.ServletContext;
+
+/**
+ * Event class that is fired from a ServletContextListener
+ *
+ * @author Stuart Douglas
+ *
+ */
+public class ServletContextInitializedEvent
+{
+ ServletContext servletContext;
+
+ public ServletContextInitializedEvent(ServletContext servletContext)
+ {
+ this.servletContext = servletContext;
+ }
+
+ public ServletContext getServletContext()
+ {
+ return servletContext;
+ }
+
+}
Added: extensions/trunk/src/main/java/org/jboss/weld/extensions/resources/servlet/ServletResourceExtension.java
===================================================================
--- extensions/trunk/src/main/java/org/jboss/weld/extensions/resources/servlet/ServletResourceExtension.java (rev 0)
+++ extensions/trunk/src/main/java/org/jboss/weld/extensions/resources/servlet/ServletResourceExtension.java 2010-04-09 13:07:07 UTC (rev 6084)
@@ -0,0 +1,37 @@
+package org.jboss.weld.extensions.resources.servlet;
+
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.Set;
+
+import javax.enterprise.event.Observes;
+import javax.enterprise.inject.spi.Extension;
+import javax.servlet.ServletContext;
+
+/**
+ * Portable extension that listens for the creation of ServletContexts and
+ * stored them for other extensions to Consume
+ *
+ * @author stuart
+ *
+ */
+public class ServletResourceExtension implements Extension
+{
+ protected Set<ServletContext> servletContexts = new HashSet<ServletContext>();
+
+ public void registerServletContext(@Observes ServletContextInitializedEvent event)
+ {
+ servletContexts.add(event.getServletContext());
+ }
+
+ public void removeServletContext(@Observes ServletContextDestroyedEvent event)
+ {
+ servletContexts.remove(event.getServletContext());
+ }
+
+ public Set<ServletContext> getServletContexts()
+ {
+ return Collections.unmodifiableSet(servletContexts);
+ }
+
+}
Modified: extensions/trunk/src/main/java/org/jboss/weld/extensions/resources/spi/ResourceLoader.java
===================================================================
--- extensions/trunk/src/main/java/org/jboss/weld/extensions/resources/spi/ResourceLoader.java 2010-04-09 11:28:53 UTC (rev 6083)
+++ extensions/trunk/src/main/java/org/jboss/weld/extensions/resources/spi/ResourceLoader.java 2010-04-09 13:07:07 UTC (rev 6084)
@@ -2,6 +2,7 @@
import java.io.InputStream;
import java.net.URL;
+import java.util.Set;
public interface ResourceLoader
{
@@ -10,4 +11,6 @@
public InputStream getResourceAsStream(String name);
+ public Set<URL> getResources(String name);
+
}
Modified: extensions/trunk/src/main/java/org/jboss/weld/extensions/resources/spi/ResourceLoaderImpl.java
===================================================================
--- extensions/trunk/src/main/java/org/jboss/weld/extensions/resources/spi/ResourceLoaderImpl.java 2010-04-09 11:28:53 UTC (rev 6083)
+++ extensions/trunk/src/main/java/org/jboss/weld/extensions/resources/spi/ResourceLoaderImpl.java 2010-04-09 13:07:07 UTC (rev 6084)
@@ -1,18 +1,33 @@
package org.jboss.weld.extensions.resources.spi;
+import java.io.IOException;
import java.io.InputStream;
+import java.net.MalformedURLException;
import java.net.URL;
+import java.util.Enumeration;
+import java.util.HashSet;
+import java.util.Set;
+import javax.inject.Inject;
+import javax.servlet.ServletContext;
+
import org.jboss.weld.extensions.resources.ResourceProducer;
+import org.jboss.weld.extensions.resources.servlet.ServletResourceExtension;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class ResourceLoaderImpl implements ResourceLoader
{
-
+
+ private final Set<ServletContext> servletContexts;
+
private static final Logger log = LoggerFactory.getLogger("org.jboss.weld.extensions.resources");
- private ResourceLoaderImpl() {}
+ @Inject
+ private ResourceLoaderImpl(ServletResourceExtension extension)
+ {
+ servletContexts = extension.getServletContexts();
+ }
public InputStream getResourceAsStream(String name)
{
@@ -38,12 +53,22 @@
return stream;
}
}
+ String slashedName = getSlashedName(name);
+ for (ServletContext context : servletContexts)
+ {
+ InputStream stream = context.getResourceAsStream(slashedName);
+ if (stream != null)
+ {
+ log.trace("Loaded resource from ServletContext: " + slashedName);
+ return stream;
+ }
+ }
return null;
}
public URL getResource(String name)
{
- // Always use the strippedName, classloader always assumes no starting /
+ // Always use the strippedName, classloader always assumes no starting /
String strippedName = getStrippedName(name);
// Try to load from the TCCL
if (Thread.currentThread().getContextClassLoader() != null)
@@ -65,12 +90,93 @@
return url;
}
}
+ String slashedName = getSlashedName(name);
+ // Try to load from the ServletContext
+ for (ServletContext context : servletContexts)
+ {
+ try
+ {
+ URL url = context.getResource(slashedName);
+ if (url != null)
+ {
+ log.trace("Loaded resource from ServletContext: " + slashedName);
+ return url;
+ }
+ }
+ catch (MalformedURLException e)
+ {
+ log.error("Malformed URL loading " + name, e);
+ }
+ }
return null;
}
+
+ public Set<URL> getResources(String name)
+ {
+ Set<URL> urls = new HashSet<URL>();
+ // Always use the strippedName, classloader always assumes no starting /
+ String strippedName = getStrippedName(name);
+ // Try to load from the TCCL
+ if (Thread.currentThread().getContextClassLoader() != null)
+ {
+ try
+ {
+ Enumeration<URL> urlEnum = Thread.currentThread().getContextClassLoader().getResources(strippedName);
+ while (urlEnum.hasMoreElements())
+ {
+ urls.add(urlEnum.nextElement());
+ }
+ }
+ catch (IOException e)
+ {
+ // we are probably not going to recover from an IOException
+ throw new RuntimeException(e);
+ }
+ }
+ // Try to load from the extension's classloader
+ else
+ {
+ try
+ {
+ Enumeration<URL> urlEnum = ResourceProducer.class.getClassLoader().getResources(strippedName);
+ while (urlEnum.hasMoreElements())
+ {
+ urls.add(urlEnum.nextElement());
+ }
+ }
+ catch (IOException e)
+ {
+ throw new RuntimeException(e);
+ }
+ }
+ String slashedName = getSlashedName(name);
+ for (ServletContext context : servletContexts)
+ {
+ try
+ {
+ URL url = context.getResource(slashedName);
+ if (url != null)
+ {
+ urls.add(url);
+ }
+ }
+ catch (MalformedURLException e)
+ {
+ log.error("Malformed URL loading " + name, e);
+ }
+ }
+ return urls;
+ }
+
private static String getStrippedName(String name)
{
return name.startsWith("/") ? name.substring(1) : name;
}
+ private static String getSlashedName(String name)
+ {
+ return name.startsWith("/") ? name : "/" + name;
+ }
+
}
Modified: extensions/trunk/src/main/resources/META-INF/services/javax.enterprise.inject.spi.Extension
===================================================================
--- extensions/trunk/src/main/resources/META-INF/services/javax.enterprise.inject.spi.Extension 2010-04-09 11:28:53 UTC (rev 6083)
+++ extensions/trunk/src/main/resources/META-INF/services/javax.enterprise.inject.spi.Extension 2010-04-09 13:07:07 UTC (rev 6084)
@@ -1 +1,2 @@
-org.jboss.weld.extensions.genericbeans.GenericExtension
\ No newline at end of file
+org.jboss.weld.extensions.genericbeans.GenericExtension
+org.jboss.weld.extensions.resources.servlet.ServletResourceExtension
\ No newline at end of file
14 years, 7 months
Weld SVN: r6083 - in core/trunk: tests/src/test/java/org/jboss/weld/tests/proxy/weld56 and 3 other directories.
by weld-commits@lists.jboss.org
Author: nickarls
Date: 2010-04-09 07:28:53 -0400 (Fri, 09 Apr 2010)
New Revision: 6083
Added:
core/trunk/tests/src/test/resources/org/jboss/weld/tests/proxy/
core/trunk/tests/src/test/resources/org/jboss/weld/tests/proxy/weld56/
core/trunk/tests/src/test/resources/org/jboss/weld/tests/proxy/weld56/org.jboss.weld.enableUnsafeProxies
Modified:
core/trunk/impl/src/main/java/org/jboss/weld/util/reflection/instantiation/InstantiatorFactory.java
core/trunk/tests/src/test/java/org/jboss/weld/tests/proxy/weld56/ProxyTest.java
Log:
WELD-56
Modified: core/trunk/impl/src/main/java/org/jboss/weld/util/reflection/instantiation/InstantiatorFactory.java
===================================================================
--- core/trunk/impl/src/main/java/org/jboss/weld/util/reflection/instantiation/InstantiatorFactory.java 2010-04-08 11:55:46 UTC (rev 6082)
+++ core/trunk/impl/src/main/java/org/jboss/weld/util/reflection/instantiation/InstantiatorFactory.java 2010-04-09 11:28:53 UTC (rev 6083)
@@ -19,7 +19,9 @@
import java.util.ArrayList;
import java.util.List;
+import org.jboss.weld.Container;
import org.jboss.weld.bootstrap.api.Service;
+import org.jboss.weld.resources.spi.ResourceLoader;
/**
* A factory class for obtaining the first available instantiator
@@ -31,6 +33,7 @@
public class InstantiatorFactory implements Service
{
private static Instantiator availableInstantiator;
+ private static boolean enabled;
private static final List<Instantiator> instantiators = new ArrayList<Instantiator>()
{
@@ -50,6 +53,7 @@
break;
}
}
+ enabled = Container.instance().services().get(ResourceLoader.class).getResource("META-INF/org.jboss.weld.enableUnsafeProxies") != null;
}
public static Instantiator getInstantiator()
@@ -59,7 +63,7 @@
public static boolean useInstantiators()
{
- return "true".equals(System.getProperty("org.jboss.weld.instantiators"));
+ return enabled;
}
public void cleanup()
Modified: core/trunk/tests/src/test/java/org/jboss/weld/tests/proxy/weld56/ProxyTest.java
===================================================================
--- core/trunk/tests/src/test/java/org/jboss/weld/tests/proxy/weld56/ProxyTest.java 2010-04-08 11:55:46 UTC (rev 6082)
+++ core/trunk/tests/src/test/java/org/jboss/weld/tests/proxy/weld56/ProxyTest.java 2010-04-09 11:28:53 UTC (rev 6083)
@@ -1,14 +1,21 @@
package org.jboss.weld.tests.proxy.weld56;
import org.jboss.testharness.impl.packaging.Artifact;
+import org.jboss.testharness.impl.packaging.IntegrationTest;
+import org.jboss.testharness.impl.packaging.Packaging;
+import org.jboss.testharness.impl.packaging.PackagingType;
+import org.jboss.testharness.impl.packaging.Resource;
import org.jboss.weld.test.AbstractWeldTest;
import org.testng.annotations.Test;
@Artifact
+@IntegrationTest
+(a)Packaging(PackagingType.WAR)
+@Resource(source = "org.jboss.weld.enableUnsafeProxies", destination = "WEB-INF/classes/META-INF/org.jboss.weld.enableUnsafeProxies")
public class ProxyTest extends AbstractWeldTest
{
- @Test(groups="broken")
+ @Test
public void testProxy()
{
assert "ping".equals(getReference(Foo.class).ping());
Added: core/trunk/tests/src/test/resources/org/jboss/weld/tests/proxy/weld56/org.jboss.weld.enableUnsafeProxies
===================================================================
--- core/trunk/tests/src/test/resources/org/jboss/weld/tests/proxy/weld56/org.jboss.weld.enableUnsafeProxies (rev 0)
+++ core/trunk/tests/src/test/resources/org/jboss/weld/tests/proxy/weld56/org.jboss.weld.enableUnsafeProxies 2010-04-09 11:28:53 UTC (rev 6083)
@@ -0,0 +1 @@
+#
\ No newline at end of file
14 years, 7 months
Weld SVN: r6082 - in core/trunk: impl/src/main/java/org/jboss/weld/servlet and 1 other directories.
by weld-commits@lists.jboss.org
Author: nickarls
Date: 2010-04-08 07:55:46 -0400 (Thu, 08 Apr 2010)
New Revision: 6082
Modified:
core/trunk/impl/src/main/java/org/jboss/weld/context/ContextLifecycle.java
core/trunk/impl/src/main/java/org/jboss/weld/servlet/ServletLifecycle.java
core/trunk/tests/src/main/java/org/jboss/weld/mock/cluster/AbstractClusterTest.java
Log:
Fix clustering test (don't serialize beanstore)
Modified: core/trunk/impl/src/main/java/org/jboss/weld/context/ContextLifecycle.java
===================================================================
--- core/trunk/impl/src/main/java/org/jboss/weld/context/ContextLifecycle.java 2010-04-08 09:46:20 UTC (rev 6081)
+++ core/trunk/impl/src/main/java/org/jboss/weld/context/ContextLifecycle.java 2010-04-08 11:55:46 UTC (rev 6082)
@@ -37,6 +37,7 @@
import org.jboss.weld.context.api.BeanStore;
import org.jboss.weld.context.api.helpers.ConcurrentHashMapBeanStore;
import org.jboss.weld.context.beanstore.HashMapBeanStore;
+import org.jboss.weld.servlet.HttpPassThruSessionBeanStore;
import org.slf4j.cal10n.LocLogger;
/**
@@ -201,8 +202,7 @@
private void activateSessionContext()
{
-// activateContext(sessionContext, new HttpPassThruSessionBeanStore());
- sessionContext.setActive(true);
+ activateContext(sessionContext, new HttpPassThruSessionBeanStore());
}
public void endApplication()
Modified: core/trunk/impl/src/main/java/org/jboss/weld/servlet/ServletLifecycle.java
===================================================================
--- core/trunk/impl/src/main/java/org/jboss/weld/servlet/ServletLifecycle.java 2010-04-08 09:46:20 UTC (rev 6081)
+++ core/trunk/impl/src/main/java/org/jboss/weld/servlet/ServletLifecycle.java 2010-04-08 11:55:46 UTC (rev 6082)
@@ -91,14 +91,15 @@
*/
public void beginRequest(HttpServletRequest request)
{
- if (!RequestBeanStoreCache.isSet(request))
+ if (RequestBeanStoreCache.isSet(request))
{
- BeanStore requestBeanStore = new ConcurrentHashMapBeanStore();
- RequestBeanStoreCache.set(request, requestBeanStore);
- lifecycle.beginRequest(request.getRequestURI(), requestBeanStore);
- restoreSessionContext(request);
- restoreConversationContext(request);
+ return;
}
+ BeanStore requestBeanStore = new ConcurrentHashMapBeanStore();
+ RequestBeanStoreCache.set(request, requestBeanStore);
+ lifecycle.beginRequest(request.getRequestURI(), requestBeanStore);
+ restoreSessionContext(request);
+ restoreConversationContext(request);
}
/**
@@ -111,7 +112,7 @@
protected BeanStore restoreSessionContext(HttpServletRequest request)
{
HttpPassThruSessionBeanStore sessionBeanStore = HttpPassThruOnDemandSessionBeanStore.of(request);
- HttpSession session = request.getSession(true);
+ HttpSession session = request.getSession();
String sessionId = session == null ? "Inactive session" : session.getId();
lifecycle.restoreSession(sessionId, sessionBeanStore);
if (session != null)
Modified: core/trunk/tests/src/main/java/org/jboss/weld/mock/cluster/AbstractClusterTest.java
===================================================================
--- core/trunk/tests/src/main/java/org/jboss/weld/mock/cluster/AbstractClusterTest.java 2010-04-08 09:46:20 UTC (rev 6081)
+++ core/trunk/tests/src/main/java/org/jboss/weld/mock/cluster/AbstractClusterTest.java 2010-04-08 11:55:46 UTC (rev 6082)
@@ -23,14 +23,22 @@
import java.io.ObjectOutputStream;
import java.lang.reflect.Field;
import java.util.Collection;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import javax.enterprise.inject.spi.PassivationCapable;
+
import org.jboss.weld.Container;
import org.jboss.weld.bootstrap.api.Singleton;
import org.jboss.weld.context.ContextLifecycle;
import org.jboss.weld.context.api.BeanStore;
+import org.jboss.weld.context.api.ContextualInstance;
+import org.jboss.weld.context.beanstore.HashMapBeanStore;
import org.jboss.weld.manager.BeanManagerImpl;
import org.jboss.weld.mock.MockEELifecycle;
import org.jboss.weld.mock.TestContainer;
+import org.jboss.weld.serialization.spi.helpers.SerializableContextual;
import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeClass;
@@ -38,21 +46,21 @@
{
private Singleton<Container> singleton;
-
+
@BeforeClass
public void beforeClass() throws Exception
{
singleton = (Singleton) getInstanceField().get(null);
getInstanceField().set(null, new SwitchableSingletonProvider().create(Container.class));
}
-
+
private static Field getInstanceField() throws Exception
{
Field field = Container.class.getDeclaredField("instance");
field.setAccessible(true);
return field;
}
-
+
@AfterClass
public void afterClass() throws Exception
{
@@ -63,26 +71,48 @@
{
// Bootstrap container
SwitchableSingletonProvider.use(id);
-
+
TestContainer container = new TestContainer(new MockEELifecycle(), classes, null);
container.startContainer();
container.ensureRequestActive();
-
+
return container;
}
-
+
protected void use(int id)
{
SwitchableSingletonProvider.use(id);
}
+ private Map<String, ContextualInstance<?>> getContextualInstances(BeanStore beanStore)
+ {
+ Map<String, ContextualInstance<?>> instances = new HashMap<String, ContextualInstance<?>>();
+ for (String id : beanStore.getContextualIds())
+ {
+ instances.put(id, beanStore.get(id));
+ }
+ return instances;
+ }
+
+ private BeanStore setContextualInstances(Map<String, ContextualInstance<?>> instances)
+ {
+ BeanStore beanStore = new HashMapBeanStore();
+ for (Map.Entry<String, ContextualInstance<?>> i : instances.entrySet())
+ {
+ beanStore.put(i.getKey(), i.getValue());
+ }
+ return beanStore;
+ }
+
+ @SuppressWarnings("unchecked")
protected void replicateSession(int fromId, BeanManagerImpl fromBeanManager, int toId, BeanManagerImpl toBeanManager) throws Exception
{
// Mimic replicating the session
BeanStore sessionBeanStore = fromBeanManager.getServices().get(ContextLifecycle.class).getSessionContext().getBeanStore();
- byte[] bytes = serialize(sessionBeanStore);
+ Map<String, ContextualInstance<?>> contextuals = getContextualInstances(sessionBeanStore);
+ byte[] bytes = serialize(contextuals);
use(toId);
- BeanStore replicatedSessionBeanStore = (BeanStore) deserialize(bytes);
+ BeanStore replicatedSessionBeanStore = setContextualInstances((Map<String, ContextualInstance<?>>) deserialize(bytes));
toBeanManager.getServices().get(ContextLifecycle.class).getSessionContext().setBeanStore(replicatedSessionBeanStore);
use(fromId);
}
14 years, 7 months
Weld SVN: r6081 - cdi-tck/branches/1.0/impl/src/main/java/org/jboss/jsr299/tck/tests/decorators/invocation.
by weld-commits@lists.jboss.org
Author: pete.muir(a)jboss.org
Date: 2010-04-08 05:46:20 -0400 (Thu, 08 Apr 2010)
New Revision: 6081
Modified:
cdi-tck/branches/1.0/impl/src/main/java/org/jboss/jsr299/tck/tests/decorators/invocation/DecoratorInvocationTest.java
Log:
Remove incorrect assertion assignment (needs port to trunk)
Modified: cdi-tck/branches/1.0/impl/src/main/java/org/jboss/jsr299/tck/tests/decorators/invocation/DecoratorInvocationTest.java
===================================================================
--- cdi-tck/branches/1.0/impl/src/main/java/org/jboss/jsr299/tck/tests/decorators/invocation/DecoratorInvocationTest.java 2010-04-07 16:17:38 UTC (rev 6080)
+++ cdi-tck/branches/1.0/impl/src/main/java/org/jboss/jsr299/tck/tests/decorators/invocation/DecoratorInvocationTest.java 2010-04-08 09:46:20 UTC (rev 6081)
@@ -55,7 +55,6 @@
@Test
@SpecAssertions({
- @SpecAssertion(section="8.2", id="b"),
@SpecAssertion(section="8.4", id="d"),
@SpecAssertion(section="8.4", id="e"),
@SpecAssertion(section="8.4", id="f"),
14 years, 7 months
Weld SVN: r6080 - extensions/tags.
by weld-commits@lists.jboss.org
Author: dan.j.allen
Date: 2010-04-07 12:17:38 -0400 (Wed, 07 Apr 2010)
New Revision: 6080
Removed:
extensions/tags/1.0.0.Practice/
Log:
remove practice tag
14 years, 7 months
Weld SVN: r6079 - in core/trunk: impl/src/main/java/org/jboss/weld/servlet and 1 other directories.
by weld-commits@lists.jboss.org
Author: nickarls
Date: 2010-04-07 08:03:06 -0400 (Wed, 07 Apr 2010)
New Revision: 6079
Modified:
core/trunk/impl/src/main/java/org/jboss/weld/context/ContextLifecycle.java
core/trunk/impl/src/main/java/org/jboss/weld/servlet/ServletLifecycle.java
core/trunk/tests/src/test/java/org/jboss/weld/tests/scope/ScopeTest.java
Log:
Unbreaking endRequest
Modified: core/trunk/impl/src/main/java/org/jboss/weld/context/ContextLifecycle.java
===================================================================
--- core/trunk/impl/src/main/java/org/jboss/weld/context/ContextLifecycle.java 2010-04-07 02:40:50 UTC (rev 6078)
+++ core/trunk/impl/src/main/java/org/jboss/weld/context/ContextLifecycle.java 2010-04-07 12:03:06 UTC (rev 6079)
@@ -26,11 +26,11 @@
import static org.jboss.weld.logging.LoggerFactory.loggerFactory;
import static org.jboss.weld.logging.messages.ContextMessage.APPLICATION_ENDED;
import static org.jboss.weld.logging.messages.ContextMessage.APPLICATION_STARTED;
+import static org.jboss.weld.logging.messages.ContextMessage.CONVERSATION_RESTORED;
import static org.jboss.weld.logging.messages.ContextMessage.REQUEST_ENDED;
import static org.jboss.weld.logging.messages.ContextMessage.REQUEST_STARTED;
import static org.jboss.weld.logging.messages.ContextMessage.SESSION_ENDED;
import static org.jboss.weld.logging.messages.ContextMessage.SESSION_RESTORED;
-import static org.jboss.weld.logging.messages.ContextMessage.CONVERSATION_RESTORED;
import org.jboss.weld.bootstrap.api.Lifecycle;
import org.jboss.weld.bootstrap.api.Service;
@@ -196,12 +196,13 @@
private void activateConversationContext()
{
- activateContext(conversationContext, new ConcurrentHashMapBeanStore());
+ activateContext(conversationContext, new HashMapBeanStore());
}
private void activateSessionContext()
{
- activateContext(sessionContext, new ConcurrentHashMapBeanStore());
+// activateContext(sessionContext, new HttpPassThruSessionBeanStore());
+ sessionContext.setActive(true);
}
public void endApplication()
@@ -270,7 +271,6 @@
public void endSession(String id, BeanStore sessionBeanStore)
{
log.trace(SESSION_ENDED, id);
- destroyConversationContext();
destroySessionContext(sessionBeanStore);
}
Modified: core/trunk/impl/src/main/java/org/jboss/weld/servlet/ServletLifecycle.java
===================================================================
--- core/trunk/impl/src/main/java/org/jboss/weld/servlet/ServletLifecycle.java 2010-04-07 02:40:50 UTC (rev 6078)
+++ core/trunk/impl/src/main/java/org/jboss/weld/servlet/ServletLifecycle.java 2010-04-07 12:03:06 UTC (rev 6079)
@@ -177,9 +177,9 @@
{
return;
}
- teardownRequest(request);
teardownConversation();
teardownSession(request);
+ teardownRequest(request);
}
private void teardownRequest(HttpServletRequest request)
Modified: core/trunk/tests/src/test/java/org/jboss/weld/tests/scope/ScopeTest.java
===================================================================
--- core/trunk/tests/src/test/java/org/jboss/weld/tests/scope/ScopeTest.java 2010-04-07 02:40:50 UTC (rev 6078)
+++ core/trunk/tests/src/test/java/org/jboss/weld/tests/scope/ScopeTest.java 2010-04-07 12:03:06 UTC (rev 6079)
@@ -73,6 +73,7 @@
{
ContextLifecycle lifecycle = Container.instance().services().get(ContextLifecycle.class);
lifecycle.endRequest("test", lifecycle.getRequestContext().getBeanStore());
+ lifecycle.restoreSession("test", new HashMapBeanStore());
lifecycle.beginRequest("test", new HashMapBeanStore());
}
14 years, 7 months
Weld SVN: r6077 - extensions/tags.
by weld-commits@lists.jboss.org
Author: dan.j.allen
Date: 2010-04-06 22:40:45 -0400 (Tue, 06 Apr 2010)
New Revision: 6077
Added:
extensions/tags/1.0.0.Practice/
Log:
[maven-scm] copy for tag 1.0.0.Practice
Copied: extensions/tags/1.0.0.Practice (from rev 6076, extensions/trunk)
14 years, 7 months
Weld SVN: r6075 - in core/trunk: impl/src/main/java/org/jboss/weld/conversation and 4 other directories.
by weld-commits@lists.jboss.org
Author: nickarls
Date: 2010-04-06 04:25:59 -0400 (Tue, 06 Apr 2010)
New Revision: 6075
Modified:
core/trunk/impl/src/main/java/org/jboss/weld/context/ContextLifecycle.java
core/trunk/impl/src/main/java/org/jboss/weld/conversation/AbstractConversationManager.java
core/trunk/impl/src/main/java/org/jboss/weld/logging/messages/ContextMessage.java
core/trunk/impl/src/main/java/org/jboss/weld/servlet/HttpPassThruOnDemandSessionBeanStore.java
core/trunk/impl/src/main/java/org/jboss/weld/servlet/ServletLifecycle.java
core/trunk/impl/src/main/resources/org/jboss/weld/messages/context_en.properties
core/trunk/tests/src/test/java/org/jboss/weld/tests/scope/ScopeTest.java
Log:
Clean up lifecycles (ContextLifecycle, ServletLifecycle, AbstractConversationManager)
Fix broken (until otherwise proven) test
Modified: core/trunk/impl/src/main/java/org/jboss/weld/context/ContextLifecycle.java
===================================================================
--- core/trunk/impl/src/main/java/org/jboss/weld/context/ContextLifecycle.java 2010-04-01 08:18:22 UTC (rev 6074)
+++ core/trunk/impl/src/main/java/org/jboss/weld/context/ContextLifecycle.java 2010-04-06 08:25:59 UTC (rev 6075)
@@ -30,6 +30,7 @@
import static org.jboss.weld.logging.messages.ContextMessage.REQUEST_STARTED;
import static org.jboss.weld.logging.messages.ContextMessage.SESSION_ENDED;
import static org.jboss.weld.logging.messages.ContextMessage.SESSION_RESTORED;
+import static org.jboss.weld.logging.messages.ContextMessage.CONVERSATION_RESTORED;
import org.jboss.weld.bootstrap.api.Lifecycle;
import org.jboss.weld.bootstrap.api.Service;
@@ -43,11 +44,21 @@
* destroying all the built in contexts
*
* @author Pete Muir
+ * @author Nicklas Karlsson
*
*/
public class ContextLifecycle implements Lifecycle, Service
{
-
+ /*
+ * Naming conventions:
+ *
+ * "activating a context" = setting a non-null BeanStore and setting active to true
+ * "deactivating a context" = setting a null BeanStore and setting active to false
+ * "destroying a context" = activating the context, calling destroy(), deactivating the context
+ * "restoring a context" = alias for activating the context
+ *
+ */
+
private static final LocLogger log = loggerFactory().getLogger(CONTEXT);
private final AbstractApplicationContext applicationContext;
@@ -67,36 +78,36 @@
this.dependentContext = dependentContext;
}
- public void restoreSession(String id, BeanStore sessionBeanStore)
+ public AbstractApplicationContext getApplicationContext()
{
- log.trace(SESSION_RESTORED, id);
- setupContext(sessionContext, sessionBeanStore);
+ return applicationContext;
}
- public void endSession(String id, BeanStore sessionBeanStore)
+ public AbstractApplicationContext getSingletonContext()
{
- log.trace(SESSION_ENDED, id);
- teardownContext(sessionContext);
+ return singletonContext;
}
- public void beginRequest(String id, BeanStore requestBeanStore)
+ public SessionContext getSessionContext()
{
- log.trace(REQUEST_STARTED, id);
- dependentContext.setActive(true);
- setupContext(requestContext, requestBeanStore);
- setupConversationContext();
+ return sessionContext;
}
- public void endRequest(String id, BeanStore requestBeanStore)
+ public ConversationContext getConversationContext()
{
- log.trace(REQUEST_ENDED, id);
- requestContext.setBeanStore(requestBeanStore);
- dependentContext.setActive(false);
- teardownContext(requestContext);
- conversationContext.setBeanStore(null);
- conversationContext.setActive(false);
+ return conversationContext;
}
+ public RequestContext getRequestContext()
+ {
+ return requestContext;
+ }
+
+ public DependentContext getDependentContext()
+ {
+ return dependentContext;
+ }
+
public boolean isRequestActive()
{
return singletonContext.isActive() && applicationContext.isActive() && requestContext.isActive() && dependentContext.isActive();
@@ -117,100 +128,216 @@
return singletonContext.isActive() && applicationContext.isActive() && sessionContext.isActive() && dependentContext.isActive();
}
+ public void cleanup()
+ {
+ dependentContext.cleanup();
+ requestContext.cleanup();
+ conversationContext.cleanup();
+ sessionContext.cleanup();
+ singletonContext.cleanup();
+ applicationContext.cleanup();
+ }
+
public void beginApplication(BeanStore applicationBeanStore)
{
log.trace(APPLICATION_STARTED, "");
- setupContext(applicationContext, applicationBeanStore);
- setupContext(singletonContext, new ConcurrentHashMapBeanStore());
+ activateApplicationContext(applicationBeanStore);
+ activateSingletonContext();
}
+ private void activateApplicationContext(BeanStore applicationBeanStore)
+ {
+ activateContext(applicationContext, applicationBeanStore);
+ }
+
+ private void activateContext(AbstractApplicationContext context, BeanStore beanStore)
+ {
+ if (beanStore == null)
+ {
+ throw new IllegalArgumentException("null bean store for " + context);
+ }
+ context.setBeanStore(beanStore);
+ context.setActive(true);
+ }
+
+ private void activateSingletonContext()
+ {
+ activateContext(singletonContext, new ConcurrentHashMapBeanStore());
+ }
+
+ public void beginRequest(String id, BeanStore requestBeanStore)
+ {
+ log.trace(REQUEST_STARTED, id);
+ activateDependentContext();
+ activateRequestContext(requestBeanStore);
+ activateConversationContext();
+ activateSessionContext();
+ }
+
+ private void activateDependentContext()
+ {
+ dependentContext.setActive(true);
+ }
+
+ private void activateRequestContext(BeanStore requestBeanStore)
+ {
+ activateContext(requestContext, requestBeanStore);
+ }
+
+ private void activateContext(AbstractThreadLocalMapContext context, BeanStore beanStore)
+ {
+ if (beanStore == null)
+ {
+ throw new IllegalArgumentException("null bean store for " + context);
+ }
+ context.setBeanStore(beanStore);
+ context.setActive(true);
+ }
+
+ private void activateConversationContext()
+ {
+ activateContext(conversationContext, new ConcurrentHashMapBeanStore());
+ }
+
+ private void activateSessionContext()
+ {
+ activateContext(sessionContext, new ConcurrentHashMapBeanStore());
+ }
+
public void endApplication()
{
log.trace(APPLICATION_ENDED, "");
- teardownContext(applicationContext);
- teardownContext(singletonContext);
+ destroyApplicationContext();
+ destroySingletonContext();
}
- public void cleanup()
+ private void destroyApplicationContext()
{
- dependentContext.cleanup();
- requestContext.cleanup();
- conversationContext.cleanup();
- sessionContext.cleanup();
- singletonContext.cleanup();
- applicationContext.cleanup();
+ destroyContext(applicationContext);
}
- public AbstractApplicationContext getApplicationContext()
+ private void destroyContext(AbstractApplicationContext context)
{
- return applicationContext;
+ if (context.getBeanStore() == null)
+ {
+ return;
+ }
+ activateContext(context, context.getBeanStore());
+ context.destroy();
+ deactivateContext(context);
}
- public AbstractApplicationContext getSingletonContext()
+ private void deactivateContext(AbstractApplicationContext context)
{
- return singletonContext;
+ context.setBeanStore(null);
+ context.setActive(false);
}
- public SessionContext getSessionContext()
+ private void destroySingletonContext()
{
- return sessionContext;
+ destroyContext(singletonContext);
}
- public ConversationContext getConversationContext()
+ public void endRequest(String id, BeanStore requestBeanStore)
{
- return conversationContext;
+ log.trace(REQUEST_ENDED, id);
+ deactivateDependentContext();
+ destroyRequestContext(requestBeanStore);
+ deactivateConversationContext();
+ deactivateSessionContext();
}
- public RequestContext getRequestContext()
+ private void deactivateDependentContext()
{
- return requestContext;
+ dependentContext.setActive(false);
}
- public DependentContext getDependentContext()
+ private void destroyRequestContext(BeanStore requestBeanStore)
{
- return dependentContext;
+ destroyContext(requestContext, requestBeanStore);
}
- public void setupConversationContext()
+ private void deactivateConversationContext()
{
- setupContext(conversationContext, new HashMapBeanStore());
+ deactivateContext(conversationContext);
}
- public void teardownConversationContext()
+ public void deactivateSessionContext()
{
- teardownContext(conversationContext);
+ deactivateContext(sessionContext);
}
- private void setupContext(AbstractThreadLocalMapContext context, BeanStore beanStore)
+ public void endSession(String id, BeanStore sessionBeanStore)
{
- context.setBeanStore(beanStore);
- context.setActive(true);
+ log.trace(SESSION_ENDED, id);
+ destroyConversationContext();
+ destroySessionContext(sessionBeanStore);
}
- private void setupContext(AbstractApplicationContext context, BeanStore beanStore)
+ private void destroyConversationContext()
{
- context.setBeanStore(beanStore);
- context.setActive(true);
+ destroyContext(conversationContext, conversationContext.getBeanStore());
}
-
- private void teardownContext(AbstractThreadLocalMapContext context)
+
+ private void destroySessionContext(BeanStore sessionBeanStore)
{
- if (context.getBeanStore() == null)
- {
- return;
- }
- context.setActive(true);
+ destroyContext(sessionContext, sessionBeanStore);
+ }
+
+ private void destroyContext(AbstractThreadLocalMapContext context, BeanStore beanStore)
+ {
+ activateContext(context, beanStore);
context.destroy();
- context.setBeanStore(null);
- context.setActive(false);
+ deactivateContext(context);
}
-
- private void teardownContext(AbstractApplicationContext context)
+
+ private void deactivateContext(AbstractThreadLocalMapContext context)
{
- context.setActive(true);
- context.destroy();
context.setBeanStore(null);
context.setActive(false);
- }
+ }
-}
+ public void restoreSession(String id, BeanStore sessionBeanStore)
+ {
+ log.trace(SESSION_RESTORED, id);
+ activateSessionContext(sessionBeanStore);
+ }
+
+ private void activateSessionContext(BeanStore sessionBeanStore)
+ {
+ activateContext(sessionContext, sessionBeanStore);
+ }
+
+ public void restoreConversation(String id, BeanStore conversationBeanStore)
+ {
+ log.trace(CONVERSATION_RESTORED, id);
+ activateConversationContext(new HashMapBeanStore());
+ conversationContext.loadTransientBeanStore(conversationBeanStore);
+ }
+
+ private void activateConversationContext(BeanStore conversationBeanStore)
+ {
+ activateContext(conversationContext, conversationBeanStore);
+ }
+
+ public void setupConversationContext()
+ {
+ activateConversationContext();
+ }
+
+ public void teardownConversationContext()
+ {
+ destroyConversationContext();
+ }
+
+ public boolean isSessionContextActive()
+ {
+ return sessionContext.isActive();
+ }
+
+ public boolean isRequestContextActive()
+ {
+ return requestContext.isActive();
+ }
+
+}
\ No newline at end of file
Modified: core/trunk/impl/src/main/java/org/jboss/weld/conversation/AbstractConversationManager.java
===================================================================
--- core/trunk/impl/src/main/java/org/jboss/weld/conversation/AbstractConversationManager.java 2010-04-01 08:18:22 UTC (rev 6074)
+++ core/trunk/impl/src/main/java/org/jboss/weld/conversation/AbstractConversationManager.java 2010-04-06 08:25:59 UTC (rev 6075)
@@ -167,7 +167,7 @@
}
String oldConversation = conversation.toString();
conversation.switchTo(resumedManagedConversation.getConversation());
- getConversationContext().loadTransientBeanStore(getBeanStore(cid));
+ getContextLifeCycle().restoreConversation(cid, getBeanStore(cid));
log.trace(CONVERSATION_SWITCHED, oldConversation, conversation);
return this;
}
@@ -297,17 +297,22 @@
public ConversationManager2 setupContext()
{
- Container.instance().services().get(ContextLifecycle.class).setupConversationContext();
+ getContextLifeCycle().setupConversationContext();
return this;
}
public ConversationManager2 teardownContext()
{
- Container.instance().services().get(ContextLifecycle.class).teardownConversationContext();
+ getContextLifeCycle().teardownConversationContext();
destroyBackgroundConversations();
return this;
}
+ private ContextLifecycle getContextLifeCycle()
+ {
+ return Container.instance().services().get(ContextLifecycle.class);
+ }
+
public String generateConversationId()
{
return conversationIdGenerator.nextId();
Modified: core/trunk/impl/src/main/java/org/jboss/weld/logging/messages/ContextMessage.java
===================================================================
--- core/trunk/impl/src/main/java/org/jboss/weld/logging/messages/ContextMessage.java 2010-04-01 08:18:22 UTC (rev 6074)
+++ core/trunk/impl/src/main/java/org/jboss/weld/logging/messages/ContextMessage.java 2010-04-06 08:25:59 UTC (rev 6075)
@@ -47,6 +47,7 @@
@MessageId("000210") DEPENDENT_INSTANCE_ATTACHED,
@MessageId("000211") DELIMITER_IN_PREFIX,
@MessageId("000212") CONTEXTUAL_IS_NULL,
- @MessageId("000213") NO_BEAN_STORE_AVAILABLE;
+ @MessageId("000213") NO_BEAN_STORE_AVAILABLE,
+ @MessageId("000214") CONVERSATION_RESTORED;
}
Modified: core/trunk/impl/src/main/java/org/jboss/weld/servlet/HttpPassThruOnDemandSessionBeanStore.java
===================================================================
--- core/trunk/impl/src/main/java/org/jboss/weld/servlet/HttpPassThruOnDemandSessionBeanStore.java 2010-04-01 08:18:22 UTC (rev 6074)
+++ core/trunk/impl/src/main/java/org/jboss/weld/servlet/HttpPassThruOnDemandSessionBeanStore.java 2010-04-06 08:25:59 UTC (rev 6075)
@@ -30,7 +30,7 @@
{
private final HttpServletRequest request;
- public HttpPassThruOnDemandSessionBeanStore(HttpServletRequest request)
+ protected HttpPassThruOnDemandSessionBeanStore(HttpServletRequest request)
{
this.request = request;
if (request.getSession(false) != null)
@@ -48,4 +48,9 @@
}
super.setAttribute(key, instance);
}
+
+ public static HttpPassThruSessionBeanStore of(HttpServletRequest request)
+ {
+ return new HttpPassThruOnDemandSessionBeanStore(request);
+ }
}
Modified: core/trunk/impl/src/main/java/org/jboss/weld/servlet/ServletLifecycle.java
===================================================================
--- core/trunk/impl/src/main/java/org/jboss/weld/servlet/ServletLifecycle.java 2010-04-01 08:18:22 UTC (rev 6074)
+++ core/trunk/impl/src/main/java/org/jboss/weld/servlet/ServletLifecycle.java 2010-04-06 08:25:59 UTC (rev 6075)
@@ -38,7 +38,8 @@
/**
* Implementation of the Weld lifecycle that can react to servlet events and
- * drives the Session, Conversation and Request (for Servlet requests) lifecycle
+ * drives the Servlet based lifecycles of the Session, Conversation and Request
+ * contexts
*
* @author Pete Muir
* @author Nicklas Karlsson
@@ -46,12 +47,33 @@
*/
public class ServletLifecycle
{
-
private final ContextLifecycle lifecycle;
- public static final String REQUEST_ATTRIBUTE_NAME = ServletLifecycle.class.getName() + ".requestBeanStore";
+ private static class RequestBeanStoreCache
+ {
+ private static final String REQUEST_ATTRIBUTE_NAME = ServletLifecycle.class.getName() + ".requestBeanStore";
+ public static void clear(HttpServletRequest request)
+ {
+ request.removeAttribute(REQUEST_ATTRIBUTE_NAME);
+ }
+ public static BeanStore get(HttpServletRequest request)
+ {
+ return (BeanStore) request.getAttribute(REQUEST_ATTRIBUTE_NAME);
+ }
+
+ public static void set(HttpServletRequest request, BeanStore requestBeanStore)
+ {
+ request.setAttribute(REQUEST_ATTRIBUTE_NAME, requestBeanStore);
+ }
+
+ public static boolean isSet(HttpServletRequest request)
+ {
+ return get(request) != null;
+ }
+ }
+
/**
* Constructor
*
@@ -63,65 +85,23 @@
}
/**
- * Begins a session
+ * Begins a HTTP request. Sets the session into the session context
*
- * @param session The HTTP session
+ * @param request The request
*/
- public void beginSession(HttpSession session)
+ public void beginRequest(HttpServletRequest request)
{
- HttpPassThruSessionBeanStore beanStore = (HttpPassThruSessionBeanStore) lifecycle.getSessionContext().getBeanStore();
- if (beanStore == null)
+ if (!RequestBeanStoreCache.isSet(request))
{
- restoreSessionContext(session);
+ BeanStore requestBeanStore = new ConcurrentHashMapBeanStore();
+ RequestBeanStoreCache.set(request, requestBeanStore);
+ lifecycle.beginRequest(request.getRequestURI(), requestBeanStore);
+ restoreSessionContext(request);
+ restoreConversationContext(request);
}
- else
- {
- beanStore.attachToSession(session);
- }
}
/**
- * Ends a session, setting up a mock request if necessary
- *
- * @param session The HTTP session
- */
- public void endSession(HttpSession session)
- {
- ServletConversationManager conversationManager = (ServletConversationManager) conversationManager(session.getServletContext());
- if (lifecycle.getSessionContext().isActive())
- {
- HttpPassThruSessionBeanStore beanStore = (HttpPassThruSessionBeanStore) lifecycle.getSessionContext().getBeanStore();
- if (lifecycle.getRequestContext().isActive())
- {
- // Probably invalidated during request. This will be terminated
- // at the end of the request.
- beanStore.invalidate();
- conversationManager.invalidateSession();
- }
- else
- {
- lifecycle.endSession(session.getId(), beanStore);
- }
- }
- else if (lifecycle.getRequestContext().isActive())
- {
- BeanStore store = restoreSessionContext(session);
- conversationManager.destroyBackgroundConversations();
- lifecycle.endSession(session.getId(), store);
- }
- else
- {
- BeanStore mockRequest = new ConcurrentHashMapBeanStore();
-
- lifecycle.beginRequest("endSession-" + session.getId(), mockRequest);
- BeanStore sessionBeanStore = restoreSessionContext(session);
- lifecycle.endSession(session.getId(), sessionBeanStore);
- lifecycle.endRequest("endSession-" + session.getId(), mockRequest);
- }
-
- }
-
- /**
* Restore the session from the underlying session object. Also allow the
* session to be injected by the Session manager
*
@@ -130,9 +110,10 @@
*/
protected BeanStore restoreSessionContext(HttpServletRequest request)
{
- HttpPassThruSessionBeanStore sessionBeanStore = new HttpPassThruOnDemandSessionBeanStore(request);
+ HttpPassThruSessionBeanStore sessionBeanStore = HttpPassThruOnDemandSessionBeanStore.of(request);
HttpSession session = request.getSession(true);
- lifecycle.restoreSession(session == null ? "Inactive session" : session.getId(), sessionBeanStore);
+ String sessionId = session == null ? "Inactive session" : session.getId();
+ lifecycle.restoreSession(sessionId, sessionBeanStore);
if (session != null)
{
sessionBeanStore.attachToSession(session);
@@ -141,32 +122,50 @@
return sessionBeanStore;
}
- protected BeanStore restoreSessionContext(HttpSession session)
+ private void restoreConversationContext(HttpServletRequest request)
{
- HttpPassThruSessionBeanStore beanStore = new HttpPassThruSessionBeanStore();
- beanStore.attachToSession(session);
- lifecycle.restoreSession(session.getId(), beanStore);
- httpSessionManager(session.getServletContext()).setSession(session);
- return beanStore;
+ // FIXME: HC "cid"
+ conversationManager(request.getSession().getServletContext()).setupConversation(request.getParameter("cid"));
}
/**
- * Begins a HTTP request. Sets the session into the session context
+ * Begins a session
*
- * @param request The request
+ * @param session The HTTP session
*/
- public void beginRequest(HttpServletRequest request)
+ public void beginSession(HttpSession session)
{
- if (request.getAttribute(REQUEST_ATTRIBUTE_NAME) == null)
+ HttpPassThruSessionBeanStore beanStore = getSessionBeanStore();
+ if (beanStore == null)
{
- BeanStore beanStore = new ConcurrentHashMapBeanStore();
- request.setAttribute(REQUEST_ATTRIBUTE_NAME, beanStore);
- lifecycle.beginRequest(request.getRequestURI(), beanStore);
- restoreSessionContext(request);
- conversationManager(request.getSession().getServletContext()).setupConversation(request.getParameter("cid"));
+ restoreSessionContext(session);
}
+ else
+ {
+ beanStore.attachToSession(session);
+ }
}
+ private HttpPassThruSessionBeanStore getSessionBeanStore()
+ {
+ return (HttpPassThruSessionBeanStore) lifecycle.getSessionContext().getBeanStore();
+ }
+
+ protected BeanStore restoreSessionContext(HttpSession session)
+ {
+ String sessionId = session.getId();
+ HttpPassThruSessionBeanStore beanStore = new HttpPassThruSessionBeanStore();
+ beanStore.attachToSession(session);
+ lifecycle.restoreSession(sessionId, beanStore);
+ cacheSession(session);
+ return beanStore;
+ }
+
+ private void cacheSession(HttpSession session)
+ {
+ httpSessionManager(session.getServletContext()).setSession(session);
+ }
+
/**
* Ends a HTTP request
*
@@ -174,40 +173,111 @@
*/
public void endRequest(HttpServletRequest request)
{
- if (request.getAttribute(REQUEST_ATTRIBUTE_NAME) == null)
+ if (!RequestBeanStoreCache.isSet(request))
{
return;
}
- HttpPassThruSessionBeanStore sessionBeanStore = (HttpPassThruSessionBeanStore) lifecycle.getSessionContext().getBeanStore();
- conversationManager(sessionBeanStore.getServletContext()).teardownConversation();
teardownRequest(request);
- lifecycle.getConversationContext().setBeanStore(null);
- lifecycle.getConversationContext().setActive(false);
+ teardownConversation();
teardownSession(request);
}
-
+
+ private void teardownRequest(HttpServletRequest request)
+ {
+ BeanStore beanStore = RequestBeanStoreCache.get(request);
+ if (beanStore == null)
+ {
+ throw new ForbiddenStateException(REQUEST_SCOPE_BEAN_STORE_MISSING);
+ }
+ lifecycle.endRequest(request.getRequestURI(), beanStore);
+ RequestBeanStoreCache.clear(request);
+ }
+
+ private void teardownConversation()
+ {
+ conversationManager(getServletContext()).teardownConversation();
+ }
+
+ private ServletContext getServletContext()
+ {
+ return getSessionBeanStore().getServletContext();
+ }
+
private void teardownSession(HttpServletRequest request)
{
- HttpPassThruSessionBeanStore sessionBeanStore = (HttpPassThruSessionBeanStore) lifecycle.getSessionContext().getBeanStore();
- if ((sessionBeanStore != null) && (sessionBeanStore.isInvalidated()))
+ HttpPassThruSessionBeanStore sessionBeanStore = getSessionBeanStore();
+ if (isSessionBeanStoreInvalid(sessionBeanStore))
{
- conversationManager(sessionBeanStore.getServletContext()).teardownContext();
+ conversationManager(getServletContext()).teardownContext();
lifecycle.endSession(request.getRequestedSessionId(), sessionBeanStore);
}
- lifecycle.getSessionContext().setActive(false);
- lifecycle.getSessionContext().setBeanStore(null);
-
+ lifecycle.deactivateSessionContext();
}
-
- private void teardownRequest(HttpServletRequest request)
+
+ private boolean isSessionBeanStoreInvalid(HttpPassThruSessionBeanStore sessionBeanStore)
{
- BeanStore beanStore = (BeanStore) request.getAttribute(REQUEST_ATTRIBUTE_NAME);
- if (beanStore == null)
+ return sessionBeanStore != null && sessionBeanStore.isInvalidated();
+ }
+
+ /**
+ * Ends a session, setting up a mock request if necessary
+ *
+ * @param session The HTTP session
+ */
+ public void endSession(HttpSession session)
+ {
+ if (lifecycle.isSessionContextActive())
{
- throw new ForbiddenStateException(REQUEST_SCOPE_BEAN_STORE_MISSING);
+ activeSessionTermination(session);
}
- lifecycle.endRequest(request.getRequestURI(), beanStore);
- request.removeAttribute(REQUEST_ATTRIBUTE_NAME);
+ else if (lifecycle.isRequestContextActive())
+ {
+ activeRequestTermination(session);
+ }
+ else
+ {
+ mockedSessionTermination(session);
+ }
}
+ private void activeRequestTermination(HttpSession session)
+ {
+ String sessionId = session.getId();
+ BeanStore store = restoreSessionContext(session);
+ getServletConversationManager().destroyBackgroundConversations();
+ lifecycle.endSession(sessionId, store);
+ }
+
+ private ServletConversationManager getServletConversationManager()
+ {
+ return (ServletConversationManager) conversationManager(getServletContext());
+ }
+
+ private void activeSessionTermination(HttpSession session)
+ {
+ String sessionId = session.getId();
+ HttpPassThruSessionBeanStore beanStore = getSessionBeanStore();
+ if (lifecycle.isRequestContextActive())
+ {
+ // Probably invalidated during request. This will be terminated
+ // at the end of the request.
+ beanStore.invalidate();
+ getServletConversationManager().invalidateSession();
+ }
+ else
+ {
+ lifecycle.endSession(sessionId, beanStore);
+ }
+ }
+
+ private void mockedSessionTermination(HttpSession session)
+ {
+ String sessionId = session.getId();
+ BeanStore mockRequest = new ConcurrentHashMapBeanStore();
+ lifecycle.beginRequest("endSession-" + sessionId, mockRequest);
+ BeanStore sessionBeanStore = restoreSessionContext(session);
+ lifecycle.endSession(session.getId(), sessionBeanStore);
+ lifecycle.endRequest("endSession-" + sessionId, mockRequest);
+ }
+
}
Modified: core/trunk/impl/src/main/resources/org/jboss/weld/messages/context_en.properties
===================================================================
--- core/trunk/impl/src/main/resources/org/jboss/weld/messages/context_en.properties 2010-04-01 08:18:22 UTC (rev 6074)
+++ core/trunk/impl/src/main/resources/org/jboss/weld/messages/context_en.properties 2010-04-06 08:25:59 UTC (rev 6075)
@@ -11,4 +11,5 @@
DEPENDENT_INSTANCE_ATTACHED=Attached dependent instance {0} to {1}
DELIMITER_IN_PREFIX=The delimiter \\"{0}\\" should not be in the prefix \\"{1}\\"
CONTEXTUAL_IS_NULL=No contextual specified to retrieve (null)
-NO_BEAN_STORE_AVAILABLE=No bean store available for {0}
+NO_BEAN_STORE_AVAILABLE=No bean store available for {0}
+CONVERSATION_RESTORED=Restoring conversation {0}
Modified: core/trunk/tests/src/test/java/org/jboss/weld/tests/scope/ScopeTest.java
===================================================================
--- core/trunk/tests/src/test/java/org/jboss/weld/tests/scope/ScopeTest.java 2010-04-01 08:18:22 UTC (rev 6074)
+++ core/trunk/tests/src/test/java/org/jboss/weld/tests/scope/ScopeTest.java 2010-04-06 08:25:59 UTC (rev 6075)
@@ -64,9 +64,9 @@
newRequest();
assert tempConsumer.getSpecialTemp().getNumber() == 10;
- assert tempConsumer.getUselessTemp().getNumber() == 102;
+ assert tempConsumer.getUselessTemp().getNumber() == 11;
assert getReference(specialTempBean).getNumber() == 10;
- assert getReference(uselessTempBean).getNumber() == 102;
+ assert getReference(uselessTempBean).getNumber() == 11;
}
private void newRequest()
14 years, 7 months