Skip to content

Commit

Permalink
AMQ-6871 - By default only send generic platform details
Browse files Browse the repository at this point in the history
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 5fa0bbd)
  • Loading branch information
cshannon committed Dec 6, 2017
1 parent 1cfc9ff commit d2e49be
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 50 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
import org.apache.activemq.wireformat.WireFormatFactory;

/**
*
*
*/
public class OpenWireFormatFactory implements WireFormatFactory {

Expand All @@ -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);
Expand All @@ -65,6 +67,9 @@ public WireFormat createWireFormat() {
}
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");
Expand Down Expand Up @@ -190,4 +195,12 @@ public String getPlatformDetails() {
public void setPlatformDetails(String platformDetails) {
this.platformDetails = platformDetails;
}

public boolean isIncludePlatformDetails() {
return includePlatformDetails;
}

public void setIncludePlatformDetails(boolean includePlatformDetails) {
this.includePlatformDetails = includePlatformDetails;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,15 @@
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;
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;
Expand All @@ -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<WireFormatInfo> clientWf = new AtomicReference<WireFormatInfo>();
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
Expand Down Expand Up @@ -100,23 +124,4 @@ public void testMarshalClientProperties() throws IOException {
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();
}
}

}

0 comments on commit d2e49be

Please sign in to comment.