You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tomee.apache.org by rm...@apache.org on 2015/04/16 23:24:12 UTC
tomee git commit: TOMEE-1550 plugins on amq broker when embedded in
amq5factory format
Repository: tomee
Updated Branches:
refs/heads/master 98ac5e5c5 -> 0465cb52b
TOMEE-1550 plugins on amq broker when embedded in amq5factory format
Project: http://git-wip-us.apache.org/repos/asf/tomee/repo
Commit: http://git-wip-us.apache.org/repos/asf/tomee/commit/0465cb52
Tree: http://git-wip-us.apache.org/repos/asf/tomee/tree/0465cb52
Diff: http://git-wip-us.apache.org/repos/asf/tomee/diff/0465cb52
Branch: refs/heads/master
Commit: 0465cb52bba27708e2de313b9303065d99c203dc
Parents: 98ac5e5
Author: Romain Manni-Bucau <rm...@apache.org>
Authored: Thu Apr 16 23:24:05 2015 +0200
Committer: Romain Manni-Bucau <rm...@apache.org>
Committed: Thu Apr 16 23:24:05 2015 +0200
----------------------------------------------------------------------
.../resource/activemq/ActiveMQ5Factory.java | 44 ++++++++++++++++--
.../resource/activemq/ActiveMQ5FactoryTest.java | 47 ++++++++++++++++++++
2 files changed, 87 insertions(+), 4 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/tomee/blob/0465cb52/container/openejb-core/src/main/java/org/apache/openejb/resource/activemq/ActiveMQ5Factory.java
----------------------------------------------------------------------
diff --git a/container/openejb-core/src/main/java/org/apache/openejb/resource/activemq/ActiveMQ5Factory.java b/container/openejb-core/src/main/java/org/apache/openejb/resource/activemq/ActiveMQ5Factory.java
index 0bbf54b..0d9f5df 100644
--- a/container/openejb-core/src/main/java/org/apache/openejb/resource/activemq/ActiveMQ5Factory.java
+++ b/container/openejb-core/src/main/java/org/apache/openejb/resource/activemq/ActiveMQ5Factory.java
@@ -19,6 +19,7 @@ package org.apache.openejb.resource.activemq;
import org.apache.activemq.broker.BrokerFactory;
import org.apache.activemq.broker.BrokerFactoryHandler;
+import org.apache.activemq.broker.BrokerPlugin;
import org.apache.activemq.broker.BrokerService;
import org.apache.activemq.ra.ActiveMQResourceAdapter;
import org.apache.activemq.store.PersistenceAdapter;
@@ -32,10 +33,8 @@ import org.apache.openejb.util.LogCategory;
import org.apache.openejb.util.Logger;
import org.apache.xbean.propertyeditor.PropertyEditorException;
import org.apache.xbean.propertyeditor.PropertyEditors;
+import org.apache.xbean.recipe.ObjectRecipe;
-import javax.naming.Context;
-import javax.naming.NamingException;
-import javax.sql.DataSource;
import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
@@ -43,15 +42,20 @@ import java.lang.reflect.Modifier;
import java.net.URI;
import java.util.Collection;
import java.util.HashMap;
+import java.util.Iterator;
+import java.util.LinkedList;
import java.util.Locale;
import java.util.Map;
import java.util.Properties;
import java.util.concurrent.atomic.AtomicBoolean;
+import javax.naming.Context;
+import javax.naming.NamingException;
+import javax.sql.DataSource;
public class ActiveMQ5Factory implements BrokerFactoryHandler {
private static Properties properties;
- private static final Map<URI, BrokerService> brokers = new HashMap<URI, BrokerService>();
+ protected static final Map<URI, BrokerService> brokers = new HashMap<URI, BrokerService>();
private static Throwable throwable;
private static final AtomicBoolean started = new AtomicBoolean(false);
@@ -84,8 +88,12 @@ public class ActiveMQ5Factory implements BrokerFactoryHandler {
persistenceAdapter = null;
}
+ final BrokerPlugin[] plugins = createPlugins(params);
final URI uri = new URI(cleanUpUri(brokerURI.getSchemeSpecificPart(), compositeData.getParameters(), params));
broker = BrokerFactory.createBroker(uri);
+ if (plugins != null) {
+ broker.setPlugins(plugins);
+ }
brokers.put(brokerURI, broker);
if (persistenceAdapter != null) {
@@ -245,6 +253,34 @@ public class ActiveMQ5Factory implements BrokerFactoryHandler {
return broker;
}
+ private BrokerPlugin[] createPlugins(final Map<String, String> params) {
+ final String plugins = params.remove("amq.plugins");
+ if (plugins == null) {
+ return null;
+ }
+
+ final Collection<BrokerPlugin> instances = new LinkedList<>();
+ for (final String p : plugins.split(" *, *")) {
+ if (p.isEmpty()) {
+ continue;
+ }
+
+ final String prefix = p + ".";
+ final ObjectRecipe recipe = new ObjectRecipe(params.remove(prefix + "class"));
+ final Iterator<Map.Entry<String, String>> iterator = params.entrySet().iterator();
+ while (iterator.hasNext()) {
+ final Map.Entry<String, String> entry = iterator.next();
+ final String key = entry.getKey();
+ if (key.startsWith(prefix)) {
+ recipe.setProperty(key.substring(prefix.length()), entry.getValue());
+ iterator.remove();
+ }
+ }
+ instances.add(BrokerPlugin.class.cast(recipe.create()));
+ }
+ return instances.toArray(new BrokerPlugin[instances.size()]);
+ }
+
private static String cleanUpUri(final String schemeSpecificPart, final Map<String, String> parameters, final Map<String, String> params) {
String uri = schemeSpecificPart;
for (final Map.Entry<String, String> entry : parameters.entrySet()) {
http://git-wip-us.apache.org/repos/asf/tomee/blob/0465cb52/container/openejb-core/src/test/java/org/apache/openejb/resource/activemq/ActiveMQ5FactoryTest.java
----------------------------------------------------------------------
diff --git a/container/openejb-core/src/test/java/org/apache/openejb/resource/activemq/ActiveMQ5FactoryTest.java b/container/openejb-core/src/test/java/org/apache/openejb/resource/activemq/ActiveMQ5FactoryTest.java
new file mode 100644
index 0000000..1a80fbd
--- /dev/null
+++ b/container/openejb-core/src/test/java/org/apache/openejb/resource/activemq/ActiveMQ5FactoryTest.java
@@ -0,0 +1,47 @@
+/**
+ *
+ * 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.resource.activemq;
+
+import org.apache.activemq.broker.BrokerService;
+import org.apache.activemq.security.JaasAuthenticationPlugin;
+import org.junit.Test;
+
+import java.net.URI;
+
+import static org.apache.openejb.util.NetworkUtil.getNextAvailablePort;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+
+public class ActiveMQ5FactoryTest {
+ @Test
+ public void setPlugins() throws Exception {
+ final URI brokerURI = new URI("amq5factory:broker:(tcp://localhost:" + getNextAvailablePort() + ")?" +
+ "amq.plugins=jaas&" +
+ "jaas.class=" + JaasAuthenticationPlugin.class.getName() + "&" +
+ "jaas.discoverLoginConfig=false");
+ final BrokerService bs = new ActiveMQ5Factory().createBroker(brokerURI);
+ bs.stop();
+ ActiveMQ5Factory.brokers.remove(brokerURI);
+ assertNotNull(bs.getPlugins());
+ assertEquals(1, bs.getPlugins().length);
+ assertTrue(JaasAuthenticationPlugin.class.isInstance(bs.getPlugins()[0]));
+ assertFalse(JaasAuthenticationPlugin.class.cast(bs.getPlugins()[0]).isDiscoverLoginConfig()); // default is true
+ }
+}