From d2e49be3a8f21d862726c1f6bc9e1caa6ee8b581 Mon Sep 17 00:00:00 2001 From: "Christopher L. Shannon (cshannon)" Date: Wed, 29 Nov 2017 12:43:20 -0500 Subject: [PATCH] AMQ-6871 - By default only send generic platform details The default behavior by the OpenWire client will be to send generic platform details to the server with a new flag to send more specific information. (cherry picked from commit 5fa0bbd5156f29d97dcf48fd9fdb6a0488a8df1a) --- .../activemq/ActiveMQConnectionMetaData.java | 1 + .../openwire/OpenWireFormatFactory.java | 17 ++- .../WireFormatInfoPropertiesTest.java | 101 +++++++++--------- 3 files changed, 69 insertions(+), 50 deletions(-) diff --git a/activemq-client/src/main/java/org/apache/activemq/ActiveMQConnectionMetaData.java b/activemq-client/src/main/java/org/apache/activemq/ActiveMQConnectionMetaData.java index ff6c38ff13..38c976108e 100644 --- a/activemq-client/src/main/java/org/apache/activemq/ActiveMQConnectionMetaData.java +++ b/activemq-client/src/main/java/org/apache/activemq/ActiveMQConnectionMetaData.java @@ -33,6 +33,7 @@ public final class ActiveMQConnectionMetaData implements ConnectionMetaData { public static final int PROVIDER_MAJOR_VERSION; public static final int PROVIDER_MINOR_VERSION; public static final String PROVIDER_NAME = "ActiveMQ"; + public static final String DEFAULT_PLATFORM_DETAILS = "Java"; public static final String PLATFORM_DETAILS; public static final ActiveMQConnectionMetaData INSTANCE = new ActiveMQConnectionMetaData(); diff --git a/activemq-client/src/main/java/org/apache/activemq/openwire/OpenWireFormatFactory.java b/activemq-client/src/main/java/org/apache/activemq/openwire/OpenWireFormatFactory.java index ba6d643ef0..2614ad780c 100644 --- a/activemq-client/src/main/java/org/apache/activemq/openwire/OpenWireFormatFactory.java +++ b/activemq-client/src/main/java/org/apache/activemq/openwire/OpenWireFormatFactory.java @@ -22,7 +22,7 @@ import org.apache.activemq.wireformat.WireFormat; import org.apache.activemq.wireformat.WireFormatFactory; /** - * + * */ public class OpenWireFormatFactory implements WireFormatFactory { @@ -44,8 +44,10 @@ public class OpenWireFormatFactory implements WireFormatFactory { private String host=null; private String providerName = ActiveMQConnectionMetaData.PROVIDER_NAME; private String providerVersion = ActiveMQConnectionMetaData.PROVIDER_VERSION; - private String platformDetails = ActiveMQConnectionMetaData.PLATFORM_DETAILS; + private String platformDetails = ActiveMQConnectionMetaData.DEFAULT_PLATFORM_DETAILS; + private boolean includePlatformDetails = false; + @Override public WireFormat createWireFormat() { WireFormatInfo info = new WireFormatInfo(); info.setVersion(version); @@ -65,6 +67,9 @@ public class OpenWireFormatFactory implements WireFormatFactory { } info.setProviderName(providerName); info.setProviderVersion(providerVersion); + if (includePlatformDetails) { + platformDetails = ActiveMQConnectionMetaData.PLATFORM_DETAILS; + } info.setPlatformDetails(platformDetails); } catch (Exception e) { IllegalStateException ise = new IllegalStateException("Could not configure WireFormatInfo"); @@ -190,4 +195,12 @@ public class OpenWireFormatFactory implements WireFormatFactory { public void setPlatformDetails(String platformDetails) { this.platformDetails = platformDetails; } + + public boolean isIncludePlatformDetails() { + return includePlatformDetails; + } + + public void setIncludePlatformDetails(boolean includePlatformDetails) { + this.includePlatformDetails = includePlatformDetails; + } } diff --git a/activemq-unit-tests/src/test/java/org/apache/activemq/openwire/WireFormatInfoPropertiesTest.java b/activemq-unit-tests/src/test/java/org/apache/activemq/openwire/WireFormatInfoPropertiesTest.java index 5c0608d021..2eedd6595f 100644 --- a/activemq-unit-tests/src/test/java/org/apache/activemq/openwire/WireFormatInfoPropertiesTest.java +++ b/activemq-unit-tests/src/test/java/org/apache/activemq/openwire/WireFormatInfoPropertiesTest.java @@ -25,7 +25,6 @@ import java.io.DataInputStream; import java.io.DataOutputStream; import java.io.IOException; import java.net.URI; -import java.util.concurrent.atomic.AtomicReference; import org.apache.activemq.ActiveMQConnection; import org.apache.activemq.ActiveMQConnectionFactory; @@ -33,7 +32,8 @@ import org.apache.activemq.ActiveMQConnectionMetaData; import org.apache.activemq.broker.BrokerService; import org.apache.activemq.broker.TransportConnector; import org.apache.activemq.command.WireFormatInfo; -import org.apache.activemq.transport.DefaultTransportListener; +import org.junit.After; +import org.junit.Before; import org.junit.Test; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -42,36 +42,60 @@ public class WireFormatInfoPropertiesTest { static final Logger LOG = LoggerFactory.getLogger(WireFormatInfoPropertiesTest.class); - protected BrokerService master; - protected String brokerUri; + private BrokerService service; + private String brokerUri; + private TransportConnector connector; + + @Before + public void before() throws Exception { + service = new BrokerService(); + connector = service.addConnector("tcp://localhost:0"); + brokerUri = connector.getPublishableConnectString(); + service.setPersistent(false); + service.setUseJmx(false); + service.setBrokerName("Master"); + service.start(); + service.waitUntilStarted(); + } + + @After + public void after() throws Exception { + if (service != null) { + service.stop(); + service.waitUntilStopped(); + } + } @Test - public void testClientProperties() throws Exception{ - BrokerService service = createBrokerService(); - try { - ActiveMQConnectionFactory factory = new ActiveMQConnectionFactory(new URI(brokerUri)); - ActiveMQConnection conn = (ActiveMQConnection)factory.createConnection(); - final AtomicReference clientWf = new AtomicReference(); - conn.addTransportListener(new DefaultTransportListener() { - @Override - public void onCommand(Object command) { - if (command instanceof WireFormatInfo) { - clientWf.set((WireFormatInfo)command); - } - } - }); - conn.start(); - if (clientWf.get() == null) { - fail("Wire format info is null"); - } - assertTrue(clientWf.get().getProperties().containsKey("ProviderName")); - assertTrue(clientWf.get().getProperties().containsKey("ProviderVersion")); - assertTrue(clientWf.get().getProperties().containsKey("PlatformDetails")); - assertTrue(clientWf.get().getProviderName().equals(ActiveMQConnectionMetaData.PROVIDER_NAME)); - assertTrue(clientWf.get().getPlatformDetails().equals(ActiveMQConnectionMetaData.PLATFORM_DETAILS)); - } finally { - stopBroker(service); + public void testClientPropertiesWithDefaultPlatformDetails() throws Exception{ + WireFormatInfo clientWf = testClientProperties(brokerUri); + assertTrue(clientWf.getPlatformDetails().equals(ActiveMQConnectionMetaData.DEFAULT_PLATFORM_DETAILS)); + } + + @Test + public void testClientPropertiesWithPlatformDetails() throws Exception{ + WireFormatInfo clientWf = testClientProperties(brokerUri + "?wireFormat.includePlatformDetails=true"); + assertTrue(clientWf.getPlatformDetails().equals(ActiveMQConnectionMetaData.PLATFORM_DETAILS)); + } + + private WireFormatInfo testClientProperties(String brokerUri) throws Exception { + ActiveMQConnectionFactory factory = new ActiveMQConnectionFactory(new URI(brokerUri)); + ActiveMQConnection conn = (ActiveMQConnection)factory.createConnection(); + conn.start(); + + assertTrue(connector.getConnections().size() == 1); + final WireFormatInfo clientWf = connector.getConnections().get(0).getRemoteWireFormatInfo(); + if (clientWf == null) { + fail("Wire format info is null"); } + + //verify properties that the client sends to the broker + assertTrue(clientWf.getProperties().containsKey("ProviderName")); + assertTrue(clientWf.getProperties().containsKey("ProviderVersion")); + assertTrue(clientWf.getProperties().containsKey("PlatformDetails")); + assertTrue(clientWf.getProviderName().equals(ActiveMQConnectionMetaData.PROVIDER_NAME)); + + return clientWf; } @Test @@ -100,23 +124,4 @@ public class WireFormatInfoPropertiesTest { assertTrue(result.getPlatformDetails().equals(orig.getPlatformDetails())); } - private BrokerService createBrokerService() throws Exception { - BrokerService service = new BrokerService(); - TransportConnector connector = service.addConnector("tcp://localhost:0"); - brokerUri = connector.getPublishableConnectString(); - service.setPersistent(false); - service.setUseJmx(false); - service.setBrokerName("Master"); - service.start(); - service.waitUntilStarted(); - return service; - } - - private void stopBroker(BrokerService service) throws Exception { - if (service != null) { - service.stop(); - service.waitUntilStopped(); - } - } - }