You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@deltaspike.apache.org by st...@apache.org on 2012/08/06 04:20:01 UTC
[3/4] git commit: DELTASPIKE-207 move to ContextsService and fix
ServletContext invocations
DELTASPIKE-207 move to ContextsService and fix ServletContext invocations
Project: http://git-wip-us.apache.org/repos/asf/incubator-deltaspike/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-deltaspike/commit/439252fa
Tree: http://git-wip-us.apache.org/repos/asf/incubator-deltaspike/tree/439252fa
Diff: http://git-wip-us.apache.org/repos/asf/incubator-deltaspike/diff/439252fa
Branch: refs/heads/master
Commit: 439252fa891916db0ac1ae1673eafa954bb8f288
Parents: da18697
Author: Mark Struberg <st...@apache.org>
Authored: Mon Aug 6 04:16:05 2012 +0200
Committer: Mark Struberg <st...@apache.org>
Committed: Mon Aug 6 04:16:05 2012 +0200
----------------------------------------------------------------------
deltaspike/cdictrl/impl-owb/pom.xml | 19 +++
.../cdise/owb/OpenWebBeansContainerControl.java | 29 +++--
.../cdise/owb/OpenWebBeansContextControl.java | 123 ++++++---------
.../org/apache/deltaspike/cdise/owb/OwbHelper.java | 19 +++
4 files changed, 108 insertions(+), 82 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-deltaspike/blob/439252fa/deltaspike/cdictrl/impl-owb/pom.xml
----------------------------------------------------------------------
diff --git a/deltaspike/cdictrl/impl-owb/pom.xml b/deltaspike/cdictrl/impl-owb/pom.xml
index 63cc152..e3473f8 100644
--- a/deltaspike/cdictrl/impl-owb/pom.xml
+++ b/deltaspike/cdictrl/impl-owb/pom.xml
@@ -111,4 +111,23 @@
</plugins>
</build>
+ <profiles>
+ <profile>
+ <id>owbweb</id>
+ <!-- use this test to check with the web scanner and proxies -->
+
+ <dependencies>
+ <dependency>
+ <groupId>org.apache.openwebbeans</groupId>
+ <artifactId>openwebbeans-web</artifactId>
+ <version>${owb.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.geronimo.specs</groupId>
+ <artifactId>geronimo-el_2.2_spec</artifactId>
+ </dependency>
+ </dependencies>
+ </profile>
+ </profiles>
+
</project>
http://git-wip-us.apache.org/repos/asf/incubator-deltaspike/blob/439252fa/deltaspike/cdictrl/impl-owb/src/main/java/org/apache/deltaspike/cdise/owb/OpenWebBeansContainerControl.java
----------------------------------------------------------------------
diff --git a/deltaspike/cdictrl/impl-owb/src/main/java/org/apache/deltaspike/cdise/owb/OpenWebBeansContainerControl.java b/deltaspike/cdictrl/impl-owb/src/main/java/org/apache/deltaspike/cdise/owb/OpenWebBeansContainerControl.java
index 23d58c5..d94ae74 100644
--- a/deltaspike/cdictrl/impl-owb/src/main/java/org/apache/deltaspike/cdise/owb/OpenWebBeansContainerControl.java
+++ b/deltaspike/cdictrl/impl-owb/src/main/java/org/apache/deltaspike/cdise/owb/OpenWebBeansContainerControl.java
@@ -43,9 +43,9 @@ public class OpenWebBeansContainerControl implements CdiContainer
@Override
public BeanManager getBeanManager()
{
- if (this.lifecycle == null)
+ if (lifecycle == null)
{
- initLifecycle();
+ return null;
}
return lifecycle.getBeanManager();
}
@@ -53,8 +53,15 @@ public class OpenWebBeansContainerControl implements CdiContainer
@Override
public synchronized void boot()
{
- initLifecycle();
- lifecycle.startApplication(null);
+ lifecycle = WebBeansContext.currentInstance().getService(ContainerLifecycle.class);
+
+ Object mockServletContextEvent = null;
+ if (OpenWebBeansContextControl.isServletApiAvailable())
+ {
+ mockServletContextEvent = OwbHelper.getMockServletContextEvent();
+ }
+
+ lifecycle.startApplication(mockServletContextEvent);
}
@Override
@@ -67,8 +74,15 @@ public class OpenWebBeansContainerControl implements CdiContainer
if (lifecycle != null)
{
- lifecycle.stopApplication(null);
+ Object mockServletContextEvent = null;
+ if (OpenWebBeansContextControl.isServletApiAvailable())
+ {
+ mockServletContextEvent = OwbHelper.getMockServletContextEvent();
+ }
+
+ lifecycle.stopApplication(mockServletContextEvent);
}
+ lifecycle = null;
}
@Override
@@ -84,9 +98,4 @@ public class OpenWebBeansContainerControl implements CdiContainer
}
return ctxCtrl;
}
-
- private void initLifecycle()
- {
- lifecycle = WebBeansContext.getInstance().getService(ContainerLifecycle.class);
- }
}
http://git-wip-us.apache.org/repos/asf/incubator-deltaspike/blob/439252fa/deltaspike/cdictrl/impl-owb/src/main/java/org/apache/deltaspike/cdise/owb/OpenWebBeansContextControl.java
----------------------------------------------------------------------
diff --git a/deltaspike/cdictrl/impl-owb/src/main/java/org/apache/deltaspike/cdise/owb/OpenWebBeansContextControl.java b/deltaspike/cdictrl/impl-owb/src/main/java/org/apache/deltaspike/cdise/owb/OpenWebBeansContextControl.java
index c8467c0..9e8ba98 100644
--- a/deltaspike/cdictrl/impl-owb/src/main/java/org/apache/deltaspike/cdise/owb/OpenWebBeansContextControl.java
+++ b/deltaspike/cdictrl/impl-owb/src/main/java/org/apache/deltaspike/cdise/owb/OpenWebBeansContextControl.java
@@ -23,14 +23,13 @@ import javax.enterprise.context.ConversationScoped;
import javax.enterprise.context.Dependent;
import javax.enterprise.context.RequestScoped;
import javax.enterprise.context.SessionScoped;
-import javax.enterprise.context.spi.Context;
import javax.inject.Singleton;
import java.lang.annotation.Annotation;
import org.apache.deltaspike.cdise.api.ContextControl;
import org.apache.webbeans.config.WebBeansContext;
-import org.apache.webbeans.context.ContextFactory;
+import org.apache.webbeans.spi.ContextsService;
/**
* OWB specific impl of the {@link ContextControl}
@@ -42,24 +41,13 @@ public class OpenWebBeansContextControl implements ContextControl
@Override
public void startContexts()
{
- ContextFactory contextFactory = getContextFactory();
+ ContextsService contextsService = getContextsService();
- Object mockSession = null;
- if (isServletApiAvailable())
- {
- mockSession = OwbHelper.getMockSession();
- }
- Object mockServletContextEvent = null;
- if (isServletApiAvailable())
- {
- mockServletContextEvent = OwbHelper.getMockServletContextEvent();
- }
-
- contextFactory.initSingletonContext(mockServletContextEvent);
- contextFactory.initApplicationContext(mockServletContextEvent);
- contextFactory.initSessionContext(mockSession);
- contextFactory.initRequestContext(null);
- contextFactory.initConversationContext(null);
+ startSingletonScope();
+ startApplicationScope();
+ startSessionScope();
+ startRequestScope();
+ startConversationScope();
}
public void stopContexts()
@@ -112,7 +100,7 @@ public class OpenWebBeansContextControl implements ContextControl
}
}
- private static boolean isServletApiAvailable()
+ static boolean isServletApiAvailable()
{
try
{
@@ -130,41 +118,52 @@ public class OpenWebBeansContextControl implements ContextControl
* start scopes
*/
+ private void startSingletonScope()
+ {
+ ContextsService contextsService = getContextsService();
+ Object mockServletContext = null;
+ if (isServletApiAvailable())
+ {
+ mockServletContext = OwbHelper.getMockServletContext();
+ }
+ contextsService.startContext(Singleton.class, mockServletContext);
+ }
+
private void startApplicationScope()
{
- ContextFactory contextFactory = getContextFactory();
- Object mockServletContextEvent = null;
+ ContextsService contextsService = getContextsService();
+ Object mockServletContext = null;
if (isServletApiAvailable())
{
- mockServletContextEvent = OwbHelper.getMockServletContextEvent();
+ mockServletContext = OwbHelper.getMockServletContext();
}
- contextFactory.initApplicationContext(mockServletContextEvent);
+ contextsService.startContext(ApplicationScoped.class, mockServletContext);
}
private void startSessionScope()
{
- ContextFactory contextFactory = getContextFactory();
+ ContextsService contextsService = getContextsService();
Object mockSession = null;
if (isServletApiAvailable())
{
mockSession = OwbHelper.getMockSession();
}
- contextFactory.initSessionContext(mockSession);
+ contextsService.startContext(SessionScoped.class, mockSession);
}
private void startRequestScope()
{
- ContextFactory contextFactory = getContextFactory();
+ ContextsService contextsService = getContextsService();
- contextFactory.initRequestContext(null);
+ contextsService.startContext(RequestScoped.class, null);
}
private void startConversationScope()
{
- ContextFactory contextFactory = getContextFactory();
+ ContextsService contextsService = getContextsService();
- contextFactory.initConversationContext(null);
+ contextsService.startContext(ConversationScoped.class, null);
}
/*
@@ -173,77 +172,57 @@ public class OpenWebBeansContextControl implements ContextControl
private void stopSingletonScope()
{
- ContextFactory contextFactory = getContextFactory();
+ ContextsService contextsService = getContextsService();
- Context context = contextFactory.getStandardContext(Singleton.class);
- if (context != null)
+ Object mockServletContext = null;
+ if (isServletApiAvailable())
{
- Object mockServletContextEvent = null;
- if (isServletApiAvailable())
- {
- mockServletContextEvent = OwbHelper.getMockServletContextEvent();
- }
- contextFactory.destroySingletonContext(mockServletContextEvent);
+ mockServletContext = OwbHelper.getMockServletContext();
}
+ contextsService.endContext(Singleton.class, mockServletContext);
}
private void stopApplicationScope()
{
- ContextFactory contextFactory = getContextFactory();
+ ContextsService contextsService = getContextsService();
- Context context = contextFactory.getStandardContext(ApplicationScoped.class);
- if (context != null)
+ Object mockServletContext = null;
+ if (isServletApiAvailable())
{
- Object mockServletContextEvent = null;
- if (isServletApiAvailable())
- {
- mockServletContextEvent = OwbHelper.getMockServletContextEvent();
- }
- contextFactory.destroyApplicationContext(mockServletContextEvent);
+ mockServletContext = OwbHelper.getMockServletContext();
}
+ contextsService.endContext(ApplicationScoped.class, mockServletContext);
}
private void stopSessionScope()
{
- ContextFactory contextFactory = getContextFactory();
+ ContextsService contextsService = getContextsService();
- Context context = contextFactory.getStandardContext(SessionScoped.class);
- if (context != null)
+ Object mockSession = null;
+ if (isServletApiAvailable())
{
- Object mockSession = null;
- if (isServletApiAvailable())
- {
- mockSession = OwbHelper.getMockSession();
- }
- contextFactory.destroySessionContext(mockSession);
+ mockSession = OwbHelper.getMockSession();
}
+ contextsService.endContext(SessionScoped.class, mockSession);
}
private void stopRequestScope()
{
- ContextFactory contextFactory = getContextFactory();
+ ContextsService contextsService = getContextsService();
- Context context = contextFactory.getStandardContext(RequestScoped.class);
- if (context != null)
- {
- contextFactory.destroyRequestContext(null);
- }
+ contextsService.endContext(RequestScoped.class, null);
}
private void stopConversationScope()
{
- ContextFactory contextFactory = getContextFactory();
+ ContextsService contextsService = getContextsService();
- Context context = contextFactory.getStandardContext(ConversationScoped.class);
- if (context != null)
- {
- contextFactory.destroyConversationContext();
- }
+ contextsService.endContext(ConversationScoped.class, null);
}
- private ContextFactory getContextFactory()
+ private ContextsService getContextsService()
{
- WebBeansContext webBeansContext = WebBeansContext.getInstance();
- return webBeansContext.getContextFactory();
+ WebBeansContext webBeansContext = WebBeansContext.currentInstance();
+ return webBeansContext.getContextsService();
}
}
http://git-wip-us.apache.org/repos/asf/incubator-deltaspike/blob/439252fa/deltaspike/cdictrl/impl-owb/src/main/java/org/apache/deltaspike/cdise/owb/OwbHelper.java
----------------------------------------------------------------------
diff --git a/deltaspike/cdictrl/impl-owb/src/main/java/org/apache/deltaspike/cdise/owb/OwbHelper.java b/deltaspike/cdictrl/impl-owb/src/main/java/org/apache/deltaspike/cdise/owb/OwbHelper.java
index bd6d2f1..b4ff77f 100644
--- a/deltaspike/cdictrl/impl-owb/src/main/java/org/apache/deltaspike/cdise/owb/OwbHelper.java
+++ b/deltaspike/cdictrl/impl-owb/src/main/java/org/apache/deltaspike/cdise/owb/OwbHelper.java
@@ -40,4 +40,23 @@ public class OwbHelper
return new ServletContextEvent(MockServletContext.getInstance());
}
+ public static Object getMockServletContext()
+ {
+ return MockServletContext.getInstance();
+ }
+
+
+ public static boolean isServletApiAvailable()
+ {
+ try
+ {
+ Class servletClass = Class.forName("javax.servlet.http.HttpSession");
+ return servletClass != null;
+ }
+ catch (ClassNotFoundException e)
+ {
+ return false;
+ }
+ }
+
}