You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tomee.apache.org by an...@apache.org on 2014/07/08 21:40:55 UTC

svn commit: r1608914 - in /tomee/tomee/branches/tomee-1.7.x: ./ container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/event/ container/openejb-core/src/main/java/org/apache/openejb/config/ container/openejb-core/src/test/java/org/ap...

Author: andygumbrecht
Date: Tue Jul  8 19:40:54 2014
New Revision: 1608914

URL: http://svn.apache.org/r1608914
Log:
Merged revision(s) 1608538-1608854 from tomee/tomee/trunk

Added:
    tomee/tomee/branches/tomee-1.7.x/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/event/BeanContextsInitializedEvent.java
      - copied unchanged from r1608854, tomee/tomee/trunk/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/event/BeanContextsInitializedEvent.java
    tomee/tomee/branches/tomee-1.7.x/container/openejb-core/src/test/java/org/apache/openejb/tool/
      - copied from r1608854, tomee/tomee/trunk/container/openejb-core/src/test/java/org/apache/openejb/tool/
    tomee/tomee/branches/tomee-1.7.x/server/openejb-cxf-rs/src/test/java/org/apache/openejb/server/cxf/rs/NoPathOnImplTest.java
      - copied unchanged from r1608854, tomee/tomee/trunk/server/openejb-cxf-rs/src/test/java/org/apache/openejb/server/cxf/rs/NoPathOnImplTest.java
    tomee/tomee/branches/tomee-1.7.x/server/openejb-cxf-rs/src/test/java/org/apache/openejb/server/cxf/rs/ProvidersShouldBeScannedTest.java
      - copied unchanged from r1608854, tomee/tomee/trunk/server/openejb-cxf-rs/src/test/java/org/apache/openejb/server/cxf/rs/ProvidersShouldBeScannedTest.java
Modified:
    tomee/tomee/branches/tomee-1.7.x/   (props changed)
    tomee/tomee/branches/tomee-1.7.x/container/openejb-core/src/main/java/org/apache/openejb/config/AnnotationDeployer.java
    tomee/tomee/branches/tomee-1.7.x/container/openejb-core/src/main/java/org/apache/openejb/config/CmpJpaConversion.java
    tomee/tomee/branches/tomee-1.7.x/itests/openejb-itests-client/src/main/java/org/apache/openejb/test/IvmTestServer.java
    tomee/tomee/branches/tomee-1.7.x/itests/openejb-itests-client/src/main/java/org/apache/openejb/test/NumberedTestCase.java
    tomee/tomee/branches/tomee-1.7.x/itests/openejb-itests-client/src/main/java/org/apache/openejb/test/entity/cmr/AbstractCMRTest.java
    tomee/tomee/branches/tomee-1.7.x/server/openejb-cxf-rs/src/main/java/org/apache/openejb/server/cxf/rs/CxfRsHttpListener.java
    tomee/tomee/branches/tomee-1.7.x/server/openejb-rest/src/main/java/org/apache/openejb/server/rest/RESTService.java

Propchange: tomee/tomee/branches/tomee-1.7.x/
------------------------------------------------------------------------------
  Merged /tomee/tomee/trunk:r1608538-1608854

Modified: tomee/tomee/branches/tomee-1.7.x/container/openejb-core/src/main/java/org/apache/openejb/config/AnnotationDeployer.java
URL: http://svn.apache.org/viewvc/tomee/tomee/branches/tomee-1.7.x/container/openejb-core/src/main/java/org/apache/openejb/config/AnnotationDeployer.java?rev=1608914&r1=1608913&r2=1608914&view=diff
==============================================================================
--- tomee/tomee/branches/tomee-1.7.x/container/openejb-core/src/main/java/org/apache/openejb/config/AnnotationDeployer.java (original)
+++ tomee/tomee/branches/tomee-1.7.x/container/openejb-core/src/main/java/org/apache/openejb/config/AnnotationDeployer.java Tue Jul  8 19:40:54 2014
@@ -5457,6 +5457,18 @@ public class AnnotationDeployer implemen
                 } else {
                     webModule.getEjbRestServices().add(clazz.getName());
                 }
+            } else if (clazz.isInterface()) {
+                final Class api = clazz;
+                final List<Class> impl = finder.findImplementations(api);
+                if (impl != null && impl.size() == 1) { // single impl so that's the service
+                    final Class implClass = impl.iterator().next();
+                    final String name = implClass.getName();
+                    if (!isEJB(implClass)) {
+                        classes.add(name);
+                    } else {
+                        webModule.getEjbRestServices().add(name);
+                    }
+                }
             }
         }
 

Modified: tomee/tomee/branches/tomee-1.7.x/container/openejb-core/src/main/java/org/apache/openejb/config/CmpJpaConversion.java
URL: http://svn.apache.org/viewvc/tomee/tomee/branches/tomee-1.7.x/container/openejb-core/src/main/java/org/apache/openejb/config/CmpJpaConversion.java?rev=1608914&r1=1608913&r2=1608914&view=diff
==============================================================================
--- tomee/tomee/branches/tomee-1.7.x/container/openejb-core/src/main/java/org/apache/openejb/config/CmpJpaConversion.java (original)
+++ tomee/tomee/branches/tomee-1.7.x/container/openejb-core/src/main/java/org/apache/openejb/config/CmpJpaConversion.java Tue Jul  8 19:40:54 2014
@@ -58,6 +58,7 @@ import org.apache.openejb.jee.jpa.unit.P
 import org.apache.openejb.jee.jpa.unit.TransactionType;
 import org.apache.openejb.jee.oejb3.EjbDeployment;
 import org.apache.openejb.jee.oejb3.OpenejbJar;
+import org.apache.openejb.loader.SystemInstance;
 import org.apache.openejb.util.LogCategory;
 import org.apache.openejb.util.Logger;
 import org.apache.openejb.util.Strings;
@@ -196,7 +197,10 @@ public class CmpJpaConversion implements
             // persistenceUnit.setNonJtaDataSource("java:openejb/Resource/Default Unmanaged JDBC Database");
             // todo paramterize this
             final Properties properties = new Properties();
-            properties.setProperty("openjpa.jdbc.SynchronizeMappings", "buildSchema(ForeignKeys=true, Indexes=false, IgnoreErrors=true)");
+            final String property = SystemInstance.get().getProperty("openejb.cmp.openjpa.jdbc.SynchronizeMappings", "buildSchema(ForeignKeys=true, Indexes=false, IgnoreErrors=true)");
+            if (property != null && !property.isEmpty()) {
+                properties.setProperty("openjpa.jdbc.SynchronizeMappings", property);
+            }
             // properties.setProperty("openjpa.DataCache", "false");
             properties.setProperty("openjpa.Log", "DefaultLevel=INFO");
             persistenceUnit.setProperties(properties);
@@ -216,7 +220,9 @@ public class CmpJpaConversion implements
             return appModule.getModuleId();
         }
         for (final EjbModule ejbModule : appModule.getEjbModules()) {
-            return ejbModule.getModuleId();
+            if (ejbModule.getModuleId() != null) {
+                return ejbModule.getModuleId();
+            }
         }
         throw new IllegalStateException("Comp must be in an ejb module, this one has none: " + appModule);
     }
@@ -290,7 +296,7 @@ public class CmpJpaConversion implements
         final Attributes leftAttributes = leftEntity.getAttributes();
         final Map<String, RelationField> leftRelationships = leftAttributes.getRelationshipFieldMap();
 
-        String leftFieldName = null;
+        final String leftFieldName;
         boolean leftSynthetic = false;
         if (leftRole.getCmrField() != null) {
             leftFieldName = leftRole.getCmrField().getCmrFieldName();
@@ -300,7 +306,7 @@ public class CmpJpaConversion implements
         }
         final boolean leftIsOne = leftRole.getMultiplicity() == Multiplicity.ONE;
 
-        String rightFieldName = null;
+        final String rightFieldName;
         boolean rightSynthetic = false;
         if (rightRole.getCmrField() != null) {
             rightFieldName = rightRole.getCmrField().getCmrFieldName();
@@ -316,7 +322,7 @@ public class CmpJpaConversion implements
             //
 
             // left
-            OneToOne leftOneToOne = null;
+            final OneToOne leftOneToOne;
             leftOneToOne = new OneToOne();
             leftOneToOne.setName(leftFieldName);
             leftOneToOne.setSyntheticField(leftSynthetic);
@@ -324,7 +330,7 @@ public class CmpJpaConversion implements
             addRelationship(leftOneToOne, leftRelationships, leftAttributes.getOneToOne());
 
             // right
-            OneToOne rightOneToOne = null;
+            final OneToOne rightOneToOne;
             rightOneToOne = new OneToOne();
             rightOneToOne.setName(rightFieldName);
             rightOneToOne.setSyntheticField(rightSynthetic);
@@ -341,7 +347,7 @@ public class CmpJpaConversion implements
             //
 
             // left
-            OneToMany leftOneToMany = null;
+            final OneToMany leftOneToMany;
             leftOneToMany = new OneToMany();
             leftOneToMany.setName(leftFieldName);
             leftOneToMany.setSyntheticField(leftSynthetic);
@@ -350,7 +356,7 @@ public class CmpJpaConversion implements
             addRelationship(leftOneToMany, leftRelationships, leftAttributes.getOneToMany());
 
             // right
-            ManyToOne rightManyToOne = null;
+            final ManyToOne rightManyToOne;
             rightManyToOne = new ManyToOne();
             rightManyToOne.setName(rightFieldName);
             rightManyToOne.setSyntheticField(rightSynthetic);
@@ -366,7 +372,7 @@ public class CmpJpaConversion implements
             //
 
             // left
-            ManyToOne leftManyToOne = null;
+            final ManyToOne leftManyToOne;
             leftManyToOne = new ManyToOne();
             leftManyToOne.setName(leftFieldName);
             leftManyToOne.setSyntheticField(leftSynthetic);
@@ -374,7 +380,7 @@ public class CmpJpaConversion implements
             addRelationship(leftManyToOne, leftRelationships, leftAttributes.getManyToOne());
 
             // right
-            OneToMany rightOneToMany = null;
+            final OneToMany rightOneToMany;
             rightOneToMany = new OneToMany();
             rightOneToMany.setName(rightFieldName);
             rightOneToMany.setSyntheticField(rightSynthetic);
@@ -391,7 +397,7 @@ public class CmpJpaConversion implements
             //
 
             // left
-            ManyToMany leftManyToMany = null;
+            final ManyToMany leftManyToMany;
             leftManyToMany = new ManyToMany();
             leftManyToMany.setName(leftFieldName);
             leftManyToMany.setSyntheticField(leftSynthetic);
@@ -399,7 +405,7 @@ public class CmpJpaConversion implements
             addRelationship(leftManyToMany, leftRelationships, leftAttributes.getManyToMany());
 
             // right
-            ManyToMany rightManyToMany = null;
+            final ManyToMany rightManyToMany;
             rightManyToMany = new ManyToMany();
             rightManyToMany.setName(rightFieldName);
             rightManyToMany.setSyntheticField(rightSynthetic);
@@ -414,7 +420,7 @@ public class CmpJpaConversion implements
     }
 
     private <R extends RelationField> R addRelationship(final R relationship, final Map<String, RelationField> existing, final List<R> relationships) {
-        R r = null;
+        R r;
 
         try {
             r = (R) existing.get(relationship.getKey());
@@ -675,7 +681,7 @@ public class CmpJpaConversion implements
             allFields.add(cmpField.getFieldName());
         }
 
-        Class<?> beanClass = null;
+        final Class<?> beanClass;
 
         try {
             beanClass = classLoader.loadClass(bean.getEjbClass());
@@ -777,7 +783,7 @@ public class CmpJpaConversion implements
             mapping.addField(field);
             primaryKeyFields.add(fieldName);
         } else if (bean.getPrimKeyClass() != null) {
-            Class<?> pkClass = null;
+            final Class<?> pkClass;
             try {
                 pkClass = classLoader.loadClass(bean.getPrimKeyClass());
                 MappedSuperclass idclass = null;
@@ -891,10 +897,10 @@ public class CmpJpaConversion implements
             // we have a primary key class.  We need to define the mappings between the key class fields 
             // and the bean's managed fields. 
 
-            Class<?> pkClass = null;
+            final Class<?> pkClass;
             try {
                 pkClass = classLoader.loadClass(bean.getPrimKeyClass());
-                MappedSuperclass superclass = null;
+                MappedSuperclass superclass;
                 MappedSuperclass idclass = null;
                 for (final Field pkField : pkClass.getFields()) {
                     final String fieldName = pkField.getName();
@@ -996,7 +1002,7 @@ public class CmpJpaConversion implements
 
 
     private static Class loadClass(final ClassLoader classLoader, final String className) {
-        Class ejbClass = null;
+        final Class ejbClass;
         try {
             ejbClass = classLoader.loadClass(className);
         } catch (final ClassNotFoundException e) {

Modified: tomee/tomee/branches/tomee-1.7.x/itests/openejb-itests-client/src/main/java/org/apache/openejb/test/IvmTestServer.java
URL: http://svn.apache.org/viewvc/tomee/tomee/branches/tomee-1.7.x/itests/openejb-itests-client/src/main/java/org/apache/openejb/test/IvmTestServer.java?rev=1608914&r1=1608913&r2=1608914&view=diff
==============================================================================
--- tomee/tomee/branches/tomee-1.7.x/itests/openejb-itests-client/src/main/java/org/apache/openejb/test/IvmTestServer.java (original)
+++ tomee/tomee/branches/tomee-1.7.x/itests/openejb-itests-client/src/main/java/org/apache/openejb/test/IvmTestServer.java Tue Jul  8 19:40:54 2014
@@ -16,52 +16,55 @@
  */
 package org.apache.openejb.test;
 
-import java.util.Properties;
-
 import javax.naming.Context;
 import javax.naming.InitialContext;
+import java.util.Properties;
 
 /**
- * 
- * @version $Rev$ $Date$ 
+ * @version $Rev$ $Date$
  */
+@SuppressWarnings("UnusedDeclaration")
 public class IvmTestServer implements TestServer {
 
     private Properties properties;
 
-    public void init(final Properties props){
-        
+    public void init(final Properties props) {
+
         properties = props;
-        
-        try{
+
+        try {
             props.put(Context.INITIAL_CONTEXT_FACTORY, "org.apache.openejb.core.LocalInitialContextFactory");
+
+            props.put("My DataSource", "new://Resource?type=DataSource");
+            props.put("My DataSource.JdbcUrl", "jdbc:hsqldb:mem:IvmTestServer;hsqldb.tx=MVCC");
+
             final Properties p = new Properties();
             p.putAll(props);
             p.put("openejb.loader", "embed");
-            new InitialContext( p );    // initialize openejb via constructing jndi tree
-            
-        //OpenEJB.init(properties);
-        }catch(final Exception oe){
+            new InitialContext(p);    // initialize openejb via constructing jndi tree
+
+            //OpenEJB.init(properties);
+        } catch (final Exception oe) {
             System.out.println("=========================");
-            System.out.println(""+oe.getMessage());
+            System.out.println("" + oe.getMessage());
             System.out.println("=========================");
             oe.printStackTrace();
             throw new RuntimeException("OpenEJB could not be initiated");
         }
     }
 
-    public void destroy(){
+    public void destroy() {
     }
 
-    public void start(){
+    public void start() {
     }
 
-    public void stop(){
+    public void stop() {
 
     }
 
-    public Properties getContextEnvironment(){
-        return (Properties)properties.clone();
+    public Properties getContextEnvironment() {
+        return (Properties) properties.clone();
     }
 
 }

Modified: tomee/tomee/branches/tomee-1.7.x/itests/openejb-itests-client/src/main/java/org/apache/openejb/test/NumberedTestCase.java
URL: http://svn.apache.org/viewvc/tomee/tomee/branches/tomee-1.7.x/itests/openejb-itests-client/src/main/java/org/apache/openejb/test/NumberedTestCase.java?rev=1608914&r1=1608913&r2=1608914&view=diff
==============================================================================
--- tomee/tomee/branches/tomee-1.7.x/itests/openejb-itests-client/src/main/java/org/apache/openejb/test/NumberedTestCase.java (original)
+++ tomee/tomee/branches/tomee-1.7.x/itests/openejb-itests-client/src/main/java/org/apache/openejb/test/NumberedTestCase.java Tue Jul  8 19:40:54 2014
@@ -16,113 +16,113 @@
  */
 package org.apache.openejb.test;
 
+import junit.framework.Protectable;
+import junit.framework.Test;
+import junit.framework.TestResult;
+import org.junit.Assert;
+
 import java.lang.reflect.InvocationTargetException;
 import java.lang.reflect.Method;
 import java.util.Iterator;
 
-import org.junit.Assert;
-import junit.framework.Protectable;
-import junit.framework.Test;
-import junit.framework.TestResult;
-public class NumberedTestCase extends Assert implements Test{
-    
+public class NumberedTestCase extends Assert implements Test {
+
     Method[] testMethods = new Method[]{};
     protected static final String standardPrefix = "test##_";
-    
+
     class MethodComparator implements java.util.Comparator {
-        
-        public int compare(final Object o1, final Object o2){
-                final Method m1 = (Method)o1;
-                final Method m2 = (Method)o2;
-                return m1.getName().compareTo(m2.getName());
-        }
-        public boolean equals(final Object other){
-            if(other instanceof MethodComparator)
-                return true;
-            else
-                return false;
+
+        public int compare(final Object o1, final Object o2) {
+            final Method m1 = (Method) o1;
+            final Method m2 = (Method) o2;
+            return m1.getName().compareTo(m2.getName());
+        }
+
+        public boolean equals(final Object other) {
+            return MethodComparator.class.isInstance(other);
         }
     }
-                        
 
-    public NumberedTestCase(){
-        try{
+
+    @SuppressWarnings("unchecked")
+    public NumberedTestCase() {
+        try {
             // Get all methods of the subclass
             final Method[] methods = getClass().getMethods();
             final java.util.TreeSet tm = new java.util.TreeSet(new MethodComparator());
 
             // Add the ones that start with "test"
-            for (int i=0; i < methods.length; i++){
-                if (methods[i].getName().startsWith("test")){
-                    tm.add(methods[i]);
+            for (final Method method : methods) {
+                if (method.getName().startsWith("test")) {
+                    tm.add(method);
                 }
             }
             testMethods = new Method[tm.size()];
             final Iterator orderedMethods = tm.iterator();
-            for(int i=0;orderedMethods.hasNext();i++){
-                testMethods[i]=(Method)orderedMethods.next();
+            for (int i = 0; orderedMethods.hasNext(); i++) {
+                testMethods[i] = (Method) orderedMethods.next();
             }
-        } catch (final Exception e){
+        } catch (final Exception e) {
             throw new RuntimeException(e.getMessage());
         }
     }
-    
-    protected void setUp() throws Exception{
+
+    protected void setUp() throws Exception {
     }
 
-    protected void tearDown() throws Exception{
+    protected void tearDown() throws Exception {
     }
-    
+
     /**
      * Counts the number of test cases that will be run by this test.
      */
     public int countTestCases() {
         return testMethods.length;
     }
-    
+
     /**
      * Runs a test and collects its result in a TestResult instance.
      */
     public void run(final TestResult result) {
-        try{
+        try {
             setUp();
-        } catch (final Exception e){
+        } catch (final Exception e) {
             e.printStackTrace();
             final Test test = new TestSetup();
-        
+
             result.addError(test, e);
             return;
         }
-        for (int i=0; i < testMethods.length; i++){
-            run(result, testMethods[i]);
+        for (final Method testMethod : testMethods) {
+            run(result, testMethod);
         }
-        try{
+        try {
             tearDown();
-        } catch (final Exception e){
+        } catch (final Exception e) {
             e.printStackTrace();
             final Test test = new TestTearDown();
-        
+
             result.addError(test, e);
-            return;
         }
     }
 
     protected void run(final TestResult result, final Method testMethod) {
         final Test test = createTest(testMethod);
         result.startTest(test);
-        final Protectable p= new Protectable() {
+        final Protectable p = new Protectable() {
             public void protect() throws Throwable {
                 runTestMethod(testMethod);
             }
         };
+        //System.out.println(">>" + NumberedTestCase.class.getName() + "> started: " + testMethod.toGenericString());
         result.runProtected(test, p);
         result.endTest(test);
+        //System.out.println(">>" + NumberedTestCase.class.getName() + "> done: " + testMethod.toGenericString());
     }
-    
 
-    protected Test createTest(final Method testMethod){
-        final Test test = new NamedTest(testMethod);
-        return test;
+
+    protected Test createTest(final Method testMethod) {
+        return new NamedTest(testMethod);
     }
 
     protected void runTestMethod(final Method testMethod) throws Throwable {
@@ -138,23 +138,23 @@ public class NumberedTestCase extends As
     }
 
 
-    public String toString(){
+    public String toString() {
         return name();
     }
 
-    public String name(){
+    public String name() {
         return "";
     }
-    
-    protected String createTestName(final Method testMethod){
+
+    protected String createTestName(final Method testMethod) {
         return name() + removePrefix(testMethod.getName());
     }
 
-    protected static String removePrefix(final String name){
+    protected static String removePrefix(final String name) {
         return removePrefix(standardPrefix, name);
     }
-    
-    protected static String removePrefix(final String prefix, final String name){
+
+    protected static String removePrefix(final String prefix, final String name) {
         return name.substring(prefix.length());
     }
 
@@ -189,8 +189,8 @@ public class NumberedTestCase extends As
         public void run(final TestResult result) {
         }
 
-        public String getName(){
-            return name()+".setUp()";
+        public String getName() {
+            return name() + ".setUp()";
         }
 
         public String toString() {
@@ -206,8 +206,8 @@ public class NumberedTestCase extends As
         public void run(final TestResult result) {
         }
 
-        public String getName(){
-            return name()+".tearDown()";
+        public String getName() {
+            return name() + ".tearDown()";
         }
 
         public String toString() {

Modified: tomee/tomee/branches/tomee-1.7.x/itests/openejb-itests-client/src/main/java/org/apache/openejb/test/entity/cmr/AbstractCMRTest.java
URL: http://svn.apache.org/viewvc/tomee/tomee/branches/tomee-1.7.x/itests/openejb-itests-client/src/main/java/org/apache/openejb/test/entity/cmr/AbstractCMRTest.java?rev=1608914&r1=1608913&r2=1608914&view=diff
==============================================================================
--- tomee/tomee/branches/tomee-1.7.x/itests/openejb-itests-client/src/main/java/org/apache/openejb/test/entity/cmr/AbstractCMRTest.java (original)
+++ tomee/tomee/branches/tomee-1.7.x/itests/openejb-itests-client/src/main/java/org/apache/openejb/test/entity/cmr/AbstractCMRTest.java Tue Jul  8 19:40:54 2014
@@ -17,24 +17,23 @@
 package org.apache.openejb.test.entity.cmr;
 
 
-import javax.transaction.SystemException;
+import org.apache.openejb.test.TestManager;
+
+import javax.naming.InitialContext;
+import javax.naming.NamingException;
+import javax.sql.DataSource;
 import javax.transaction.HeuristicMixedException;
 import javax.transaction.HeuristicRollbackException;
 import javax.transaction.RollbackException;
 import javax.transaction.Status;
+import javax.transaction.SystemException;
 import javax.transaction.TransactionManager;
-import javax.sql.DataSource;
-import javax.naming.InitialContext;
-import javax.naming.Context;
-import javax.naming.NamingException;
-import java.util.Properties;
-import java.sql.SQLException;
 import java.sql.Connection;
-import java.sql.Statement;
 import java.sql.ResultSet;
 import java.sql.ResultSetMetaData;
-
-import org.apache.openejb.test.TestManager;
+import java.sql.SQLException;
+import java.sql.Statement;
+import java.util.Properties;
 
 /**
  * @version $Revision$ $Date$
@@ -44,8 +43,8 @@ public abstract class AbstractCMRTest ex
     protected DataSource ds;
     protected InitialContext initialContext;
 
-    public AbstractCMRTest(final String name){
-        super("Entity.CMR."+name);
+    public AbstractCMRTest(final String name) {
+        super("Entity.CMR." + name);
     }
 
     protected void beginTransaction() throws Exception {
@@ -58,6 +57,8 @@ public abstract class AbstractCMRTest ex
             transactionManager.commit();
         } else if (status != Status.STATUS_NO_TRANSACTION) {
             transactionManager.rollback();
+        } else {
+            throw new IllegalStateException("tx status: " + status);
         }
     }
 
@@ -74,7 +75,7 @@ public abstract class AbstractCMRTest ex
 
         initialContext = new InitialContext(properties);
 
-        final InitialContext jndiContext = new InitialContext( );
+        final InitialContext jndiContext = new InitialContext();
         transactionManager = (TransactionManager) jndiContext.lookup("java:openejb/TransactionManager");
         try {
             ds = (DataSource) jndiContext.lookup("java:openejb/Resource/My DataSource");
@@ -93,7 +94,7 @@ public abstract class AbstractCMRTest ex
             resultSet = statement.executeQuery("SELECT * FROM " + table);
             final ResultSetMetaData setMetaData = resultSet.getMetaData();
             final int columnCount = setMetaData.getColumnCount();
-            while(resultSet.next()) {
+            while (resultSet.next()) {
                 final StringBuilder row = new StringBuilder();
                 for (int i = 1; i <= columnCount; i++) {
                     if (i > 1) {
@@ -117,6 +118,7 @@ public abstract class AbstractCMRTest ex
         try {
             resultSet.close();
         } catch (final SQLException e) {
+            //Ignore
         }
     }
 
@@ -125,6 +127,7 @@ public abstract class AbstractCMRTest ex
         try {
             statement.close();
         } catch (final SQLException e) {
+            //Ignore
         }
     }
 
@@ -133,6 +136,7 @@ public abstract class AbstractCMRTest ex
         try {
             connection.close();
         } catch (final SQLException e) {
+            //Ignore
         }
     }
 }

Modified: tomee/tomee/branches/tomee-1.7.x/server/openejb-cxf-rs/src/main/java/org/apache/openejb/server/cxf/rs/CxfRsHttpListener.java
URL: http://svn.apache.org/viewvc/tomee/tomee/branches/tomee-1.7.x/server/openejb-cxf-rs/src/main/java/org/apache/openejb/server/cxf/rs/CxfRsHttpListener.java?rev=1608914&r1=1608913&r2=1608914&view=diff
==============================================================================
--- tomee/tomee/branches/tomee-1.7.x/server/openejb-cxf-rs/src/main/java/org/apache/openejb/server/cxf/rs/CxfRsHttpListener.java (original)
+++ tomee/tomee/branches/tomee-1.7.x/server/openejb-cxf-rs/src/main/java/org/apache/openejb/server/cxf/rs/CxfRsHttpListener.java Tue Jul  8 19:40:54 2014
@@ -32,7 +32,6 @@ import org.apache.cxf.jaxrs.model.Operat
 import org.apache.cxf.jaxrs.model.ProviderInfo;
 import org.apache.cxf.jaxrs.model.wadl.WadlGenerator;
 import org.apache.cxf.jaxrs.provider.JAXBElementProvider;
-import org.apache.cxf.jaxrs.provider.json.JSONProvider;
 import org.apache.cxf.service.invoker.Invoker;
 import org.apache.cxf.transport.http.AbstractHTTPDestination;
 import org.apache.cxf.transport.http.HTTPTransportFactory;
@@ -246,7 +245,7 @@ public class CxfRsHttpListener implement
                            final Collection<Object> additionalProviders,
                            final ServiceConfiguration configuration) {
         deploy(contextRoot, loadedClazz, fullContext, new OpenEJBPerRequestPojoResourceProvider(loader, loadedClazz, injections, context, owbCtx),
-                null, app, null, additionalProviders, configuration);
+            null, app, null, additionalProviders, configuration);
     }
 
     @Override
@@ -257,8 +256,7 @@ public class CxfRsHttpListener implement
                           final ServiceConfiguration configuration) {
         final Object proxy = ProxyEJB.subclassProxy(beanContext);
 
-        deploy(contextRoot, beanContext.getBeanClass(), fullContext, new NoopResourceProvider(beanContext.getBeanClass(), proxy),
-                proxy, null, new OpenEJBEJBInvoker(Collections.singleton(beanContext)), additionalProviders, configuration);
+        deploy(contextRoot, beanContext.getBeanClass(), fullContext, new NoopResourceProvider(beanContext.getBeanClass(), proxy), proxy, null, new OpenEJBEJBInvoker(Collections.singleton(beanContext)), additionalProviders, configuration);
     }
 
     private void deploy(final String contextRoot, final Class<?> clazz, final String address, final ResourceProvider rp, final Object serviceBean,
@@ -320,9 +318,14 @@ public class CxfRsHttpListener implement
                 instances.add(o);
             }
         }
+
         return instances;
     }
 
+    private static void addMandatoryProviders(final Collection<Object> instances) {
+        instances.add(EJBAccessExceptionMapper.INSTANCE);
+    }
+
     private Object newProvider(final Class<?> clazz) throws IllegalAccessException, InstantiationException {
         return clazz.newInstance();
     }
@@ -507,29 +510,29 @@ public class CxfRsHttpListener implement
 
             // Init and register MBeans
             final ObjectNameBuilder jmxName = new ObjectNameBuilder("openejb.management")
-                    .set("j2eeType", "JAX-RS")
-                    .set("J2EEServer", "openejb")
-                    .set("J2EEApplication", base)
-                    .set("EndpointType", resource.type)
-                    .set("name", resource.classname);
+                .set("j2eeType", "JAX-RS")
+                .set("J2EEServer", "openejb")
+                .set("J2EEApplication", base)
+                .set("EndpointType", resource.type)
+                .set("name", resource.classname);
 
             final ObjectName jmxObjectName = jmxName.build();
             LocalMBeanServer.registerDynamicWrapperSilently(
-                    new RestServiceMBean(resource),
-                    jmxObjectName);
+                new RestServiceMBean(resource),
+                jmxObjectName);
 
             jmxNames.add(jmxObjectName);
 
             LOGGER.info("     Service URI: "
-                    + Logs.forceLength(resource.address, addressSize, true) + " -> "
-                    + Logs.forceLength(resource.type, 4, false) + " "
-                    + Logs.forceLength(resource.classname, classSize, true));
+                + Logs.forceLength(resource.address, addressSize, true) + " -> "
+                + Logs.forceLength(resource.type, 4, false) + " "
+                + Logs.forceLength(resource.classname, classSize, true));
 
             for (final Logs.LogOperationEndpointInfo log : resource.operations) {
                 LOGGER.info("          "
-                        + Logs.forceLength(log.http, resource.methodSize, false) + " "
-                        + Logs.forceLength(log.address, addressSize, true) + " ->      "
-                        + Logs.forceLength(log.method, resource.methodStrSize, true));
+                    + Logs.forceLength(log.http, resource.methodSize, false) + " "
+                    + Logs.forceLength(log.address, addressSize, true) + " ->      "
+                    + Logs.forceLength(log.method, resource.methodStrSize, true));
             }
 
             resource.operations.clear();
@@ -545,7 +548,7 @@ public class CxfRsHttpListener implement
         return factory;
     }
 
-    private void configureFactory(final Collection<Object> additionalProviders, final ServiceConfiguration serviceConfiguration, final JAXRSServerFactoryBean factory) {
+    private void configureFactory(final Collection<Object> givenAdditionalProviders, final ServiceConfiguration serviceConfiguration, final JAXRSServerFactoryBean factory) {
         CxfUtil.configureEndpoint(factory, serviceConfiguration, CXF_JAXRS_PREFIX);
 
         final Collection<ServiceInfo> services = serviceConfiguration.getAvailableServices();
@@ -562,7 +565,7 @@ public class CxfRsHttpListener implement
                 ResourceComparator instance = (ResourceComparator) ServiceInfos.resolve(services, resourceComparator);
                 if (instance == null) {
                     instance = (ResourceComparator) Thread.currentThread().getContextClassLoader()
-                            .loadClass(resourceComparator).newInstance();
+                        .loadClass(resourceComparator).newInstance();
                 }
                 factory.setResourceComparator(instance);
             } catch (final Exception e) {
@@ -604,6 +607,10 @@ public class CxfRsHttpListener implement
             }
         }
 
+        // another property to configure the scanning of providers but this one is consistent with current cxf config
+        // the other one is more generic but need another file
+        final boolean ignoreAutoProviders = "false".equalsIgnoreCase(serviceConfiguration.getProperties().getProperty(CXF_JAXRS_PREFIX + "skip-provider-scanning"));
+        final Collection<Object> additionalProviders = ignoreAutoProviders ? Collections.emptyList() : givenAdditionalProviders;
         List<Object> providers = null;
         if (providersConfig != null) {
             providers = ServiceInfos.resolve(services, providersConfig.toArray(new String[providersConfig.size()]), ProviderFactory.INSTANCE);
@@ -612,7 +619,7 @@ public class CxfRsHttpListener implement
             }
         }
         if (providers == null) {
-            providers = new ArrayList<Object>();
+            providers = new ArrayList<Object>(4);
             if (additionalProviders != null && !additionalProviders.isEmpty()) {
                 providers.addAll(providers(services, additionalProviders));
             } else {
@@ -620,10 +627,14 @@ public class CxfRsHttpListener implement
             }
         }
 
-        // add the EJB access exception mapper
-        providers.add(EJBAccessExceptionMapper.INSTANCE);
+        if (!ignoreAutoProviders) {
+            addMandatoryProviders(providers);
+        }
 
-        LOGGER.info("Using providers " + providers);
+        LOGGER.info("Using providers:");
+        for (final Object provider : providers) {
+            LOGGER.info("     " + provider);
+        }
         factory.setProviders(providers);
     }
 
@@ -633,11 +644,9 @@ public class CxfRsHttpListener implement
         jaxbProperties.put(Marshaller.JAXB_FRAGMENT, true);
         jaxb.setMarshallerProperties(jaxbProperties);
 
-        final JSONProvider json = new JSONProvider();
-        // TOMEE-514
-        // json.setSerializeAsArray(true);
-
-        return Arrays.asList((Object) jaxb, json);
+        final List<Object> providers = new ArrayList<Object>(4);
+        providers.add(jaxb);
+        return providers;
     }
 
     private static class ProviderFactory implements ServiceInfos.Factory {

Modified: tomee/tomee/branches/tomee-1.7.x/server/openejb-rest/src/main/java/org/apache/openejb/server/rest/RESTService.java
URL: http://svn.apache.org/viewvc/tomee/tomee/branches/tomee-1.7.x/server/openejb-rest/src/main/java/org/apache/openejb/server/rest/RESTService.java?rev=1608914&r1=1608913&r2=1608914&view=diff
==============================================================================
--- tomee/tomee/branches/tomee-1.7.x/server/openejb-rest/src/main/java/org/apache/openejb/server/rest/RESTService.java (original)
+++ tomee/tomee/branches/tomee-1.7.x/server/openejb-rest/src/main/java/org/apache/openejb/server/rest/RESTService.java Tue Jul  8 19:40:54 2014
@@ -125,21 +125,12 @@ public abstract class RESTService implem
             context = webContext.getAppContext().getAppJndiContext();
         }
 
-        final Collection<Object> additionalProviders = new HashSet<Object>();
-        if (useDiscoveredProviders()) {
-            for (final String name : webApp.jaxRsProviders) {
-                try {
-                    additionalProviders.add(classLoader.loadClass(name));
-                } catch (final ClassNotFoundException e) {
-                    LOGGER.warning("can't load '" + name + "'", e);
-                }
-            }
-            additionalProviders.addAll(appProviders(appInfo, classLoader));
-        }
-
         final ClassLoader oldLoader = Thread.currentThread().getContextClassLoader();
         Thread.currentThread().setContextClassLoader(classLoader);
 
+        final Collection<Object> additionalProviders = new HashSet<Object>();
+        addAppProvidersIfNeeded(appInfo, webApp, classLoader, additionalProviders);
+
         Collection<IdPropertiesInfo> pojoConfigurations = null; // done lazily
         try {
             boolean deploymentWithApplication = "true".equalsIgnoreCase(appInfo.properties.getProperty(OPENEJB_USE_APPLICATION_PROPERTY, APPLICATION_DEPLOYMENT));
@@ -295,6 +286,14 @@ public abstract class RESTService implem
         }
     }
 
+    private void addAppProvidersIfNeeded(final AppInfo appInfo, final WebAppInfo webApp, final ClassLoader classLoader, final Collection<Object> additionalProviders) {
+        if (useDiscoveredProviders(appInfo)) {
+            final Set<String> jaxRsProviders = new HashSet<String>(webApp.jaxRsProviders);
+            jaxRsProviders.addAll(appInfo.jaxRsProviders);
+            additionalProviders.addAll(appProviders(jaxRsProviders, classLoader));
+        }
+    }
+
     private void addEjbToApplication(final Application application, final Map<String, EJBRestServiceInfo> restEjbs) {
         for (final Map.Entry<String, EJBRestServiceInfo> ejb : restEjbs.entrySet()) {
             application.getClasses().add(ejb.getValue().context.getBeanClass());
@@ -374,7 +373,7 @@ public abstract class RESTService implem
                 } else {
                     pojoConfigurations = PojoUtil.findPojoConfig(pojoConfigurations, appInfo, webApp);
                     deploySingleton(webApp.contextRoot, appPrefix, o, appInstance, classLoader, additionalProviders,
-                            new ServiceConfiguration(PojoUtil.findConfiguration(pojoConfigurations, o.getClass().getName()), appInfo.services));
+                        new ServiceConfiguration(PojoUtil.findConfiguration(pojoConfigurations, o.getClass().getName()), appInfo.services));
                 }
             }
 
@@ -388,7 +387,7 @@ public abstract class RESTService implem
                 } else {
                     pojoConfigurations = PojoUtil.findPojoConfig(pojoConfigurations, appInfo, webApp);
                     deployPojo(webApp.contextRoot, appPrefix, clazz, appInstance, classLoader, injections, context, owbCtx, additionalProviders,
-                            new ServiceConfiguration(PojoUtil.findConfiguration(pojoConfigurations, clazz.getName()), appInfo.services));
+                        new ServiceConfiguration(PojoUtil.findConfiguration(pojoConfigurations, clazz.getName()), appInfo.services));
                 }
             }
 
@@ -411,15 +410,15 @@ public abstract class RESTService implem
                         deployEJB(webApp.contextRoot, appPrefix, restEjbs.get(clazz).context, additionalProviders, appInfo.services);
                     } else {
                         deployPojo(webApp.contextRoot, appPrefix, ctx.getBeanClass(), null, ctx.getClassLoader(), ctx.getInjections(), context,
-                                owbCtx, additionalProviders, new ServiceConfiguration(ctx.getProperties(), appInfo.services));
+                            owbCtx, additionalProviders, new ServiceConfiguration(ctx.getProperties(), appInfo.services));
                     }
                 } else {
                     try {
                         final Class<?> loadedClazz = classLoader.loadClass(clazz);
                         pojoConfigurations = PojoUtil.findPojoConfig(pojoConfigurations, appInfo, webApp);
                         deployPojo(webApp.contextRoot, appPrefix, loadedClazz, null, classLoader, injections, context, owbCtx,
-                                additionalProviders,
-                                new ServiceConfiguration(PojoUtil.findConfiguration(pojoConfigurations, loadedClazz.getName()), appInfo.services));
+                            additionalProviders,
+                            new ServiceConfiguration(PojoUtil.findConfiguration(pojoConfigurations, loadedClazz.getName()), appInfo.services));
                     } catch (final ClassNotFoundException e) {
                         throw new OpenEJBRestRuntimeException("can't find class " + clazz, e);
                     }
@@ -462,8 +461,8 @@ public abstract class RESTService implem
 
         services.add(new DeployedService(address.complete, contextRoot, application.getClass().getName()));
         listener.deployApplication(application, address.complete.substring(0, address.complete.length() - wildcard.length()), nopath.substring(NOPATH_PREFIX.length(), nopath.length() - wildcard.length()), additionalProviders, restEjbs, // app config
-                classLoader, injections, context, owbCtx, // injection/webapp context
-                new ServiceConfiguration(configuration, appInfo.services)); // deployment config
+            classLoader, injections, context, owbCtx, // injection/webapp context
+            new ServiceConfiguration(configuration, appInfo.services)); // deployment config
     }
 
     private static String appPrefix(final WebAppInfo info, final Class<?> appClazz) {
@@ -535,15 +534,23 @@ public abstract class RESTService implem
         return restEjbs.containsKey(clazz) && !BeanType.MANAGED.equals(restEjbs.get(clazz).context.getComponentType());
     }
 
-    private boolean useDiscoveredProviders() {
-        return SystemInstance.get().getOptions().get(OPENEJB_JAXRS_PROVIDERS_AUTO_PROP, false);
+    private boolean useDiscoveredProviders(final AppInfo appInfo) {
+        final String value = appInfo.properties.getProperty(OPENEJB_JAXRS_PROVIDERS_AUTO_PROP);
+        if (value != null) {
+            return "true".equalsIgnoreCase(value.trim());
+        }
+        return SystemInstance.get().getOptions().get(OPENEJB_JAXRS_PROVIDERS_AUTO_PROP, true);
     }
 
-    private Collection<Object> appProviders(final AppInfo appInfo, final ClassLoader classLoader) {
+    private Collection<Object> appProviders(final Collection<String> jaxRsProviders, final ClassLoader classLoader) {
         final Collection<Object> additionalProviders = new HashSet<Object>();
-        for (final String name : appInfo.jaxRsProviders) {
+        for (final String name : jaxRsProviders) {
             try {
-                additionalProviders.add(classLoader.loadClass(name));
+                final Class<?> providerClass = classLoader.loadClass(name);
+                if (providerClass.getAnnotation(Deprecated.class) != null) {
+                    continue;
+                }
+                additionalProviders.add(providerClass);
             } catch (final ClassNotFoundException e) {
                 LOGGER.warning("can't load '" + name + "'", e);
             }
@@ -575,8 +582,8 @@ public abstract class RESTService implem
                     }
 
                     final Collection<Object> providers;
-                    if (useDiscoveredProviders()) {
-                        providers = appProviders(appInfo, appClassLoader);
+                    if (useDiscoveredProviders(appInfo)) {
+                        providers = appProviders(appInfo.jaxRsProviders, appClassLoader);
                     } else {
                         providers = new ArrayList<Object>();
                     }
@@ -612,16 +619,16 @@ public abstract class RESTService implem
                         }
 
                         deployApplication(appInfo, next.getValue().path, restEjbs, comp.getClassLoader(), comp.getInjections(),
-                                containerSystem.getAppContext(appInfo.appId).getWebBeansContext(), comp.getJndiContext(),
-                                providers, pojoConfigurations, application, wildcard);
+                            containerSystem.getAppContext(appInfo.appId).getWebBeansContext(), comp.getJndiContext(),
+                            providers, pojoConfigurations, application, wildcard);
                     } else {
                         for (final Map.Entry<String, EJBRestServiceInfo> ejb : restEjbs.entrySet()) {
                             final BeanContext ctx = ejb.getValue().context;
                             if (BeanType.MANAGED.equals(ctx.getComponentType())) {
                                 deployPojo("", ejb.getValue().path, ctx.getBeanClass(), null, ctx.getClassLoader(), ctx.getInjections(),
-                                        ctx.getJndiContext(),
-                                        containerSystem.getAppContext(appInfo.appId).getWebBeansContext(),
-                                        providers, new ServiceConfiguration(ctx.getProperties(), appInfo.services));
+                                    ctx.getJndiContext(),
+                                    containerSystem.getAppContext(appInfo.appId).getWebBeansContext(),
+                                    providers, new ServiceConfiguration(ctx.getProperties(), appInfo.services));
                             } else {
                                 deployEJB("", ejb.getValue().path, ctx, providers, appInfo.services);
                             }
@@ -735,7 +742,7 @@ public abstract class RESTService implem
 
         services.add(new DeployedService(address.complete, contextRoot, loadedClazz.getName()));
         listener.deployPojo(classLoader, contextRoot, getFullContext(address.base, contextRoot), loadedClazz, app, injections, context, owbCtx,
-                additionalProviders, config);
+            additionalProviders, config);
 
         LOGGER.info("REST Service: " + address.complete + "  -> Pojo " + loadedClazz.getName());
     }
@@ -747,7 +754,7 @@ public abstract class RESTService implem
 
         services.add(new DeployedService(address.complete, context, beanContext.getBeanClass().getName()));
         listener.deployEJB(context, getFullContext(address.base, context), beanContext,
-                additionalProviders, new ServiceConfiguration(beanContext.getProperties(), serviceInfos));
+            additionalProviders, new ServiceConfiguration(beanContext.getProperties(), serviceInfos));
 
         LOGGER.info("REST Service: " + address.complete + "  -> EJB " + beanContext.getEjbName());
     }