You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@qpid.apache.org by ro...@apache.org on 2015/06/17 15:50:44 UTC
qpid-jms git commit: QPIDJMS-74: add useful details as connection
properties in the Open frame
Repository: qpid-jms
Updated Branches:
refs/heads/master a91170e29 -> 1731b2e46
QPIDJMS-74: add useful details as connection properties in the Open frame
Project: http://git-wip-us.apache.org/repos/asf/qpid-jms/repo
Commit: http://git-wip-us.apache.org/repos/asf/qpid-jms/commit/1731b2e4
Tree: http://git-wip-us.apache.org/repos/asf/qpid-jms/tree/1731b2e4
Diff: http://git-wip-us.apache.org/repos/asf/qpid-jms/diff/1731b2e4
Branch: refs/heads/master
Commit: 1731b2e469455375df765d7ad987cbce7442591f
Parents: a91170e
Author: Robert Gemmell <ro...@apache.org>
Authored: Wed Jun 17 14:47:05 2015 +0100
Committer: Robert Gemmell <ro...@apache.org>
Committed: Wed Jun 17 14:47:05 2015 +0100
----------------------------------------------------------------------
.../org/apache/qpid/jms/util/version.txt | 1 +
.../org/apache/qpid/jms/version.txt | 1 -
.../apache/qpid/jms/JmsConnectionMetaData.java | 58 ++---------
.../qpid/jms/provider/amqp/AmqpConnection.java | 16 ++-
.../qpid/jms/provider/amqp/AmqpSupport.java | 4 +
.../apache/qpid/jms/util/MetaDataSupport.java | 103 +++++++++++++++++++
.../integration/ConnectionIntegrationTest.java | 27 ++++-
.../qpid/jms/test/testpeer/TestAmqpPeer.java | 18 ++--
8 files changed, 164 insertions(+), 64 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/qpid-jms/blob/1731b2e4/qpid-jms-client/src/main/filtered-resources/org/apache/qpid/jms/util/version.txt
----------------------------------------------------------------------
diff --git a/qpid-jms-client/src/main/filtered-resources/org/apache/qpid/jms/util/version.txt b/qpid-jms-client/src/main/filtered-resources/org/apache/qpid/jms/util/version.txt
new file mode 100644
index 0000000..f2ab45c
--- /dev/null
+++ b/qpid-jms-client/src/main/filtered-resources/org/apache/qpid/jms/util/version.txt
@@ -0,0 +1 @@
+${project.version}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/qpid-jms/blob/1731b2e4/qpid-jms-client/src/main/filtered-resources/org/apache/qpid/jms/version.txt
----------------------------------------------------------------------
diff --git a/qpid-jms-client/src/main/filtered-resources/org/apache/qpid/jms/version.txt b/qpid-jms-client/src/main/filtered-resources/org/apache/qpid/jms/version.txt
deleted file mode 100644
index f2ab45c..0000000
--- a/qpid-jms-client/src/main/filtered-resources/org/apache/qpid/jms/version.txt
+++ /dev/null
@@ -1 +0,0 @@
-${project.version}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/qpid-jms/blob/1731b2e4/qpid-jms-client/src/main/java/org/apache/qpid/jms/JmsConnectionMetaData.java
----------------------------------------------------------------------
diff --git a/qpid-jms-client/src/main/java/org/apache/qpid/jms/JmsConnectionMetaData.java b/qpid-jms-client/src/main/java/org/apache/qpid/jms/JmsConnectionMetaData.java
index 1be96af..3b65e80 100644
--- a/qpid-jms-client/src/main/java/org/apache/qpid/jms/JmsConnectionMetaData.java
+++ b/qpid-jms-client/src/main/java/org/apache/qpid/jms/JmsConnectionMetaData.java
@@ -16,67 +16,21 @@
*/
package org.apache.qpid.jms;
-import java.io.BufferedReader;
-import java.io.InputStream;
-import java.io.InputStreamReader;
-import java.nio.charset.Charset;
import java.util.Enumeration;
import java.util.Vector;
-import java.util.regex.Matcher;
-import java.util.regex.Pattern;
import javax.jms.ConnectionMetaData;
+import org.apache.qpid.jms.util.MetaDataSupport;
+
/**
* A <CODE>ConnectionMetaData</CODE> object provides information describing
* the <CODE>Connection</CODE> object.
*/
public final class JmsConnectionMetaData implements ConnectionMetaData {
- public static final String PROVIDER_VERSION;
- public static final int PROVIDER_MAJOR_VERSION;
- public static final int PROVIDER_MINOR_VERSION;
-
public static final JmsConnectionMetaData INSTANCE = new JmsConnectionMetaData();
- static {
- String version = null;
- int major = 0;
- int minor = 0;
- try {
- Package p = Package.getPackage(JmsConnectionMetaData.class.getPackage().getName());
- if (p != null) {
- version = p.getImplementationVersion();
- Pattern pattern = Pattern.compile("(\\d+)\\.(\\d+).*");
- Matcher m = pattern.matcher(version);
- if (m.matches()) {
- major = Integer.parseInt(m.group(1));
- minor = Integer.parseInt(m.group(2));
- }
- }
- } catch (Throwable e) {
- InputStream in = null;
- String path = JmsConnectionMetaData.class.getPackage().getName().replace(".", "/");
- if ((in = JmsConnectionMetaData.class.getResourceAsStream("/" + path + "/version.txt")) != null) {
- try {
- BufferedReader reader = new BufferedReader(new InputStreamReader(in, Charset.forName("US-ASCII")));
- version = reader.readLine();
- Pattern pattern = Pattern.compile("(\\d+)\\.(\\d+).*");
- Matcher m = pattern.matcher(version);
- if (m.matches()) {
- major = Integer.parseInt(m.group(1));
- minor = Integer.parseInt(m.group(2));
- }
- reader.close();
- } catch(Throwable err) {
- }
- }
- }
- PROVIDER_VERSION = version;
- PROVIDER_MAJOR_VERSION = major;
- PROVIDER_MINOR_VERSION = minor;
- }
-
private JmsConnectionMetaData() {}
/**
@@ -116,7 +70,7 @@ public final class JmsConnectionMetaData implements ConnectionMetaData {
*/
@Override
public String getJMSProviderName() {
- return "QpidJMS";
+ return MetaDataSupport.PROVIDER_NAME;
}
/**
@@ -126,7 +80,7 @@ public final class JmsConnectionMetaData implements ConnectionMetaData {
*/
@Override
public String getProviderVersion() {
- return PROVIDER_VERSION;
+ return MetaDataSupport.PROVIDER_VERSION;
}
/**
@@ -136,7 +90,7 @@ public final class JmsConnectionMetaData implements ConnectionMetaData {
*/
@Override
public int getProviderMajorVersion() {
- return PROVIDER_MAJOR_VERSION;
+ return MetaDataSupport.PROVIDER_MAJOR_VERSION;
}
/**
@@ -146,7 +100,7 @@ public final class JmsConnectionMetaData implements ConnectionMetaData {
*/
@Override
public int getProviderMinorVersion() {
- return PROVIDER_MINOR_VERSION;
+ return MetaDataSupport.PROVIDER_MINOR_VERSION;
}
/**
http://git-wip-us.apache.org/repos/asf/qpid-jms/blob/1731b2e4/qpid-jms-client/src/main/java/org/apache/qpid/jms/provider/amqp/AmqpConnection.java
----------------------------------------------------------------------
diff --git a/qpid-jms-client/src/main/java/org/apache/qpid/jms/provider/amqp/AmqpConnection.java b/qpid-jms-client/src/main/java/org/apache/qpid/jms/provider/amqp/AmqpConnection.java
index 74683ae..af2b431 100644
--- a/qpid-jms-client/src/main/java/org/apache/qpid/jms/provider/amqp/AmqpConnection.java
+++ b/qpid-jms-client/src/main/java/org/apache/qpid/jms/provider/amqp/AmqpConnection.java
@@ -20,6 +20,7 @@ import static org.apache.qpid.jms.provider.amqp.AmqpSupport.SOLE_CONNECTION_CAPA
import java.net.URI;
import java.util.HashMap;
+import java.util.LinkedHashMap;
import java.util.Map;
import javax.jms.JMSException;
@@ -34,6 +35,7 @@ import org.apache.qpid.jms.meta.JmsSessionInfo;
import org.apache.qpid.jms.provider.AsyncResult;
import org.apache.qpid.jms.provider.amqp.message.AmqpJmsMessageFactory;
import org.apache.qpid.jms.util.IOExceptionSupport;
+import org.apache.qpid.jms.util.MetaDataSupport;
import org.apache.qpid.proton.amqp.Symbol;
import org.apache.qpid.proton.engine.Connection;
import org.slf4j.Logger;
@@ -87,9 +89,17 @@ public class AmqpConnection extends AmqpAbstractResource<JmsConnectionInfo, Conn
hostname = null;
}
- getEndpoint().setHostname(hostname);
- getEndpoint().setContainer(resource.getClientId());
- getEndpoint().setDesiredCapabilities(new Symbol[] { SOLE_CONNECTION_CAPABILITY });
+ Map<Symbol, Object> props = new LinkedHashMap<Symbol, Object>();
+ props.put(AmqpSupport.PRODUCT, MetaDataSupport.PROVIDER_NAME);
+ props.put(AmqpSupport.VERSION, MetaDataSupport.PROVIDER_VERSION);
+ props.put(AmqpSupport.PLATFORM, MetaDataSupport.PLATFORM_DETAILS);
+
+ Connection conn = getEndpoint();
+ conn.setHostname(hostname);
+ conn.setContainer(resource.getClientId());
+ conn.setDesiredCapabilities(new Symbol[] { SOLE_CONNECTION_CAPABILITY });
+ conn.setProperties(props);
+
super.doOpen();
}
http://git-wip-us.apache.org/repos/asf/qpid-jms/blob/1731b2e4/qpid-jms-client/src/main/java/org/apache/qpid/jms/provider/amqp/AmqpSupport.java
----------------------------------------------------------------------
diff --git a/qpid-jms-client/src/main/java/org/apache/qpid/jms/provider/amqp/AmqpSupport.java b/qpid-jms-client/src/main/java/org/apache/qpid/jms/provider/amqp/AmqpSupport.java
index 2dce4ca..29d94ab 100644
--- a/qpid-jms-client/src/main/java/org/apache/qpid/jms/provider/amqp/AmqpSupport.java
+++ b/qpid-jms-client/src/main/java/org/apache/qpid/jms/provider/amqp/AmqpSupport.java
@@ -36,4 +36,8 @@ public class AmqpSupport {
// Symbols used for connection properties
public static final Symbol QUEUE_PREFIX = Symbol.valueOf("queue-prefix");
public static final Symbol TOPIC_PREFIX = Symbol.valueOf("topic-prefix");
+
+ public static final Symbol PRODUCT = Symbol.valueOf("product");
+ public static final Symbol VERSION = Symbol.valueOf("version");
+ public static final Symbol PLATFORM = Symbol.valueOf("platform");
}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/qpid-jms/blob/1731b2e4/qpid-jms-client/src/main/java/org/apache/qpid/jms/util/MetaDataSupport.java
----------------------------------------------------------------------
diff --git a/qpid-jms-client/src/main/java/org/apache/qpid/jms/util/MetaDataSupport.java b/qpid-jms-client/src/main/java/org/apache/qpid/jms/util/MetaDataSupport.java
new file mode 100644
index 0000000..47789fd
--- /dev/null
+++ b/qpid-jms-client/src/main/java/org/apache/qpid/jms/util/MetaDataSupport.java
@@ -0,0 +1,103 @@
+/*
+ * 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.qpid.jms.util;
+
+import java.io.BufferedReader;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.nio.charset.StandardCharsets;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class MetaDataSupport {
+ private static final Logger LOG = LoggerFactory.getLogger(MetaDataSupport.class);
+
+ public static final String PROVIDER_NAME = "QpidJMS";
+ public static final String PROVIDER_VERSION;
+ public static final int PROVIDER_MAJOR_VERSION;
+ public static final int PROVIDER_MINOR_VERSION;
+ public static final String PLATFORM_DETAILS = buildPlatformDetails();
+
+ static {
+ String version = "unknown";
+ int major = 0;
+ int minor = 0;
+ try {
+ Package p = Package.getPackage(MetaDataSupport.class.getPackage().getName());
+ if (p != null) {
+ version = p.getImplementationVersion();
+ Pattern pattern = Pattern.compile("(\\d+)\\.(\\d+).*");
+ Matcher m = pattern.matcher(version);
+ if (m.matches()) {
+ major = Integer.parseInt(m.group(1));
+ minor = Integer.parseInt(m.group(2));
+ }
+ }
+ } catch (Throwable e) {
+ LOG.trace("Problem generating primary version details", e);
+
+ InputStream in = null;
+ String path = MetaDataSupport.class.getPackage().getName().replace(".", "/");
+ if ((in = MetaDataSupport.class.getResourceAsStream("/" + path + "/version.txt")) != null) {
+ try {
+ BufferedReader reader = new BufferedReader(new InputStreamReader(in, StandardCharsets.US_ASCII));
+ version = reader.readLine();
+ Pattern pattern = Pattern.compile("(\\d+)\\.(\\d+).*");
+ Matcher m = pattern.matcher(version);
+ if (m.matches()) {
+ major = Integer.parseInt(m.group(1));
+ minor = Integer.parseInt(m.group(2));
+ }
+ reader.close();
+ } catch(Throwable err) {
+ LOG.trace("Problem generating fallback version details", err);
+ }
+ }
+ }
+
+ PROVIDER_VERSION = version;
+ PROVIDER_MAJOR_VERSION = major;
+ PROVIDER_MINOR_VERSION = minor;
+ }
+
+ private static String buildPlatformDetails()
+ {
+ String details = "unknown";
+ try {
+ StringBuilder platformInfo = new StringBuilder(System.getProperty("java.version"));
+ platformInfo.append(", ");
+ platformInfo.append(System.getProperty("java.vm.version"));
+ platformInfo.append(", ");
+ platformInfo.append(System.getProperty("java.vendor"));
+ platformInfo.append(", ");
+ platformInfo.append(System.getProperty("os.name"));
+ platformInfo.append(", ");
+ platformInfo.append(System.getProperty("os.version"));
+ platformInfo.append(", ");
+ platformInfo.append(System.getProperty("os.arch"));
+
+ details = platformInfo.toString();
+ } catch (Throwable e) {
+ LOG.trace("Problem generating platform details string", e);
+ }
+
+ return details;
+ }
+}
http://git-wip-us.apache.org/repos/asf/qpid-jms/blob/1731b2e4/qpid-jms-client/src/test/java/org/apache/qpid/jms/integration/ConnectionIntegrationTest.java
----------------------------------------------------------------------
diff --git a/qpid-jms-client/src/test/java/org/apache/qpid/jms/integration/ConnectionIntegrationTest.java b/qpid-jms-client/src/test/java/org/apache/qpid/jms/integration/ConnectionIntegrationTest.java
index b2166ac..c0dea10 100644
--- a/qpid-jms-client/src/test/java/org/apache/qpid/jms/integration/ConnectionIntegrationTest.java
+++ b/qpid-jms-client/src/test/java/org/apache/qpid/jms/integration/ConnectionIntegrationTest.java
@@ -23,8 +23,10 @@ package org.apache.qpid.jms.integration;
import static org.apache.qpid.jms.provider.amqp.AmqpSupport.NETWORK_HOST;
import static org.apache.qpid.jms.provider.amqp.AmqpSupport.OPEN_HOSTNAME;
import static org.apache.qpid.jms.provider.amqp.AmqpSupport.PORT;
+import static org.hamcrest.Matchers.allOf;
import static org.hamcrest.Matchers.arrayContaining;
import static org.hamcrest.Matchers.equalTo;
+import static org.hamcrest.Matchers.hasEntry;
import static org.hamcrest.Matchers.nullValue;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
@@ -52,18 +54,19 @@ import javax.jms.Session;
import org.apache.qpid.jms.JmsConnection;
import org.apache.qpid.jms.JmsConnectionFactory;
import org.apache.qpid.jms.provider.ProviderRedirectedException;
+import org.apache.qpid.jms.provider.amqp.AmqpSupport;
import org.apache.qpid.jms.test.QpidJmsTestCase;
import org.apache.qpid.jms.test.Wait;
import org.apache.qpid.jms.test.testpeer.TestAmqpPeer;
import org.apache.qpid.jms.test.testpeer.basictypes.AmqpError;
import org.apache.qpid.jms.test.testpeer.basictypes.ConnectionError;
import org.apache.qpid.jms.test.testpeer.matchers.CoordinatorMatcher;
+import org.apache.qpid.jms.util.MetaDataSupport;
import org.apache.qpid.proton.amqp.Symbol;
import org.apache.qpid.proton.amqp.transaction.TxnCapability;
import org.hamcrest.Matcher;
import org.junit.Test;
-// TODO find a way to make the test abort immediately if the TestAmqpPeer throws an exception
public class ConnectionIntegrationTest extends QpidJmsTestCase {
private final IntegrationTestFixture testFixture = new IntegrationTestFixture();
@@ -125,6 +128,28 @@ public class ConnectionIntegrationTest extends QpidJmsTestCase {
}
@Test(timeout = 5000)
+ public void testConnectionPropertiesContainExpectedMetaData() throws Exception {
+ try (TestAmqpPeer testPeer = new TestAmqpPeer();) {
+
+ Matcher<?> connPropsMatcher = allOf(hasEntry(AmqpSupport.PRODUCT, MetaDataSupport.PROVIDER_NAME),
+ hasEntry(AmqpSupport.VERSION, MetaDataSupport.PROVIDER_VERSION),
+ hasEntry(AmqpSupport.PLATFORM, MetaDataSupport.PLATFORM_DETAILS));
+
+ testPeer.expectSaslAnonymousConnect(null, null, connPropsMatcher, null);
+ testPeer.expectBegin(true);
+
+ ConnectionFactory factory = new JmsConnectionFactory("amqp://localhost:" + testPeer.getServerPort() + "?jms.clientID=foo");
+ Connection connection = factory.createConnection();
+
+ testPeer.waitForAllHandlersToComplete(1000);
+ assertNull(testPeer.getThrowable());
+
+ testPeer.expectClose();
+ connection.close();
+ }
+ }
+
+ @Test(timeout = 5000)
public void testAmqpHostnameSetByDefault() throws Exception {
doAmqpHostnameTestImpl("localhost", false, equalTo("localhost"));
}
http://git-wip-us.apache.org/repos/asf/qpid-jms/blob/1731b2e4/qpid-jms-client/src/test/java/org/apache/qpid/jms/test/testpeer/TestAmqpPeer.java
----------------------------------------------------------------------
diff --git a/qpid-jms-client/src/test/java/org/apache/qpid/jms/test/testpeer/TestAmqpPeer.java b/qpid-jms-client/src/test/java/org/apache/qpid/jms/test/testpeer/TestAmqpPeer.java
index 164d2ee..88a59a5 100644
--- a/qpid-jms-client/src/test/java/org/apache/qpid/jms/test/testpeer/TestAmqpPeer.java
+++ b/qpid-jms-client/src/test/java/org/apache/qpid/jms/test/testpeer/TestAmqpPeer.java
@@ -370,7 +370,7 @@ public class TestAmqpPeer implements AutoCloseable
}
public void expectSaslConnect(Symbol mechanism, Matcher<Binary> initialResponseMatcher, Symbol[] desiredCapabilities, Symbol[] serverCapabilities,
- Map<Symbol, Object> serverProperties, Matcher<?> idleTimeoutMatcher, Matcher<?> hostnameMatcher)
+ Matcher<?> clientPropertiesMatcher, Map<Symbol, Object> serverProperties, Matcher<?> idleTimeoutMatcher, Matcher<?> hostnameMatcher)
{
SaslMechanismsFrame saslMechanismsFrame = new SaslMechanismsFrame().setSaslServerMechanisms(mechanism);
addHandler(new HeaderHandlerImpl(AmqpHeader.SASL_HEADER, AmqpHeader.SASL_HEADER,
@@ -444,6 +444,10 @@ public class TestAmqpPeer implements AutoCloseable
openMatcher.withHostname(hostnameMatcher);
}
+ if(clientPropertiesMatcher != null) {
+ openMatcher.withProperties(clientPropertiesMatcher);
+ }
+
addHandler(openMatcher);
}
@@ -462,7 +466,7 @@ public class TestAmqpPeer implements AutoCloseable
Matcher<Binary> initialResponseMatcher = equalTo(new Binary(data));
- expectSaslConnect(PLAIN, initialResponseMatcher, desiredCapabilities, serverCapabilities, serverProperties, null, null);
+ expectSaslConnect(PLAIN, initialResponseMatcher, desiredCapabilities, serverCapabilities, null, serverProperties, null, null);
}
public void expectSaslExternalConnect()
@@ -472,7 +476,7 @@ public class TestAmqpPeer implements AutoCloseable
throw new IllegalStateException("need-client-cert must be enabled on the test peer");
}
- expectSaslConnect(EXTERNAL, equalTo(new Binary(new byte[0])), new Symbol[] { AmqpSupport.SOLE_CONNECTION_CAPABILITY }, null, null, null, null);
+ expectSaslConnect(EXTERNAL, equalTo(new Binary(new byte[0])), new Symbol[] { AmqpSupport.SOLE_CONNECTION_CAPABILITY }, null, null, null, null, null);
}
public void expectSaslAnonymousConnect()
@@ -482,12 +486,12 @@ public class TestAmqpPeer implements AutoCloseable
public void expectSaslAnonymousConnect(Matcher<?> idleTimeoutMatcher, Matcher<?> hostnameMatcher)
{
- expectSaslAnonymousConnect(idleTimeoutMatcher, hostnameMatcher, null);
+ expectSaslAnonymousConnect(idleTimeoutMatcher, hostnameMatcher, null, null);
}
- public void expectSaslAnonymousConnect(Matcher<?> idleTimeoutMatcher, Matcher<?> hostnameMatcher, Map<Symbol, Object> serverProperties)
+ public void expectSaslAnonymousConnect(Matcher<?> idleTimeoutMatcher, Matcher<?> hostnameMatcher, Matcher<?> propertiesMatcher, Map<Symbol, Object> serverProperties)
{
- expectSaslConnect(ANONYMOUS, equalTo(new Binary(new byte[0])), new Symbol[] { AmqpSupport.SOLE_CONNECTION_CAPABILITY }, null, serverProperties, idleTimeoutMatcher, hostnameMatcher);
+ expectSaslConnect(ANONYMOUS, equalTo(new Binary(new byte[0])), new Symbol[] { AmqpSupport.SOLE_CONNECTION_CAPABILITY }, null, propertiesMatcher, serverProperties, idleTimeoutMatcher, hostnameMatcher);
}
public void expectFailingSaslConnect(Symbol[] serverMechs, Symbol clientSelectedMech)
@@ -541,7 +545,7 @@ public class TestAmqpPeer implements AutoCloseable
Map<Symbol, Object> serverProperties = new HashMap<Symbol, Object>();
serverProperties.put(AmqpSupport.CONNECTION_OPEN_FAILED, true);
- expectSaslAnonymousConnect(null, null, serverProperties);
+ expectSaslAnonymousConnect(null, null, null, serverProperties);
// Now generate the Close frame with the supplied error
final CloseFrame closeFrame = new CloseFrame();
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@qpid.apache.org
For additional commands, e-mail: commits-help@qpid.apache.org