Author: pete.muir(a)jboss.org
Date: 2009-04-06 20:03:19 -0400 (Mon, 06 Apr 2009)
New Revision: 2326
Added:
extensions/trunk/tomcat/extras/
extensions/trunk/tomcat/extras/pom.xml
extensions/trunk/tomcat/extras/src/
extensions/trunk/tomcat/extras/src/etc/
extensions/trunk/tomcat/extras/src/etc/header.txt
extensions/trunk/tomcat/extras/src/main/
extensions/trunk/tomcat/extras/src/main/java/
extensions/trunk/tomcat/extras/src/main/java/org/
extensions/trunk/tomcat/extras/src/main/java/org/jboss/
extensions/trunk/tomcat/extras/src/main/java/org/jboss/webbeans/
extensions/trunk/tomcat/extras/src/main/java/org/jboss/webbeans/environment/
extensions/trunk/tomcat/extras/src/main/java/org/jboss/webbeans/environment/servlet/
extensions/trunk/tomcat/extras/src/main/java/org/jboss/webbeans/environment/tomcat/
extensions/trunk/tomcat/extras/src/main/java/org/jboss/webbeans/environment/tomcat/ForwardingAnnotationProcessor.java
extensions/trunk/tomcat/extras/src/main/java/org/jboss/webbeans/environment/tomcat/WebBeansLifecycleListener.java
extensions/trunk/tomcat/extras/src/main/resources/
extensions/trunk/tomcat/extras/src/test/
extensions/trunk/tomcat/extras/src/test/java/
extensions/trunk/tomcat/extras/src/test/resources/
Removed:
extensions/trunk/tomcat/build/target/
Modified:
extensions/trunk/tomcat/build/.classpath
extensions/trunk/tomcat/build/.settings/org.eclipse.jdt.core.prefs
extensions/trunk/tomcat/build/pom.xml
extensions/trunk/tomcat/int/pom.xml
extensions/trunk/tomcat/int/src/main/java/org/jboss/webbeans/environment/servlet/Listener.java
Log:
POC for servlet injection in Tomcat
Modified: extensions/trunk/tomcat/build/.classpath
===================================================================
--- extensions/trunk/tomcat/build/.classpath 2009-04-06 21:54:22 UTC (rev 2325)
+++ extensions/trunk/tomcat/build/.classpath 2009-04-07 00:03:19 UTC (rev 2326)
@@ -1,6 +1,8 @@
<classpath>
<classpathentry kind="output" path="target/classes"/>
<classpathentry kind="con"
path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
+ <classpathentry kind="var"
path="M2_REPO/org/apache/tomcat/annotations-api/6.0.18/annotations-api-6.0.18.jar"/>
+ <classpathentry kind="var"
path="M2_REPO/org/apache/tomcat/catalina/6.0.18/catalina-6.0.18.jar"/>
<classpathentry kind="var"
path="M2_REPO/dom4j/dom4j/1.6.1/dom4j-1.6.1.jar"
sourcepath="M2_REPO/dom4j/dom4j/1.6.1/dom4j-1.6.1-sources.jar"/>
<classpathentry kind="var"
path="M2_REPO/javassist/javassist/3.8.1.GA/javassist-3.8.1.GA.jar"
sourcepath="M2_REPO/javassist/javassist/3.8.1.GA/javassist-3.8.1.GA-sources.jar"/>
<classpathentry kind="var"
path="M2_REPO/org/jboss/webbeans/jsr299-api/1.0.0-SNAPSHOT/jsr299-api-1.0.0-SNAPSHOT.jar"
sourcepath="M2_REPO/org/jboss/webbeans/jsr299-api/1.0.0-SNAPSHOT/jsr299-api-1.0.0-SNAPSHOT-sources.jar">
@@ -8,6 +10,8 @@
<attribute
value="jar:file:/Users/pmuir/.m2/repository/org/jboss/webbeans/jsr299-api/1.0.0-SNAPSHOT/jsr299-api-1.0.0-SNAPSHOT-javadoc.jar!/"
name="javadoc_location"/>
</attributes>
</classpathentry>
+ <classpathentry kind="var"
path="M2_REPO/org/apache/tomcat/juli/6.0.18/juli-6.0.18.jar"/>
+ <classpathentry kind="var"
path="M2_REPO/org/apache/tomcat/servlet-api/6.0.18/servlet-api-6.0.18.jar"/>
<classpathentry kind="var"
path="M2_REPO/org/jboss/webbeans/webbeans-api/1.0.0-SNAPSHOT/webbeans-api-1.0.0-SNAPSHOT.jar"
sourcepath="M2_REPO/org/jboss/webbeans/webbeans-api/1.0.0-SNAPSHOT/webbeans-api-1.0.0-SNAPSHOT-sources.jar">
<attributes>
<attribute
value="jar:file:/Users/pmuir/.m2/repository/org/jboss/webbeans/webbeans-api/1.0.0-SNAPSHOT/webbeans-api-1.0.0-SNAPSHOT-javadoc.jar!/"
name="javadoc_location"/>
Modified: extensions/trunk/tomcat/build/.settings/org.eclipse.jdt.core.prefs
===================================================================
--- extensions/trunk/tomcat/build/.settings/org.eclipse.jdt.core.prefs 2009-04-06 21:54:22
UTC (rev 2325)
+++ extensions/trunk/tomcat/build/.settings/org.eclipse.jdt.core.prefs 2009-04-07 00:03:19
UTC (rev 2326)
@@ -1,4 +1,4 @@
-#Mon Apr 06 17:56:29 BST 2009
+#Tue Apr 07 00:46:08 BST 2009
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.5
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.source=1.5
Modified: extensions/trunk/tomcat/build/pom.xml
===================================================================
--- extensions/trunk/tomcat/build/pom.xml 2009-04-06 21:54:22 UTC (rev 2325)
+++ extensions/trunk/tomcat/build/pom.xml 2009-04-07 00:03:19 UTC (rev 2326)
@@ -54,6 +54,10 @@
<artifactSet>
<excludes>
<exclude>xml-apis:xml-apis</exclude>
+ <exclude>org.apache.tomcat:catalina</exclude>
+ <exclude>org.apache.tomcat:servlet-api</exclude>
+ <exclude>org.apache.tomcat:juli</exclude>
+ <exclude>org.apache.tomcat:annotations-api</exclude>
</excludes>
</artifactSet>
</configuration>
Added: extensions/trunk/tomcat/extras/pom.xml
===================================================================
--- extensions/trunk/tomcat/extras/pom.xml (rev 0)
+++ extensions/trunk/tomcat/extras/pom.xml 2009-04-07 00:03:19 UTC (rev 2326)
@@ -0,0 +1,55 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project
xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
http://maven.apache.org/maven-v4_0_0.xsd">
+ <parent>
+ <artifactId>webbeans-tomcat-parent</artifactId>
+ <groupId>org.jboss.webbeans.tomcat</groupId>
+ <version>1.0.0-SNAPSHOT</version>
+ </parent>
+ <modelVersion>4.0.0</modelVersion>
+ <groupId>org.jboss.webbeans.tomcat</groupId>
+ <artifactId>webbeans-tomcat-extras</artifactId>
+ <version>1.0.0-SNAPSHOT</version>
+ <packaging>jar</packaging>
+ <name>Web Beans Tomcat Integration</name>
+ <
url>http://www.seamframework.org/WebBeans</url>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.testng</groupId>
+ <artifactId>testng</artifactId>
+ <scope>test</scope>
+ <classifier>jdk15</classifier>
+ <exclusions>
+ <exclusion>
+ <artifactId>junit</artifactId>
+ <groupId>junit</groupId>
+ </exclusion>
+ </exclusions>
+ </dependency>
+
+ <dependency>
+ <groupId>org.jboss.webbeans</groupId>
+ <artifactId>webbeans-spi</artifactId>
+ </dependency>
+
+ <dependency>
+ <groupId>javax.servlet</groupId>
+ <artifactId>servlet-api</artifactId>
+ <scope>provided</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>org.jboss.webbeans</groupId>
+ <artifactId>webbeans-logging</artifactId>
+ </dependency>
+
+ <dependency>
+ <groupId>org.apache.tomcat</groupId>
+ <artifactId>catalina</artifactId>
+ <version>6.0.18</version>
+ </dependency>
+
+
+ </dependencies>
+
+</project>
Added: extensions/trunk/tomcat/extras/src/etc/header.txt
===================================================================
--- extensions/trunk/tomcat/extras/src/etc/header.txt (rev 0)
+++ extensions/trunk/tomcat/extras/src/etc/header.txt 2009-04-07 00:03:19 UTC (rev 2326)
@@ -0,0 +1,14 @@
+JBoss, Home of Professional Open Source
+Copyright 2008, Red Hat Middleware LLC, and individual contributors
+by the @authors tag. See the copyright.txt in the distribution for a
+full listing of individual contributors.
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+http://www.apache.org/licenses/LICENSE-2.0
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
Added:
extensions/trunk/tomcat/extras/src/main/java/org/jboss/webbeans/environment/tomcat/ForwardingAnnotationProcessor.java
===================================================================
---
extensions/trunk/tomcat/extras/src/main/java/org/jboss/webbeans/environment/tomcat/ForwardingAnnotationProcessor.java
(rev 0)
+++
extensions/trunk/tomcat/extras/src/main/java/org/jboss/webbeans/environment/tomcat/ForwardingAnnotationProcessor.java 2009-04-07
00:03:19 UTC (rev 2326)
@@ -0,0 +1,29 @@
+package org.jboss.webbeans.environment.tomcat;
+
+import java.lang.reflect.InvocationTargetException;
+
+import javax.naming.NamingException;
+
+import org.apache.AnnotationProcessor;
+
+public abstract class ForwardingAnnotationProcessor implements AnnotationProcessor
+{
+
+ protected abstract AnnotationProcessor delegate();
+
+ public void postConstruct(Object instance) throws IllegalAccessException,
InvocationTargetException
+ {
+ delegate().postConstruct(instance);
+ }
+
+ public void preDestroy(Object instance) throws IllegalAccessException,
InvocationTargetException
+ {
+ delegate().preDestroy(instance);
+ }
+
+ public void processAnnotations(Object instance) throws IllegalAccessException,
InvocationTargetException, NamingException
+ {
+ delegate().processAnnotations(instance);
+ }
+
+}
Added:
extensions/trunk/tomcat/extras/src/main/java/org/jboss/webbeans/environment/tomcat/WebBeansLifecycleListener.java
===================================================================
---
extensions/trunk/tomcat/extras/src/main/java/org/jboss/webbeans/environment/tomcat/WebBeansLifecycleListener.java
(rev 0)
+++
extensions/trunk/tomcat/extras/src/main/java/org/jboss/webbeans/environment/tomcat/WebBeansLifecycleListener.java 2009-04-07
00:03:19 UTC (rev 2326)
@@ -0,0 +1,48 @@
+package org.jboss.webbeans.environment.tomcat;
+
+import java.lang.reflect.InvocationTargetException;
+
+import javax.naming.NamingException;
+import javax.servlet.ServletContext;
+
+import org.apache.AnnotationProcessor;
+import org.apache.catalina.LifecycleEvent;
+import org.apache.catalina.LifecycleListener;
+import org.apache.catalina.core.StandardContext;
+
+public class WebBeansLifecycleListener implements LifecycleListener
+{
+
+ public void lifecycleEvent(LifecycleEvent event)
+ {
+ if (event.getType().equals("after_start") && event.getLifecycle()
instanceof StandardContext)
+ {
+ StandardContext context = (StandardContext) event.getLifecycle();
+ final ServletContext servletContext = context.getServletContext();
+ final AnnotationProcessor annotationProcessor =
context.getAnnotationProcessor();
+ context.setAnnotationProcessor(new ForwardingAnnotationProcessor()
+ {
+
+ @Override
+ protected AnnotationProcessor delegate()
+ {
+ return annotationProcessor;
+ }
+
+ @Override
+ public void processAnnotations(Object instance) throws
IllegalAccessException, InvocationTargetException, NamingException
+ {
+ super.processAnnotations(instance);
+ Object o =
servletContext.getAttribute("org.jboss.webbeans.environment.tomcat.WebBeansAnnotationProcessor");
+ if (o != null)
+ {
+ AnnotationProcessor processor = (AnnotationProcessor) o;
+ processor.processAnnotations(instance);
+ }
+ }
+
+ });
+ }
+ }
+
+}
Modified: extensions/trunk/tomcat/int/pom.xml
===================================================================
--- extensions/trunk/tomcat/int/pom.xml 2009-04-06 21:54:22 UTC (rev 2325)
+++ extensions/trunk/tomcat/int/pom.xml 2009-04-07 00:03:19 UTC (rev 2326)
@@ -42,6 +42,13 @@
<groupId>org.jboss.webbeans</groupId>
<artifactId>webbeans-logging</artifactId>
</dependency>
+
+ <dependency>
+ <groupId>org.apache.tomcat</groupId>
+ <artifactId>catalina</artifactId>
+ <version>6.0.18</version>
+ <scope>provided</scope>
+ </dependency>
</dependencies>
Modified:
extensions/trunk/tomcat/int/src/main/java/org/jboss/webbeans/environment/servlet/Listener.java
===================================================================
---
extensions/trunk/tomcat/int/src/main/java/org/jboss/webbeans/environment/servlet/Listener.java 2009-04-06
21:54:22 UTC (rev 2325)
+++
extensions/trunk/tomcat/int/src/main/java/org/jboss/webbeans/environment/servlet/Listener.java 2009-04-07
00:03:19 UTC (rev 2326)
@@ -29,6 +29,9 @@
import org.jboss.webbeans.environment.servlet.discovery.TomcatWebBeanDiscovery;
import org.jboss.webbeans.environment.servlet.resources.ReadOnlyNamingContext;
import org.jboss.webbeans.environment.servlet.util.Reflections;
+import org.jboss.webbeans.environment.tomcat.WebBeansAnnotationProcessor;
+import org.jboss.webbeans.log.Log;
+import org.jboss.webbeans.log.Logging;
import org.jboss.webbeans.manager.api.WebBeansManager;
import org.jboss.webbeans.resources.spi.NamingContext;
import org.jboss.webbeans.resources.spi.ResourceServices;
@@ -42,6 +45,8 @@
public class Listener extends ForwardingServletListener
{
+ private static final Log log = Logging.getLog(Listener.class);
+
private static final String BOOTSTRAP_IMPL_CLASS_NAME =
"org.jboss.webbeans.bootstrap.WebBeansBootstrap";
private static final String WEB_BEANS_LISTENER_CLASS_NAME =
"org.jboss.webbeans.servlet.WebBeansListener";
private static final String APPLICATION_BEAN_STORE_ATTRIBUTE_NAME =
Listener.class.getName() + ".applicationBeanStore";
@@ -105,9 +110,44 @@
bootstrap.setApplicationContext(applicationBeanStore);
bootstrap.initialize();
manager = bootstrap.getManager();
+
+ boolean tomcat = true;
+ try
+ {
+ Reflections.loadClass("org.apache.AnnotationProcessor",
Object.class);
+ }
+ catch (ClassNotFoundException e)
+ {
+ log.info("JSR-299 injection will not be available in Servlets, Filters etc.
This facility is only available in Tomcat");
+ tomcat = false;
+ }
+ catch (NoClassDefFoundError e)
+ {
+ log.info("JSR-299 injection will not be available in Servlets, Filters etc.
This facility is only available in Tomcat");
+ tomcat = false;
+ }
+
+ if (tomcat)
+ {
+ // Try pushing a Tomcat AnnotationProcessor into the servlet context
+ try
+ {
+ Class<?> clazz =
Reflections.loadClass(WebBeansAnnotationProcessor.class.getName(), Object.class);
+ Object annotationProcessor =
clazz.getConstructor(WebBeansManager.class).newInstance(manager);
+
sce.getServletContext().setAttribute(WebBeansAnnotationProcessor.class.getName(),
annotationProcessor);
+ }
+ catch (Exception e)
+ {
+ log.error("Unable to create Tomcat AnnotationProcessor. JSR-299
injection will not be available in Servlets, Filters etc.", e);
+ }
+ }
+
+
bootstrap.boot();
super.contextInitialized(sce);
}
+
+
@Override
protected ServletListener delegate()