Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJoakim Erdfelt2014-10-10 14:05:54 +0000
committerJoakim Erdfelt2014-10-10 14:05:54 +0000
commitb478d490624d90c1e72f3cba44cb5e7c841aafa9 (patch)
treecd7b420ac9f3178f63933a906f03ceaf8e84a1b6 /jetty-cdi
parentcba0ce2b9e2b93a79047de6866ba34960d854bc4 (diff)
downloadorg.eclipse.jetty.project-b478d490624d90c1e72f3cba44cb5e7c841aafa9.tar.gz
org.eclipse.jetty.project-b478d490624d90c1e72f3cba44cb5e7c841aafa9.tar.xz
org.eclipse.jetty.project-b478d490624d90c1e72f3cba44cb5e7c841aafa9.zip
Tweaking WeldDeploymentBinding for more accurate weld setup
Diffstat (limited to 'jetty-cdi')
-rw-r--r--jetty-cdi/pom.xml5
-rw-r--r--jetty-cdi/src/main/config/modules/cdi.mod1
-rw-r--r--jetty-cdi/src/main/java/org/eclipse/jetty/cdi/WeldDeploymentBinding.java24
3 files changed, 30 insertions, 0 deletions
diff --git a/jetty-cdi/pom.xml b/jetty-cdi/pom.xml
index 5f5073cdec..102592e681 100644
--- a/jetty-cdi/pom.xml
+++ b/jetty-cdi/pom.xml
@@ -37,6 +37,11 @@
<dependencies>
<dependency>
<groupId>org.eclipse.jetty</groupId>
+ <artifactId>jetty-plus</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-deploy</artifactId>
<version>${project.version}</version>
</dependency>
diff --git a/jetty-cdi/src/main/config/modules/cdi.mod b/jetty-cdi/src/main/config/modules/cdi.mod
index b66263eb43..68dea58b62 100644
--- a/jetty-cdi/src/main/config/modules/cdi.mod
+++ b/jetty-cdi/src/main/config/modules/cdi.mod
@@ -5,6 +5,7 @@
[depend]
deploy
annotations
+plus
# JSP (and EL) are requirements for CDI and Weld
jsp
diff --git a/jetty-cdi/src/main/java/org/eclipse/jetty/cdi/WeldDeploymentBinding.java b/jetty-cdi/src/main/java/org/eclipse/jetty/cdi/WeldDeploymentBinding.java
index ba43c7b89c..24cee5ff3d 100644
--- a/jetty-cdi/src/main/java/org/eclipse/jetty/cdi/WeldDeploymentBinding.java
+++ b/jetty-cdi/src/main/java/org/eclipse/jetty/cdi/WeldDeploymentBinding.java
@@ -18,10 +18,15 @@
package org.eclipse.jetty.cdi;
+import javax.naming.Reference;
+
import org.eclipse.jetty.deploy.App;
import org.eclipse.jetty.deploy.AppLifeCycle;
import org.eclipse.jetty.deploy.graph.Node;
+import org.eclipse.jetty.plus.jndi.Resource;
import org.eclipse.jetty.server.handler.ContextHandler;
+import org.eclipse.jetty.util.log.Log;
+import org.eclipse.jetty.util.log.Logger;
import org.eclipse.jetty.webapp.WebAppContext;
/**
@@ -29,6 +34,8 @@ import org.eclipse.jetty.webapp.WebAppContext;
*/
public class WeldDeploymentBinding implements AppLifeCycle.Binding
{
+ private static final Logger LOG = Log.getLogger(WeldDeploymentBinding.class);
+
public String[] getBindingTargets()
{
return new String[]
@@ -47,12 +54,23 @@ public class WeldDeploymentBinding implements AppLifeCycle.Binding
{
WebAppContext webapp = (WebAppContext)handler;
+ if (!wantsCDI(webapp))
+ {
+ LOG.info("No CDI features discovered, not adding Weld to context: {}",webapp);
+ return;
+ }
+
// Add context specific weld container reference.
// See https://issues.jboss.org/browse/WELD-1710
// and https://github.com/weld/core/blob/2.2.5.Final/environments/servlet/core/src/main/java/org/jboss/weld/environment/servlet/WeldServletLifecycle.java#L244-L253
webapp.setInitParameter("org.jboss.weld.environment.container.class",
"org.jboss.weld.environment.jetty.JettyContainer");
+ // Setup Weld BeanManager reference
+ Reference ref = new Reference("javax.enterprise.inject.spi.BeanManager",
+ "org.jboss.weld.resources.ManagerObjectFactory", null);
+ new Resource(webapp,"BeanManager",ref);
+
// webapp cannot change / replace weld classes
webapp.addSystemClass("org.jboss.weld.");
webapp.addSystemClass("org.jboss.classfilewriter.");
@@ -66,4 +84,10 @@ public class WeldDeploymentBinding implements AppLifeCycle.Binding
webapp.addServerClass("-com.google.common.");
}
}
+
+ private boolean wantsCDI(WebAppContext webapp)
+ {
+ // TODO implement search for various "bean.xml" entries.
+ return true;
+ }
}

Back to the top