[jboss-cvs] JBossAS SVN: r110025 - in trunk/tomcat/src/main/java/org/jboss/web/tomcat/service: deployers and 1 other directory.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Fri Dec 17 22:04:20 EST 2010


Author: marius.bogoevici
Date: 2010-12-17 22:04:20 -0500 (Fri, 17 Dec 2010)
New Revision: 110025

Added:
   trunk/tomcat/src/main/java/org/jboss/web/tomcat/service/CDIExceptionStore.java
Modified:
   trunk/tomcat/src/main/java/org/jboss/web/tomcat/service/TomcatInjectionContainer.java
   trunk/tomcat/src/main/java/org/jboss/web/tomcat/service/deployers/TomcatDeployment.java
Log:
JBAS-8278 Fail deployment on CDI definition error

Added: trunk/tomcat/src/main/java/org/jboss/web/tomcat/service/CDIExceptionStore.java
===================================================================
--- trunk/tomcat/src/main/java/org/jboss/web/tomcat/service/CDIExceptionStore.java	                        (rev 0)
+++ trunk/tomcat/src/main/java/org/jboss/web/tomcat/service/CDIExceptionStore.java	2010-12-18 03:04:20 UTC (rev 110025)
@@ -0,0 +1,58 @@
+/*
+ * 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.web.tomcat.service;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+
+/**
+ * @author Marius Bogoevici
+ */
+public class CDIExceptionStore
+{
+   private static ThreadLocal<List<Exception>> exceptions = new ThreadLocal<List<Exception>>()
+   {
+      @Override
+      protected List<Exception> initialValue()
+      {
+         return new ArrayList<Exception>();
+      }
+   };
+
+   public static void reset()
+   {
+      exceptions.get().clear();
+   }
+
+   public static void add(Exception e)
+   {
+      exceptions.get().add(e);
+   }
+
+   public static List<Exception> currentExceptions()
+   {
+      return Collections.unmodifiableList(exceptions.get());
+   }
+}
+

Modified: trunk/tomcat/src/main/java/org/jboss/web/tomcat/service/TomcatInjectionContainer.java
===================================================================
--- trunk/tomcat/src/main/java/org/jboss/web/tomcat/service/TomcatInjectionContainer.java	2010-12-18 03:00:21 UTC (rev 110024)
+++ trunk/tomcat/src/main/java/org/jboss/web/tomcat/service/TomcatInjectionContainer.java	2010-12-18 03:04:20 UTC (rev 110025)
@@ -70,7 +70,6 @@
 import org.jboss.reloaded.naming.spi.JavaEEComponent;
 import org.jboss.web.WebApplication;
 import org.jboss.web.tomcat.service.injection.TomcatInjectionUtils;
-import org.jboss.web.tomcat.service.injection.WebEJBHandler;
 
 /**
  * The TomcatInjectionContainer.
@@ -285,7 +284,18 @@
 
    public void newInstance(Object instance) throws IllegalAccessException, InvocationTargetException, NamingException
    {
-      processInjectors(instance);
+      try
+      {
+         processInjectors(instance);
+      }
+      catch (Exception e)
+      {
+         if (e.getClass().getName().equals("org.jboss.weld.exceptions.DefinitionException"))
+         {
+            // according to the CDI spec, definition exceptions are critical
+            CDIExceptionStore.add(e);
+         }
+      }
       if (!catalinaContext.getIgnoreAnnotations())
       {
          processDynamicBeanAnnotations(instance);

Modified: trunk/tomcat/src/main/java/org/jboss/web/tomcat/service/deployers/TomcatDeployment.java
===================================================================
--- trunk/tomcat/src/main/java/org/jboss/web/tomcat/service/deployers/TomcatDeployment.java	2010-12-18 03:00:21 UTC (rev 110024)
+++ trunk/tomcat/src/main/java/org/jboss/web/tomcat/service/deployers/TomcatDeployment.java	2010-12-18 03:04:20 UTC (rev 110025)
@@ -68,6 +68,7 @@
 import org.jboss.web.tomcat.security.RunAsListener;
 import org.jboss.web.tomcat.security.SecurityAssociationValve;
 import org.jboss.web.tomcat.security.SecurityContextEstablishmentValve;
+import org.jboss.web.tomcat.service.CDIExceptionStore;
 import org.jboss.web.tomcat.service.NamingListener;
 import org.jboss.web.tomcat.service.TomcatInjectionContainer;
 import org.jboss.web.tomcat.service.WebCtxLoader;
@@ -289,8 +290,14 @@
          // JBAS-8406: Temp hack, will move to NamingListener
          CurrentComponent.push(component);
          // Start it
+         CDIExceptionStore.reset();
          context.start();
          // Build the ENC
+         // JBAS-8278: abort deployment if there are CDI definitions errors
+         if (CDIExceptionStore.currentExceptions().size()>0)
+         {
+            throw CDIExceptionStore.currentExceptions().get(0);
+         }
       }
       catch (Throwable t)
       {
@@ -309,6 +316,8 @@
          JBossContextConfig.deploymentUnitLocal.set(null);
          // JBAS-8406: Temp hack, will move to NamingListener
          CurrentComponent.pop();
+         // JBAS-8278
+         CDIExceptionStore.reset();
       }
       if (context.getState() != 1)
       {



More information about the jboss-cvs-commits mailing list