You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tomee.apache.org by jg...@apache.org on 2017/08/02 23:06:12 UTC

[1/9] tomee git commit: Ensure @PreDestroy is called for application resources

Repository: tomee
Updated Branches:
  refs/heads/master cb6baa010 -> d25943021


Ensure @PreDestroy is called for application resources


Project: http://git-wip-us.apache.org/repos/asf/tomee/repo
Commit: http://git-wip-us.apache.org/repos/asf/tomee/commit/cce266a4
Tree: http://git-wip-us.apache.org/repos/asf/tomee/tree/cce266a4
Diff: http://git-wip-us.apache.org/repos/asf/tomee/diff/cce266a4

Branch: refs/heads/master
Commit: cce266a4f2ceca41ed88702cd71aa9f487c6eb4a
Parents: 8ed192c
Author: Jonathan Gallimore <jo...@jrg.me.uk>
Authored: Wed Jul 12 18:16:48 2017 +0100
Committer: Jonathan Gallimore <jo...@jrg.me.uk>
Committed: Wed Jul 12 20:46:25 2017 +0100

----------------------------------------------------------------------
 .../openejb/assembler/classic/Assembler.java    |  7 ++
 .../ApplicationResourceLifecycleTest.java       | 99 ++++++++++++++++++++
 .../src/test/resources/app-resources.xml        | 21 +++++
 3 files changed, 127 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/tomee/blob/cce266a4/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/Assembler.java
----------------------------------------------------------------------
diff --git a/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/Assembler.java b/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/Assembler.java
index 18cc218..d0c0958 100644
--- a/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/Assembler.java
+++ b/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/Assembler.java
@@ -2484,6 +2484,13 @@ public class Assembler extends AssemblerTool implements org.apache.openejb.spi.A
                 if (!binding.getName().equals(objName)) {
                     continue;
                 }
+                if (DestroyableResource.class.isInstance(binding.getObject())) {
+                    final DestroyableResource destroyableResource = DestroyableResource.class.cast(binding.getObject());
+                    destroyableResource.destroyResource();
+                    globalContext.unbind(name);
+                    return;
+                }
+
                 if (!LazyObjectReference.class.isInstance(binding.getObject())) {
                     continue;
                 }

http://git-wip-us.apache.org/repos/asf/tomee/blob/cce266a4/container/openejb-core/src/test/java/org/apache/openejb/assembler/classic/ApplicationResourceLifecycleTest.java
----------------------------------------------------------------------
diff --git a/container/openejb-core/src/test/java/org/apache/openejb/assembler/classic/ApplicationResourceLifecycleTest.java b/container/openejb-core/src/test/java/org/apache/openejb/assembler/classic/ApplicationResourceLifecycleTest.java
new file mode 100644
index 0000000..1b44277
--- /dev/null
+++ b/container/openejb-core/src/test/java/org/apache/openejb/assembler/classic/ApplicationResourceLifecycleTest.java
@@ -0,0 +1,99 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.apache.openejb.assembler.classic;
+
+import org.apache.openejb.OpenEJB;
+import org.apache.openejb.OpenEJBException;
+import org.apache.openejb.config.AppModule;
+import org.apache.openejb.config.ConfigurationFactory;
+import org.apache.openejb.config.EjbModule;
+import org.apache.openejb.core.LocalInitialContextFactory;
+import org.apache.openejb.jee.EjbJar;
+import org.apache.openejb.jee.SingletonBean;
+import org.junit.Test;
+
+import javax.annotation.PostConstruct;
+import javax.annotation.PreDestroy;
+import javax.naming.Context;
+import javax.naming.InitialContext;
+import javax.naming.NamingException;
+import java.io.IOException;
+import java.util.Properties;
+import java.util.concurrent.atomic.AtomicBoolean;
+
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+
+public class ApplicationResourceLifecycleTest {
+
+    private static final AtomicBoolean POST_CONSTRUCT = new AtomicBoolean(false);
+    private static final AtomicBoolean PRE_DESTROY = new AtomicBoolean(false);
+
+
+    @Test
+    public void test() throws OpenEJBException, NamingException, IOException {
+        final ConfigurationFactory config = new ConfigurationFactory();
+        final Assembler assembler = new Assembler();
+
+        assembler.createTransactionManager(config.configureService(TransactionServiceInfo.class));
+        assembler.createSecurityService(config.configureService(SecurityServiceInfo.class));
+
+        final AppModule app = new AppModule(ApplicationResourceLifecycleTest.class.getClassLoader(), ApplicationResourceLifecycleTest.class.getSimpleName());
+
+        final EjbJar ejbJar = new EjbJar();
+        ejbJar.addEnterpriseBean(new SingletonBean(ApplicationResource.class));
+        app.getEjbModules().add(new EjbModule(ejbJar));
+        app.getEjbModules().iterator().next().getAltDDs().put("resources.xml", getClass().getClassLoader().getResource("app-resources.xml"));
+
+        assembler.createApplication(config.configureApplication(app));
+
+        final Properties properties = new Properties();
+        properties.setProperty(Context.INITIAL_CONTEXT_FACTORY, LocalInitialContextFactory.class.getName());
+        properties.setProperty("openejb.embedded.initialcontext.close", "destroy");
+
+        // some hack to be sure to call destroy()
+        InitialContext context = new InitialContext(properties);
+        assertNotNull(context);
+
+        assertTrue(POST_CONSTRUCT.getAndSet(false));
+        assertFalse(PRE_DESTROY.get());
+
+        ApplicationResource bean = (ApplicationResource) context.lookup("ApplicationResourceLocalBean");
+
+        assertNotNull(bean);
+        context.close();
+
+        OpenEJB.destroy();
+        assertFalse(POST_CONSTRUCT.get());
+        assertTrue(PRE_DESTROY.get());
+    }
+
+    public static class ApplicationResource {
+
+        @PostConstruct
+        public void start() {
+            POST_CONSTRUCT.set(true);
+        }
+
+        @PreDestroy
+        public void stop() {
+            PRE_DESTROY.set(true);
+        }
+
+    }
+}

http://git-wip-us.apache.org/repos/asf/tomee/blob/cce266a4/container/openejb-core/src/test/resources/app-resources.xml
----------------------------------------------------------------------
diff --git a/container/openejb-core/src/test/resources/app-resources.xml b/container/openejb-core/src/test/resources/app-resources.xml
new file mode 100644
index 0000000..60a42c2
--- /dev/null
+++ b/container/openejb-core/src/test/resources/app-resources.xml
@@ -0,0 +1,21 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+    Licensed to the Apache Software Foundation (ASF) under one or more
+    contributor license agreements.  See the NOTICE file distributed with
+    this work for additional information regarding copyright ownership.
+    The ASF licenses this file to You 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.
+-->
+<resources>
+    <Resource id="ApplicationResource" class-name="org.apache.openejb.assembler.classic.ApplicationResourceLifecycleTest$ApplicationResource">
+    </Resource>
+</resources>
\ No newline at end of file


[5/9] tomee git commit: Applying Romain's test format

Posted by jg...@apache.org.
Applying Romain's test format


Project: http://git-wip-us.apache.org/repos/asf/tomee/repo
Commit: http://git-wip-us.apache.org/repos/asf/tomee/commit/cf1295be
Tree: http://git-wip-us.apache.org/repos/asf/tomee/tree/cf1295be
Diff: http://git-wip-us.apache.org/repos/asf/tomee/diff/cf1295be

Branch: refs/heads/master
Commit: cf1295be75a2c109ec55407537fd742e02c55ac5
Parents: 7baf260
Author: Jonathan Gallimore <jo...@jrg.me.uk>
Authored: Wed Jul 19 15:47:50 2017 +0100
Committer: Jonathan Gallimore <jo...@jrg.me.uk>
Committed: Wed Jul 19 15:47:50 2017 +0100

----------------------------------------------------------------------
 .../ApplicationResourceLifecycleTest.java       | 103 ++++++++-----------
 1 file changed, 44 insertions(+), 59 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/tomee/blob/cf1295be/container/openejb-core/src/test/java/org/apache/openejb/assembler/classic/ApplicationResourceLifecycleTest.java
----------------------------------------------------------------------
diff --git a/container/openejb-core/src/test/java/org/apache/openejb/assembler/classic/ApplicationResourceLifecycleTest.java b/container/openejb-core/src/test/java/org/apache/openejb/assembler/classic/ApplicationResourceLifecycleTest.java
index 1b44277..48c0c6b 100644
--- a/container/openejb-core/src/test/java/org/apache/openejb/assembler/classic/ApplicationResourceLifecycleTest.java
+++ b/container/openejb-core/src/test/java/org/apache/openejb/assembler/classic/ApplicationResourceLifecycleTest.java
@@ -16,84 +16,69 @@
  */
 package org.apache.openejb.assembler.classic;
 
-import org.apache.openejb.OpenEJB;
-import org.apache.openejb.OpenEJBException;
-import org.apache.openejb.config.AppModule;
-import org.apache.openejb.config.ConfigurationFactory;
-import org.apache.openejb.config.EjbModule;
-import org.apache.openejb.core.LocalInitialContextFactory;
-import org.apache.openejb.jee.EjbJar;
-import org.apache.openejb.jee.SingletonBean;
+import org.apache.openejb.config.sys.Resources;
+import org.apache.openejb.testing.ApplicationComposers;
+import org.apache.openejb.testing.Classes;
+import org.apache.openejb.testing.Module;
+import org.apache.openejb.testing.SimpleLog;
 import org.junit.Test;
 
 import javax.annotation.PostConstruct;
 import javax.annotation.PreDestroy;
-import javax.naming.Context;
-import javax.naming.InitialContext;
-import javax.naming.NamingException;
-import java.io.IOException;
-import java.util.Properties;
-import java.util.concurrent.atomic.AtomicBoolean;
+import javax.annotation.Resource;
 
 import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertNotNull;
 import static org.junit.Assert.assertTrue;
 
+@Classes
+@SimpleLog
 public class ApplicationResourceLifecycleTest {
-
-    private static final AtomicBoolean POST_CONSTRUCT = new AtomicBoolean(false);
-    private static final AtomicBoolean PRE_DESTROY = new AtomicBoolean(false);
-
+    @Resource(name = "test")
+    private MyResource resource;
+
+    @Module
+    public Resources resources() {
+        return new Resources() {{
+            getResource().add(new org.apache.openejb.config.sys.Resource() {{
+                setId("test");
+                setClassName(MyResource.class.getName());
+            }});
+        }};
+    }
 
     @Test
-    public void test() throws OpenEJBException, NamingException, IOException {
-        final ConfigurationFactory config = new ConfigurationFactory();
-        final Assembler assembler = new Assembler();
-
-        assembler.createTransactionManager(config.configureService(TransactionServiceInfo.class));
-        assembler.createSecurityService(config.configureService(SecurityServiceInfo.class));
-
-        final AppModule app = new AppModule(ApplicationResourceLifecycleTest.class.getClassLoader(), ApplicationResourceLifecycleTest.class.getSimpleName());
-
-        final EjbJar ejbJar = new EjbJar();
-        ejbJar.addEnterpriseBean(new SingletonBean(ApplicationResource.class));
-        app.getEjbModules().add(new EjbModule(ejbJar));
-        app.getEjbModules().iterator().next().getAltDDs().put("resources.xml", getClass().getClassLoader().getResource("app-resources.xml"));
-
-        assembler.createApplication(config.configureApplication(app));
-
-        final Properties properties = new Properties();
-        properties.setProperty(Context.INITIAL_CONTEXT_FACTORY, LocalInitialContextFactory.class.getName());
-        properties.setProperty("openejb.embedded.initialcontext.close", "destroy");
-
-        // some hack to be sure to call destroy()
-        InitialContext context = new InitialContext(properties);
-        assertNotNull(context);
-
-        assertTrue(POST_CONSTRUCT.getAndSet(false));
-        assertFalse(PRE_DESTROY.get());
-
-        ApplicationResource bean = (ApplicationResource) context.lookup("ApplicationResourceLocalBean");
-
-        assertNotNull(bean);
-        context.close();
-
-        OpenEJB.destroy();
-        assertFalse(POST_CONSTRUCT.get());
-        assertTrue(PRE_DESTROY.get());
+    public void lifecycle() throws Exception {
+        new ApplicationComposers(this).evaluate(this, new Runnable() {
+            @Override
+            public void run() {
+                assertTrue(resource.init);
+                assertFalse(resource.destroy);
+            }
+        });
+        assertTrue(resource.init);
+        assertTrue(resource.destroy);
     }
 
-    public static class ApplicationResource {
+    public static class MyResource {
+        private boolean init;
+        private boolean destroy;
 
         @PostConstruct
-        public void start() {
-            POST_CONSTRUCT.set(true);
+        private void init() {
+            init = true;
         }
 
         @PreDestroy
-        public void stop() {
-            PRE_DESTROY.set(true);
+        private void destroy() {
+            destroy = true;
+        }
+
+        public boolean isInit() {
+            return init;
         }
 
+        public boolean isDestroy() {
+            return destroy;
+        }
     }
 }


[7/9] tomee git commit: Merge branch 'master' into resource-pre-destroy-master

Posted by jg...@apache.org.
Merge branch 'master' into resource-pre-destroy-master


Project: http://git-wip-us.apache.org/repos/asf/tomee/repo
Commit: http://git-wip-us.apache.org/repos/asf/tomee/commit/ac5049fe
Tree: http://git-wip-us.apache.org/repos/asf/tomee/tree/ac5049fe
Diff: http://git-wip-us.apache.org/repos/asf/tomee/diff/ac5049fe

Branch: refs/heads/master
Commit: ac5049fe1a8bdede3842cb1850ff680475fbc6ab
Parents: 9a6010b c7bebb5
Author: Jonathan Gallimore <jo...@jrg.me.uk>
Authored: Thu Jul 20 08:57:40 2017 +0100
Committer: Jonathan Gallimore <jo...@jrg.me.uk>
Committed: Thu Jul 20 08:57:40 2017 +0100

----------------------------------------------------------------------
 .../tests/naming/IvmContextServlet.java         | 59 ++++++++++++++++++++
 .../arquillian/tests/naming/IvmContextTest.java | 58 ++++++++++++++++---
 .../arquillian/tests/naming/NamingBean.java     | 31 +++-------
 3 files changed, 118 insertions(+), 30 deletions(-)
----------------------------------------------------------------------



[4/9] tomee git commit: Work in progress

Posted by jg...@apache.org.
Work in progress


Project: http://git-wip-us.apache.org/repos/asf/tomee/repo
Commit: http://git-wip-us.apache.org/repos/asf/tomee/commit/7baf2605
Tree: http://git-wip-us.apache.org/repos/asf/tomee/tree/7baf2605
Diff: http://git-wip-us.apache.org/repos/asf/tomee/diff/7baf2605

Branch: refs/heads/master
Commit: 7baf2605453814ccc9226a31b9a27550fee218cb
Parents: c376184
Author: Jonathan Gallimore <jo...@jrg.me.uk>
Authored: Wed Jul 19 15:39:38 2017 +0100
Committer: Jonathan Gallimore <jo...@jrg.me.uk>
Committed: Wed Jul 19 15:39:38 2017 +0100

----------------------------------------------------------------------
 .../openejb/assembler/classic/Assembler.java    | 83 ++++++++++++++++++--
 .../openejb/assembler/classic/ResourceInfo.java |  2 +
 2 files changed, 77 insertions(+), 8 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/tomee/blob/7baf2605/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/Assembler.java
----------------------------------------------------------------------
diff --git a/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/Assembler.java b/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/Assembler.java
index d0c0958..853e05c 100644
--- a/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/Assembler.java
+++ b/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/Assembler.java
@@ -1232,6 +1232,12 @@ public class Assembler extends AssemblerTool implements org.apache.openejb.spi.A
                     final List<Method> preDestroys = finder == null ?
                             Collections.<Method>emptyList() : finder.findAnnotatedMethods(PreDestroy.class);
 
+                    resourceInfo.postConstructMethods = new ArrayList<>();
+                    resourceInfo.preDestroyMethods = new ArrayList<>();
+
+                    addMethodsToResourceInfo(resourceInfo.postConstructMethods, PostConstruct.class, postConstructs);
+                    addMethodsToResourceInfo(resourceInfo.preDestroyMethods, PreDestroy.class, preDestroys);
+
                     CreationalContext<?> creationalContext = null;
                     Object originalResource = null;
                     if (!postConstructs.isEmpty() || initialize) {
@@ -1288,6 +1294,7 @@ public class Assembler extends AssemblerTool implements org.apache.openejb.spi.A
                             if (originalResource == null) {
                                 originalResource = containerSystemContext.lookup(name);
                             }
+
                             this.bindResource(resourceInfo.id, new ResourceInstance(name, originalResource, preDestroys, creationalContext), true);
                         }
                     }
@@ -1310,6 +1317,18 @@ public class Assembler extends AssemblerTool implements org.apache.openejb.spi.A
         }
     }
 
+    private void addMethodsToResourceInfo(final List<String> list, final Class type, final List<Method> methodList) throws OpenEJBException {
+        for (final Method method : methodList) {
+            if (method.getParameterTypes().length > 0) {
+                throw new OpenEJBException(type.getSimpleName() + " method " +
+                        method.getDeclaringClass().getName() + "."
+                        + method.getName() + " should have zero arguments");
+            }
+
+            list.add(method.getName());
+        }
+    }
+
     private static boolean isTemplatizedResource(final ResourceInfo resourceInfo) { // ~ container resource even if not 100% right
         return resourceInfo.className == null || resourceInfo.className.isEmpty();
     }
@@ -1991,9 +2010,61 @@ public class Assembler extends AssemblerTool implements org.apache.openejb.spi.A
             doResourceDestruction(name, className, object);
         }
 
+        callPreDestroy(name, object);
         removeResourceInfo(name);
     }
 
+    private void callPreDestroy(final String name, final Object object) {
+        if (object == null) {
+            return;
+        }
+
+        if (ResourceInstance.class.isInstance(object)) {
+            ResourceInstance.class.cast(object).destroyResource();
+            return;
+        }
+
+        final Class<?> objectClass = object.getClass();
+
+        final ResourceInfo ri = findResourceInfo(name);
+        if (ri == null) {
+            return;
+        }
+
+        final Set<String> destroyMethods = new HashSet<>();
+        if (ri.preDestroy != null) {
+            destroyMethods.add(ri.preDestroy);
+        }
+
+        if (ri.preDestroyMethods != null && ri.preDestroyMethods.size() > 0) {
+            destroyMethods.addAll(ri.preDestroyMethods);
+        }
+
+        for (final String destroyMethod : destroyMethods) {
+            try {
+                final Method p = objectClass.getDeclaredMethod(destroyMethod);
+                if (!p.isAccessible()) {
+                    SetAccessible.on(p);
+                }
+                p.invoke(object);
+            } catch (Exception e) {
+                logger.error("Unable to call pre destroy method " + destroyMethod + " on "
+                        + objectClass.getName() + ". Continuing with resource destruction.", e);
+            }
+        }
+    }
+
+    private ResourceInfo findResourceInfo(String name) {
+        List<ResourceInfo> resourceInfos = config.facilities.resources;
+        for (final ResourceInfo resourceInfo : resourceInfos) {
+            if (resourceInfo.id.equals(name)) {
+                return resourceInfo;
+            }
+        }
+
+        return null;
+    }
+
     private void doResourceDestruction(final String name, final String className, final Object jndiObject) {
         final ResourceBeforeDestroyed event = new ResourceBeforeDestroyed(jndiObject, name);
         SystemInstance.get().fireEvent(event);
@@ -2056,7 +2127,7 @@ public class Assembler extends AssemblerTool implements org.apache.openejb.spi.A
         }
     }
 
-    public void removeResourceInfo(final String name) {
+    public ResourceInfo removeResourceInfo(final String name) {
         try {
             //Ensure ResourceInfo for this resource is removed
             final OpenEjbConfiguration configuration = SystemInstance.get().getComponent(OpenEjbConfiguration.class);
@@ -2070,12 +2141,14 @@ public class Assembler extends AssemblerTool implements org.apache.openejb.spi.A
                 final ResourceInfo info = iterator.next();
                 if (name.equals(info.id)) {
                     iterator.remove();
-                    break;
+                    return info;
                 }
             }
         } catch (final Exception e) {
             logger.debug("Failed to purge resource on destroy: " + e.getMessage());
         }
+
+        return null;
     }
 
     private static Object unwrapReference(final Object object) {
@@ -2484,12 +2557,6 @@ public class Assembler extends AssemblerTool implements org.apache.openejb.spi.A
                 if (!binding.getName().equals(objName)) {
                     continue;
                 }
-                if (DestroyableResource.class.isInstance(binding.getObject())) {
-                    final DestroyableResource destroyableResource = DestroyableResource.class.cast(binding.getObject());
-                    destroyableResource.destroyResource();
-                    globalContext.unbind(name);
-                    return;
-                }
 
                 if (!LazyObjectReference.class.isInstance(binding.getObject())) {
                     continue;

http://git-wip-us.apache.org/repos/asf/tomee/blob/7baf2605/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/ResourceInfo.java
----------------------------------------------------------------------
diff --git a/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/ResourceInfo.java b/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/ResourceInfo.java
index 5a2ace9..52791c9 100644
--- a/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/ResourceInfo.java
+++ b/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/ResourceInfo.java
@@ -24,6 +24,8 @@ public class ResourceInfo extends ServiceInfo {
     public String jndiName = "";
     public String postConstruct;
     public String preDestroy;
+    public List<String> postConstructMethods;
+    public List<String> preDestroyMethods;
     public String originAppName; // if define by an app
     public List<String> aliases = new ArrayList<>();
     public List<String> dependsOn = new ArrayList<>();


[9/9] tomee git commit: Merge remote-tracking branch 'apache/master' into resource-pre-destroy-master

Posted by jg...@apache.org.
Merge remote-tracking branch 'apache/master' into resource-pre-destroy-master


Project: http://git-wip-us.apache.org/repos/asf/tomee/repo
Commit: http://git-wip-us.apache.org/repos/asf/tomee/commit/d2594302
Tree: http://git-wip-us.apache.org/repos/asf/tomee/tree/d2594302
Diff: http://git-wip-us.apache.org/repos/asf/tomee/diff/d2594302

Branch: refs/heads/master
Commit: d25943021b8c584b1161d908f57d2a3142a3e88c
Parents: e83b40d cb6baa0
Author: Jonathan Gallimore <jo...@jrg.me.uk>
Authored: Thu Aug 3 00:05:40 2017 +0100
Committer: Jonathan Gallimore <jo...@jrg.me.uk>
Committed: Thu Aug 3 00:05:40 2017 +0100

----------------------------------------------------------------------
 .../apache/openejb/core/mdb/MdbContainer.java   |  21 ++-
 .../core/mdb/ResourceAdapterControlTest.java    |  16 +-
 .../mdb/ResourceAdapterDeliveryActiveTest.java  | 184 +++++++++++++++++++
 pom.xml                                         |   2 +-
 .../org/apache/tomee/embedded/Container.java    |  28 +++
 5 files changed, 241 insertions(+), 10 deletions(-)
----------------------------------------------------------------------



[3/9] tomee git commit: Revert "Check the binding for LazyResources and Destroyable resources first"

Posted by jg...@apache.org.
Revert "Check the binding for LazyResources and Destroyable resources first"

This reverts commit 96973e9ac09f96b9fea13b97380a2f82cb157f61.


Project: http://git-wip-us.apache.org/repos/asf/tomee/repo
Commit: http://git-wip-us.apache.org/repos/asf/tomee/commit/c3761843
Tree: http://git-wip-us.apache.org/repos/asf/tomee/tree/c3761843
Diff: http://git-wip-us.apache.org/repos/asf/tomee/diff/c3761843

Branch: refs/heads/master
Commit: c3761843e20447fc484843d6d3765d951edda4c3
Parents: 96973e9
Author: Jonathan Gallimore <jo...@jrg.me.uk>
Authored: Fri Jul 14 16:57:23 2017 +0100
Committer: Jonathan Gallimore <jo...@jrg.me.uk>
Committed: Fri Jul 14 16:57:23 2017 +0100

----------------------------------------------------------------------
 .../openejb/assembler/classic/Assembler.java    | 59 ++++++++++----------
 1 file changed, 31 insertions(+), 28 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/tomee/blob/c3761843/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/Assembler.java
----------------------------------------------------------------------
diff --git a/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/Assembler.java b/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/Assembler.java
index 13c27e6..d0c0958 100644
--- a/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/Assembler.java
+++ b/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/Assembler.java
@@ -2469,40 +2469,43 @@ public class Assembler extends AssemblerTool implements org.apache.openejb.spi.A
     }
 
     private void destroyLookedUpResource(final Context globalContext, final String id, final String name) throws NamingException {
-        // check to see if the resource is a LazyObjectReference that has not been initialized
-        // if it is, we'll remove the LazyObjectReference, rather than do a lookup causing it
-        // to be instantiated
-        final String ctx = name.substring(0, name.lastIndexOf("/"));
-        final String objName = name.substring(ctx.length() + 1);
-
-        final NamingEnumeration<Binding> bindings = globalContext.listBindings(ctx);
-        while (bindings.hasMoreElements()) {
-            final Binding binding = bindings.nextElement();
-            if (!binding.getName().equals(objName)) {
-                continue;
-            }
 
-            if (DestroyableResource.class.isInstance(binding.getObject())) {
-                final DestroyableResource destroyableResource = DestroyableResource.class.cast(binding.getObject());
-                destroyableResource.destroyResource();
-                globalContext.unbind(name);
-                return;
-            }
+        final Object object;
 
-            if (!LazyObjectReference.class.isInstance(binding.getObject())) {
-                continue;
-            }
+        try {
+            object = globalContext.lookup(name);
+        } catch (final NamingException e) {
+            // if we catch a NamingException, check to see if the resource is a LaztObjectReference that has not been initialized correctly
+            final String ctx = name.substring(0, name.lastIndexOf("/"));
+            final String objName = name.substring(ctx.length() + 1);
+            final NamingEnumeration<Binding> bindings = globalContext.listBindings(ctx);
+            while (bindings.hasMoreElements()) {
+                final Binding binding = bindings.nextElement();
+                if (!binding.getName().equals(objName)) {
+                    continue;
+                }
+                if (DestroyableResource.class.isInstance(binding.getObject())) {
+                    final DestroyableResource destroyableResource = DestroyableResource.class.cast(binding.getObject());
+                    destroyableResource.destroyResource();
+                    globalContext.unbind(name);
+                    return;
+                }
 
-            final LazyObjectReference<?> ref = LazyObjectReference.class.cast(binding.getObject());
-            if (!ref.isInitialized()) {
-                globalContext.unbind(name);
-                removeResourceInfo(id);
-                return;
+                if (!LazyObjectReference.class.isInstance(binding.getObject())) {
+                    continue;
+                }
+
+                final LazyObjectReference<?> ref = LazyObjectReference.class.cast(binding.getObject());
+                if (! ref.isInitialized()) {
+                    globalContext.unbind(name);
+                    removeResourceInfo(name);
+                    return;
+                }
             }
+
+            throw e;
         }
 
-        // otherwise, look the object up and remove it
-        final Object object = globalContext.lookup(name);
         final String clazz;
         if (object == null) { // should it be possible?
             clazz = "?";


[8/9] tomee git commit: Merge remote-tracking branch 'apache/master' into resource-pre-destroy-master

Posted by jg...@apache.org.
Merge remote-tracking branch 'apache/master' into resource-pre-destroy-master


Project: http://git-wip-us.apache.org/repos/asf/tomee/repo
Commit: http://git-wip-us.apache.org/repos/asf/tomee/commit/e83b40dc
Tree: http://git-wip-us.apache.org/repos/asf/tomee/tree/e83b40dc
Diff: http://git-wip-us.apache.org/repos/asf/tomee/diff/e83b40dc

Branch: refs/heads/master
Commit: e83b40dc624b171bf446a01f3745431f81c10920
Parents: ac5049f cf5ed05
Author: Jonathan Gallimore <jo...@jrg.me.uk>
Authored: Tue Jul 25 11:07:30 2017 +0100
Committer: Jonathan Gallimore <jo...@jrg.me.uk>
Committed: Tue Jul 25 11:07:30 2017 +0100

----------------------------------------------------------------------
 .../ActivationConfigPropertyOverride.java       |  39 ++++-
 .../openejb/core/ivm/naming/IvmContext.java     |  10 +-
 .../apache/openejb/core/mdb/MdbContainer.java   |  31 ++--
 ...ContainerOverwriteBothConfigurationTest.java | 152 ++++++++++++++++++
 ...erOverwriteIdContainerConfigurationTest.java | 150 ++++++++++++++++++
 ...tainerOverwriteMessageConfigurationTest.java | 150 ++++++++++++++++++
 ...rwriteReadTheContainerConfigurationTest.java | 147 +++++++++++++++++
 ...ContainerOverwriteSystemContainerIdTest.java | 158 +++++++++++++++++++
 .../ActivationContainerOverwriteSystemTest.java | 158 +++++++++++++++++++
 .../ActivationConfigPropertyOverrideTest.java   |  27 +++-
 .../openejb/core/ivm/naming/IvmContextTest.java |   4 +-
 .../openejb/ivm/naming/IvmContextTest.java      | 122 +++++++++++++-
 .../cxf/rs/AppPropertiesPropagationTest.java    |  10 +-
 13 files changed, 1132 insertions(+), 26 deletions(-)
----------------------------------------------------------------------



[2/9] tomee git commit: Check the binding for LazyResources and Destroyable resources first

Posted by jg...@apache.org.
Check the binding for LazyResources and Destroyable resources first


Project: http://git-wip-us.apache.org/repos/asf/tomee/repo
Commit: http://git-wip-us.apache.org/repos/asf/tomee/commit/96973e9a
Tree: http://git-wip-us.apache.org/repos/asf/tomee/tree/96973e9a
Diff: http://git-wip-us.apache.org/repos/asf/tomee/diff/96973e9a

Branch: refs/heads/master
Commit: 96973e9ac09f96b9fea13b97380a2f82cb157f61
Parents: cce266a
Author: Jonathan Gallimore <jo...@jrg.me.uk>
Authored: Thu Jul 13 09:50:34 2017 +0100
Committer: Jonathan Gallimore <jo...@jrg.me.uk>
Committed: Thu Jul 13 09:50:34 2017 +0100

----------------------------------------------------------------------
 .../openejb/assembler/classic/Assembler.java    | 59 ++++++++++----------
 1 file changed, 28 insertions(+), 31 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/tomee/blob/96973e9a/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/Assembler.java
----------------------------------------------------------------------
diff --git a/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/Assembler.java b/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/Assembler.java
index d0c0958..13c27e6 100644
--- a/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/Assembler.java
+++ b/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/Assembler.java
@@ -2469,43 +2469,40 @@ public class Assembler extends AssemblerTool implements org.apache.openejb.spi.A
     }
 
     private void destroyLookedUpResource(final Context globalContext, final String id, final String name) throws NamingException {
+        // check to see if the resource is a LazyObjectReference that has not been initialized
+        // if it is, we'll remove the LazyObjectReference, rather than do a lookup causing it
+        // to be instantiated
+        final String ctx = name.substring(0, name.lastIndexOf("/"));
+        final String objName = name.substring(ctx.length() + 1);
+
+        final NamingEnumeration<Binding> bindings = globalContext.listBindings(ctx);
+        while (bindings.hasMoreElements()) {
+            final Binding binding = bindings.nextElement();
+            if (!binding.getName().equals(objName)) {
+                continue;
+            }
 
-        final Object object;
-
-        try {
-            object = globalContext.lookup(name);
-        } catch (final NamingException e) {
-            // if we catch a NamingException, check to see if the resource is a LaztObjectReference that has not been initialized correctly
-            final String ctx = name.substring(0, name.lastIndexOf("/"));
-            final String objName = name.substring(ctx.length() + 1);
-            final NamingEnumeration<Binding> bindings = globalContext.listBindings(ctx);
-            while (bindings.hasMoreElements()) {
-                final Binding binding = bindings.nextElement();
-                if (!binding.getName().equals(objName)) {
-                    continue;
-                }
-                if (DestroyableResource.class.isInstance(binding.getObject())) {
-                    final DestroyableResource destroyableResource = DestroyableResource.class.cast(binding.getObject());
-                    destroyableResource.destroyResource();
-                    globalContext.unbind(name);
-                    return;
-                }
-
-                if (!LazyObjectReference.class.isInstance(binding.getObject())) {
-                    continue;
-                }
+            if (DestroyableResource.class.isInstance(binding.getObject())) {
+                final DestroyableResource destroyableResource = DestroyableResource.class.cast(binding.getObject());
+                destroyableResource.destroyResource();
+                globalContext.unbind(name);
+                return;
+            }
 
-                final LazyObjectReference<?> ref = LazyObjectReference.class.cast(binding.getObject());
-                if (! ref.isInitialized()) {
-                    globalContext.unbind(name);
-                    removeResourceInfo(name);
-                    return;
-                }
+            if (!LazyObjectReference.class.isInstance(binding.getObject())) {
+                continue;
             }
 
-            throw e;
+            final LazyObjectReference<?> ref = LazyObjectReference.class.cast(binding.getObject());
+            if (!ref.isInitialized()) {
+                globalContext.unbind(name);
+                removeResourceInfo(id);
+                return;
+            }
         }
 
+        // otherwise, look the object up and remove it
+        final Object object = globalContext.lookup(name);
         final String clazz;
         if (object == null) { // should it be possible?
             clazz = "?";


[6/9] tomee git commit: Merge remote-tracking branch 'apache/master' into resource-pre-destroy-master

Posted by jg...@apache.org.
Merge remote-tracking branch 'apache/master' into resource-pre-destroy-master


Project: http://git-wip-us.apache.org/repos/asf/tomee/repo
Commit: http://git-wip-us.apache.org/repos/asf/tomee/commit/9a6010bb
Tree: http://git-wip-us.apache.org/repos/asf/tomee/tree/9a6010bb
Diff: http://git-wip-us.apache.org/repos/asf/tomee/diff/9a6010bb

Branch: refs/heads/master
Commit: 9a6010bbe9d47ce79ec5ffe57d08f901bff88a60
Parents: cf1295b 5830c20
Author: Jonathan Gallimore <jo...@jrg.me.uk>
Authored: Wed Jul 19 19:57:44 2017 +0100
Committer: Jonathan Gallimore <jo...@jrg.me.uk>
Committed: Wed Jul 19 19:57:44 2017 +0100

----------------------------------------------------------------------
 .../arquillian/tests/naming/IvmContextTest.java |  67 +++++++
 .../arquillian/tests/naming/NamingBean.java     | 135 ++++++++++++++
 .../tests/naming/list-context-ejbjar.xml        |  38 ++++
 .../openejb/core/ivm/naming/IvmContext.java     |  22 +--
 .../openejb/ivm/naming/IvmContextTest.java      | 186 ++++++++++++++++++-
 .../cxf/rs/AppPropertiesPropagationTest.java    | 131 +++++++++++++
 .../server/rest/InternalApplication.java        |   7 +
 7 files changed, 568 insertions(+), 18 deletions(-)
----------------------------------------------------------------------