Adds configuration
Project: http://git-wip-us.apache.org/repos/asf/tomee/repo Commit: http://git-wip-us.apache.org/repos/asf/tomee/commit/b5764137 Tree: http://git-wip-us.apache.org/repos/asf/tomee/tree/b5764137 Diff: http://git-wip-us.apache.org/repos/asf/tomee/diff/b5764137 Branch: refs/heads/master Commit: b57641372214ab5dce8e0e446f815cd1fdd87603 Parents: 1e87ba3 Author: Otavio Santana <[email protected]> Authored: Tue Jul 11 10:05:03 2017 -0300 Committer: Otavio Santana <[email protected]> Committed: Tue Jul 11 10:05:03 2017 -0300 ---------------------------------------------------------------------- .../ActivationConfigPropertyOverride.java | 4 - .../apache/openejb/core/mdb/MdbContainer.java | 40 ++--- .../openejb/activemq/AMQXASupportTest.java | 43 +++-- .../activemq/ActivationContainerTest.java | 162 +++++++++++++++++++ 4 files changed, 205 insertions(+), 44 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/tomee/blob/b5764137/container/openejb-core/src/main/java/org/apache/openejb/config/ActivationConfigPropertyOverride.java ---------------------------------------------------------------------- diff --git a/container/openejb-core/src/main/java/org/apache/openejb/config/ActivationConfigPropertyOverride.java b/container/openejb-core/src/main/java/org/apache/openejb/config/ActivationConfigPropertyOverride.java index be29a34..597c13b 100644 --- a/container/openejb-core/src/main/java/org/apache/openejb/config/ActivationConfigPropertyOverride.java +++ b/container/openejb-core/src/main/java/org/apache/openejb/config/ActivationConfigPropertyOverride.java @@ -31,7 +31,6 @@ import org.apache.openejb.util.LogCategory; import org.apache.openejb.util.Logger; import org.apache.openejb.util.PropertyPlaceHolderHelper; -import java.util.ArrayList; import java.util.List; import java.util.Map; import java.util.Properties; @@ -88,14 +87,11 @@ public class ActivationConfigPropertyOverride implements DynamicDeployer { } } - // now try to use special keys final Properties overrides = ConfigurationFactory.getOverrides(properties, "mdb.activation", "EnterpriseBean"); overrides.putAll(ConfigurationFactory.getOverrides(properties, mdb.getMessagingType() + ".activation", "EnterpriseBean")); overrides.putAll(ConfigurationFactory.getOverrides(properties, ejbName + ".activation", "EnterpriseBean")); overrides.putAll(ConfigurationFactory.getOverrides(properties, ejbDeployment.getDeploymentId() + ".activation", "EnterpriseBean")); -// overrides.putAll(ConfigurationFactory.getOverrides(configuration, "mdb.activation", "EnterpriseBean")); - //overides any configuration there already exist // If we don't have any overrides, skip to the next if (overrides.size() == 0) { http://git-wip-us.apache.org/repos/asf/tomee/blob/b5764137/container/openejb-core/src/main/java/org/apache/openejb/core/mdb/MdbContainer.java ---------------------------------------------------------------------- diff --git a/container/openejb-core/src/main/java/org/apache/openejb/core/mdb/MdbContainer.java b/container/openejb-core/src/main/java/org/apache/openejb/core/mdb/MdbContainer.java index 7aec0a2..5bbcb94 100644 --- a/container/openejb-core/src/main/java/org/apache/openejb/core/mdb/MdbContainer.java +++ b/container/openejb-core/src/main/java/org/apache/openejb/core/mdb/MdbContainer.java @@ -70,7 +70,6 @@ import javax.validation.ConstraintViolationException; import javax.validation.Validator; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; -import java.util.ArrayList; import java.util.Arrays; import java.util.List; import java.util.Map; @@ -108,7 +107,7 @@ public class MdbContainer implements RpcContainer { private final XAResourceWrapper xaResourceWrapper; private final InboundRecovery inboundRecovery; - private final Properties configuration = new Properties(); + private final Properties properties = new Properties(); public MdbContainer(final Object containerID, final SecurityService securityService, final ResourceAdapter resourceAdapter, final Class messageListenerInterface, final Class activationSpecClass, final int instanceLimit, @@ -124,8 +123,8 @@ public class MdbContainer implements RpcContainer { inboundRecovery = SystemInstance.get().getComponent(InboundRecovery.class); } - public Properties getConfiguration() { - return configuration; + public Properties getProperties() { + return properties; } public BeanContext[] getBeanContexts() { @@ -240,10 +239,6 @@ public class MdbContainer implements RpcContainer { } } - private static String getOrDefault(final Map<String, String> map, final String key, final String defaultValue) { - return map.get(key) != null ? map.get(key) : defaultValue; - } - private ActivationSpec createActivationSpec(final BeanContext beanContext) throws OpenEJBException { try { // initialize the object recipe @@ -251,15 +246,18 @@ public class MdbContainer implements RpcContainer { objectRecipe.allow(Option.IGNORE_MISSING_PROPERTIES); objectRecipe.disallow(Option.FIELD_INJECTION); + final Properties containerActivationProperties = new Properties(); + addActivationProperties(containerActivationProperties, "activation.", properties); + addActivationProperties(containerActivationProperties, "mdb.container." + containerID + ".activation.", SystemInstance.get().getProperties()); + + for (final String propertyName : containerActivationProperties.stringPropertyNames()) { + objectRecipe.setMethodProperty(propertyName, containerActivationProperties.getProperty(propertyName)); + } + final Map<String, String> beanContextActivationProperties = beanContext.getActivationProperties(); - List<String> activations = new ArrayList<>(); final Map<String, String> activationProperties = beanContextActivationProperties; for (final Map.Entry<String, String> entry : activationProperties.entrySet()) { objectRecipe.setMethodProperty(entry.getKey(), entry.getValue()); - if (entry.getKey().startsWith("activation")) { - configuration.put("mdb." + entry.getKey(), entry.getValue()); - activations.add(entry.getKey()); - } } objectRecipe.setMethodProperty("beanClass", beanContext.getBeanClass()); @@ -273,9 +271,6 @@ public class MdbContainer implements RpcContainer { unusedProperties.remove("destinationLookup"); unusedProperties.remove("connectionFactoryLookup"); unusedProperties.remove("beanClass"); - for (String activation : activations) { - unusedProperties.remove(activation); - } if (!unusedProperties.isEmpty()) { final String text = "No setter found for the activation spec properties: " + unusedProperties; if (failOnUnknownActivationSpec) { @@ -313,6 +308,15 @@ public class MdbContainer implements RpcContainer { } } + private void addActivationProperties(final Properties target, final String prefix, final Properties source) { + for (final String propertyName : source.stringPropertyNames()) { + if (! propertyName.startsWith(prefix)) continue; + + final String activationPropertyName = propertyName.substring(prefix.length()); + target.setProperty(activationPropertyName, source.getProperty(propertyName)); + } + } + public void start(final BeanContext info) throws OpenEJBException { final EjbTimerService timerService = info.getEjbTimerService(); if (timerService != null) { @@ -625,7 +629,7 @@ public class MdbContainer implements RpcContainer { } public void start() throws ResourceException { - if (!started.compareAndSet(false, true)) { + if (! started.compareAndSet(false, true)) { return; } @@ -641,7 +645,7 @@ public class MdbContainer implements RpcContainer { } public void stop() { - if (!started.compareAndSet(true, false)) { + if (! started.compareAndSet(true, false)) { return; } http://git-wip-us.apache.org/repos/asf/tomee/blob/b5764137/container/openejb-core/src/test/java/org/apache/openejb/activemq/AMQXASupportTest.java ---------------------------------------------------------------------- diff --git a/container/openejb-core/src/test/java/org/apache/openejb/activemq/AMQXASupportTest.java b/container/openejb-core/src/test/java/org/apache/openejb/activemq/AMQXASupportTest.java index 80fe01f..1391f1e 100644 --- a/container/openejb-core/src/test/java/org/apache/openejb/activemq/AMQXASupportTest.java +++ b/container/openejb-core/src/test/java/org/apache/openejb/activemq/AMQXASupportTest.java @@ -5,14 +5,14 @@ * 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 - * <p> - * http://www.apache.org/licenses/LICENSE-2.0 - * <p> - * 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. + * + * 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.activemq; @@ -57,22 +57,22 @@ public class AMQXASupportTest { public Properties config() { return new PropertiesBuilder() - .p("amq", "new://Resource?type=ActiveMQResourceAdapter") - .p("amq.DataSource", "") - .p("amq.BrokerXmlConfig", "broker:(vm://localhost)") + .p("amq", "new://Resource?type=ActiveMQResourceAdapter") + .p("amq.DataSource", "") + .p("amq.BrokerXmlConfig", "broker:(vm://localhost)") - .p("target", "new://Resource?type=Queue") + .p("target", "new://Resource?type=Queue") - .p("mdbs", "new://Container?type=MESSAGE") - .p("mdbs.ResourceAdapter", "amq") + .p("mdbs", "new://Container?type=MESSAGE") + .p("mdbs.ResourceAdapter", "amq") - .p("cf", "new://Resource?type=" + ConnectionFactory.class.getName()) - .p("cf.ResourceAdapter", "amq") + .p("cf", "new://Resource?type=" + ConnectionFactory.class.getName()) + .p("cf.ResourceAdapter", "amq") - .p("xaCf", "new://Resource?class-name=" + ActiveMQXAConnectionFactory.class.getName()) - .p("xaCf.BrokerURL", "vm://localhost") + .p("xaCf", "new://Resource?class-name=" + ActiveMQXAConnectionFactory.class.getName()) + .p("xaCf.BrokerURL", "vm://localhost") - .build(); + .build(); } @Module @@ -128,9 +128,8 @@ public class AMQXASupportTest { } @MessageDriven(activationConfig = { - @ActivationConfigProperty(propertyName = "destinationType", propertyValue = "javax.jms.Queue"), - @ActivationConfigProperty(propertyName = "destination", propertyValue = "target"), - @ActivationConfigProperty(propertyName = "activation.configuration", propertyValue = "aaaa") + @ActivationConfigProperty(propertyName = "destinationType", propertyValue = "javax.jms.Queue"), + @ActivationConfigProperty(propertyName = "destination", propertyValue = "target") }) public static class Listener implements MessageListener { public static CountDownLatch latch; http://git-wip-us.apache.org/repos/asf/tomee/blob/b5764137/container/openejb-core/src/test/java/org/apache/openejb/activemq/ActivationContainerTest.java ---------------------------------------------------------------------- diff --git a/container/openejb-core/src/test/java/org/apache/openejb/activemq/ActivationContainerTest.java b/container/openejb-core/src/test/java/org/apache/openejb/activemq/ActivationContainerTest.java new file mode 100644 index 0000000..2d40007 --- /dev/null +++ b/container/openejb-core/src/test/java/org/apache/openejb/activemq/ActivationContainerTest.java @@ -0,0 +1,162 @@ +/** + * 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 + * <p> + * http://www.apache.org/licenses/LICENSE-2.0 + * <p> + * 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.activemq; + +import org.apache.activemq.ActiveMQXAConnectionFactory; +import org.apache.openejb.jee.MessageDrivenBean; +import org.apache.openejb.junit.ApplicationComposer; +import org.apache.openejb.testing.Configuration; +import org.apache.openejb.testing.Module; +import org.apache.openejb.testng.PropertiesBuilder; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; + +import javax.annotation.Resource; +import javax.ejb.ActivationConfigProperty; +import javax.ejb.MessageDriven; +import javax.jms.Connection; +import javax.jms.ConnectionFactory; +import javax.jms.JMSException; +import javax.jms.Message; +import javax.jms.MessageListener; +import javax.jms.MessageProducer; +import javax.jms.Queue; +import javax.jms.Session; +import javax.jms.TextMessage; +import javax.jms.XAConnection; +import javax.jms.XAConnectionFactory; +import java.util.Properties; +import java.util.concurrent.CountDownLatch; +import java.util.concurrent.TimeUnit; + +import static org.hamcrest.CoreMatchers.instanceOf; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertThat; +import static org.junit.Assert.assertTrue; + +@RunWith(ApplicationComposer.class) +public class ActivationContainerTest { + private static final String TEXT = "foo"; + + @Configuration + public Properties config() { + return new PropertiesBuilder() + + .p("amq", "new://Resource?type=ActiveMQResourceAdapter") + .p("amq.DataSource", "") + .p("amq.BrokerXmlConfig", "broker:(vm://localhost)") + + .p("target", "new://Resource?type=Queue") + + .p("mdbs", "new://Container?type=MESSAGE") + .p("mdbs.ResourceAdapter", "amq") + + .p("cf", "new://Resource?type=" + ConnectionFactory.class.getName()) + .p("cf.ResourceAdapter", "amq") + + .p("xaCf", "new://Resource?class-name=" + ActiveMQXAConnectionFactory.class.getName()) + .p("xaCf.BrokerURL", "vm://localhost") + + .build(); + } + + @Module + public MessageDrivenBean jar() { + return new MessageDrivenBean(Listener.class); + } + + @Resource(name = "target") + private Queue destination; + + @Resource(name = "xaCf") + private XAConnectionFactory xacf; + + @Resource(name = "cf") + private ConnectionFactory cf; + + @Before + public void resetLatch() { + Listener.reset(); + } + + @Test + public void standardCode() throws Exception { + assertNotNull(cf); + + + final Connection connection = cf.createConnection(); + testConnection(connection); + } + + @Test + public void xaCode() throws Exception { + assertNotNull(xacf); + + final Connection connection = xacf.createXAConnection(); + assertThat(connection, instanceOf(XAConnection.class)); + testConnection(connection); + } + + private void testConnection(final Connection connection) throws JMSException, InterruptedException { + try { + final Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); + final MessageProducer producer = session.createProducer(destination); + producer.send(session.createTextMessage(TEXT)); + assertTrue(Listener.sync()); + } finally { + try { + connection.close(); + } catch (final JMSException e) { + //no-op + } + } + } + + @MessageDriven(activationConfig = { + @ActivationConfigProperty(propertyName = "destinationType", propertyValue = "javax.jms.Queue"), + @ActivationConfigProperty(propertyName = "destination", propertyValue = "target"), + @ActivationConfigProperty(propertyName = "activation.configuration", propertyValue = "aaaa") + }) + public static class Listener implements MessageListener { + public static CountDownLatch latch; + public static boolean ok = false; + + @Override + public void onMessage(final Message message) { + try { + try { + ok = TextMessage.class.isInstance(message) && TEXT.equals(TextMessage.class.cast(message).getText()); + } catch (final JMSException e) { + // no-op + } + } finally { + latch.countDown(); + } + } + + public static void reset() { + latch = new CountDownLatch(1); + ok = false; + } + + public static boolean sync() throws InterruptedException { + latch.await(1, TimeUnit.MINUTES); + return ok; + } + } +}
