mirror of https://github.com/apache/activemq.git
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:
parent
1cfc9ff9a6
commit
d2e49be3a8
|
@ -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();
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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<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
|
||||
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue