From 00340c86e0f2654fcf3fea4b827f951035190062 Mon Sep 17 00:00:00 2001 From: Ulf Lilleengen Date: Mon, 7 Nov 2016 12:30:39 +0100 Subject: [PATCH] ARTEMIS-814: Support specifying connection properties --- .../protocol/amqp/client/AMQPClientConnectionFactory.java | 8 ++++++-- .../protocol/amqp/proton/AMQPConnectionContext.java | 4 ++-- .../protocol/amqp/proton/handler/ProtonHandler.java | 4 +++- .../artemis/tests/integration/amqp/ProtonTest.java | 3 ++- 4 files changed, 13 insertions(+), 6 deletions(-) diff --git a/artemis-protocols/artemis-amqp-protocol/src/main/java/org/apache/activemq/artemis/protocol/amqp/client/AMQPClientConnectionFactory.java b/artemis-protocols/artemis-amqp-protocol/src/main/java/org/apache/activemq/artemis/protocol/amqp/client/AMQPClientConnectionFactory.java index 5807809a03..b8851bb7e0 100644 --- a/artemis-protocols/artemis-amqp-protocol/src/main/java/org/apache/activemq/artemis/protocol/amqp/client/AMQPClientConnectionFactory.java +++ b/artemis-protocols/artemis-amqp-protocol/src/main/java/org/apache/activemq/artemis/protocol/amqp/client/AMQPClientConnectionFactory.java @@ -24,7 +24,9 @@ import org.apache.activemq.artemis.protocol.amqp.proton.AMQPConnectionContext; import org.apache.activemq.artemis.protocol.amqp.proton.AMQPConstants; import org.apache.activemq.artemis.protocol.amqp.proton.handler.EventHandler; import org.apache.activemq.artemis.spi.core.remoting.Connection; +import org.apache.qpid.proton.amqp.Symbol; +import java.util.Map; import java.util.Optional; import java.util.concurrent.Executor; @@ -35,11 +37,13 @@ public class AMQPClientConnectionFactory { private final ActiveMQServer server; private final String containerId; + private final Map connectionProperties; private final int ttl; - public AMQPClientConnectionFactory(ActiveMQServer server, String containerId, int ttl) { + public AMQPClientConnectionFactory(ActiveMQServer server, String containerId, Map connectionProperties, int ttl) { this.server = server; this.containerId = containerId; + this.connectionProperties = connectionProperties; this.ttl = ttl; } @@ -55,7 +59,7 @@ public class AMQPClientConnectionFactory { connectionCallback.setProtonConnectionDelegate(delegate); - amqpConnection.open(); + amqpConnection.open(connectionProperties); return delegate; } } diff --git a/artemis-protocols/artemis-amqp-protocol/src/main/java/org/apache/activemq/artemis/protocol/amqp/proton/AMQPConnectionContext.java b/artemis-protocols/artemis-amqp-protocol/src/main/java/org/apache/activemq/artemis/protocol/amqp/proton/AMQPConnectionContext.java index bdccd96c7a..0f9e89e660 100644 --- a/artemis-protocols/artemis-amqp-protocol/src/main/java/org/apache/activemq/artemis/protocol/amqp/proton/AMQPConnectionContext.java +++ b/artemis-protocols/artemis-amqp-protocol/src/main/java/org/apache/activemq/artemis/protocol/amqp/proton/AMQPConnectionContext.java @@ -205,8 +205,8 @@ public class AMQPConnectionContext extends ProtonInitializable { return ExtCapability.getCapabilities(); } - public void open() { - handler.open(containerId); + public void open(Map connectionProperties) { + handler.open(containerId, connectionProperties); } public String getContainer() { diff --git a/artemis-protocols/artemis-amqp-protocol/src/main/java/org/apache/activemq/artemis/protocol/amqp/proton/handler/ProtonHandler.java b/artemis-protocols/artemis-amqp-protocol/src/main/java/org/apache/activemq/artemis/protocol/amqp/proton/handler/ProtonHandler.java index b4ddda0afe..945d01ebf7 100644 --- a/artemis-protocols/artemis-amqp-protocol/src/main/java/org/apache/activemq/artemis/protocol/amqp/proton/handler/ProtonHandler.java +++ b/artemis-protocols/artemis-amqp-protocol/src/main/java/org/apache/activemq/artemis/protocol/amqp/proton/handler/ProtonHandler.java @@ -30,6 +30,7 @@ import org.apache.activemq.artemis.protocol.amqp.sasl.SASLResult; import org.apache.activemq.artemis.protocol.amqp.sasl.ServerSASL; import org.apache.activemq.artemis.utils.ByteUtil; import org.apache.qpid.proton.Proton; +import org.apache.qpid.proton.amqp.Symbol; import org.apache.qpid.proton.amqp.transport.ErrorCondition; import org.apache.qpid.proton.engine.Collector; import org.apache.qpid.proton.engine.Connection; @@ -358,9 +359,10 @@ public class ProtonHandler extends ProtonInitializable { } - public void open(String containerId) { + public void open(String containerId, Map connectionProperties) { this.transport.open(); this.connection.setContainer(containerId); + this.connection.setProperties(connectionProperties); this.connection.open(); flush(); } diff --git a/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/amqp/ProtonTest.java b/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/amqp/ProtonTest.java index e5d2f64d30..1a1021efd5 100644 --- a/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/amqp/ProtonTest.java +++ b/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/amqp/ProtonTest.java @@ -28,6 +28,7 @@ import java.net.URI; import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; +import java.util.Collections; import java.util.Enumeration; import java.util.LinkedHashMap; import java.util.Map; @@ -977,7 +978,7 @@ public class ProtonTest extends ProtonTestBase { final Map config = new LinkedHashMap<>(); config.put(TransportConstants.HOST_PROP_NAME, "localhost"); config.put(TransportConstants.PORT_PROP_NAME, "5673"); - ProtonClientConnectionManager lifeCycleListener = new ProtonClientConnectionManager(new AMQPClientConnectionFactory(server, server.getConfiguration().getName(), 5000), Optional.empty()); + ProtonClientConnectionManager lifeCycleListener = new ProtonClientConnectionManager(new AMQPClientConnectionFactory(server, "myid", Collections.singletonMap(Symbol.getSymbol("myprop"), "propvalue"), 5000), Optional.empty()); ProtonClientProtocolManager protocolManager = new ProtonClientProtocolManager(new ProtonProtocolManagerFactory(), server); NettyConnector connector = new NettyConnector(config, lifeCycleListener, lifeCycleListener, server.getExecutorFactory().getExecutor(), server.getExecutorFactory().getExecutor(), server.getScheduledPool(), protocolManager); connector.start();