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 5fa0bbd515)
This commit is contained in:
Christopher L. Shannon (cshannon) 2017-11-29 12:43:20 -05:00
parent 1cfc9ff9a6
commit d2e49be3a8
3 changed files with 69 additions and 50 deletions

View File

@ -33,6 +33,7 @@ public final class ActiveMQConnectionMetaData implements ConnectionMetaData {
public static final int PROVIDER_MAJOR_VERSION; public static final int PROVIDER_MAJOR_VERSION;
public static final int PROVIDER_MINOR_VERSION; public static final int PROVIDER_MINOR_VERSION;
public static final String PROVIDER_NAME = "ActiveMQ"; public static final String PROVIDER_NAME = "ActiveMQ";
public static final String DEFAULT_PLATFORM_DETAILS = "Java";
public static final String PLATFORM_DETAILS; public static final String PLATFORM_DETAILS;
public static final ActiveMQConnectionMetaData INSTANCE = new ActiveMQConnectionMetaData(); public static final ActiveMQConnectionMetaData INSTANCE = new ActiveMQConnectionMetaData();

View File

@ -44,8 +44,10 @@ public class OpenWireFormatFactory implements WireFormatFactory {
private String host=null; private String host=null;
private String providerName = ActiveMQConnectionMetaData.PROVIDER_NAME; private String providerName = ActiveMQConnectionMetaData.PROVIDER_NAME;
private String providerVersion = ActiveMQConnectionMetaData.PROVIDER_VERSION; 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() { public WireFormat createWireFormat() {
WireFormatInfo info = new WireFormatInfo(); WireFormatInfo info = new WireFormatInfo();
info.setVersion(version); info.setVersion(version);
@ -65,6 +67,9 @@ public class OpenWireFormatFactory implements WireFormatFactory {
} }
info.setProviderName(providerName); info.setProviderName(providerName);
info.setProviderVersion(providerVersion); info.setProviderVersion(providerVersion);
if (includePlatformDetails) {
platformDetails = ActiveMQConnectionMetaData.PLATFORM_DETAILS;
}
info.setPlatformDetails(platformDetails); info.setPlatformDetails(platformDetails);
} catch (Exception e) { } catch (Exception e) {
IllegalStateException ise = new IllegalStateException("Could not configure WireFormatInfo"); IllegalStateException ise = new IllegalStateException("Could not configure WireFormatInfo");
@ -190,4 +195,12 @@ public class OpenWireFormatFactory implements WireFormatFactory {
public void setPlatformDetails(String platformDetails) { public void setPlatformDetails(String platformDetails) {
this.platformDetails = platformDetails; this.platformDetails = platformDetails;
} }
public boolean isIncludePlatformDetails() {
return includePlatformDetails;
}
public void setIncludePlatformDetails(boolean includePlatformDetails) {
this.includePlatformDetails = includePlatformDetails;
}
} }

View File

@ -25,7 +25,6 @@ import java.io.DataInputStream;
import java.io.DataOutputStream; import java.io.DataOutputStream;
import java.io.IOException; import java.io.IOException;
import java.net.URI; import java.net.URI;
import java.util.concurrent.atomic.AtomicReference;
import org.apache.activemq.ActiveMQConnection; import org.apache.activemq.ActiveMQConnection;
import org.apache.activemq.ActiveMQConnectionFactory; 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.BrokerService;
import org.apache.activemq.broker.TransportConnector; import org.apache.activemq.broker.TransportConnector;
import org.apache.activemq.command.WireFormatInfo; 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.junit.Test;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
@ -42,36 +42,60 @@ public class WireFormatInfoPropertiesTest {
static final Logger LOG = LoggerFactory.getLogger(WireFormatInfoPropertiesTest.class); static final Logger LOG = LoggerFactory.getLogger(WireFormatInfoPropertiesTest.class);
protected BrokerService master; private BrokerService service;
protected String brokerUri; 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 @Test
public void testClientProperties() throws Exception{ public void testClientPropertiesWithDefaultPlatformDetails() throws Exception{
BrokerService service = createBrokerService(); WireFormatInfo clientWf = testClientProperties(brokerUri);
try { assertTrue(clientWf.getPlatformDetails().equals(ActiveMQConnectionMetaData.DEFAULT_PLATFORM_DETAILS));
ActiveMQConnectionFactory factory = new ActiveMQConnectionFactory(new URI(brokerUri)); }
ActiveMQConnection conn = (ActiveMQConnection)factory.createConnection();
final AtomicReference<WireFormatInfo> clientWf = new AtomicReference<WireFormatInfo>(); @Test
conn.addTransportListener(new DefaultTransportListener() { public void testClientPropertiesWithPlatformDetails() throws Exception{
@Override WireFormatInfo clientWf = testClientProperties(brokerUri + "?wireFormat.includePlatformDetails=true");
public void onCommand(Object command) { assertTrue(clientWf.getPlatformDetails().equals(ActiveMQConnectionMetaData.PLATFORM_DETAILS));
if (command instanceof WireFormatInfo) { }
clientWf.set((WireFormatInfo)command);
} private WireFormatInfo testClientProperties(String brokerUri) throws Exception {
} ActiveMQConnectionFactory factory = new ActiveMQConnectionFactory(new URI(brokerUri));
}); ActiveMQConnection conn = (ActiveMQConnection)factory.createConnection();
conn.start(); conn.start();
if (clientWf.get() == null) {
fail("Wire format info is null"); assertTrue(connector.getConnections().size() == 1);
} final WireFormatInfo clientWf = connector.getConnections().get(0).getRemoteWireFormatInfo();
assertTrue(clientWf.get().getProperties().containsKey("ProviderName")); if (clientWf == null) {
assertTrue(clientWf.get().getProperties().containsKey("ProviderVersion")); fail("Wire format info is null");
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);
} }
//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 @Test
@ -100,23 +124,4 @@ public class WireFormatInfoPropertiesTest {
assertTrue(result.getPlatformDetails().equals(orig.getPlatformDetails())); 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();
}
}
} }