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 2020/07/04 19:30:31 UTC
[tomee] branch master updated (e06749d -> ec78018)
This is an automated email from the ASF dual-hosted git repository.
jgallimore pushed a change to branch master
in repository https://gitbox.apache.org/repos/asf/tomee.git.
from e06749d Merge pull request #655 from Daniel-Dos/TOMEE-2832
new 6594a74 Turn off ActiveMQ's JMX connection creation, and by default set create to false on vm:// server URLs
new ec78018 Single imports
The 2 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails. The revisions
listed as "add" were already present in the repository and have only
been added to this reference.
Summary of changes:
.../resource/activemq/ActiveMQResourceAdapter.java | 17 +++++
.../java/org/apache/openejb/util/URISupport.java | 26 ++++++++
.../org/apache/openejb/activemq/ServerUrlTest.java | 78 ++++++++++++++++++++++
.../org/apache/openejb/util/URISupportTest.java | 60 +++++++++++++++++
.../org/apache/openejb/loader/SystemInstance.java | 14 ++++
5 files changed, 195 insertions(+)
create mode 100644 container/openejb-core/src/test/java/org/apache/openejb/activemq/ServerUrlTest.java
[tomee] 02/02: Single imports
Posted by jg...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
jgallimore pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/tomee.git
commit ec78018cca20f28dbc24bd9df76980ad54f5e5a7
Author: Jonathan Gallimore <jo...@jrg.me.uk>
AuthorDate: Sat Jul 4 20:30:02 2020 +0100
Single imports
---
.../openejb/resource/activemq/ActiveMQResourceAdapter.java | 7 ++++++-
.../src/main/java/org/apache/openejb/util/URISupport.java | 9 ++++++++-
2 files changed, 14 insertions(+), 2 deletions(-)
diff --git a/container/openejb-core/src/main/java/org/apache/openejb/resource/activemq/ActiveMQResourceAdapter.java b/container/openejb-core/src/main/java/org/apache/openejb/resource/activemq/ActiveMQResourceAdapter.java
index 0eac18a..f66ef00 100644
--- a/container/openejb-core/src/main/java/org/apache/openejb/resource/activemq/ActiveMQResourceAdapter.java
+++ b/container/openejb-core/src/main/java/org/apache/openejb/resource/activemq/ActiveMQResourceAdapter.java
@@ -52,7 +52,12 @@ import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;
import java.net.URISyntaxException;
-import java.util.*;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.Locale;
+import java.util.Map;
+import java.util.Properties;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.TimeUnit;
diff --git a/container/openejb-core/src/main/java/org/apache/openejb/util/URISupport.java b/container/openejb-core/src/main/java/org/apache/openejb/util/URISupport.java
index a3c4c1d..2557708 100644
--- a/container/openejb-core/src/main/java/org/apache/openejb/util/URISupport.java
+++ b/container/openejb-core/src/main/java/org/apache/openejb/util/URISupport.java
@@ -22,7 +22,14 @@ import java.net.URI;
import java.net.URISyntaxException;
import java.net.URLDecoder;
import java.net.URLEncoder;
-import java.util.*;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.LinkedHashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
/**
* Swiped verbatim from ActiveMQ... the URI kings.
[tomee] 01/02: Turn off ActiveMQ's JMX connection creation,
and by default set create to false on vm:// server URLs
Posted by jg...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
jgallimore pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/tomee.git
commit 6594a74d216e96d6ad540f9385fbbd099c2e4182
Author: Jonathan Gallimore <jo...@jrg.me.uk>
AuthorDate: Sat Jul 4 20:13:10 2020 +0100
Turn off ActiveMQ's JMX connection creation, and by default set create to false on vm:// server URLs
---
.../resource/activemq/ActiveMQResourceAdapter.java | 22 ++++--
.../java/org/apache/openejb/util/URISupport.java | 31 +++++++--
.../org/apache/openejb/activemq/ServerUrlTest.java | 78 ++++++++++++++++++++++
.../org/apache/openejb/util/URISupportTest.java | 60 +++++++++++++++++
.../org/apache/openejb/loader/SystemInstance.java | 14 ++++
5 files changed, 194 insertions(+), 11 deletions(-)
diff --git a/container/openejb-core/src/main/java/org/apache/openejb/resource/activemq/ActiveMQResourceAdapter.java b/container/openejb-core/src/main/java/org/apache/openejb/resource/activemq/ActiveMQResourceAdapter.java
index 1437a95..0eac18a 100644
--- a/container/openejb-core/src/main/java/org/apache/openejb/resource/activemq/ActiveMQResourceAdapter.java
+++ b/container/openejb-core/src/main/java/org/apache/openejb/resource/activemq/ActiveMQResourceAdapter.java
@@ -52,11 +52,7 @@ import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;
import java.net.URISyntaxException;
-import java.util.Collection;
-import java.util.Iterator;
-import java.util.Locale;
-import java.util.Map;
-import java.util.Properties;
+import java.util.*;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.TimeUnit;
@@ -68,6 +64,11 @@ public class ActiveMQResourceAdapter extends org.apache.activemq.ra.ActiveMQReso
private String startupTimeout = "60000";
private BootstrapContext bootstrapContext;
private final Map<BeanContext, ObjectName> mbeanNames = new ConcurrentHashMap<>();
+ private static final Map<String,String> PREVENT_CREATION_PARAMS = new HashMap<String, String>() { {
+ put("create", "false");
+ }};
+
+ private static final Logger LOGGER = Logger.getInstance(LogCategory.ACTIVEMQ, ActiveMQ5Factory.class);
public String getDataSource() {
return dataSource;
@@ -94,6 +95,17 @@ public class ActiveMQResourceAdapter extends org.apache.activemq.ra.ActiveMQReso
@Override
public void setServerUrl(final String url) {
+ try {
+ final URISupport.CompositeData compositeData = URISupport.parseComposite(URLs.uri(url));
+ if ("vm".equals(compositeData.getScheme())) {
+ super.setServerUrl(URISupport.addParameters(URLs.uri(url), PREVENT_CREATION_PARAMS).toString());
+ return;
+ }
+ } catch (URISyntaxException e) {
+ // if we hit an exception, we'll log this and simple pass the URL we were given to ActiveMQ.
+ LOGGER.error("Error occurred while processing ActiveMQ ServerUrl: " + url, e);
+ }
+
super.setServerUrl(url);
}
diff --git a/container/openejb-core/src/main/java/org/apache/openejb/util/URISupport.java b/container/openejb-core/src/main/java/org/apache/openejb/util/URISupport.java
index cd24995..a3c4c1d 100644
--- a/container/openejb-core/src/main/java/org/apache/openejb/util/URISupport.java
+++ b/container/openejb-core/src/main/java/org/apache/openejb/util/URISupport.java
@@ -22,12 +22,7 @@ import java.net.URI;
import java.net.URISyntaxException;
import java.net.URLDecoder;
import java.net.URLEncoder;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Collections;
-import java.util.LinkedHashMap;
-import java.util.List;
-import java.util.Map;
+import java.util.*;
/**
* Swiped verbatim from ActiveMQ... the URI kings.
@@ -377,4 +372,28 @@ public class URISupport {
return result;
}
+
+ /**
+ * This method adds new parameters to a URI. Any parameters provided that already exist in the URI will *not* be replaced.
+ * @param uri The URI to add parameters to
+ * @param newParameters The parameters to add
+ * @return The URI with the new parameters added
+ * @throws URISyntaxException If there is a syntax error with the provided URI.
+ */
+ public static URI addParameters(final URI uri, final Map<String, String> newParameters) throws URISyntaxException {
+ if (newParameters == null || newParameters.size() == 0) {
+ return uri;
+ }
+
+ final Map<String, String> parameters = new HashMap<>(parseParamters(uri));
+
+ final Set<String> keys = newParameters.keySet();
+ for (final String key : keys) {
+ if (! parameters.containsKey(key)) {
+ parameters.put(key, newParameters.get(key));
+ }
+ }
+
+ return createRemainingURI(uri, parameters);
+ }
}
diff --git a/container/openejb-core/src/test/java/org/apache/openejb/activemq/ServerUrlTest.java b/container/openejb-core/src/test/java/org/apache/openejb/activemq/ServerUrlTest.java
new file mode 100644
index 0000000..906bcfb
--- /dev/null
+++ b/container/openejb-core/src/test/java/org/apache/openejb/activemq/ServerUrlTest.java
@@ -0,0 +1,78 @@
+/**
+ * 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.openejb.junit.ApplicationComposer;
+import org.apache.openejb.testing.Classes;
+import org.apache.openejb.testing.Configuration;
+import org.apache.openejb.testing.SimpleLog;
+import org.apache.openejb.testng.PropertiesBuilder;
+import org.junit.Assert;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+import javax.annotation.Resource;
+import javax.ejb.EJB;
+import javax.ejb.Singleton;
+import javax.jms.Connection;
+import javax.jms.ConnectionFactory;
+import javax.jms.JMSException;
+import javax.resource.ResourceException;
+import java.util.Properties;
+
+@SimpleLog
+@RunWith(ApplicationComposer.class)
+@Classes(cdi = true, innerClassesAsBean = true)
+public class ServerUrlTest {
+
+ @EJB
+ private ConnectionTestBean testBean;
+
+ @Configuration
+ public Properties config() {
+ return new PropertiesBuilder()
+ .p("amq", "new://Resource?type=ActiveMQResourceAdapter")
+ .p("amq.BrokerXmlConfig", "broker:(vm://broker)?useJmx=true")
+ .p("amq.ServerUrl", "vm://broker")
+ .p("amqcf", "new://Resource?type=javax.jms.ConnectionFactory")
+ .p("amqcf.ResourceAdapter", "amq")
+
+ .build();
+ }
+
+ @Test
+ public void test() throws Exception {
+ try {
+ testBean.testConnection();
+ Assert.fail("Expected exception not thrown");
+ } catch (JMSException e) {
+ Assert.assertTrue(e.getMessage().contains("Broker named 'broker' does not exist"));
+ }
+ }
+
+ @Singleton
+ public static class ConnectionTestBean {
+
+ @Resource
+ private ConnectionFactory cf;
+
+ public void testConnection() throws Exception {
+ final Connection connection = cf.createConnection();
+ connection.close();
+ }
+ }
+}
diff --git a/container/openejb-core/src/test/java/org/apache/openejb/util/URISupportTest.java b/container/openejb-core/src/test/java/org/apache/openejb/util/URISupportTest.java
index 88f6caa..0e784a6 100644
--- a/container/openejb-core/src/test/java/org/apache/openejb/util/URISupportTest.java
+++ b/container/openejb-core/src/test/java/org/apache/openejb/util/URISupportTest.java
@@ -19,6 +19,9 @@ package org.apache.openejb.util;
import junit.framework.TestCase;
import java.net.URI;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Map;
/**
* @version $Rev$ $Date$
@@ -48,4 +51,61 @@ public class URISupportTest extends TestCase {
assertTrue(resolvedB.equals(absoluteB));
}
+ public void testAddNewParameters() throws Exception {
+ final Map<String, String> parameters = new HashMap<>();
+ parameters.put("create", "false");
+
+ final URI uri = URISupport.addParameters(URLs.uri("vm://broker"), parameters);
+ assertEquals("vm://broker?create=false", uri.toString());
+ }
+
+ public void testDoNotReplaceAnExistingParameters() throws Exception {
+ final Map<String, String> parameters = new HashMap<>();
+ parameters.put("create", "false");
+
+ final URI uri = URISupport.addParameters(URLs.uri("vm://broker?create=true"), parameters);
+ assertEquals("vm://broker?create=true", uri.toString());
+ }
+
+ public void testAddToSetOfAlreadyExistingParameters() throws Exception {
+ final Map<String, String> parameters = new HashMap<>();
+ parameters.put("create", "false");
+
+ final URI uri = URISupport.addParameters(URLs.uri("vm://broker?foo=bar&boo=baz&welcome=helloworld"), parameters);
+ final Map<String, String> actual = URISupport.parseParamters(uri);
+
+ assertEquals(4, actual.size());
+ assertEquals("bar", actual.get("foo"));
+ assertEquals("baz", actual.get("boo"));
+ assertEquals("helloworld", actual.get("welcome"));
+ assertEquals("false", actual.get("create"));
+ }
+
+ public void testAddToSetOfAlreadyExistingParametersButDontOverwriteExistingParameter() throws Exception {
+ final Map<String, String> parameters = new HashMap<>();
+ parameters.put("create", "false");
+
+ final URI uri = URISupport.addParameters(URLs.uri("vm://broker?foo=bar&boo=baz&welcome=helloworld&create=true"), parameters);
+ final Map<String, String> actual = URISupport.parseParamters(uri);
+
+ assertEquals(4, actual.size());
+ assertEquals("bar", actual.get("foo"));
+ assertEquals("baz", actual.get("boo"));
+ assertEquals("helloworld", actual.get("welcome"));
+ assertEquals("true", actual.get("create"));
+ }
+
+ public void testNullParameters() throws Exception {
+ final URI initial = URLs.uri("vm://broker?foo=bar&boo=baz&welcome=helloworld&create=true");
+ final URI uri = URISupport.addParameters(initial, null);
+
+ assertEquals(initial, uri);
+ }
+
+ public void testEmptyParameters() throws Exception {
+ final URI initial = URLs.uri("vm://broker?foo=bar&boo=baz&welcome=helloworld&create=true");
+ final URI uri = URISupport.addParameters(initial, Collections.emptyMap());
+
+ assertEquals(initial, uri);
+ }
}
diff --git a/container/openejb-loader/src/main/java/org/apache/openejb/loader/SystemInstance.java b/container/openejb-loader/src/main/java/org/apache/openejb/loader/SystemInstance.java
index 063e913..c41bb37 100644
--- a/container/openejb-loader/src/main/java/org/apache/openejb/loader/SystemInstance.java
+++ b/container/openejb-loader/src/main/java/org/apache/openejb/loader/SystemInstance.java
@@ -41,6 +41,7 @@ import java.util.concurrent.atomic.AtomicReference;
public final class SystemInstance {
private static final String PROFILE_PROP = "openejb.profile";
private static final String DEFAULT_PROFILE = "development";
+ public static final String ACTIVEMQ_CREATE_JMX_CONNECTOR = "org.apache.activemq.broker.jmx.createConnector";
private final long startTime = System.currentTimeMillis();
@@ -111,6 +112,9 @@ public final class SystemInstance {
}
}
this.internalProperties.putAll(properties);
+
+ setDefaults();
+
this.options = new Options(internalProperties, new Options(System.getProperties()));
this.home = new FileUtils("openejb.home", "user.dir", this.internalProperties);
this.base = new FileUtils("openejb.base", "openejb.home", this.internalProperties);
@@ -129,6 +133,16 @@ public final class SystemInstance {
System.setProperty("derby.system.home", System.getProperty("derby.system.home", baseDirCanonicalPath));
}
+ /**
+ * This method sets some specific defaults. We shouldn't add to this unless there's a really good reason -
+ * e.g. we need to override an upstream component's defaults.
+ */
+ private void setDefaults() {
+ if (! this.internalProperties.containsKey(ACTIVEMQ_CREATE_JMX_CONNECTOR)) {
+ this.internalProperties.setProperty(ACTIVEMQ_CREATE_JMX_CONNECTOR, Boolean.FALSE.toString());
+ }
+ }
+
public <E> E fireEvent(final E event) {
return observerManager.fireEvent(event);
}