Another attempt at the cdi / weld integration

This commit is contained in:
Joakim Erdfelt 2014-10-09 16:33:12 -07:00
parent 8e1fc56f6f
commit f4a0754a76
6 changed files with 96 additions and 1 deletions

View File

@ -35,5 +35,10 @@
</build>
<dependencies>
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-deploy</artifactId>
<version>${project.version}</version>
</dependency>
</dependencies>
</project>

View File

@ -0,0 +1,19 @@
<?xml version="1.0"?>
<!DOCTYPE Configure PUBLIC "-//Jetty//Configure//EN" "http://www.eclipse.org/jetty/configure_9_0.dtd">
<!-- =============================================================== -->
<!-- Mixin the Weld / CDI classes to the class loader -->
<!-- =============================================================== -->
<Configure id="Server" class="org.eclipse.jetty.server.Server">
<Ref refid="DeploymentManager">
<Call name="addLifeCycleBinding">
<Arg>
<New
class="org.eclipse.jetty.cdi.WeldDeploymentBinding">
</New>
</Arg>
</Call>
</Ref>
</Configure>

View File

@ -3,6 +3,7 @@
#
[depend]
deploy
annotations
# JSP (and EL) are requirements for CDI and Weld
jsp
@ -15,6 +16,9 @@ http://central.maven.org/maven2/org/jboss/weld/servlet/weld-servlet/2.2.5.Final/
lib/weld/weld-servlet-2.2.5.Final.jar
lib/jetty-cdi-${jetty.version}.jar
[xml]
etc/jetty-cdi.xml
[license]
Weld is an open source project hosted on Github and released under the Apache 2.0 license.
http://weld.cdi-spec.org/

View File

@ -0,0 +1,66 @@
//
// ========================================================================
// Copyright (c) 1995-2014 Mort Bay Consulting Pty. Ltd.
// ------------------------------------------------------------------------
// All rights reserved. This program and the accompanying materials
// are made available under the terms of the Eclipse Public License v1.0
// and Apache License v2.0 which accompanies this distribution.
//
// The Eclipse Public License is available at
// http://www.eclipse.org/legal/epl-v10.html
//
// The Apache License v2.0 is available at
// http://www.opensource.org/licenses/apache2.0.php
//
// You may elect to redistribute this code under either of these licenses.
// ========================================================================
//
package org.eclipse.jetty.cdi;
import org.eclipse.jetty.deploy.App;
import org.eclipse.jetty.deploy.AppLifeCycle;
import org.eclipse.jetty.deploy.graph.Node;
import org.eclipse.jetty.server.handler.ContextHandler;
import org.eclipse.jetty.webapp.WebAppContext;
/**
* Perform some basic weld configuration of WebAppContext
*/
public class WeldDeploymentBinding implements AppLifeCycle.Binding
{
public String[] getBindingTargets()
{
return new String[]
{ "deploying" };
}
public void processBinding(Node node, App app) throws Exception
{
ContextHandler handler = app.getContextHandler();
if (handler == null)
{
throw new NullPointerException("No Handler created for App: " + app);
}
if (handler instanceof WebAppContext)
{
WebAppContext webapp = (WebAppContext)handler;
webapp.setInitParameter("org.jboss.weld.environment.container.class",
"org.jboss.weld.environment.jetty.JettyContainer");
// webapp cannot change / replace weld classes
webapp.addSystemClass("org.jboss.weld.");
webapp.addSystemClass("org.jboss.classfilewriter.");
webapp.addSystemClass("org.jboss.logging.");
webapp.addSystemClass("com.google.common.");
// don't hide weld classes from webapps (allow webapp to use ones from system classloader)
webapp.addServerClass("-org.jboss.weld.");
webapp.addServerClass("-org.jboss.classfilewriter.");
webapp.addServerClass("-org.jboss.logging.");
webapp.addServerClass("-com.google.common.");
}
}
}

View File

@ -443,6 +443,7 @@
<module>jetty-annotations</module>
<module>jetty-jndi</module>
<module>jetty-jaas</module>
<module>jetty-cdi</module>
<module>jetty-spring</module>
<module>jetty-client</module>
<module>jetty-proxy</module>

View File

@ -146,7 +146,7 @@
<arg file="${jetty.home}"/>
<arg file="${jetty.base}"/>
</exec>
<waitfor maxwait="1" maxwaitunit="minute"
<waitfor maxwait="5" maxwaitunit="second"
checkevery="100" checkeveryunit="millisecond">
<http url="http://localhost:58080/cdi-webapp/"/>
</waitfor>