Skip to content

Commit d2e49be

Browse files
committed
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 5fa0bbd)
1 parent 1cfc9ff commit d2e49be

File tree

3 files changed

+69
-50
lines changed

3 files changed

+69
-50
lines changed

activemq-client/src/main/java/org/apache/activemq/ActiveMQConnectionMetaData.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ public final class ActiveMQConnectionMetaData implements ConnectionMetaData {
3333
public static final int PROVIDER_MAJOR_VERSION;
3434
public static final int PROVIDER_MINOR_VERSION;
3535
public static final String PROVIDER_NAME = "ActiveMQ";
36+
public static final String DEFAULT_PLATFORM_DETAILS = "Java";
3637
public static final String PLATFORM_DETAILS;
3738

3839
public static final ActiveMQConnectionMetaData INSTANCE = new ActiveMQConnectionMetaData();

activemq-client/src/main/java/org/apache/activemq/openwire/OpenWireFormatFactory.java

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
import org.apache.activemq.wireformat.WireFormatFactory;
2323

2424
/**
25-
*
25+
*
2626
*/
2727
public class OpenWireFormatFactory implements WireFormatFactory {
2828

@@ -44,8 +44,10 @@ public class OpenWireFormatFactory implements WireFormatFactory {
4444
private String host=null;
4545
private String providerName = ActiveMQConnectionMetaData.PROVIDER_NAME;
4646
private String providerVersion = ActiveMQConnectionMetaData.PROVIDER_VERSION;
47-
private String platformDetails = ActiveMQConnectionMetaData.PLATFORM_DETAILS;
47+
private String platformDetails = ActiveMQConnectionMetaData.DEFAULT_PLATFORM_DETAILS;
48+
private boolean includePlatformDetails = false;
4849

50+
@Override
4951
public WireFormat createWireFormat() {
5052
WireFormatInfo info = new WireFormatInfo();
5153
info.setVersion(version);
@@ -65,6 +67,9 @@ public WireFormat createWireFormat() {
6567
}
6668
info.setProviderName(providerName);
6769
info.setProviderVersion(providerVersion);
70+
if (includePlatformDetails) {
71+
platformDetails = ActiveMQConnectionMetaData.PLATFORM_DETAILS;
72+
}
6873
info.setPlatformDetails(platformDetails);
6974
} catch (Exception e) {
7075
IllegalStateException ise = new IllegalStateException("Could not configure WireFormatInfo");
@@ -190,4 +195,12 @@ public String getPlatformDetails() {
190195
public void setPlatformDetails(String platformDetails) {
191196
this.platformDetails = platformDetails;
192197
}
198+
199+
public boolean isIncludePlatformDetails() {
200+
return includePlatformDetails;
201+
}
202+
203+
public void setIncludePlatformDetails(boolean includePlatformDetails) {
204+
this.includePlatformDetails = includePlatformDetails;
205+
}
193206
}

activemq-unit-tests/src/test/java/org/apache/activemq/openwire/WireFormatInfoPropertiesTest.java

Lines changed: 53 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -25,15 +25,15 @@
2525
import java.io.DataOutputStream;
2626
import java.io.IOException;
2727
import java.net.URI;
28-
import java.util.concurrent.atomic.AtomicReference;
2928

3029
import org.apache.activemq.ActiveMQConnection;
3130
import org.apache.activemq.ActiveMQConnectionFactory;
3231
import org.apache.activemq.ActiveMQConnectionMetaData;
3332
import org.apache.activemq.broker.BrokerService;
3433
import org.apache.activemq.broker.TransportConnector;
3534
import org.apache.activemq.command.WireFormatInfo;
36-
import org.apache.activemq.transport.DefaultTransportListener;
35+
import org.junit.After;
36+
import org.junit.Before;
3737
import org.junit.Test;
3838
import org.slf4j.Logger;
3939
import org.slf4j.LoggerFactory;
@@ -42,36 +42,60 @@ public class WireFormatInfoPropertiesTest {
4242

4343
static final Logger LOG = LoggerFactory.getLogger(WireFormatInfoPropertiesTest.class);
4444

45-
protected BrokerService master;
46-
protected String brokerUri;
45+
private BrokerService service;
46+
private String brokerUri;
47+
private TransportConnector connector;
48+
49+
@Before
50+
public void before() throws Exception {
51+
service = new BrokerService();
52+
connector = service.addConnector("tcp://localhost:0");
53+
brokerUri = connector.getPublishableConnectString();
54+
service.setPersistent(false);
55+
service.setUseJmx(false);
56+
service.setBrokerName("Master");
57+
service.start();
58+
service.waitUntilStarted();
59+
}
60+
61+
@After
62+
public void after() throws Exception {
63+
if (service != null) {
64+
service.stop();
65+
service.waitUntilStopped();
66+
}
67+
}
4768

4869
@Test
49-
public void testClientProperties() throws Exception{
50-
BrokerService service = createBrokerService();
51-
try {
52-
ActiveMQConnectionFactory factory = new ActiveMQConnectionFactory(new URI(brokerUri));
53-
ActiveMQConnection conn = (ActiveMQConnection)factory.createConnection();
54-
final AtomicReference<WireFormatInfo> clientWf = new AtomicReference<WireFormatInfo>();
55-
conn.addTransportListener(new DefaultTransportListener() {
56-
@Override
57-
public void onCommand(Object command) {
58-
if (command instanceof WireFormatInfo) {
59-
clientWf.set((WireFormatInfo)command);
60-
}
61-
}
62-
});
63-
conn.start();
64-
if (clientWf.get() == null) {
65-
fail("Wire format info is null");
66-
}
67-
assertTrue(clientWf.get().getProperties().containsKey("ProviderName"));
68-
assertTrue(clientWf.get().getProperties().containsKey("ProviderVersion"));
69-
assertTrue(clientWf.get().getProperties().containsKey("PlatformDetails"));
70-
assertTrue(clientWf.get().getProviderName().equals(ActiveMQConnectionMetaData.PROVIDER_NAME));
71-
assertTrue(clientWf.get().getPlatformDetails().equals(ActiveMQConnectionMetaData.PLATFORM_DETAILS));
72-
} finally {
73-
stopBroker(service);
70+
public void testClientPropertiesWithDefaultPlatformDetails() throws Exception{
71+
WireFormatInfo clientWf = testClientProperties(brokerUri);
72+
assertTrue(clientWf.getPlatformDetails().equals(ActiveMQConnectionMetaData.DEFAULT_PLATFORM_DETAILS));
73+
}
74+
75+
@Test
76+
public void testClientPropertiesWithPlatformDetails() throws Exception{
77+
WireFormatInfo clientWf = testClientProperties(brokerUri + "?wireFormat.includePlatformDetails=true");
78+
assertTrue(clientWf.getPlatformDetails().equals(ActiveMQConnectionMetaData.PLATFORM_DETAILS));
79+
}
80+
81+
private WireFormatInfo testClientProperties(String brokerUri) throws Exception {
82+
ActiveMQConnectionFactory factory = new ActiveMQConnectionFactory(new URI(brokerUri));
83+
ActiveMQConnection conn = (ActiveMQConnection)factory.createConnection();
84+
conn.start();
85+
86+
assertTrue(connector.getConnections().size() == 1);
87+
final WireFormatInfo clientWf = connector.getConnections().get(0).getRemoteWireFormatInfo();
88+
if (clientWf == null) {
89+
fail("Wire format info is null");
7490
}
91+
92+
//verify properties that the client sends to the broker
93+
assertTrue(clientWf.getProperties().containsKey("ProviderName"));
94+
assertTrue(clientWf.getProperties().containsKey("ProviderVersion"));
95+
assertTrue(clientWf.getProperties().containsKey("PlatformDetails"));
96+
assertTrue(clientWf.getProviderName().equals(ActiveMQConnectionMetaData.PROVIDER_NAME));
97+
98+
return clientWf;
7599
}
76100

77101
@Test
@@ -100,23 +124,4 @@ public void testMarshalClientProperties() throws IOException {
100124
assertTrue(result.getPlatformDetails().equals(orig.getPlatformDetails()));
101125
}
102126

103-
private BrokerService createBrokerService() throws Exception {
104-
BrokerService service = new BrokerService();
105-
TransportConnector connector = service.addConnector("tcp://localhost:0");
106-
brokerUri = connector.getPublishableConnectString();
107-
service.setPersistent(false);
108-
service.setUseJmx(false);
109-
service.setBrokerName("Master");
110-
service.start();
111-
service.waitUntilStarted();
112-
return service;
113-
}
114-
115-
private void stopBroker(BrokerService service) throws Exception {
116-
if (service != null) {
117-
service.stop();
118-
service.waitUntilStopped();
119-
}
120-
}
121-
122127
}

0 commit comments

Comments
 (0)