Weld SVN: r6105 - servlet/trunk/tests/src/test/java/org/jboss/weld/test/tomcat/lookup.
by weld-commits@lists.jboss.org
Author: mazi
Date: 2010-04-13 11:19:46 -0400 (Tue, 13 Apr 2010)
New Revision: 6105
Modified:
servlet/trunk/tests/src/test/java/org/jboss/weld/test/tomcat/lookup/FilterInjectionTest.java
servlet/trunk/tests/src/test/java/org/jboss/weld/test/tomcat/lookup/ListenerInjectionTest.java
servlet/trunk/tests/src/test/java/org/jboss/weld/test/tomcat/lookup/ServletInjectionTest.java
Log:
WELDX-84: Removed obsolete log.info's
Modified: servlet/trunk/tests/src/test/java/org/jboss/weld/test/tomcat/lookup/FilterInjectionTest.java
===================================================================
--- servlet/trunk/tests/src/test/java/org/jboss/weld/test/tomcat/lookup/FilterInjectionTest.java 2010-04-13 15:16:46 UTC (rev 6104)
+++ servlet/trunk/tests/src/test/java/org/jboss/weld/test/tomcat/lookup/FilterInjectionTest.java 2010-04-13 15:19:46 UTC (rev 6105)
@@ -37,7 +37,6 @@
@BeforeClass
public void beforeClass() throws Throwable
{
- log.info("To run the servlet filter injection test you must add tomcat-support.jar to $CATALINA_BASE/lib");
super.beforeClass();
}
Modified: servlet/trunk/tests/src/test/java/org/jboss/weld/test/tomcat/lookup/ListenerInjectionTest.java
===================================================================
--- servlet/trunk/tests/src/test/java/org/jboss/weld/test/tomcat/lookup/ListenerInjectionTest.java 2010-04-13 15:16:46 UTC (rev 6104)
+++ servlet/trunk/tests/src/test/java/org/jboss/weld/test/tomcat/lookup/ListenerInjectionTest.java 2010-04-13 15:19:46 UTC (rev 6105)
@@ -38,7 +38,6 @@
@BeforeClass
public void beforeClass() throws Throwable
{
- log.info("To run the servlet listener injection test you must add tomcat-support.jar to $CATALINA_BASE/lib");
super.beforeClass();
}
Modified: servlet/trunk/tests/src/test/java/org/jboss/weld/test/tomcat/lookup/ServletInjectionTest.java
===================================================================
--- servlet/trunk/tests/src/test/java/org/jboss/weld/test/tomcat/lookup/ServletInjectionTest.java 2010-04-13 15:16:46 UTC (rev 6104)
+++ servlet/trunk/tests/src/test/java/org/jboss/weld/test/tomcat/lookup/ServletInjectionTest.java 2010-04-13 15:19:46 UTC (rev 6105)
@@ -37,7 +37,6 @@
@BeforeClass
public void beforeClass() throws Throwable
{
- log.info("To run the servlet injection test you must add tomcat-support.jar to $CATALINA_BASE/lib");
super.beforeClass();
}
14 years, 8 months
Weld SVN: r6104 - servlet/trunk/int/src/main/java/org/jboss/weld/environment/servlet/inject.
by weld-commits@lists.jboss.org
Author: mazi
Date: 2010-04-13 11:16:46 -0400 (Tue, 13 Apr 2010)
New Revision: 6104
Modified:
servlet/trunk/int/src/main/java/org/jboss/weld/environment/servlet/inject/AbstractInjector.java
Log:
removed an obsolete comment
Modified: servlet/trunk/int/src/main/java/org/jboss/weld/environment/servlet/inject/AbstractInjector.java
===================================================================
--- servlet/trunk/int/src/main/java/org/jboss/weld/environment/servlet/inject/AbstractInjector.java 2010-04-13 15:10:51 UTC (rev 6103)
+++ servlet/trunk/int/src/main/java/org/jboss/weld/environment/servlet/inject/AbstractInjector.java 2010-04-13 15:16:46 UTC (rev 6104)
@@ -32,10 +32,6 @@
/**
* Provides support for Weld injection into servlets, servlet filters etc.
*
- * Used to wrap the Weld classes (WeldManager) so that they are not seen from tomcat-support.
- * tomcat-support thus does not depend on Weld, which is deployed within the war and may be
- * deployed several times (within several wars) in a single servlet container.
- *
* @author Pete Muir
* @author <a href="mailto:matija.mazi@gmail.com">Matija Mazi</a>
*/
14 years, 8 months
Weld SVN: r6103 - in servlet/trunk/tests/src/test: resources/org/jboss/weld/test/tomcat/lookup and 1 other directory.
by weld-commits@lists.jboss.org
Author: mazi
Date: 2010-04-13 11:10:51 -0400 (Tue, 13 Apr 2010)
New Revision: 6103
Added:
servlet/trunk/tests/src/test/java/org/jboss/weld/test/tomcat/lookup/BatListener.java
servlet/trunk/tests/src/test/java/org/jboss/weld/test/tomcat/lookup/BatServlet.java
servlet/trunk/tests/src/test/java/org/jboss/weld/test/tomcat/lookup/CatFilter.java
servlet/trunk/tests/src/test/java/org/jboss/weld/test/tomcat/lookup/FilterInjectionTest.java
servlet/trunk/tests/src/test/java/org/jboss/weld/test/tomcat/lookup/ListenerInjectionTest.java
servlet/trunk/tests/src/test/resources/org/jboss/weld/test/tomcat/lookup/web-filter-injection.xml
servlet/trunk/tests/src/test/resources/org/jboss/weld/test/tomcat/lookup/web-listener-injection.xml
Log:
WELDX-83: Tests for injection into Filters and (some) Listeners on Tomcat standalone
Added: servlet/trunk/tests/src/test/java/org/jboss/weld/test/tomcat/lookup/BatListener.java
===================================================================
--- servlet/trunk/tests/src/test/java/org/jboss/weld/test/tomcat/lookup/BatListener.java (rev 0)
+++ servlet/trunk/tests/src/test/java/org/jboss/weld/test/tomcat/lookup/BatListener.java 2010-04-13 15:10:51 UTC (rev 6103)
@@ -0,0 +1,64 @@
+package org.jboss.weld.test.tomcat.lookup;
+
+import org.jboss.weld.servlet.api.ServletListener;
+
+import javax.inject.Inject;
+import javax.servlet.ServletContextEvent;
+import javax.servlet.ServletRequestEvent;
+import javax.servlet.http.HttpSessionEvent;
+
+public class BatListener implements ServletListener
+{
+ public static final String BAT_ATTRIBUTE_NAME = "batAttribute";
+
+ @Inject Sewer sewer;
+
+ public void contextInitialized(ServletContextEvent sce)
+ {
+ if (isSewerNameOk()) {
+ sce.getServletContext().setAttribute(BAT_ATTRIBUTE_NAME, Boolean.TRUE);
+ }
+ }
+
+ public void contextDestroyed(ServletContextEvent sce)
+ {
+ isSewerNameOk();
+ }
+
+ public void requestInitialized(ServletRequestEvent sre)
+ {
+ if (isSewerNameOk()) {
+ sre.getServletRequest().setAttribute(BAT_ATTRIBUTE_NAME, Boolean.TRUE);
+ }
+ }
+
+ public void requestDestroyed(ServletRequestEvent sre)
+ {
+ isSewerNameOk();
+ }
+
+ public void sessionCreated(HttpSessionEvent se)
+ {
+ if (isSewerNameOk()) {
+ se.getSession().setAttribute(BAT_ATTRIBUTE_NAME, Boolean.TRUE);
+ }
+ }
+
+ public void sessionDestroyed(HttpSessionEvent se)
+ {
+ isSewerNameOk();
+ }
+
+ private boolean isSewerNameOk() throws NullPointerException
+ {
+ try
+ {
+ return Sewer.NAME.equals(sewer.getName());
+ }
+ catch (NullPointerException e)
+ {
+ e.printStackTrace();
+ return false;
+ }
+ }
+}
Added: servlet/trunk/tests/src/test/java/org/jboss/weld/test/tomcat/lookup/BatServlet.java
===================================================================
--- servlet/trunk/tests/src/test/java/org/jboss/weld/test/tomcat/lookup/BatServlet.java (rev 0)
+++ servlet/trunk/tests/src/test/java/org/jboss/weld/test/tomcat/lookup/BatServlet.java 2010-04-13 15:10:51 UTC (rev 6103)
@@ -0,0 +1,26 @@
+package org.jboss.weld.test.tomcat.lookup;
+
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpServlet;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import java.io.IOException;
+
+public class BatServlet extends HttpServlet
+{
+ @Override
+ protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException
+ {
+ resp.setStatus(getStatus(req));
+ }
+
+ private int getStatus(HttpServletRequest req)
+ {
+ return req.getAttribute(BatListener.BAT_ATTRIBUTE_NAME) == Boolean.TRUE &&
+ req.getSession().getAttribute(BatListener.BAT_ATTRIBUTE_NAME) == Boolean.TRUE &&
+ req.getSession().getServletContext().getAttribute(BatListener.BAT_ATTRIBUTE_NAME) == Boolean.TRUE
+ ? HttpServletResponse.SC_OK
+ : HttpServletResponse.SC_INTERNAL_SERVER_ERROR;
+ }
+
+}
Added: servlet/trunk/tests/src/test/java/org/jboss/weld/test/tomcat/lookup/CatFilter.java
===================================================================
--- servlet/trunk/tests/src/test/java/org/jboss/weld/test/tomcat/lookup/CatFilter.java (rev 0)
+++ servlet/trunk/tests/src/test/java/org/jboss/weld/test/tomcat/lookup/CatFilter.java 2010-04-13 15:10:51 UTC (rev 6103)
@@ -0,0 +1,32 @@
+package org.jboss.weld.test.tomcat.lookup;
+
+import javax.inject.Inject;
+import javax.servlet.*;
+import javax.servlet.http.HttpServletResponse;
+import java.io.IOException;
+
+public class CatFilter implements Filter
+{
+
+ @Inject Sewer sewer;
+
+ public void init(FilterConfig filterConfig) throws ServletException
+ {
+ isSewerNameOk();
+ }
+
+ public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException
+ {
+ ((HttpServletResponse)response).setStatus(isSewerNameOk() ? HttpServletResponse.SC_OK : HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
+ }
+
+ public void destroy()
+ {
+ isSewerNameOk();
+ }
+
+ private boolean isSewerNameOk() throws NullPointerException
+ {
+ return Sewer.NAME.equals(sewer.getName());
+ }
+}
\ No newline at end of file
Added: servlet/trunk/tests/src/test/java/org/jboss/weld/test/tomcat/lookup/FilterInjectionTest.java
===================================================================
--- servlet/trunk/tests/src/test/java/org/jboss/weld/test/tomcat/lookup/FilterInjectionTest.java (rev 0)
+++ servlet/trunk/tests/src/test/java/org/jboss/weld/test/tomcat/lookup/FilterInjectionTest.java 2010-04-13 15:10:51 UTC (rev 6103)
@@ -0,0 +1,52 @@
+package org.jboss.weld.test.tomcat.lookup;
+
+
+
+import javax.servlet.http.HttpServletResponse;
+
+import org.apache.commons.httpclient.HttpClient;
+import org.apache.commons.httpclient.HttpMethod;
+import org.apache.commons.httpclient.methods.GetMethod;
+import org.jboss.testharness.impl.packaging.Artifact;
+import org.jboss.testharness.impl.packaging.Classes;
+import org.jboss.testharness.impl.packaging.IntegrationTest;
+import org.jboss.testharness.impl.packaging.Resource;
+import org.jboss.testharness.impl.packaging.Resources;
+import org.jboss.weld.test.AbstractWeldTest;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.testng.annotations.BeforeClass;
+import org.testng.annotations.Test;
+
+@Artifact(addCurrentPackage=false)
+@IntegrationTest(runLocally=true)
+@Resources({
+ @Resource(source="context-servlet-injection.xml", destination="/META-INF/context.xml"),
+ @Resource(source="web-filter-injection.xml", destination="/WEB-INF/web.xml")
+})
+@Classes({
+ CatFilter.class,
+ Sewer.class
+})
+public class FilterInjectionTest extends AbstractWeldTest
+{
+
+ private static final Logger log = LoggerFactory.getLogger(FilterInjectionTest.class);
+
+ @Override
+ @BeforeClass
+ public void beforeClass() throws Throwable
+ {
+ log.info("To run the servlet filter injection test you must add tomcat-support.jar to $CATALINA_BASE/lib");
+ super.beforeClass();
+ }
+
+
+ @Test
+ public void testFilterInjection() throws Exception
+ {
+ HttpClient client = new HttpClient();
+ HttpMethod method = new GetMethod(getContextPath() + "/cat");
+ assert client.executeMethod(method) == HttpServletResponse.SC_OK;
+ }
+}
Added: servlet/trunk/tests/src/test/java/org/jboss/weld/test/tomcat/lookup/ListenerInjectionTest.java
===================================================================
--- servlet/trunk/tests/src/test/java/org/jboss/weld/test/tomcat/lookup/ListenerInjectionTest.java (rev 0)
+++ servlet/trunk/tests/src/test/java/org/jboss/weld/test/tomcat/lookup/ListenerInjectionTest.java 2010-04-13 15:10:51 UTC (rev 6103)
@@ -0,0 +1,57 @@
+package org.jboss.weld.test.tomcat.lookup;
+
+
+
+import javax.servlet.http.HttpServletResponse;
+
+import org.apache.commons.httpclient.HttpClient;
+import org.apache.commons.httpclient.HttpMethod;
+import org.apache.commons.httpclient.methods.GetMethod;
+import org.jboss.testharness.impl.packaging.Artifact;
+import org.jboss.testharness.impl.packaging.Classes;
+import org.jboss.testharness.impl.packaging.IntegrationTest;
+import org.jboss.testharness.impl.packaging.Resource;
+import org.jboss.testharness.impl.packaging.Resources;
+import org.jboss.weld.test.AbstractWeldTest;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.testng.annotations.BeforeClass;
+import org.testng.annotations.Test;
+
+@Artifact(addCurrentPackage=false)
+@IntegrationTest(runLocally=true)
+@Resources({
+ @Resource(source="context-servlet-injection.xml", destination="/META-INF/context.xml"),
+ @Resource(source="web-listener-injection.xml", destination="/WEB-INF/web.xml")
+})
+@Classes({
+ BatListener.class,
+ BatServlet.class,
+ Sewer.class
+})
+public class ListenerInjectionTest extends AbstractWeldTest
+{
+
+ private static final Logger log = LoggerFactory.getLogger(ListenerInjectionTest.class);
+
+ @Override
+ @BeforeClass
+ public void beforeClass() throws Throwable
+ {
+ log.info("To run the servlet listener injection test you must add tomcat-support.jar to $CATALINA_BASE/lib");
+ super.beforeClass();
+ }
+
+
+ // This test currently fails showing that injection into Listeners doesn't
+ // work in Tomcat standalone.
+// @Test
+ public void testListenerInjection() throws Exception
+ {
+ HttpClient client = new HttpClient();
+ HttpMethod method = new GetMethod(getContextPath() + "/bat");
+ int sc = client.executeMethod(method);
+ System.out.println("sc = " + sc);
+ assert sc == HttpServletResponse.SC_OK;
+ }
+}
Added: servlet/trunk/tests/src/test/resources/org/jboss/weld/test/tomcat/lookup/web-filter-injection.xml
===================================================================
--- servlet/trunk/tests/src/test/resources/org/jboss/weld/test/tomcat/lookup/web-filter-injection.xml (rev 0)
+++ servlet/trunk/tests/src/test/resources/org/jboss/weld/test/tomcat/lookup/web-filter-injection.xml 2010-04-13 15:10:51 UTC (rev 6103)
@@ -0,0 +1,28 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<web-app version="2.5"
+ xmlns="http://java.sun.com/xml/ns/javaee"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
+
+ <display-name>JBoss Test Harness</display-name>
+
+ <listener>
+ <listener-class>org.jboss.testharness.impl.runner.servlet.HarnessServletListener</listener-class>
+ </listener>
+
+ <listener>
+ <listener-class>org.jboss.weld.environment.servlet.Listener</listener-class>
+ </listener>
+
+ <filter>
+ <filter-name>Cat Filter</filter-name>
+ <filter-class>org.jboss.weld.test.tomcat.lookup.CatFilter</filter-class>
+ </filter>
+
+ <filter-mapping>
+ <filter-name>Cat Filter</filter-name>
+ <url-pattern>/cat</url-pattern>
+ </filter-mapping>
+
+</web-app>
Added: servlet/trunk/tests/src/test/resources/org/jboss/weld/test/tomcat/lookup/web-listener-injection.xml
===================================================================
--- servlet/trunk/tests/src/test/resources/org/jboss/weld/test/tomcat/lookup/web-listener-injection.xml (rev 0)
+++ servlet/trunk/tests/src/test/resources/org/jboss/weld/test/tomcat/lookup/web-listener-injection.xml 2010-04-13 15:10:51 UTC (rev 6103)
@@ -0,0 +1,32 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<web-app version="2.5"
+ xmlns="http://java.sun.com/xml/ns/javaee"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
+
+ <display-name>JBoss Test Harness</display-name>
+
+ <listener>
+ <listener-class>org.jboss.testharness.impl.runner.servlet.HarnessServletListener</listener-class>
+ </listener>
+
+ <listener>
+ <listener-class>org.jboss.weld.environment.servlet.Listener</listener-class>
+ </listener>
+
+ <listener>
+ <listener-class>org.jboss.weld.test.tomcat.lookup.BatListener</listener-class>
+ </listener>
+
+ <servlet>
+ <servlet-name>Bat Servlet</servlet-name>
+ <servlet-class>org.jboss.weld.test.tomcat.lookup.BatServlet</servlet-class>
+ </servlet>
+
+ <servlet-mapping>
+ <servlet-name>Bat Servlet</servlet-name>
+ <url-pattern>/bat</url-pattern>
+ </servlet-mapping>
+
+</web-app>
14 years, 8 months
Weld SVN: r6102 - in servlet/trunk: int/src/main/java/org/jboss/weld/environment/tomcat and 2 other directories.
by weld-commits@lists.jboss.org
Author: mazi
Date: 2010-04-13 10:57:17 -0400 (Tue, 13 Apr 2010)
New Revision: 6102
Added:
servlet/trunk/int/src/main/java/org/jboss/weld/environment/tomcat/ForwardingAnnotationProcessor.java
servlet/trunk/int/src/main/java/org/jboss/weld/environment/tomcat/WeldForwardingAnnotationProcessor.java
Removed:
servlet/trunk/support/src/main/java/org/jboss/weld/environment/tomcat/ForwardingAnnotationProcessor.java
servlet/trunk/support/src/main/java/org/jboss/weld/environment/tomcat/WeldLifecycleListener.java
Modified:
servlet/trunk/int/src/main/java/org/jboss/weld/environment/servlet/Listener.java
servlet/trunk/tests/src/test/resources/org/jboss/weld/test/tomcat/lookup/context-servlet-injection.xml
servlet/trunk/tests/src/test/resources/org/jboss/weld/test/tomcat/lookup/context.xml
Log:
WELDX-84: Move tomcat servlet injection support from weld-tomcat-support.jar into weld-servlet.jar
Modified: servlet/trunk/int/src/main/java/org/jboss/weld/environment/servlet/Listener.java
===================================================================
--- servlet/trunk/int/src/main/java/org/jboss/weld/environment/servlet/Listener.java 2010-04-13 14:38:02 UTC (rev 6101)
+++ servlet/trunk/int/src/main/java/org/jboss/weld/environment/servlet/Listener.java 2010-04-13 14:57:17 UTC (rev 6102)
@@ -33,7 +33,7 @@
import org.jboss.weld.environment.servlet.services.ServletResourceInjectionServices;
import org.jboss.weld.environment.servlet.services.ServletServicesImpl;
import org.jboss.weld.environment.servlet.util.Reflections;
-import org.jboss.weld.environment.tomcat.WeldAnnotationProcessor;
+import org.jboss.weld.environment.tomcat.WeldForwardingAnnotationProcessor;
import org.jboss.weld.injection.spi.ResourceInjectionServices;
import org.jboss.weld.manager.api.WeldManager;
import org.jboss.weld.servlet.api.ServletListener;
@@ -87,9 +87,9 @@
try
{
Reflections.classForName("org.apache.AnnotationProcessor");
- sce.getServletContext().removeAttribute(WeldAnnotationProcessor.class.getName());
+ WeldForwardingAnnotationProcessor.restoreAnnotationProcessor(sce);
}
- catch (IllegalArgumentException e) {}
+ catch (IllegalArgumentException ignore) {}
try
{
Reflections.classForName(JETTY_REQUIRED_CLASS_NAME);
@@ -145,17 +145,14 @@
if (tomcat)
{
- // Try pushing a Tomcat AnnotationProcessor into the servlet context
try
{
- Class<?> clazz = Reflections.classForName(WeldAnnotationProcessor.class.getName());
- Object annotationProcessor = clazz.getConstructor(WeldManager.class).newInstance(manager);
- sce.getServletContext().setAttribute(WeldAnnotationProcessor.class.getName(), annotationProcessor);
+ WeldForwardingAnnotationProcessor.replaceAnnotationProcessor(sce, manager);
log.info("Tomcat 6 detected, JSR-299 injection will be available in Servlets, Filters etc.");
}
catch (Exception e)
{
- log.error("Unable to create Tomcat AnnotationProcessor. JSR-299 injection will not be available in Servlets, Filters etc.", e);
+ log.error("Unable to replace Tomcat AnnotationProcessor. JSR-299 injection will not be available in Servlets, Filters etc.", e);
}
}
Added: servlet/trunk/int/src/main/java/org/jboss/weld/environment/tomcat/ForwardingAnnotationProcessor.java
===================================================================
--- servlet/trunk/int/src/main/java/org/jboss/weld/environment/tomcat/ForwardingAnnotationProcessor.java (rev 0)
+++ servlet/trunk/int/src/main/java/org/jboss/weld/environment/tomcat/ForwardingAnnotationProcessor.java 2010-04-13 14:57:17 UTC (rev 6102)
@@ -0,0 +1,29 @@
+package org.jboss.weld.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: servlet/trunk/int/src/main/java/org/jboss/weld/environment/tomcat/WeldForwardingAnnotationProcessor.java
===================================================================
--- servlet/trunk/int/src/main/java/org/jboss/weld/environment/tomcat/WeldForwardingAnnotationProcessor.java (rev 0)
+++ servlet/trunk/int/src/main/java/org/jboss/weld/environment/tomcat/WeldForwardingAnnotationProcessor.java 2010-04-13 14:57:17 UTC (rev 6102)
@@ -0,0 +1,110 @@
+package org.jboss.weld.environment.tomcat;
+
+import org.apache.AnnotationProcessor;
+import org.apache.catalina.core.StandardContext;
+import org.apache.catalina.core.ApplicationContext;
+import org.apache.catalina.core.ApplicationContextFacade;
+import org.jboss.weld.manager.api.WeldManager;
+import org.jboss.weld.environment.servlet.util.Reflections;
+
+import javax.naming.NamingException;
+import javax.servlet.ServletContextEvent;
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Field;
+
+/**
+ * @author <a href="mailto:matija.mazi@gmail.com">Matija Mazi</a>
+ *
+ * Forwards all calls in turn to two delegates: first to
+ * originalAnnotationProcessor, then to weldProcessor.
+ */
+public class WeldForwardingAnnotationProcessor extends ForwardingAnnotationProcessor
+{
+ private final AnnotationProcessor firstProcessor;
+ private final AnnotationProcessor secondProcessor;
+
+ public WeldForwardingAnnotationProcessor(AnnotationProcessor originalAnnotationProcessor, AnnotationProcessor weldProcessor)
+ {
+ this.firstProcessor = originalAnnotationProcessor;
+ this.secondProcessor = weldProcessor;
+ }
+
+ @Override
+ protected AnnotationProcessor delegate()
+ {
+ return firstProcessor;
+ }
+
+ @Override
+ public void processAnnotations(Object instance) throws IllegalAccessException, InvocationTargetException, NamingException
+ {
+ super.processAnnotations(instance);
+ secondProcessor.processAnnotations(instance);
+ }
+
+ @Override
+ public void postConstruct(Object instance) throws IllegalAccessException, InvocationTargetException
+ {
+ super.postConstruct(instance);
+ secondProcessor.postConstruct(instance);
+ }
+
+ @Override
+ public void preDestroy(Object instance) throws IllegalAccessException, InvocationTargetException
+ {
+ super.preDestroy(instance);
+ secondProcessor.preDestroy(instance);
+ }
+
+ public static void replaceAnnotationProcessor(ServletContextEvent sce, WeldManager manager)
+ {
+ StandardContext stdContext = getStandardContext(sce);
+ stdContext.setAnnotationProcessor(createInstance(manager, stdContext));
+ }
+
+ private static WeldForwardingAnnotationProcessor createInstance(WeldManager manager, StandardContext stdContext)
+ {
+ try
+ {
+ Class<?> clazz = Reflections.classForName(WeldAnnotationProcessor.class.getName());
+ AnnotationProcessor weldProcessor = (AnnotationProcessor) clazz.getConstructor(WeldManager.class).newInstance(manager);
+ return new WeldForwardingAnnotationProcessor(stdContext.getAnnotationProcessor(), weldProcessor);
+ }
+ catch (Exception e)
+ {
+ throw new RuntimeException("Cannot create WeldForwardingAnnotationProcessor", e);
+ }
+ }
+
+ private static StandardContext getStandardContext(ServletContextEvent sce)
+ {
+ try
+ {
+ // Hack into Tomcat to replace the AnnotationProcessor using reflection to access private fields
+ ApplicationContext appContext = (ApplicationContext) getContextFieldValue((ApplicationContextFacade)sce.getServletContext(), ApplicationContextFacade.class);
+ return (StandardContext) getContextFieldValue(appContext, ApplicationContext.class);
+ }
+ catch (Exception e)
+ {
+ throw new RuntimeException("Cannot get StandardContext from ServletContext", e);
+ }
+ }
+
+ private static <E> Object getContextFieldValue(E obj, Class<E> clazz)
+ throws NoSuchFieldException, IllegalAccessException
+ {
+ Field f = clazz.getDeclaredField("context");
+ f.setAccessible(true);
+ return f.get(obj);
+ }
+
+ public static void restoreAnnotationProcessor(ServletContextEvent sce)
+ {
+ StandardContext stdContext = getStandardContext(sce);
+ AnnotationProcessor ap = stdContext.getAnnotationProcessor();
+ if (ap instanceof WeldForwardingAnnotationProcessor)
+ {
+ stdContext.setAnnotationProcessor(((WeldForwardingAnnotationProcessor)ap).firstProcessor);
+ }
+ }
+}
\ No newline at end of file
Deleted: servlet/trunk/support/src/main/java/org/jboss/weld/environment/tomcat/ForwardingAnnotationProcessor.java
===================================================================
--- servlet/trunk/support/src/main/java/org/jboss/weld/environment/tomcat/ForwardingAnnotationProcessor.java 2010-04-13 14:38:02 UTC (rev 6101)
+++ servlet/trunk/support/src/main/java/org/jboss/weld/environment/tomcat/ForwardingAnnotationProcessor.java 2010-04-13 14:57:17 UTC (rev 6102)
@@ -1,29 +0,0 @@
-package org.jboss.weld.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);
- }
-
-}
Deleted: servlet/trunk/support/src/main/java/org/jboss/weld/environment/tomcat/WeldLifecycleListener.java
===================================================================
--- servlet/trunk/support/src/main/java/org/jboss/weld/environment/tomcat/WeldLifecycleListener.java 2010-04-13 14:38:02 UTC (rev 6101)
+++ servlet/trunk/support/src/main/java/org/jboss/weld/environment/tomcat/WeldLifecycleListener.java 2010-04-13 14:57:17 UTC (rev 6102)
@@ -1,89 +0,0 @@
-package org.jboss.weld.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 WeldLifecycleListener implements LifecycleListener
-{
-
- private static final AnnotationProcessor DUMMY_PROCESSOR = new AnnotationProcessor()
- {
-
- public void postConstruct(Object arg0) throws IllegalAccessException, InvocationTargetException {}
-
- public void preDestroy(Object arg0) throws IllegalAccessException, InvocationTargetException {}
-
- public void processAnnotations(Object arg0) throws IllegalAccessException, InvocationTargetException, NamingException {}
-
- };
-
- 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();
-
- // Initialize servlet injection
- final AnnotationProcessor originalAnnotationProcessor = context.getAnnotationProcessor();
- context.setAnnotationProcessor(new ForwardingAnnotationProcessor()
- {
-
- private AnnotationProcessor processor;
-
- @Override
- protected AnnotationProcessor delegate()
- {
- return originalAnnotationProcessor;
- }
-
- @Override
- public void processAnnotations(Object instance) throws IllegalAccessException, InvocationTargetException, NamingException
- {
- super.processAnnotations(instance);
- getProcessor().processAnnotations(instance);
- }
-
- @Override
- public void postConstruct(Object instance) throws IllegalAccessException, InvocationTargetException
- {
- super.postConstruct(instance);
- getProcessor().postConstruct(instance);
- }
-
- @Override
- public void preDestroy(Object instance) throws IllegalAccessException, InvocationTargetException
- {
- super.preDestroy(instance);
- getProcessor().preDestroy(instance);
- }
-
- private AnnotationProcessor getProcessor()
- {
- if (processor == null)
- {
- Object o = servletContext.getAttribute("org.jboss.weld.environment.tomcat.WeldAnnotationProcessor");
- if (o instanceof AnnotationProcessor)
- {
- processor = (AnnotationProcessor) o;
- }
- else
- {
- return DUMMY_PROCESSOR;
- }
- }
- return processor;
- }
-
- });
- }
- }
-
-}
Modified: servlet/trunk/tests/src/test/resources/org/jboss/weld/test/tomcat/lookup/context-servlet-injection.xml
===================================================================
--- servlet/trunk/tests/src/test/resources/org/jboss/weld/test/tomcat/lookup/context-servlet-injection.xml 2010-04-13 14:38:02 UTC (rev 6101)
+++ servlet/trunk/tests/src/test/resources/org/jboss/weld/test/tomcat/lookup/context-servlet-injection.xml 2010-04-13 14:57:17 UTC (rev 6102)
@@ -2,8 +2,6 @@
<Resource name="BeanManager" auth="Container"
type="javax.inject.manager.BeanManager"
factory="org.jboss.weld.resources.ManagerObjectFactory"/>
-<!-- Uncomment to enable injection into Servlet -->
- <Listener className="org.jboss.weld.environment.tomcat.WeldLifecycleListener" />
</Context>
Modified: servlet/trunk/tests/src/test/resources/org/jboss/weld/test/tomcat/lookup/context.xml
===================================================================
--- servlet/trunk/tests/src/test/resources/org/jboss/weld/test/tomcat/lookup/context.xml 2010-04-13 14:38:02 UTC (rev 6101)
+++ servlet/trunk/tests/src/test/resources/org/jboss/weld/test/tomcat/lookup/context.xml 2010-04-13 14:57:17 UTC (rev 6102)
@@ -2,8 +2,6 @@
<Resource name="BeanManager" auth="Container"
type="javax.inject.manager.BeanManager"
factory="org.jboss.weld.resources.ManagerObjectFactory"/>
-<!-- Uncomment to enable injection into Servlet -->
-<Listener className="org.jboss.weld.environment.tomcat.WeldLifecycleListener" />
+
-
</Context>
14 years, 8 months
Weld SVN: r6101 - in servlet/trunk: build and 6 other directories.
by weld-commits@lists.jboss.org
Author: mazi
Date: 2010-04-13 10:38:02 -0400 (Tue, 13 Apr 2010)
New Revision: 6101
Added:
servlet/trunk/int/src/main/java/org/jboss/weld/environment/jetty/
servlet/trunk/int/src/main/java/org/jboss/weld/environment/jetty/JettyWeldInjector.java
servlet/trunk/int/src/main/java/org/jboss/weld/environment/jetty/WeldServletHandler.java
servlet/trunk/int/src/main/java/org/jboss/weld/environment/servlet/inject/
servlet/trunk/int/src/main/java/org/jboss/weld/environment/servlet/inject/AbstractInjector.java
Modified:
servlet/trunk/build/pom.xml
servlet/trunk/int/pom.xml
servlet/trunk/int/src/main/java/org/jboss/weld/environment/servlet/Listener.java
servlet/trunk/int/src/main/java/org/jboss/weld/environment/tomcat/WeldAnnotationProcessor.java
servlet/trunk/pom.xml
Log:
WELDX-23: Servlet injection support on Jetty
Modified: servlet/trunk/build/pom.xml
===================================================================
--- servlet/trunk/build/pom.xml 2010-04-13 13:12:16 UTC (rev 6100)
+++ servlet/trunk/build/pom.xml 2010-04-13 14:38:02 UTC (rev 6101)
@@ -80,6 +80,7 @@
<exclude>org.apache.tomcat:annotations-api</exclude>
<exclude>javax.faces:jsf-api</exclude>
<exclude>javax.el:el-api</exclude>
+ <exclude>org.mortbay.jetty:jetty</exclude>
</excludes>
</artifactSet>
</configuration>
Modified: servlet/trunk/int/pom.xml
===================================================================
--- servlet/trunk/int/pom.xml 2010-04-13 13:12:16 UTC (rev 6100)
+++ servlet/trunk/int/pom.xml 2010-04-13 14:38:02 UTC (rev 6101)
@@ -61,6 +61,12 @@
</dependency>
<dependency>
+ <groupId>org.mortbay.jetty</groupId>
+ <artifactId>jetty</artifactId>
+ <scope>provided</scope>
+ </dependency>
+
+ <dependency>
<groupId>javax.faces</groupId>
<artifactId>jsf-api</artifactId>
</dependency>
Added: servlet/trunk/int/src/main/java/org/jboss/weld/environment/jetty/JettyWeldInjector.java
===================================================================
--- servlet/trunk/int/src/main/java/org/jboss/weld/environment/jetty/JettyWeldInjector.java (rev 0)
+++ servlet/trunk/int/src/main/java/org/jboss/weld/environment/jetty/JettyWeldInjector.java 2010-04-13 14:38:02 UTC (rev 6101)
@@ -0,0 +1,22 @@
+package org.jboss.weld.environment.jetty;
+
+import org.jboss.weld.environment.servlet.inject.AbstractInjector;
+import org.jboss.weld.manager.api.WeldManager;
+
+/**
+ *
+ *
+ * @author <a href="mailto:matija.mazi@gmail.com">Matija Mazi</a>
+ */
+public class JettyWeldInjector extends AbstractInjector
+{
+ public JettyWeldInjector(WeldManager manager)
+ {
+ super(manager);
+ }
+
+ public void inject(Object targetInstance)
+ {
+ super.inject(targetInstance);
+ }
+}
Added: servlet/trunk/int/src/main/java/org/jboss/weld/environment/jetty/WeldServletHandler.java
===================================================================
--- servlet/trunk/int/src/main/java/org/jboss/weld/environment/jetty/WeldServletHandler.java (rev 0)
+++ servlet/trunk/int/src/main/java/org/jboss/weld/environment/jetty/WeldServletHandler.java 2010-04-13 14:38:02 UTC (rev 6101)
@@ -0,0 +1,63 @@
+package org.jboss.weld.environment.jetty;
+
+import org.mortbay.jetty.servlet.ServletHandler;
+import org.mortbay.jetty.webapp.WebAppContext;
+import org.mortbay.log.Log;
+
+import javax.servlet.Servlet;
+import javax.servlet.Filter;
+import javax.servlet.ServletContext;
+
+/**
+ * @author <a href="mailto:matija.mazi@gmail.com">Matija Mazi</a>
+*/
+public class WeldServletHandler extends ServletHandler
+{
+ private ServletContext sco;
+ private JettyWeldInjector injector;
+
+ public WeldServletHandler(ServletHandler existingHandler, ServletContext servletContext)
+ {
+ sco = servletContext;
+ setFilters(existingHandler.getFilters());
+ setFilterMappings(existingHandler.getFilterMappings());
+ setServlets(existingHandler.getServlets());
+ setServletMappings(existingHandler.getServletMappings());
+ }
+
+ @Override
+ public Servlet customizeServlet(Servlet servlet) throws Exception
+ {
+ inject(servlet);
+ return servlet;
+ }
+
+ @Override
+ public Filter customizeFilter(Filter filter) throws Exception
+ {
+ inject(filter);
+ return filter;
+ }
+
+ protected void inject(Object injectable) {
+ if (injector == null)
+ {
+ injector = (JettyWeldInjector) sco.getAttribute(org.jboss.weld.environment.servlet.Listener.INJECTOR_ATTRIBUTE_NAME);
+ }
+ if (injector == null)
+ {
+ Log.warn("Can't find Injector in the servlet context so injection is not available for " + injectable);
+ }
+ else
+ {
+ injector.inject(injectable);
+ }
+ }
+
+ public static void process(WebAppContext wac)
+ {
+ WeldServletHandler wHanlder = new WeldServletHandler(wac.getServletHandler(), wac.getServletContext());
+ wac.setServletHandler(wHanlder);
+ wac.getSecurityHandler().setHandler(wHanlder);
+ }
+}
Modified: servlet/trunk/int/src/main/java/org/jboss/weld/environment/servlet/Listener.java
===================================================================
--- servlet/trunk/int/src/main/java/org/jboss/weld/environment/servlet/Listener.java 2010-04-13 13:12:16 UTC (rev 6100)
+++ servlet/trunk/int/src/main/java/org/jboss/weld/environment/servlet/Listener.java 2010-04-13 14:38:02 UTC (rev 6101)
@@ -28,6 +28,7 @@
import org.jboss.weld.bootstrap.api.Environments;
import org.jboss.weld.context.api.BeanStore;
import org.jboss.weld.context.api.helpers.ConcurrentHashMapBeanStore;
+import org.jboss.weld.environment.jetty.JettyWeldInjector;
import org.jboss.weld.environment.servlet.deployment.ServletDeployment;
import org.jboss.weld.environment.servlet.services.ServletResourceInjectionServices;
import org.jboss.weld.environment.servlet.services.ServletServicesImpl;
@@ -52,11 +53,13 @@
private static final String WELD_LISTENER_CLASS_NAME = "org.jboss.weld.servlet.WeldListener";
private static final String APPLICATION_BEAN_STORE_ATTRIBUTE_NAME = Listener.class.getName() + ".applicationBeanStore";
private static final String EXPRESSION_FACTORY_NAME = "org.jboss.weld.el.ExpressionFactory";
-
+ private static final String JETTY_REQUIRED_CLASS_NAME = "org.mortbay.jetty.servlet.ServletHandler";
+ public static final String INJECTOR_ATTRIBUTE_NAME = "org.jboss.weld.environment.jetty.JettyWeldInjector";
+
private final transient Bootstrap bootstrap;
private final transient ServletListener weldListener;
private WeldManager manager;
-
+
public Listener()
{
try
@@ -87,6 +90,12 @@
sce.getServletContext().removeAttribute(WeldAnnotationProcessor.class.getName());
}
catch (IllegalArgumentException e) {}
+ try
+ {
+ Reflections.classForName(JETTY_REQUIRED_CLASS_NAME);
+ sce.getServletContext().removeAttribute(INJECTOR_ATTRIBUTE_NAME);
+ }
+ catch (IllegalArgumentException ignore) {}
super.contextDestroyed(sce);
}
@@ -123,7 +132,7 @@
bootstrap.startContainer(Environments.SERVLET, deployment, applicationBeanStore).startInitialization();
manager = bootstrap.getManager(deployment.getWebAppBeanDeploymentArchive());
-
+
boolean tomcat = true;
try
{
@@ -131,10 +140,9 @@
}
catch (IllegalArgumentException 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
@@ -143,6 +151,7 @@
Class<?> clazz = Reflections.classForName(WeldAnnotationProcessor.class.getName());
Object annotationProcessor = clazz.getConstructor(WeldManager.class).newInstance(manager);
sce.getServletContext().setAttribute(WeldAnnotationProcessor.class.getName(), annotationProcessor);
+ log.info("Tomcat 6 detected, JSR-299 injection will be available in Servlets, Filters etc.");
}
catch (Exception e)
{
@@ -150,6 +159,36 @@
}
}
+ boolean jetty = true;
+ try
+ {
+ Reflections.classForName(JETTY_REQUIRED_CLASS_NAME);
+ }
+ catch (IllegalArgumentException e)
+ {
+ jetty = false;
+ }
+
+ if (jetty)
+ {
+ // Try pushing a Jetty Injector into the servlet context
+ try
+ {
+ Class<?> clazz = Reflections.classForName(JettyWeldInjector.class.getName());
+ Object injector = clazz.getConstructor(WeldManager.class).newInstance(manager);
+ sce.getServletContext().setAttribute(INJECTOR_ATTRIBUTE_NAME, injector);
+ log.info("Jetty detected, JSR-299 injection will be available in Servlets, Filters etc.");
+ }
+ catch (Exception e)
+ {
+ log.error("Unable to create JettyWeldInjector. JSR-299 injection will not be available in Servlets, Filters etc.", e);
+ }
+ }
+
+ if (!tomcat && !jetty) {
+ log.info("No supported servlet container detected, JSR-299 injection will NOT be available in Servlets, Filters etc.");
+ }
+
// Push the manager into the servlet context so we can access in JSF
if (JspFactory.getDefaultFactory() != null)
@@ -171,11 +210,11 @@
bootstrap.deployBeans().validateBeans().endInitialization();
super.contextInitialized(sce);
}
-
+
@Override
protected ServletListener delegate()
{
return weldListener;
}
-
+
}
Added: servlet/trunk/int/src/main/java/org/jboss/weld/environment/servlet/inject/AbstractInjector.java
===================================================================
--- servlet/trunk/int/src/main/java/org/jboss/weld/environment/servlet/inject/AbstractInjector.java (rev 0)
+++ servlet/trunk/int/src/main/java/org/jboss/weld/environment/servlet/inject/AbstractInjector.java 2010-04-13 14:38:02 UTC (rev 6101)
@@ -0,0 +1,67 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2010, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+
+package org.jboss.weld.environment.servlet.inject;
+
+import org.jboss.weld.manager.api.WeldManager;
+
+import javax.enterprise.context.spi.CreationalContext;
+import javax.enterprise.inject.spi.InjectionTarget;
+import java.util.Map;
+import java.util.WeakHashMap;
+
+/**
+ * Provides support for Weld injection into servlets, servlet filters etc.
+ *
+ * Used to wrap the Weld classes (WeldManager) so that they are not seen from tomcat-support.
+ * tomcat-support thus does not depend on Weld, which is deployed within the war and may be
+ * deployed several times (within several wars) in a single servlet container.
+ *
+ * @author Pete Muir
+ * @author <a href="mailto:matija.mazi@gmail.com">Matija Mazi</a>
+ */
+public abstract class AbstractInjector
+{
+ private final WeldManager manager;
+ private final Map<Class<?>, InjectionTarget<?>> cache = new WeakHashMap<Class<?>, InjectionTarget<?>>();
+
+ protected AbstractInjector(WeldManager manager)
+ {
+ if (manager == null)
+ throw new IllegalArgumentException("Null manager");
+ this.manager = manager;
+ }
+
+ protected void inject(Object instance)
+ {
+ // not data-race safe, however doesn't matter, as the injection target created for class A is interchangable for another injection target created for class A
+ // TODO Make this a concurrent cache when we switch to google collections
+ Class<?> clazz = instance.getClass();
+ if (!cache.containsKey(clazz))
+ {
+ cache.put(clazz, manager.createInjectionTarget(manager.createAnnotatedType(clazz)));
+ }
+ CreationalContext<Object> cc = manager.createCreationalContext(null);
+ InjectionTarget<Object> it = (InjectionTarget<Object>) cache.get(clazz);
+ it.inject(instance, cc);
+ }
+}
\ No newline at end of file
Modified: servlet/trunk/int/src/main/java/org/jboss/weld/environment/tomcat/WeldAnnotationProcessor.java
===================================================================
--- servlet/trunk/int/src/main/java/org/jboss/weld/environment/tomcat/WeldAnnotationProcessor.java 2010-04-13 13:12:16 UTC (rev 6100)
+++ servlet/trunk/int/src/main/java/org/jboss/weld/environment/tomcat/WeldAnnotationProcessor.java 2010-04-13 14:38:02 UTC (rev 6101)
@@ -1,53 +1,29 @@
package org.jboss.weld.environment.tomcat;
-import java.lang.reflect.InvocationTargetException;
-import java.util.Map;
-import java.util.concurrent.ConcurrentHashMap;
-
-import javax.enterprise.context.spi.CreationalContext;
-import javax.enterprise.inject.spi.InjectionTarget;
-import javax.naming.NamingException;
-
import org.apache.AnnotationProcessor;
+import org.jboss.weld.environment.servlet.inject.AbstractInjector;
import org.jboss.weld.manager.api.WeldManager;
-public class WeldAnnotationProcessor implements AnnotationProcessor
+import javax.naming.NamingException;
+import java.lang.reflect.InvocationTargetException;
+
+public class WeldAnnotationProcessor extends AbstractInjector implements AnnotationProcessor
{
-
- private final Map<Class<?>, InjectionTarget<?>> injectionTargets;
-
- private final WeldManager manager;
-
public WeldAnnotationProcessor(WeldManager manager)
{
- this.manager = manager;
- this.injectionTargets = new ConcurrentHashMap<Class<?>, InjectionTarget<?>>();
+ super(manager);
}
public void processAnnotations(Object instance) throws IllegalAccessException, InvocationTargetException, NamingException
{
- // not data-race safe, however doesn't matter, as the injection target created for class A is interchangable for another injection target created for class A
- // TODO Make this a concurrent cache when we switch to google collections
- Class<?> clazz = instance.getClass();
- if (!injectionTargets.containsKey(clazz))
- {
- injectionTargets.put(clazz, manager.createInjectionTarget(manager.createAnnotatedType(clazz)));
- }
- CreationalContext<Object> cc = manager.createCreationalContext(null);
- InjectionTarget<Object> it = (InjectionTarget<Object>) injectionTargets.get(clazz);
- it.inject(instance, cc);
+ inject(instance);
}
public void postConstruct(Object arg0) throws IllegalAccessException, InvocationTargetException
{
- // TODO Auto-generated method stub
-
}
public void preDestroy(Object arg0) throws IllegalAccessException, InvocationTargetException
{
- // TODO Auto-generated method stub
-
}
-
}
Modified: servlet/trunk/pom.xml
===================================================================
--- servlet/trunk/pom.xml 2010-04-13 13:12:16 UTC (rev 6100)
+++ servlet/trunk/pom.xml 2010-04-13 14:38:02 UTC (rev 6101)
@@ -60,6 +60,7 @@
<!-- Use JSF 2 for all extensions support, despite core using JSF 1.2 -->
<jsf.version>2.0.0-RC</jsf.version>
<tomcat.version>6.0.20</tomcat.version>
+ <jetty.version>6.1.21</jetty.version>
<uel.glassfish.version>2.1.2-b04</uel.glassfish.version>
<slf4j.version>1.5.10</slf4j.version>
<!-- Testing deps -->
@@ -148,6 +149,12 @@
</dependency>
<dependency>
+ <groupId>org.mortbay.jetty</groupId>
+ <artifactId>jetty</artifactId>
+ <version>${jetty.version}</version>
+ </dependency>
+
+ <dependency>
<groupId>org.glassfish.web</groupId>
<artifactId>el-impl</artifactId>
<version>${uel.glassfish.version}</version>
14 years, 8 months
Weld SVN: r6099 - extensions/trunk/src/main/java/org/jboss/weld/extensions/util.
by weld-commits@lists.jboss.org
Author: swd847
Date: 2010-04-13 08:16:45 -0400 (Tue, 13 Apr 2010)
New Revision: 6099
Modified:
extensions/trunk/src/main/java/org/jboss/weld/extensions/util/ReflectionUtils.java
Log:
added getConstructors
Modified: extensions/trunk/src/main/java/org/jboss/weld/extensions/util/ReflectionUtils.java
===================================================================
--- extensions/trunk/src/main/java/org/jboss/weld/extensions/util/ReflectionUtils.java 2010-04-13 02:26:13 UTC (rev 6098)
+++ extensions/trunk/src/main/java/org/jboss/weld/extensions/util/ReflectionUtils.java 2010-04-13 12:16:45 UTC (rev 6099)
@@ -115,4 +115,19 @@
}
return null;
}
+
+ public static Set<Constructor<?>> getConstructors(Class<?> clazz)
+ {
+ HashSet<Constructor<?>> ret = new HashSet();
+ Class<?> p = clazz;
+ while (p != null && p != Object.class)
+ {
+ for (Constructor<?> c : p.getDeclaredConstructors())
+ {
+ ret.add(c);
+ }
+ p = p.getSuperclass();
+ }
+ return ret;
+ }
}
14 years, 8 months
Weld SVN: r6098 - in core/trunk: tests/src/test/java/org/jboss/weld/tests/decorators/generic/extend and 1 other directory.
by weld-commits@lists.jboss.org
Author: marius.bogoevici
Date: 2010-04-12 22:26:13 -0400 (Mon, 12 Apr 2010)
New Revision: 6098
Modified:
core/trunk/impl/src/main/java/org/jboss/weld/bean/DecoratorImpl.java
core/trunk/tests/src/test/java/org/jboss/weld/tests/decorators/generic/extend/ExtendDecoratorTest.java
Log:
WELD-488 + Unit test expansion
Modified: core/trunk/impl/src/main/java/org/jboss/weld/bean/DecoratorImpl.java
===================================================================
--- core/trunk/impl/src/main/java/org/jboss/weld/bean/DecoratorImpl.java 2010-04-13 01:58:16 UTC (rev 6097)
+++ core/trunk/impl/src/main/java/org/jboss/weld/bean/DecoratorImpl.java 2010-04-13 02:26:13 UTC (rev 6098)
@@ -178,7 +178,9 @@
protected void checkDelegateType()
{
- for (Type decoratedType : getDecoratedTypes())
+ Set<Type> mostSpecificDecoratedTypes = new HashSet<Type>(Arrays.asList(getWeldAnnotated().getJavaClass().getGenericInterfaces()));
+ mostSpecificDecoratedTypes.remove(Serializable.class);
+ for (Type decoratedType : mostSpecificDecoratedTypes)
{
if (decoratedType instanceof Class<?>)
{
Modified: core/trunk/tests/src/test/java/org/jboss/weld/tests/decorators/generic/extend/ExtendDecoratorTest.java
===================================================================
--- core/trunk/tests/src/test/java/org/jboss/weld/tests/decorators/generic/extend/ExtendDecoratorTest.java 2010-04-13 01:58:16 UTC (rev 6097)
+++ core/trunk/tests/src/test/java/org/jboss/weld/tests/decorators/generic/extend/ExtendDecoratorTest.java 2010-04-13 02:26:13 UTC (rev 6098)
@@ -21,6 +21,7 @@
import org.jboss.testharness.impl.packaging.jsr299.BeansXml;
import org.jboss.weld.test.AbstractWeldTest;
+import org.testng.Assert;
import org.testng.annotations.Test;
/**
@@ -31,8 +32,13 @@
public class ExtendDecoratorTest extends AbstractWeldTest
{
- @Test(groups = "broken")
- public void testExtendedDecoratorDeploys()
+ @Test
+ public void testExtendedDecorator()
{
+ ExtendsDecorated instance = getReference(ExtendsDecorated.class);
+
+ String result = instance.decoratedEcho("hello");
+ Assert.assertEquals(result, "decorated-hello-decorated");
+
}
}
\ No newline at end of file
14 years, 8 months
Weld SVN: r6097 - in core/trunk/tests/src/test: java/org/jboss/weld/tests/decorators/generic/extend and 2 other directories.
by weld-commits@lists.jboss.org
Author: marius.bogoevici
Date: 2010-04-12 21:58:16 -0400 (Mon, 12 Apr 2010)
New Revision: 6097
Added:
core/trunk/tests/src/test/java/org/jboss/weld/tests/decorators/generic/extend/
core/trunk/tests/src/test/java/org/jboss/weld/tests/decorators/generic/extend/Decorated.java
core/trunk/tests/src/test/java/org/jboss/weld/tests/decorators/generic/extend/ExtendDecoratorTest.java
core/trunk/tests/src/test/java/org/jboss/weld/tests/decorators/generic/extend/ExtendsDecorated.java
core/trunk/tests/src/test/java/org/jboss/weld/tests/decorators/generic/extend/ExtendsDecoratedDecorator.java
core/trunk/tests/src/test/java/org/jboss/weld/tests/decorators/generic/extend/ExtendsDecoratedImpl.java
core/trunk/tests/src/test/resources/org/jboss/weld/tests/decorators/generic/extend/
core/trunk/tests/src/test/resources/org/jboss/weld/tests/decorators/generic/extend/beans.xml
Log:
Tests for WELD-488
Added: core/trunk/tests/src/test/java/org/jboss/weld/tests/decorators/generic/extend/Decorated.java
===================================================================
--- core/trunk/tests/src/test/java/org/jboss/weld/tests/decorators/generic/extend/Decorated.java (rev 0)
+++ core/trunk/tests/src/test/java/org/jboss/weld/tests/decorators/generic/extend/Decorated.java 2010-04-13 01:58:16 UTC (rev 6097)
@@ -0,0 +1,26 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, Red Hat, Inc. and/or its affiliates, 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.
+ */
+
+package org.jboss.weld.tests.decorators.generic.extend;
+
+/**
+ * @author Marius Bogoevici
+ */
+public interface Decorated<T>
+{
+ T decoratedEcho(T parameter);
+}
\ No newline at end of file
Copied: core/trunk/tests/src/test/java/org/jboss/weld/tests/decorators/generic/extend/ExtendDecoratorTest.java (from rev 6094, core/trunk/tests/src/test/java/org/jboss/weld/tests/decorators/generic/PartialDecoratorTest.java)
===================================================================
--- core/trunk/tests/src/test/java/org/jboss/weld/tests/decorators/generic/extend/ExtendDecoratorTest.java (rev 0)
+++ core/trunk/tests/src/test/java/org/jboss/weld/tests/decorators/generic/extend/ExtendDecoratorTest.java 2010-04-13 01:58:16 UTC (rev 6097)
@@ -0,0 +1,38 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, Red Hat, Inc. and/or its affiliates, 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.
+ */
+
+package org.jboss.weld.tests.decorators.generic.extend;
+
+import org.jboss.testharness.impl.packaging.Artifact;
+import org.jboss.testharness.impl.packaging.jsr299.BeansXml;
+import org.jboss.weld.test.AbstractWeldTest;
+
+import org.testng.annotations.Test;
+
+/**
+ * @author Marius Bogoevici
+ */
+@Artifact
+@BeansXml("beans.xml")
+public class ExtendDecoratorTest extends AbstractWeldTest
+{
+
+ @Test(groups = "broken")
+ public void testExtendedDecoratorDeploys()
+ {
+ }
+}
\ No newline at end of file
Added: core/trunk/tests/src/test/java/org/jboss/weld/tests/decorators/generic/extend/ExtendsDecorated.java
===================================================================
--- core/trunk/tests/src/test/java/org/jboss/weld/tests/decorators/generic/extend/ExtendsDecorated.java (rev 0)
+++ core/trunk/tests/src/test/java/org/jboss/weld/tests/decorators/generic/extend/ExtendsDecorated.java 2010-04-13 01:58:16 UTC (rev 6097)
@@ -0,0 +1,25 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, Red Hat, Inc. and/or its affiliates, 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.
+ */
+
+package org.jboss.weld.tests.decorators.generic.extend;
+
+/**
+ * @author Marius Bogoevici
+ */
+public interface ExtendsDecorated extends Decorated<String>
+{
+}
Added: core/trunk/tests/src/test/java/org/jboss/weld/tests/decorators/generic/extend/ExtendsDecoratedDecorator.java
===================================================================
--- core/trunk/tests/src/test/java/org/jboss/weld/tests/decorators/generic/extend/ExtendsDecoratedDecorator.java (rev 0)
+++ core/trunk/tests/src/test/java/org/jboss/weld/tests/decorators/generic/extend/ExtendsDecoratedDecorator.java 2010-04-13 01:58:16 UTC (rev 6097)
@@ -0,0 +1,36 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, Red Hat, Inc. and/or its affiliates, 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.
+ */
+
+package org.jboss.weld.tests.decorators.generic.extend;
+
+import javax.decorator.Decorator;
+import javax.decorator.Delegate;
+import javax.inject.Inject;
+
+/**
+ * @author Marius Bogoevici
+ */
+@Decorator
+public class ExtendsDecoratedDecorator implements ExtendsDecorated
+{
+ @Inject @Delegate ExtendsDecorated delegate;
+
+ public String decoratedEcho(String parameter)
+ {
+ return "decorated-" + parameter + "-decorated";
+ }
+}
Added: core/trunk/tests/src/test/java/org/jboss/weld/tests/decorators/generic/extend/ExtendsDecoratedImpl.java
===================================================================
--- core/trunk/tests/src/test/java/org/jboss/weld/tests/decorators/generic/extend/ExtendsDecoratedImpl.java (rev 0)
+++ core/trunk/tests/src/test/java/org/jboss/weld/tests/decorators/generic/extend/ExtendsDecoratedImpl.java 2010-04-13 01:58:16 UTC (rev 6097)
@@ -0,0 +1,29 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, Red Hat, Inc. and/or its affiliates, 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.
+ */
+
+package org.jboss.weld.tests.decorators.generic.extend;
+
+/**
+ * @author Marius Bogoevici
+ */
+public class ExtendsDecoratedImpl implements ExtendsDecorated
+{
+ public String decoratedEcho(String parameter)
+ {
+ return parameter;
+ }
+}
Copied: core/trunk/tests/src/test/resources/org/jboss/weld/tests/decorators/generic/extend/beans.xml (from rev 6094, core/trunk/tests/src/test/resources/org/jboss/weld/tests/decorators/generic/beans.xml)
===================================================================
--- core/trunk/tests/src/test/resources/org/jboss/weld/tests/decorators/generic/extend/beans.xml (rev 0)
+++ core/trunk/tests/src/test/resources/org/jboss/weld/tests/decorators/generic/extend/beans.xml 2010-04-13 01:58:16 UTC (rev 6097)
@@ -0,0 +1,5 @@
+<beans>
+ <decorators>
+ <decorator>org.jboss.weld.tests.decorators.generic.extend.ExtendsDecoratedDecorator</decorator>
+ </decorators>
+</beans>
\ No newline at end of file
14 years, 8 months
Weld SVN: r6096 - extensions/trunk/src/main/java/org/jboss/weld/extensions.
by weld-commits@lists.jboss.org
Author: swd847
Date: 2010-04-12 17:11:29 -0400 (Mon, 12 Apr 2010)
New Revision: 6096
Added:
extensions/trunk/src/main/java/org/jboss/weld/extensions/Veto.java
Modified:
extensions/trunk/src/main/java/org/jboss/weld/extensions/CoreExtension.java
Log:
@Veto annotation
Modified: extensions/trunk/src/main/java/org/jboss/weld/extensions/CoreExtension.java
===================================================================
--- extensions/trunk/src/main/java/org/jboss/weld/extensions/CoreExtension.java 2010-04-12 16:06:08 UTC (rev 6095)
+++ extensions/trunk/src/main/java/org/jboss/weld/extensions/CoreExtension.java 2010-04-12 21:11:29 UTC (rev 6096)
@@ -34,6 +34,12 @@
<X> void processAnnotatedType(@Observes final ProcessAnnotatedType<X> pat, BeanManager bm)
{
+ if (pat.getAnnotatedType().isAnnotationPresent(Veto.class))
+ {
+ pat.veto();
+ return;
+ }
+
final AnnotatedType<X> at = pat.getAnnotatedType();
ReannotatedType<X> rt = new ReannotatedType<X>(at);
Added: extensions/trunk/src/main/java/org/jboss/weld/extensions/Veto.java
===================================================================
--- extensions/trunk/src/main/java/org/jboss/weld/extensions/Veto.java (rev 0)
+++ extensions/trunk/src/main/java/org/jboss/weld/extensions/Veto.java 2010-04-12 21:11:29 UTC (rev 6096)
@@ -0,0 +1,21 @@
+package org.jboss.weld.extensions;
+
+import java.lang.annotation.Documented;
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+/**
+ * Signifies that a bean should be vetoed at startup
+ *
+ * @author Stuart Douglas
+ *
+ */
+(a)Target(ElementType.TYPE)
+(a)Retention(RetentionPolicy.RUNTIME)
+@Documented
+public @interface Veto
+{
+
+}
14 years, 8 months
Weld SVN: r6095 - in core/trunk: tests/src/test/java/org/jboss/weld/tests/decorators/multidelegate and 1 other directory.
by weld-commits@lists.jboss.org
Author: marius.bogoevici
Date: 2010-04-12 12:06:08 -0400 (Mon, 12 Apr 2010)
New Revision: 6095
Modified:
core/trunk/impl/src/main/java/org/jboss/weld/bootstrap/Validator.java
core/trunk/tests/src/test/java/org/jboss/weld/tests/decorators/multidelegate/Account.java
Log:
WELD-487: @Delegate injection points are not checked for serializability.
Modified: core/trunk/impl/src/main/java/org/jboss/weld/bootstrap/Validator.java
===================================================================
--- core/trunk/impl/src/main/java/org/jboss/weld/bootstrap/Validator.java 2010-04-12 12:37:05 UTC (rev 6094)
+++ core/trunk/impl/src/main/java/org/jboss/weld/bootstrap/Validator.java 2010-04-12 16:06:08 UTC (rev 6095)
@@ -238,8 +238,11 @@
}
for (InjectionPoint ij : decorator.getInjectionPoints())
{
- Bean<?> resolvedBean = beanManager.resolve(beanManager.getBeans(ij));
- validateInjectionPointPassivationCapable(ij, resolvedBean, beanManager);
+ if (!ij.isDelegate())
+ {
+ Bean<?> resolvedBean = beanManager.resolve(beanManager.getBeans(ij));
+ validateInjectionPointPassivationCapable(ij, resolvedBean, beanManager);
+ }
}
}
}
Modified: core/trunk/tests/src/test/java/org/jboss/weld/tests/decorators/multidelegate/Account.java
===================================================================
--- core/trunk/tests/src/test/java/org/jboss/weld/tests/decorators/multidelegate/Account.java 2010-04-12 12:37:05 UTC (rev 6094)
+++ core/trunk/tests/src/test/java/org/jboss/weld/tests/decorators/multidelegate/Account.java 2010-04-12 16:06:08 UTC (rev 6095)
@@ -1,9 +1,11 @@
package org.jboss.weld.tests.decorators.multidelegate;
+import java.io.Serializable;
import java.math.BigDecimal;
-public interface Account {
+public interface Account extends Serializable
+{
public String withdraw(BigDecimal amount);
-}
\ No newline at end of file
+}
14 years, 8 months