From 3ef98044f88dffedce8a8a40b784eb4d4b6dff1f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michael=20Andr=C3=A9=20Pearce?= Date: Sat, 4 Nov 2017 02:26:39 +0000 Subject: [PATCH] ARTEMIS-1516 - Ensure JNDI via Tomcat Resource works Apply fix so that when using JNDI via tomcat resource it works. Replace original extract of JNDIStorable taken from Qpid, and use ActiveMQ5's as fits better to address this issue. (which primary use case is users migrating from 5.x) Refactored ActiveMQConnectionFactory to externalise and turn into reference by StringRefAddr's instead of custom RefAddr which isnt standard. Refactored ActiveMQDestinations similar Refactored ActiveMQDestination to remove redundent and duplicated name field and ensured getters still behave the same --- .../artemis/utils/uri/BeanSupport.java | 34 +++++ .../jms/client/ActiveMQConnectionFactory.java | 52 +++++-- .../jms/client/ActiveMQDestination.java | 130 +++++++++-------- .../artemis/jms/client/ActiveMQQueue.java | 31 ++-- .../jms/client/ActiveMQTemporaryQueue.java | 10 +- .../jms/client/ActiveMQTemporaryTopic.java | 7 +- .../artemis/jms/client/ActiveMQTopic.java | 28 ++-- .../artemis/jndi/JNDIReferenceFactory.java | 29 ++-- .../activemq/artemis/jndi/JNDIStorable.java | 60 ++++---- .../amqp/converter/jms/ServerDestination.java | 9 +- .../amqp/converter/jms/ServerJMSMessage.java | 5 +- .../ConnectionFactoryObjectFactory.java | 25 ++++ .../SerializableObjectRefAddr.java | 29 +--- .../ra/ActiveMQRAConnectionFactoryImpl.java | 6 +- ...iveMQRAConnectionFactoryObjectFactory.java | 4 +- .../SerializableObjectRefAddr.java | 2 +- docs/user-manual/en/SUMMARY.md | 1 + docs/user-manual/en/tomcat.md | 39 +++++ examples/features/sub-modules/pom.xml | 3 +- examples/features/sub-modules/tomcat/README | 21 +++ examples/features/sub-modules/tomcat/pom.xml | 127 ++++++++++++++++ .../tomcat/sample/SendMessageController.java | 48 ++++++ .../SystemOutPrintLnMessageListener.java | 28 ++++ .../webapp/WEB-INF/application-context.xml | 50 +++++++ .../webapp/WEB-INF/dispatcher-servlet.xml | 28 ++++ .../tomcat/src/main/webapp/WEB-INF/web.xml | 41 ++++++ .../resources/context.xml | 28 ++++ .../artemis/jms/tests/ReferenceableTest.java | 9 +- .../unit/jms/jndi/ObjectFactoryTest.java | 138 ++++++++++++++++++ .../jms/jndi/StringRefAddrReferenceTest.java | 119 +++++++++++++++ .../ra/ConnectionFactoryPropertiesTest.java | 4 + .../DestinationObjectFactoryTest.java | 9 +- 32 files changed, 953 insertions(+), 201 deletions(-) create mode 100644 artemis-ra/src/main/java/org/apache/activemq/artemis/jms/referenceable/ConnectionFactoryObjectFactory.java rename artemis-jms-client/src/main/java/org/apache/activemq/artemis/jms/referenceable/DestinationObjectFactory.java => artemis-ra/src/main/java/org/apache/activemq/artemis/jms/referenceable/SerializableObjectRefAddr.java (50%) rename artemis-jms-client/src/main/java/org/apache/activemq/artemis/jms/referenceable/ConnectionFactoryObjectFactory.java => artemis-ra/src/main/java/org/apache/activemq/artemis/ra/referenceable/ActiveMQRAConnectionFactoryObjectFactory.java (91%) rename {artemis-jms-client/src/main/java/org/apache/activemq/artemis/jms => artemis-ra/src/main/java/org/apache/activemq/artemis/ra}/referenceable/SerializableObjectRefAddr.java (97%) create mode 100644 docs/user-manual/en/tomcat.md create mode 100644 examples/features/sub-modules/tomcat/README create mode 100644 examples/features/sub-modules/tomcat/pom.xml create mode 100644 examples/features/sub-modules/tomcat/src/main/java/org/apache/activemq/artemis/example/tomcat/sample/SendMessageController.java create mode 100644 examples/features/sub-modules/tomcat/src/main/java/org/apache/activemq/artemis/example/tomcat/sample/SystemOutPrintLnMessageListener.java create mode 100644 examples/features/sub-modules/tomcat/src/main/webapp/WEB-INF/application-context.xml create mode 100644 examples/features/sub-modules/tomcat/src/main/webapp/WEB-INF/dispatcher-servlet.xml create mode 100644 examples/features/sub-modules/tomcat/src/main/webapp/WEB-INF/web.xml create mode 100644 examples/features/sub-modules/tomcat/src/tomcat7-maven-plugin/resources/context.xml create mode 100644 tests/unit-tests/src/test/java/org/apache/activemq/artemis/tests/unit/jms/jndi/ObjectFactoryTest.java create mode 100644 tests/unit-tests/src/test/java/org/apache/activemq/artemis/tests/unit/jms/jndi/StringRefAddrReferenceTest.java rename tests/unit-tests/src/test/java/org/apache/activemq/artemis/tests/unit/{jms => ra}/referenceable/DestinationObjectFactoryTest.java (88%) diff --git a/artemis-commons/src/main/java/org/apache/activemq/artemis/utils/uri/BeanSupport.java b/artemis-commons/src/main/java/org/apache/activemq/artemis/utils/uri/BeanSupport.java index 70b36aba4c..94a589d970 100644 --- a/artemis-commons/src/main/java/org/apache/activemq/artemis/utils/uri/BeanSupport.java +++ b/artemis-commons/src/main/java/org/apache/activemq/artemis/utils/uri/BeanSupport.java @@ -19,12 +19,14 @@ package org.apache.activemq.artemis.utils.uri; import java.beans.PropertyDescriptor; import java.io.UnsupportedEncodingException; +import java.lang.reflect.InvocationTargetException; import java.net.URI; import java.net.URLDecoder; import java.net.URLEncoder; import java.util.HashMap; import java.util.List; import java.util.Map; +import java.util.Properties; import java.util.Set; import org.apache.commons.beanutils.BeanUtilsBean; @@ -69,6 +71,38 @@ public class BeanSupport { return obj; } + public static

P setProperties(P bean, Properties properties) + throws IllegalAccessException, NoSuchMethodException, InvocationTargetException { + synchronized (beanUtils) { + PropertyDescriptor[] descriptors = beanUtils.getPropertyUtils().getPropertyDescriptors(bean); + for (PropertyDescriptor descriptor : descriptors) { + if (descriptor.getReadMethod() != null && isWriteable(descriptor, null)) { + String value = properties.getProperty(descriptor.getName()); + if (value != null) { + beanUtils.setProperty(bean, descriptor.getName(), value); + } + } + } + } + return bean; + } + + public static

Properties getProperties(P bean, Properties properties) + throws IllegalAccessException, NoSuchMethodException, InvocationTargetException { + synchronized (beanUtils) { + PropertyDescriptor[] descriptors = beanUtils.getPropertyUtils().getPropertyDescriptors(bean); + for (PropertyDescriptor descriptor : descriptors) { + if (descriptor.getReadMethod() != null && isWriteable(descriptor, null)) { + String value = beanUtils.getProperty(bean, descriptor.getName()); + if (value != null) { + properties.put(descriptor.getName(), value); + } + } + } + } + return properties; + } + public static void setData(URI uri, HashMap properties, Set allowableProperties, diff --git a/artemis-jms-client/src/main/java/org/apache/activemq/artemis/jms/client/ActiveMQConnectionFactory.java b/artemis-jms-client/src/main/java/org/apache/activemq/artemis/jms/client/ActiveMQConnectionFactory.java index ba5359a797..bb729f69cd 100644 --- a/artemis-jms-client/src/main/java/org/apache/activemq/artemis/jms/client/ActiveMQConnectionFactory.java +++ b/artemis-jms-client/src/main/java/org/apache/activemq/artemis/jms/client/ActiveMQConnectionFactory.java @@ -30,17 +30,17 @@ import javax.jms.XAConnectionFactory; import javax.jms.XAJMSContext; import javax.jms.XAQueueConnection; import javax.jms.XATopicConnection; -import javax.naming.NamingException; -import javax.naming.Reference; -import javax.naming.Referenceable; +import javax.naming.Context; import java.io.Externalizable; import java.io.IOException; import java.io.InvalidObjectException; import java.io.ObjectInput; import java.io.ObjectOutput; +import java.lang.reflect.InvocationTargetException; import java.net.URI; import java.security.AccessController; import java.security.PrivilegedAction; +import java.util.Properties; import org.apache.activemq.artemis.api.core.DiscoveryGroupConfiguration; import org.apache.activemq.artemis.api.core.TransportConfiguration; @@ -51,18 +51,18 @@ import org.apache.activemq.artemis.api.core.client.ServerLocator; import org.apache.activemq.artemis.api.jms.ActiveMQJMSConstants; import org.apache.activemq.artemis.api.jms.JMSFactoryType; import org.apache.activemq.artemis.core.client.impl.ServerLocatorImpl; -import org.apache.activemq.artemis.jms.referenceable.ConnectionFactoryObjectFactory; -import org.apache.activemq.artemis.jms.referenceable.SerializableObjectRefAddr; +import org.apache.activemq.artemis.jndi.JNDIStorable; import org.apache.activemq.artemis.spi.core.remoting.ClientProtocolManagerFactory; import org.apache.activemq.artemis.uri.ConnectionFactoryParser; import org.apache.activemq.artemis.uri.ServerLocatorParser; import org.apache.activemq.artemis.utils.ClassloadingUtil; +import org.apache.activemq.artemis.utils.uri.BeanSupport; /** *

ActiveMQ Artemis implementation of a JMS ConnectionFactory.

*

This connection factory will use defaults defined by {@link DefaultConnectionProperties}. */ -public class ActiveMQConnectionFactory implements ConnectionFactoryOptions, Externalizable, Referenceable, ConnectionFactory, XAConnectionFactory, AutoCloseable { +public class ActiveMQConnectionFactory extends JNDIStorable implements ConnectionFactoryOptions, Externalizable, ConnectionFactory, XAConnectionFactory, AutoCloseable { private static final long serialVersionUID = -7554006056207377105L; @@ -206,10 +206,14 @@ public class ActiveMQConnectionFactory implements ConnectionFactoryOptions, Exte this(DefaultConnectionProperties.DEFAULT_BROKER_URL); } - public ActiveMQConnectionFactory(String url) { + public ActiveMQConnectionFactory(String brokerURL) { + setBrokerURL(brokerURL); + } + + private void setBrokerURL(String brokerURL) { ConnectionFactoryParser cfParser = new ConnectionFactoryParser(); try { - URI uri = cfParser.expandURI(url); + URI uri = cfParser.expandURI(brokerURL); serverLocator = ServerLocatorImpl.newLocator(uri); cfParser.populateObject(uri, this); } catch (Exception e) { @@ -380,8 +384,36 @@ public class ActiveMQConnectionFactory implements ConnectionFactoryOptions, Exte } @Override - public Reference getReference() throws NamingException { - return new Reference(this.getClass().getCanonicalName(), new SerializableObjectRefAddr("ActiveMQ-CF", this), ConnectionFactoryObjectFactory.class.getCanonicalName(), null); + protected void buildFromProperties(Properties props) { + String url = props.getProperty(Context.PROVIDER_URL); + if (url == null || url.isEmpty()) { + url = props.getProperty("brokerURL"); + } + if (url != null && url.length() > 0) { + setBrokerURL(url); + } + if (url == null || url.isEmpty()) { + throw new IllegalArgumentException(Context.PROVIDER_URL + " or " + "brokerURL is required"); + } + try { + BeanSupport.setProperties(this, props); + } catch (IllegalAccessException | NoSuchMethodException | InvocationTargetException e) { + throw new RuntimeException(e); + } + } + + @Override + protected void populateProperties(Properties props) { + try { + URI uri = toURI(); + if (uri != null) { + props.put(Context.PROVIDER_URL, uri.toASCIIString()); + props.put("brokerURL", uri.toASCIIString()); + } + BeanSupport.getProperties(this, props); + } catch (IOException | IllegalAccessException | NoSuchMethodException | InvocationTargetException e) { + throw new RuntimeException(e); + } } public boolean isHA() { diff --git a/artemis-jms-client/src/main/java/org/apache/activemq/artemis/jms/client/ActiveMQDestination.java b/artemis-jms-client/src/main/java/org/apache/activemq/artemis/jms/client/ActiveMQDestination.java index c0ab4b9e95..d374265a27 100644 --- a/artemis-jms-client/src/main/java/org/apache/activemq/artemis/jms/client/ActiveMQDestination.java +++ b/artemis-jms-client/src/main/java/org/apache/activemq/artemis/jms/client/ActiveMQDestination.java @@ -19,21 +19,18 @@ package org.apache.activemq.artemis.jms.client; import javax.jms.Destination; import javax.jms.JMSException; import javax.jms.JMSRuntimeException; -import javax.naming.NamingException; -import javax.naming.Reference; -import javax.naming.Referenceable; import java.io.Serializable; +import java.util.Properties; import java.util.UUID; import org.apache.activemq.artemis.api.core.Pair; import org.apache.activemq.artemis.api.core.SimpleString; -import org.apache.activemq.artemis.jms.referenceable.DestinationObjectFactory; -import org.apache.activemq.artemis.jms.referenceable.SerializableObjectRefAddr; +import org.apache.activemq.artemis.jndi.JNDIStorable; /** * ActiveMQ Artemis implementation of a JMS Destination. */ -public class ActiveMQDestination implements Destination, Serializable, Referenceable { +public class ActiveMQDestination extends JNDIStorable implements Destination, Serializable { // Constants ----------------------------------------------------- // Static -------------------------------------------------------- @@ -78,27 +75,27 @@ public class ActiveMQDestination implements Destination, Serializable, Reference case TEMP_TOPIC: return new ActiveMQTopic(name, true); case DESTINATION: - return new ActiveMQDestination(name, name, TYPE.DESTINATION, null); + return new ActiveMQDestination(name, TYPE.DESTINATION, null); default: throw new IllegalArgumentException("Invalid default destination type: " + defaultType); } } - public static Destination fromPrefixedName(final String address) { - if (address.startsWith(ActiveMQDestination.QUEUE_QUALIFIED_PREFIX)) { - String name = address.substring(ActiveMQDestination.QUEUE_QUALIFIED_PREFIX.length()); - return createQueue(name); - } else if (address.startsWith(ActiveMQDestination.TOPIC_QUALIFIED_PREFIX)) { - String name = address.substring(ActiveMQDestination.TOPIC_QUALIFIED_PREFIX.length()); - return createTopic(name); - } else if (address.startsWith(ActiveMQDestination.TEMP_QUEUE_QUALIFED_PREFIX)) { - String name = address.substring(ActiveMQDestination.TEMP_QUEUE_QUALIFED_PREFIX.length()); - return new ActiveMQTemporaryQueue(name, name, null); - } else if (address.startsWith(ActiveMQDestination.TEMP_TOPIC_QUALIFED_PREFIX)) { - String name = address.substring(ActiveMQDestination.TEMP_TOPIC_QUALIFED_PREFIX.length()); - return new ActiveMQTemporaryTopic(name, name, null); + public static Destination fromPrefixedName(final String name) { + if (name.startsWith(ActiveMQDestination.QUEUE_QUALIFIED_PREFIX)) { + String address = name.substring(ActiveMQDestination.QUEUE_QUALIFIED_PREFIX.length()); + return createQueue(address); + } else if (name.startsWith(ActiveMQDestination.TOPIC_QUALIFIED_PREFIX)) { + String address = name.substring(ActiveMQDestination.TOPIC_QUALIFIED_PREFIX.length()); + return createTopic(address); + } else if (name.startsWith(ActiveMQDestination.TEMP_QUEUE_QUALIFED_PREFIX)) { + String address = name.substring(ActiveMQDestination.TEMP_QUEUE_QUALIFED_PREFIX.length()); + return new ActiveMQTemporaryQueue(address, null); + } else if (name.startsWith(ActiveMQDestination.TEMP_TOPIC_QUALIFED_PREFIX)) { + String address = name.substring(ActiveMQDestination.TEMP_TOPIC_QUALIFED_PREFIX.length()); + return new ActiveMQTemporaryTopic(address, null); } else { - return new ActiveMQDestination(address, address, TYPE.DESTINATION, null); + return new ActiveMQDestination(name, TYPE.DESTINATION, null); } } @@ -191,58 +188,48 @@ public class ActiveMQDestination implements Destination, Serializable, Reference return new SimpleString(TOPIC_QUALIFIED_PREFIX + name); } - public static ActiveMQQueue createQueue(final String name) { - return new ActiveMQQueue(name); + public static ActiveMQQueue createQueue(final String address) { + return new ActiveMQQueue(address); } - public static ActiveMQTopic createTopic(final String name) { - return new ActiveMQTopic(name); + public static ActiveMQTopic createTopic(final String address) { + return new ActiveMQTopic(address); } - public static ActiveMQTemporaryQueue createTemporaryQueue(final String name, final ActiveMQSession session) { - return new ActiveMQTemporaryQueue(name, name, session); + public static ActiveMQTemporaryQueue createTemporaryQueue(final String address, final ActiveMQSession session) { + return new ActiveMQTemporaryQueue(address, session); } - public static ActiveMQTemporaryQueue createTemporaryQueue(final String name) { - return createTemporaryQueue(name, null); + public static ActiveMQTemporaryQueue createTemporaryQueue(final String address) { + return createTemporaryQueue(address, null); } public static ActiveMQTemporaryQueue createTemporaryQueue(final ActiveMQSession session) { - String name = UUID.randomUUID().toString(); + String address = UUID.randomUUID().toString(); - return createTemporaryQueue(name, session); + return createTemporaryQueue(address, session); } public static ActiveMQTemporaryTopic createTemporaryTopic(final ActiveMQSession session) { - String name = UUID.randomUUID().toString(); + String address = UUID.randomUUID().toString(); - return createTemporaryTopic(name, session); + return createTemporaryTopic(address, session); } - public static ActiveMQTemporaryTopic createTemporaryTopic(String name, final ActiveMQSession session) { - return new ActiveMQTemporaryTopic(name, name, session); + public static ActiveMQTemporaryTopic createTemporaryTopic(String address, final ActiveMQSession session) { + return new ActiveMQTemporaryTopic(address, session); } - public static ActiveMQTemporaryTopic createTemporaryTopic(String name) { - return createTemporaryTopic(name, null); + public static ActiveMQTemporaryTopic createTemporaryTopic(String address) { + return createTemporaryTopic(address, null); } // Attributes ---------------------------------------------------- - /** - * The JMS name - */ - protected final String name; - /** * The core address */ - private final String address; - - /** - * SimpleString version of address - */ - private final SimpleString simpleAddress; + private SimpleString simpleAddress; private final TYPE type; @@ -251,25 +238,34 @@ public class ActiveMQDestination implements Destination, Serializable, Reference // Constructors -------------------------------------------------- protected ActiveMQDestination(final String address, - final String name, final TYPE type, final ActiveMQSession session) { - this.address = address; - - this.name = name; - - simpleAddress = new SimpleString(address); + this.simpleAddress = SimpleString.toSimpleString(address); this.type = type; this.session = session; } - // Referenceable implementation --------------------------------------- + protected ActiveMQDestination(final SimpleString address, + final TYPE type, + final ActiveMQSession session) { + this.simpleAddress = address; - @Override - public Reference getReference() throws NamingException { - return new Reference(this.getClass().getCanonicalName(), new SerializableObjectRefAddr("ActiveMQ-DEST", this), DestinationObjectFactory.class.getCanonicalName(), null); + this.type = type; + + this.session = session; + } + + public void setAddress(String address) { + setSimpleAddress(SimpleString.toSimpleString(address)); + } + + public void setSimpleAddress(SimpleString address) { + if (address == null) { + throw new IllegalArgumentException("address cannot be null"); + } + this.simpleAddress = address; } public void delete() throws JMSException { @@ -293,7 +289,7 @@ public class ActiveMQDestination implements Destination, Serializable, Reference // Public -------------------------------------------------------- public String getAddress() { - return address; + return simpleAddress.toString(); } public SimpleString getSimpleAddress() { @@ -301,7 +297,7 @@ public class ActiveMQDestination implements Destination, Serializable, Reference } public String getName() { - return name; + return simpleAddress.toString(); } public boolean isTemporary() { @@ -324,12 +320,22 @@ public class ActiveMQDestination implements Destination, Serializable, Reference ActiveMQDestination that = (ActiveMQDestination) o; - return address.equals(that.address); + return simpleAddress.equals(that.simpleAddress); } @Override public int hashCode() { - return address.hashCode(); + return simpleAddress.hashCode(); + } + + @Override + protected void buildFromProperties(Properties props) { + setAddress(props.getProperty("address")); + } + + @Override + protected void populateProperties(Properties props) { + props.put("address", getAddress()); } // Package protected --------------------------------------------- diff --git a/artemis-jms-client/src/main/java/org/apache/activemq/artemis/jms/client/ActiveMQQueue.java b/artemis-jms-client/src/main/java/org/apache/activemq/artemis/jms/client/ActiveMQQueue.java index 2f9a47b001..2deefa974b 100644 --- a/artemis-jms-client/src/main/java/org/apache/activemq/artemis/jms/client/ActiveMQQueue.java +++ b/artemis-jms-client/src/main/java/org/apache/activemq/artemis/jms/client/ActiveMQQueue.java @@ -18,8 +18,6 @@ package org.apache.activemq.artemis.jms.client; import javax.jms.Queue; -import org.apache.activemq.artemis.api.core.SimpleString; - /** * ActiveMQ Artemis implementation of a JMS Queue. *
@@ -32,35 +30,30 @@ public class ActiveMQQueue extends ActiveMQDestination implements Queue { // Static -------------------------------------------------------- - public static SimpleString createAddressFromName(final String name) { - return new SimpleString(name); - } - // Attributes ---------------------------------------------------- // Constructors -------------------------------------------------- - - public ActiveMQQueue(final String name) { - super(name, name, TYPE.QUEUE, null); + public ActiveMQQueue() { + this(null); } - public ActiveMQQueue(final String name, boolean temporary) { - super(name, name, temporary ? TYPE.TEMP_QUEUE : TYPE.QUEUE, null); + public ActiveMQQueue(final String address) { + super(address, TYPE.QUEUE, null); + } + + public ActiveMQQueue(final String address, boolean temporary) { + super(address, temporary ? TYPE.TEMP_QUEUE : TYPE.QUEUE, null); } /** * @param address - * @param name * @param temporary * @param session */ - public ActiveMQQueue(String address, String name, boolean temporary, ActiveMQSession session) { - super(address, name, temporary ? TYPE.TEMP_QUEUE : TYPE.QUEUE, session); + public ActiveMQQueue(String address, boolean temporary, ActiveMQSession session) { + super(address, temporary ? TYPE.TEMP_QUEUE : TYPE.QUEUE, session); } - public ActiveMQQueue(final String address, final String name) { - super(address, name, TYPE.QUEUE, null); - } // Queue implementation ------------------------------------------ @@ -68,12 +61,12 @@ public class ActiveMQQueue extends ActiveMQDestination implements Queue { @Override public String getQueueName() { - return name; + return getAddress(); } @Override public String toString() { - return "ActiveMQQueue[" + name + "]"; + return "ActiveMQQueue[" + getAddress() + "]"; } @Override diff --git a/artemis-jms-client/src/main/java/org/apache/activemq/artemis/jms/client/ActiveMQTemporaryQueue.java b/artemis-jms-client/src/main/java/org/apache/activemq/artemis/jms/client/ActiveMQTemporaryQueue.java index 88a822ade7..b79c36adf8 100644 --- a/artemis-jms-client/src/main/java/org/apache/activemq/artemis/jms/client/ActiveMQTemporaryQueue.java +++ b/artemis-jms-client/src/main/java/org/apache/activemq/artemis/jms/client/ActiveMQTemporaryQueue.java @@ -37,19 +37,21 @@ public class ActiveMQTemporaryQueue extends ActiveMQQueue implements TemporaryQu // TemporaryQueue implementation ------------------------------------------ // Public -------------------------------------------------------- + public ActiveMQTemporaryQueue() { + this(null, null); + } /** * @param address - * @param name * @param session */ - public ActiveMQTemporaryQueue(String address, String name, ActiveMQSession session) { - super(address, name, true, session); + public ActiveMQTemporaryQueue(String address, ActiveMQSession session) { + super(address, true, session); } @Override public String toString() { - return "ActiveMQTemporaryQueue[" + name + "]"; + return "ActiveMQTemporaryQueue[" + getAddress() + "]"; } @Override diff --git a/artemis-jms-client/src/main/java/org/apache/activemq/artemis/jms/client/ActiveMQTemporaryTopic.java b/artemis-jms-client/src/main/java/org/apache/activemq/artemis/jms/client/ActiveMQTemporaryTopic.java index 98b5ba6c36..457663d1a7 100644 --- a/artemis-jms-client/src/main/java/org/apache/activemq/artemis/jms/client/ActiveMQTemporaryTopic.java +++ b/artemis-jms-client/src/main/java/org/apache/activemq/artemis/jms/client/ActiveMQTemporaryTopic.java @@ -29,9 +29,12 @@ public class ActiveMQTemporaryTopic extends ActiveMQTopic implements TemporaryTo // Static -------------------------------------------------------- // Constructors -------------------------------------------------- + public ActiveMQTemporaryTopic() { + this(null, null); + } - protected ActiveMQTemporaryTopic(final String address, final String name, final ActiveMQSession session) { - super(address, name, true, session); + public ActiveMQTemporaryTopic(final String address, final ActiveMQSession session) { + super(address, true, session); } // Public -------------------------------------------------------- diff --git a/artemis-jms-client/src/main/java/org/apache/activemq/artemis/jms/client/ActiveMQTopic.java b/artemis-jms-client/src/main/java/org/apache/activemq/artemis/jms/client/ActiveMQTopic.java index 94bdd25552..e22e67b65b 100644 --- a/artemis-jms-client/src/main/java/org/apache/activemq/artemis/jms/client/ActiveMQTopic.java +++ b/artemis-jms-client/src/main/java/org/apache/activemq/artemis/jms/client/ActiveMQTopic.java @@ -18,8 +18,6 @@ package org.apache.activemq.artemis.jms.client; import javax.jms.Topic; -import org.apache.activemq.artemis.api.core.SimpleString; - /** * ActiveMQ Artemis implementation of a JMS Topic. *
@@ -31,44 +29,42 @@ public class ActiveMQTopic extends ActiveMQDestination implements Topic { private static final long serialVersionUID = 7873614001276404156L; // Static -------------------------------------------------------- - public static SimpleString createAddressFromName(final String name) { - return new SimpleString(name); - } - // Attributes ---------------------------------------------------- // Constructors -------------------------------------------------- - - public ActiveMQTopic(final String name) { - this(name, false); + public ActiveMQTopic() { + this(null); } - public ActiveMQTopic(final String name, boolean temporary) { - super(name, name, TYPE.TOPIC, null); + public ActiveMQTopic(final String address) { + this(address, false); + } + + public ActiveMQTopic(final String address, boolean temporary) { + super(address, TYPE.TOPIC, null); } /** * @param address - * @param name * @param temporary * @param session */ - protected ActiveMQTopic(String address, String name, boolean temporary, ActiveMQSession session) { - super(address, name, temporary ? TYPE.TEMP_TOPIC : TYPE.TOPIC, session); + protected ActiveMQTopic(String address, boolean temporary, ActiveMQSession session) { + super(address, temporary ? TYPE.TEMP_TOPIC : TYPE.TOPIC, session); } // Topic implementation ------------------------------------------ @Override public String getTopicName() { - return name; + return getName(); } // Public -------------------------------------------------------- @Override public String toString() { - return "ActiveMQTopic[" + name + "]"; + return "ActiveMQTopic[" + getName() + "]"; } @Override diff --git a/artemis-jms-client/src/main/java/org/apache/activemq/artemis/jndi/JNDIReferenceFactory.java b/artemis-jms-client/src/main/java/org/apache/activemq/artemis/jndi/JNDIReferenceFactory.java index c22676013b..0b4b0c2677 100644 --- a/artemis-jms-client/src/main/java/org/apache/activemq/artemis/jndi/JNDIReferenceFactory.java +++ b/artemis-jms-client/src/main/java/org/apache/activemq/artemis/jndi/JNDIReferenceFactory.java @@ -19,14 +19,13 @@ package org.apache.activemq.artemis.jndi; import javax.naming.Context; import javax.naming.Name; import javax.naming.NamingException; -import javax.naming.RefAddr; import javax.naming.Reference; import javax.naming.StringRefAddr; import javax.naming.spi.ObjectFactory; import java.util.Enumeration; -import java.util.HashMap; import java.util.Hashtable; -import java.util.Map; +import java.util.Properties; + /** * Converts objects implementing JNDIStorable into a property fields so they can be @@ -63,12 +62,7 @@ public class JNDIReferenceFactory implements ObjectFactory { Class theClass = loadClass(this, reference.getClassName()); if (JNDIStorable.class.isAssignableFrom(theClass)) { JNDIStorable store = (JNDIStorable) theClass.newInstance(); - Map properties = new HashMap<>(); - for (Enumeration iter = reference.getAll(); iter.hasMoreElements();) { - StringRefAddr addr = (StringRefAddr) iter.nextElement(); - properties.put(addr.getType(), (addr.getContent() == null) ? "" : addr.getContent().toString()); - } - store.setProperties(properties); + store.setProperties(getProperties(reference)); result = store; } } else { @@ -77,6 +71,15 @@ public class JNDIReferenceFactory implements ObjectFactory { return result; } + public static Properties getProperties(Reference reference) { + Properties properties = new Properties(); + for (Enumeration iter = reference.getAll(); iter.hasMoreElements();) { + StringRefAddr addr = (StringRefAddr)iter.nextElement(); + properties.put(addr.getType(), (addr.getContent() == null) ? "" : addr.getContent()); + } + return properties; + } + /** * Create a Reference instance from a JNDIStorable object * @@ -92,10 +95,10 @@ public class JNDIReferenceFactory implements ObjectFactory { public static Reference createReference(String instanceClassName, JNDIStorable po) throws NamingException { Reference result = new Reference(instanceClassName, JNDIReferenceFactory.class.getName(), null); try { - Map props = po.getProperties(); - for (Map.Entry entry : props.entrySet()) { - StringRefAddr addr = new StringRefAddr(entry.getKey(), entry.getValue()); - result.add(addr); + Properties props = po.getProperties(); + for (Enumeration iter = props.propertyNames(); iter.hasMoreElements();) { + String key = (String)iter.nextElement(); + result.add(new StringRefAddr(key, props.getProperty(key))); } } catch (Exception e) { throw new NamingException(e.getMessage()); diff --git a/artemis-jms-client/src/main/java/org/apache/activemq/artemis/jndi/JNDIStorable.java b/artemis-jms-client/src/main/java/org/apache/activemq/artemis/jndi/JNDIStorable.java index 2c26b0a738..b25dcf24a6 100644 --- a/artemis-jms-client/src/main/java/org/apache/activemq/artemis/jndi/JNDIStorable.java +++ b/artemis-jms-client/src/main/java/org/apache/activemq/artemis/jndi/JNDIStorable.java @@ -16,32 +16,27 @@ */ package org.apache.activemq.artemis.jndi; -import javax.naming.NamingException; -import javax.naming.Reference; -import javax.naming.Referenceable; -import java.io.Externalizable; import java.io.IOException; import java.io.ObjectInput; import java.io.ObjectOutput; -import java.util.LinkedHashMap; -import java.util.Map; +import java.util.Properties; + +import javax.naming.NamingException; +import javax.naming.Reference; +import javax.naming.Referenceable; /** * Facilitates objects to be stored in JNDI as properties - * - * @since 1.0 */ -public abstract class JNDIStorable implements Referenceable, Externalizable { +public abstract class JNDIStorable implements Referenceable { /** * Set the properties that will represent the instance in JNDI * * @param props * The properties to use when building the new isntance. - * - * @return a new, unmodifiable, map containing any unused properties, or empty if none were. */ - protected abstract Map buildFromProperties(Map props); + protected abstract void buildFromProperties(Properties props); /** * Initialize the instance from properties stored in JNDI @@ -49,7 +44,7 @@ public abstract class JNDIStorable implements Referenceable, Externalizable { * @param props * The properties to use when initializing the new instance. */ - protected abstract void populateProperties(Map props); + protected abstract void populateProperties(Properties props); /** * set the properties for this instance as retrieved from JNDI @@ -59,8 +54,8 @@ public abstract class JNDIStorable implements Referenceable, Externalizable { * * @return a new, unmodifiable, map containing any unused properties, or empty if none were. */ - public synchronized Map setProperties(Map props) { - return buildFromProperties(props); + synchronized void setProperties(Properties props) { + buildFromProperties(props); } /** @@ -68,8 +63,8 @@ public abstract class JNDIStorable implements Referenceable, Externalizable { * * @return the properties */ - public synchronized Map getProperties() { - Map properties = new LinkedHashMap<>(); + synchronized Properties getProperties() { + Properties properties = new Properties(); populateProperties(properties); return properties; } @@ -87,30 +82,29 @@ public abstract class JNDIStorable implements Referenceable, Externalizable { } /** - * @see Externalizable#readExternal(ObjectInput) + * Method for class's implementing externalizable to delegate to if not custom implementing. + * + * @param in + * @throws IOException + * @throws ClassNotFoundException + * @see java.io.Externalizable#readExternal(java.io.ObjectInput) */ - @SuppressWarnings("unchecked") - @Override - public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { - Map props = (Map) in.readObject(); + public void readObject(ObjectInput in) throws IOException, ClassNotFoundException { + Properties props = (Properties)in.readObject(); if (props != null) { setProperties(props); } } /** - * @see Externalizable#writeExternal(ObjectOutput) + * Method for class's implementing externalizable to delegate to if not custom implementing. + * + * @param out + * @throws IOException + * @see java.io.Externalizable#writeExternal(java.io.ObjectOutput) */ - @Override - public void writeExternal(ObjectOutput out) throws IOException { + public void writeObject(ObjectOutput out) throws IOException { out.writeObject(getProperties()); } - protected String getProperty(Map map, String key, String defaultValue) { - String value = map.get(key); - if (value != null) { - return value; - } - return defaultValue; - } -} +} \ No newline at end of file diff --git a/artemis-protocols/artemis-amqp-protocol/src/main/java/org/apache/activemq/artemis/protocol/amqp/converter/jms/ServerDestination.java b/artemis-protocols/artemis-amqp-protocol/src/main/java/org/apache/activemq/artemis/protocol/amqp/converter/jms/ServerDestination.java index cee9ee5ed5..5a2f55bb67 100644 --- a/artemis-protocols/artemis-amqp-protocol/src/main/java/org/apache/activemq/artemis/protocol/amqp/converter/jms/ServerDestination.java +++ b/artemis-protocols/artemis-amqp-protocol/src/main/java/org/apache/activemq/artemis/protocol/amqp/converter/jms/ServerDestination.java @@ -19,6 +19,7 @@ package org.apache.activemq.artemis.protocol.amqp.converter.jms; import javax.jms.JMSException; import javax.jms.Queue; +import org.apache.activemq.artemis.api.core.SimpleString; import org.apache.activemq.artemis.jms.client.ActiveMQDestination; /** @@ -27,8 +28,12 @@ import org.apache.activemq.artemis.jms.client.ActiveMQDestination; */ public class ServerDestination extends ActiveMQDestination implements Queue { - public ServerDestination(String name) { - super(name, name, TYPE.DESTINATION, null); + public ServerDestination(String address) { + super(address, TYPE.DESTINATION, null); + } + + public ServerDestination(SimpleString address) { + super(address, TYPE.DESTINATION, null); } @Override diff --git a/artemis-protocols/artemis-amqp-protocol/src/main/java/org/apache/activemq/artemis/protocol/amqp/converter/jms/ServerJMSMessage.java b/artemis-protocols/artemis-amqp-protocol/src/main/java/org/apache/activemq/artemis/protocol/amqp/converter/jms/ServerJMSMessage.java index 5962e39b63..b070591c42 100644 --- a/artemis-protocols/artemis-amqp-protocol/src/main/java/org/apache/activemq/artemis/protocol/amqp/converter/jms/ServerJMSMessage.java +++ b/artemis-protocols/artemis-amqp-protocol/src/main/java/org/apache/activemq/artemis/protocol/amqp/converter/jms/ServerJMSMessage.java @@ -139,7 +139,7 @@ public class ServerJMSMessage implements Message { public final Destination getJMSReplyTo() throws JMSException { SimpleString reply = MessageUtil.getJMSReplyTo(message); if (reply != null) { - return new ServerDestination(reply.toString()); + return new ServerDestination(reply); } else { return null; } @@ -148,7 +148,6 @@ public class ServerJMSMessage implements Message { @Override public final void setJMSReplyTo(Destination replyTo) throws JMSException { MessageUtil.setJMSReplyTo(message, replyTo == null ? null : ((ActiveMQDestination) replyTo).getSimpleAddress()); - } @Override @@ -158,7 +157,7 @@ public class ServerJMSMessage implements Message { if (sdest == null) { return null; } else { - return new ServerDestination(sdest.toString()); + return new ServerDestination(sdest); } } diff --git a/artemis-ra/src/main/java/org/apache/activemq/artemis/jms/referenceable/ConnectionFactoryObjectFactory.java b/artemis-ra/src/main/java/org/apache/activemq/artemis/jms/referenceable/ConnectionFactoryObjectFactory.java new file mode 100644 index 0000000000..4c7a68afa7 --- /dev/null +++ b/artemis-ra/src/main/java/org/apache/activemq/artemis/jms/referenceable/ConnectionFactoryObjectFactory.java @@ -0,0 +1,25 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.activemq.artemis.jms.referenceable; + +/** + * Done for back compatibility with the package/class move. + * + * Should be removed on next major version change. + */ +public class ConnectionFactoryObjectFactory extends org.apache.activemq.artemis.ra.referenceable.ActiveMQRAConnectionFactoryObjectFactory { +} diff --git a/artemis-jms-client/src/main/java/org/apache/activemq/artemis/jms/referenceable/DestinationObjectFactory.java b/artemis-ra/src/main/java/org/apache/activemq/artemis/jms/referenceable/SerializableObjectRefAddr.java similarity index 50% rename from artemis-jms-client/src/main/java/org/apache/activemq/artemis/jms/referenceable/DestinationObjectFactory.java rename to artemis-ra/src/main/java/org/apache/activemq/artemis/jms/referenceable/SerializableObjectRefAddr.java index 896e81561f..92aaf9e9b9 100644 --- a/artemis-jms-client/src/main/java/org/apache/activemq/artemis/jms/referenceable/DestinationObjectFactory.java +++ b/artemis-ra/src/main/java/org/apache/activemq/artemis/jms/referenceable/SerializableObjectRefAddr.java @@ -6,7 +6,7 @@ * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -16,29 +16,16 @@ */ package org.apache.activemq.artemis.jms.referenceable; -import javax.naming.Context; -import javax.naming.Name; -import javax.naming.Reference; -import javax.naming.spi.ObjectFactory; -import java.util.Hashtable; +import javax.naming.NamingException; /** - * A DestinationObjectFactory. + * Done for back compatibility with the package/class move. * - * Given a Reference - reconstructs an ActiveMQDestination + * Should be removed on next major version change. */ -public class DestinationObjectFactory implements ObjectFactory { +public class SerializableObjectRefAddr extends org.apache.activemq.artemis.ra.referenceable.SerializableObjectRefAddr { - @Override - public Object getObjectInstance(final Object ref, - final Name name, - final Context ctx, - final Hashtable props) throws Exception { - Reference r = (Reference) ref; - - byte[] bytes = (byte[]) r.get("ActiveMQ-DEST").getContent(); - - // Deserialize - return SerializableObjectRefAddr.deserialize(bytes); + public SerializableObjectRefAddr(final String type, final Object content) throws NamingException { + super(type, content); } -} +} \ No newline at end of file diff --git a/artemis-ra/src/main/java/org/apache/activemq/artemis/ra/ActiveMQRAConnectionFactoryImpl.java b/artemis-ra/src/main/java/org/apache/activemq/artemis/ra/ActiveMQRAConnectionFactoryImpl.java index faf111e16b..e3c4c9d7aa 100644 --- a/artemis-ra/src/main/java/org/apache/activemq/artemis/ra/ActiveMQRAConnectionFactoryImpl.java +++ b/artemis-ra/src/main/java/org/apache/activemq/artemis/ra/ActiveMQRAConnectionFactoryImpl.java @@ -35,8 +35,8 @@ import javax.resource.ResourceException; import javax.resource.spi.ConnectionManager; import org.apache.activemq.artemis.jms.client.ActiveMQConnectionFactory; -import org.apache.activemq.artemis.jms.referenceable.ConnectionFactoryObjectFactory; -import org.apache.activemq.artemis.jms.referenceable.SerializableObjectRefAddr; +import org.apache.activemq.artemis.ra.referenceable.ActiveMQRAConnectionFactoryObjectFactory; +import org.apache.activemq.artemis.ra.referenceable.SerializableObjectRefAddr; /** * The connection factory @@ -118,7 +118,7 @@ public class ActiveMQRAConnectionFactoryImpl implements ActiveMQRAConnectionFact } if (reference == null) { try { - reference = new Reference(this.getClass().getCanonicalName(), new SerializableObjectRefAddr("ActiveMQ-CF", this), ConnectionFactoryObjectFactory.class.getCanonicalName(), null); + reference = new Reference(this.getClass().getCanonicalName(), new SerializableObjectRefAddr("ActiveMQ-CF", this), ActiveMQRAConnectionFactoryObjectFactory.class.getCanonicalName(), null); } catch (NamingException e) { ActiveMQRALogger.LOGGER.errorCreatingReference(e); } diff --git a/artemis-jms-client/src/main/java/org/apache/activemq/artemis/jms/referenceable/ConnectionFactoryObjectFactory.java b/artemis-ra/src/main/java/org/apache/activemq/artemis/ra/referenceable/ActiveMQRAConnectionFactoryObjectFactory.java similarity index 91% rename from artemis-jms-client/src/main/java/org/apache/activemq/artemis/jms/referenceable/ConnectionFactoryObjectFactory.java rename to artemis-ra/src/main/java/org/apache/activemq/artemis/ra/referenceable/ActiveMQRAConnectionFactoryObjectFactory.java index ad125f06cb..ab4e99d194 100644 --- a/artemis-jms-client/src/main/java/org/apache/activemq/artemis/jms/referenceable/ConnectionFactoryObjectFactory.java +++ b/artemis-ra/src/main/java/org/apache/activemq/artemis/ra/referenceable/ActiveMQRAConnectionFactoryObjectFactory.java @@ -14,7 +14,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.apache.activemq.artemis.jms.referenceable; +package org.apache.activemq.artemis.ra.referenceable; import javax.naming.Context; import javax.naming.Name; @@ -27,7 +27,7 @@ import java.util.Hashtable; * * Given a reference - reconstructs an ActiveMQRAConnectionFactory */ -public class ConnectionFactoryObjectFactory implements ObjectFactory { +public class ActiveMQRAConnectionFactoryObjectFactory implements ObjectFactory { @Override public Object getObjectInstance(final Object ref, diff --git a/artemis-jms-client/src/main/java/org/apache/activemq/artemis/jms/referenceable/SerializableObjectRefAddr.java b/artemis-ra/src/main/java/org/apache/activemq/artemis/ra/referenceable/SerializableObjectRefAddr.java similarity index 97% rename from artemis-jms-client/src/main/java/org/apache/activemq/artemis/jms/referenceable/SerializableObjectRefAddr.java rename to artemis-ra/src/main/java/org/apache/activemq/artemis/ra/referenceable/SerializableObjectRefAddr.java index 09c971d5c1..b4fce9fcd4 100644 --- a/artemis-jms-client/src/main/java/org/apache/activemq/artemis/jms/referenceable/SerializableObjectRefAddr.java +++ b/artemis-ra/src/main/java/org/apache/activemq/artemis/ra/referenceable/SerializableObjectRefAddr.java @@ -14,7 +14,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.apache.activemq.artemis.jms.referenceable; +package org.apache.activemq.artemis.ra.referenceable; import javax.naming.NamingException; import javax.naming.RefAddr; diff --git a/docs/user-manual/en/SUMMARY.md b/docs/user-manual/en/SUMMARY.md index 1a2f5311f6..ba488f359d 100644 --- a/docs/user-manual/en/SUMMARY.md +++ b/docs/user-manual/en/SUMMARY.md @@ -56,6 +56,7 @@ * [REST Interface](rest.md) * [Embedding Apache ActiveMQ Artemis](embedding-activemq.md) * [Apache Karaf](karaf.md) +* [Apache Tomcat](tomcat.md) * [Spring Integration](spring-integration.md) * [CDI Integration](cdi-integration.md) * [Intercepting Operations](intercepting-operations.md) diff --git a/docs/user-manual/en/tomcat.md b/docs/user-manual/en/tomcat.md new file mode 100644 index 0000000000..ac6befa228 --- /dev/null +++ b/docs/user-manual/en/tomcat.md @@ -0,0 +1,39 @@ +# Apache ActiveMQ Artemis - Apache Tomcat Support + + +##Apache Tomcat resource context client configuration + +Apache ActiveMQ Artemis provides support for configuring the client, in the tomcat resource context.xml of Tomcat container. + +This is very similar to the way this is done in ActiveMQ 5.x so anyone migrating should find this familiar. +Please note though the connection url and properties that can be set for ActiveMQ Artemis are different please see [Migration Documentation](https://activemq.apache.org/artemis/migration/) + +#### Example of Connection Factory +```` + + ... + + ... + +```` + +#### Example of Destination (Queue and Topic) + +```` + + ... + + ... + + ... + +```` + +#### Example Tomcat App + +A sample tomcat app with the container context configured as an example can be seen here: + +/examples/features/sub-modules/tomcat \ No newline at end of file diff --git a/examples/features/sub-modules/pom.xml b/examples/features/sub-modules/pom.xml index ce20c0455d..bb6aeaa243 100644 --- a/examples/features/sub-modules/pom.xml +++ b/examples/features/sub-modules/pom.xml @@ -50,7 +50,8 @@ under the License. release artemis-ra-rar - inter-broker-bridge + inter-broker-bridge + tomcat diff --git a/examples/features/sub-modules/tomcat/README b/examples/features/sub-modules/tomcat/README new file mode 100644 index 0000000000..dfc84624c7 --- /dev/null +++ b/examples/features/sub-modules/tomcat/README @@ -0,0 +1,21 @@ +# Apache ActiveMQ Artemis Tomcat Integration JNDI Resources Sample + +This is a Sample Tomcat application showing JNDI resource in tomcat context.xml for ConnectionFactory +and Destination for Apache ActiveMQ Artemis. + +The sample context.xml used by the tomcat in this example can be found under: +/src/tomcat7-maven-plugin/resources/context.xml + +To run + +start Apache ActiveMQ Artemis on port 61616 + +then + +mvn clean install tomcat7:exec-war + +then to send message + +http://localhost:8080/tomcat-sample/send + +this will cause a "hello world" message to send, and the consumer should consume and output it to sysout. \ No newline at end of file diff --git a/examples/features/sub-modules/tomcat/pom.xml b/examples/features/sub-modules/tomcat/pom.xml new file mode 100644 index 0000000000..8773f3be26 --- /dev/null +++ b/examples/features/sub-modules/tomcat/pom.xml @@ -0,0 +1,127 @@ + + + + 4.0.0 + + + org.apache.activemq.examples.modules + broker-modules + 2.5.0-SNAPSHOT + + + + artemis-tomcat-jndi-resources-sample + war + Artemis Tomcat JNDI Resources Example + + + UTF-8 + ${project.baseUri} + 1.6 + + 3.0-alpha-1 + + + + + + + org.springframework + spring-context + ${spring.version} + + + org.springframework + spring-webmvc + ${spring.version} + + + org.springframework + spring-jms + ${spring.version} + + + + + org.apache.activemq + artemis-jms-client + ${project.version} + + + + javax.servlet + servlet-api + ${servlet-api.version} + provided + + + + + + + org.apache.maven.plugins + maven-compiler-plugin + 2.3.2 + + ${java.version} + ${java.version} + + + + + org.apache.tomcat.maven + tomcat7-maven-plugin + 2.1 + + + ${project.basedir}\src\tomcat7-maven-plugin\resources\context.xml + + + + tomcat-war-exec + + exec-war + + package + + + + + org.apache.activemq.examples.modules + artemis-tomcat-jndi-resources-sample + ${project.version} + war + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/examples/features/sub-modules/tomcat/src/main/java/org/apache/activemq/artemis/example/tomcat/sample/SendMessageController.java b/examples/features/sub-modules/tomcat/src/main/java/org/apache/activemq/artemis/example/tomcat/sample/SendMessageController.java new file mode 100644 index 0000000000..eb36179bdd --- /dev/null +++ b/examples/features/sub-modules/tomcat/src/main/java/org/apache/activemq/artemis/example/tomcat/sample/SendMessageController.java @@ -0,0 +1,48 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + *

+ * http://www.apache.org/licenses/LICENSE-2.0 + *

+ * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.activemq.artemis.example.tomcat.sample; + +import javax.jms.JMSException; +import javax.jms.Message; +import javax.jms.Session; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.jms.core.JmsTemplate; +import org.springframework.jms.core.MessageCreator; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.ResponseBody; +import org.springframework.web.bind.annotation.RestController; + +@RestController +public class SendMessageController { + + @Autowired + private JmsTemplate jmsTemplate; + + + @RequestMapping("/send") + public @ResponseBody String send(@RequestParam(value="text", defaultValue="hello world") final String text) { + jmsTemplate.send(new MessageCreator() { + @Override + public Message createMessage(Session session) throws JMSException { + return session.createTextMessage(text); + } + }); + return "sent: " + text; + } +} \ No newline at end of file diff --git a/examples/features/sub-modules/tomcat/src/main/java/org/apache/activemq/artemis/example/tomcat/sample/SystemOutPrintLnMessageListener.java b/examples/features/sub-modules/tomcat/src/main/java/org/apache/activemq/artemis/example/tomcat/sample/SystemOutPrintLnMessageListener.java new file mode 100644 index 0000000000..1f57c13743 --- /dev/null +++ b/examples/features/sub-modules/tomcat/src/main/java/org/apache/activemq/artemis/example/tomcat/sample/SystemOutPrintLnMessageListener.java @@ -0,0 +1,28 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + *

+ * http://www.apache.org/licenses/LICENSE-2.0 + *

+ * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.activemq.artemis.example.tomcat.sample; + +import javax.jms.Message; +import javax.jms.MessageListener; + + +public class SystemOutPrintLnMessageListener implements MessageListener { + @Override + public void onMessage(Message message) { + System.out.println(message); + } +} diff --git a/examples/features/sub-modules/tomcat/src/main/webapp/WEB-INF/application-context.xml b/examples/features/sub-modules/tomcat/src/main/webapp/WEB-INF/application-context.xml new file mode 100644 index 0000000000..ffd4728b17 --- /dev/null +++ b/examples/features/sub-modules/tomcat/src/main/webapp/WEB-INF/application-context.xml @@ -0,0 +1,50 @@ + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/examples/features/sub-modules/tomcat/src/main/webapp/WEB-INF/dispatcher-servlet.xml b/examples/features/sub-modules/tomcat/src/main/webapp/WEB-INF/dispatcher-servlet.xml new file mode 100644 index 0000000000..b1da14dc81 --- /dev/null +++ b/examples/features/sub-modules/tomcat/src/main/webapp/WEB-INF/dispatcher-servlet.xml @@ -0,0 +1,28 @@ + + + + + + + \ No newline at end of file diff --git a/examples/features/sub-modules/tomcat/src/main/webapp/WEB-INF/web.xml b/examples/features/sub-modules/tomcat/src/main/webapp/WEB-INF/web.xml new file mode 100644 index 0000000000..974c3e461b --- /dev/null +++ b/examples/features/sub-modules/tomcat/src/main/webapp/WEB-INF/web.xml @@ -0,0 +1,41 @@ + + + + + + + org.springframework.web.context.ContextLoaderListener + + + + + contextConfigLocation + WEB-INF/application-context.xml + + + + dispatcher + org.springframework.web.servlet.DispatcherServlet + + + + dispatcher + /* + + + + \ No newline at end of file diff --git a/examples/features/sub-modules/tomcat/src/tomcat7-maven-plugin/resources/context.xml b/examples/features/sub-modules/tomcat/src/tomcat7-maven-plugin/resources/context.xml new file mode 100644 index 0000000000..9e78ccaa2b --- /dev/null +++ b/examples/features/sub-modules/tomcat/src/tomcat7-maven-plugin/resources/context.xml @@ -0,0 +1,28 @@ + + + + + + + \ No newline at end of file diff --git a/tests/jms-tests/src/test/java/org/apache/activemq/artemis/jms/tests/ReferenceableTest.java b/tests/jms-tests/src/test/java/org/apache/activemq/artemis/jms/tests/ReferenceableTest.java index 2cebf045d9..1795193bf0 100644 --- a/tests/jms-tests/src/test/java/org/apache/activemq/artemis/jms/tests/ReferenceableTest.java +++ b/tests/jms-tests/src/test/java/org/apache/activemq/artemis/jms/tests/ReferenceableTest.java @@ -25,6 +25,7 @@ import javax.jms.Session; import javax.jms.TextMessage; import javax.naming.Reference; import javax.naming.Referenceable; +import javax.naming.spi.ObjectFactory; import java.io.Serializable; import org.apache.activemq.artemis.jms.client.ActiveMQConnectionFactory; @@ -32,8 +33,6 @@ import org.apache.activemq.artemis.jms.client.ActiveMQDestination; import org.apache.activemq.artemis.jms.client.ActiveMQJMSConnectionFactory; import org.apache.activemq.artemis.jms.client.ActiveMQQueue; import org.apache.activemq.artemis.jms.client.ActiveMQTopic; -import org.apache.activemq.artemis.jms.referenceable.ConnectionFactoryObjectFactory; -import org.apache.activemq.artemis.jms.referenceable.DestinationObjectFactory; import org.apache.activemq.artemis.jms.tests.util.ProxyAssertSupport; import org.junit.Test; @@ -81,7 +80,7 @@ public class ReferenceableTest extends JMSTestCase { Class factoryClass = Class.forName(factoryName); - ConnectionFactoryObjectFactory factory = (ConnectionFactoryObjectFactory) factoryClass.newInstance(); + ObjectFactory factory = (ObjectFactory) factoryClass.newInstance(); Object instance = factory.getObjectInstance(cfRef, null, null, null); @@ -100,7 +99,7 @@ public class ReferenceableTest extends JMSTestCase { Class factoryClass = Class.forName(factoryName); - DestinationObjectFactory factory = (DestinationObjectFactory) factoryClass.newInstance(); + ObjectFactory factory = (ObjectFactory) factoryClass.newInstance(); Object instance = factory.getObjectInstance(queueRef, null, null, null); @@ -121,7 +120,7 @@ public class ReferenceableTest extends JMSTestCase { Class factoryClass = Class.forName(factoryName); - DestinationObjectFactory factory = (DestinationObjectFactory) factoryClass.newInstance(); + ObjectFactory factory = (ObjectFactory) factoryClass.newInstance(); Object instance = factory.getObjectInstance(topicRef, null, null, null); diff --git a/tests/unit-tests/src/test/java/org/apache/activemq/artemis/tests/unit/jms/jndi/ObjectFactoryTest.java b/tests/unit-tests/src/test/java/org/apache/activemq/artemis/tests/unit/jms/jndi/ObjectFactoryTest.java new file mode 100644 index 0000000000..9ceebfdf14 --- /dev/null +++ b/tests/unit-tests/src/test/java/org/apache/activemq/artemis/tests/unit/jms/jndi/ObjectFactoryTest.java @@ -0,0 +1,138 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.activemq.artemis.tests.unit.jms.jndi; + +import static org.junit.Assert.assertEquals; + +import javax.naming.Reference; + +import org.apache.activemq.artemis.api.jms.ActiveMQJMSClient; +import org.apache.activemq.artemis.jms.client.ActiveMQConnectionFactory; +import org.apache.activemq.artemis.jms.client.ActiveMQDestination; +import org.apache.activemq.artemis.jndi.JNDIReferenceFactory; +import org.apache.activemq.artemis.utils.RandomUtil; + +import org.junit.Assert; +import org.junit.Test; + +public class ObjectFactoryTest { + + @Test(timeout = 1000) + public void testConnectionFactory() throws Exception { + // Create sample connection factory + ActiveMQConnectionFactory factory = new ActiveMQConnectionFactory("vm://0"); + + String clientID = RandomUtil.randomString(); + String user = RandomUtil.randomString(); + String password = RandomUtil.randomString(); + long clientFailureCheckPeriod = RandomUtil.randomPositiveLong(); + long connectionTTL = RandomUtil.randomPositiveLong(); + long callTimeout = RandomUtil.randomPositiveLong(); + int minLargeMessageSize = RandomUtil.randomPositiveInt(); + int consumerWindowSize = RandomUtil.randomPositiveInt(); + int consumerMaxRate = RandomUtil.randomPositiveInt(); + int confirmationWindowSize = RandomUtil.randomPositiveInt(); + int producerMaxRate = RandomUtil.randomPositiveInt(); + boolean blockOnAcknowledge = RandomUtil.randomBoolean(); + boolean blockOnDurableSend = RandomUtil.randomBoolean(); + boolean blockOnNonDurableSend = RandomUtil.randomBoolean(); + boolean autoGroup = RandomUtil.randomBoolean(); + boolean preAcknowledge = RandomUtil.randomBoolean(); + String loadBalancingPolicyClassName = RandomUtil.randomString(); + boolean useGlobalPools = RandomUtil.randomBoolean(); + int scheduledThreadPoolMaxSize = RandomUtil.randomPositiveInt(); + int threadPoolMaxSize = RandomUtil.randomPositiveInt(); + long retryInterval = RandomUtil.randomPositiveLong(); + double retryIntervalMultiplier = RandomUtil.randomDouble(); + int reconnectAttempts = RandomUtil.randomPositiveInt(); + factory.setClientID(clientID); + factory.setUser(user); + factory.setPassword(password); + factory.setClientFailureCheckPeriod(clientFailureCheckPeriod); + factory.setConnectionTTL(connectionTTL); + factory.setCallTimeout(callTimeout); + factory.setMinLargeMessageSize(minLargeMessageSize); + factory.setConsumerWindowSize(consumerWindowSize); + factory.setConsumerMaxRate(consumerMaxRate); + factory.setConfirmationWindowSize(confirmationWindowSize); + factory.setProducerMaxRate(producerMaxRate); + factory.setBlockOnAcknowledge(blockOnAcknowledge); + factory.setBlockOnDurableSend(blockOnDurableSend); + factory.setBlockOnNonDurableSend(blockOnNonDurableSend); + factory.setAutoGroup(autoGroup); + factory.setPreAcknowledge(preAcknowledge); + factory.setConnectionLoadBalancingPolicyClassName(loadBalancingPolicyClassName); + factory.setUseGlobalPools(useGlobalPools); + factory.setScheduledThreadPoolMaxSize(scheduledThreadPoolMaxSize); + factory.setThreadPoolMaxSize(threadPoolMaxSize); + factory.setRetryInterval(retryInterval); + factory.setRetryIntervalMultiplier(retryIntervalMultiplier); + factory.setReconnectAttempts(reconnectAttempts); + + + // Create reference + Reference ref = JNDIReferenceFactory.createReference(factory.getClass().getName(), factory); + + // Get object created based on reference + ActiveMQConnectionFactory temp; + JNDIReferenceFactory refFactory = new JNDIReferenceFactory(); + temp = (ActiveMQConnectionFactory)refFactory.getObjectInstance(ref, null, null, null); + + // Check settings + Assert.assertEquals(clientID, temp.getClientID()); + Assert.assertEquals(user, temp.getUser()); + Assert.assertEquals(password, temp.getPassword()); + Assert.assertEquals(clientFailureCheckPeriod, temp.getClientFailureCheckPeriod()); + Assert.assertEquals(connectionTTL, temp.getConnectionTTL()); + Assert.assertEquals(callTimeout, temp.getCallTimeout()); + Assert.assertEquals(minLargeMessageSize, temp.getMinLargeMessageSize()); + Assert.assertEquals(consumerWindowSize, temp.getConsumerWindowSize()); + Assert.assertEquals(consumerMaxRate, temp.getConsumerMaxRate()); + Assert.assertEquals(confirmationWindowSize, temp.getConfirmationWindowSize()); + Assert.assertEquals(producerMaxRate, temp.getProducerMaxRate()); + Assert.assertEquals(blockOnAcknowledge, temp.isBlockOnAcknowledge()); + Assert.assertEquals(blockOnDurableSend, temp.isBlockOnDurableSend()); + Assert.assertEquals(blockOnNonDurableSend, temp.isBlockOnNonDurableSend()); + Assert.assertEquals(autoGroup, temp.isAutoGroup()); + Assert.assertEquals(preAcknowledge, temp.isPreAcknowledge()); + Assert.assertEquals(loadBalancingPolicyClassName, temp.getConnectionLoadBalancingPolicyClassName()); + Assert.assertEquals(useGlobalPools, temp.isUseGlobalPools()); + Assert.assertEquals(scheduledThreadPoolMaxSize, temp.getScheduledThreadPoolMaxSize()); + Assert.assertEquals(threadPoolMaxSize, temp.getThreadPoolMaxSize()); + Assert.assertEquals(retryInterval, temp.getRetryInterval()); + Assert.assertEquals(retryIntervalMultiplier, temp.getRetryIntervalMultiplier(), 0.0001); + Assert.assertEquals(reconnectAttempts, temp.getReconnectAttempts()); + + } + + @Test(timeout = 1000) + public void testDestination() throws Exception { + // Create sample destination + ActiveMQDestination dest = (ActiveMQDestination) ActiveMQJMSClient.createQueue(RandomUtil.randomString()); + + // Create reference + Reference ref = JNDIReferenceFactory.createReference(dest.getClass().getName(), dest); + + // Get object created based on reference + ActiveMQDestination temp; + JNDIReferenceFactory refFactory = new JNDIReferenceFactory(); + temp = (ActiveMQDestination)refFactory.getObjectInstance(ref, null, null, null); + + // Check settings + assertEquals(dest.getAddress(), temp.getAddress()); + } +} \ No newline at end of file diff --git a/tests/unit-tests/src/test/java/org/apache/activemq/artemis/tests/unit/jms/jndi/StringRefAddrReferenceTest.java b/tests/unit-tests/src/test/java/org/apache/activemq/artemis/tests/unit/jms/jndi/StringRefAddrReferenceTest.java new file mode 100644 index 0000000000..bbfbaf9fc1 --- /dev/null +++ b/tests/unit-tests/src/test/java/org/apache/activemq/artemis/tests/unit/jms/jndi/StringRefAddrReferenceTest.java @@ -0,0 +1,119 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.activemq.artemis.tests.unit.jms.jndi; + +import static org.junit.Assert.assertEquals; + +import javax.naming.Reference; +import javax.naming.StringRefAddr; +import javax.naming.spi.ObjectFactory; +import java.util.Enumeration; +import java.util.Properties; + +import org.apache.activemq.artemis.jms.client.ActiveMQConnectionFactory; +import org.apache.activemq.artemis.jms.client.ActiveMQQueue; +import org.apache.activemq.artemis.jms.client.ActiveMQTopic; +import org.apache.activemq.artemis.jndi.JNDIReferenceFactory; +import org.junit.Test; + +/** + * Test to simulate JNDI references created using String properties in containers such as Apache Tomcat. + */ +public class StringRefAddrReferenceTest { + + private static final String FACTORY = "factory"; + private static final String TYPE = "type"; + + @Test(timeout = 10000) + public void testActiveMQQueueFromPropertiesJNDI() throws Exception { + Properties properties = new Properties(); + properties.setProperty(TYPE, ActiveMQQueue.class.getName()); + properties.setProperty(FACTORY, JNDIReferenceFactory.class.getName()); + + String address = "foo.bar.queue"; + + properties.setProperty("address", address); + + Reference reference = from(properties); + ActiveMQQueue object = getObject(reference, ActiveMQQueue.class); + + assertEquals(address, object.getAddress()); + + } + + @Test(timeout = 10000) + public void testActiveMQTopicFromPropertiesJNDI() throws Exception { + Properties properties = new Properties(); + properties.setProperty(TYPE, ActiveMQTopic.class.getName()); + properties.setProperty(FACTORY, JNDIReferenceFactory.class.getName()); + + String address = "foo.bar.topic"; + + properties.setProperty("address", address); + + Reference reference = from(properties); + ActiveMQTopic object = getObject(reference, ActiveMQTopic.class); + + assertEquals(address, object.getAddress()); + + } + + @Test(timeout = 10000) + public void testActiveMQConnectionFactoryFromPropertiesJNDI() throws Exception { + Properties properties = new Properties(); + properties.setProperty(TYPE, ActiveMQConnectionFactory.class.getName()); + properties.setProperty(FACTORY, JNDIReferenceFactory.class.getName()); + + String brokerURL = "vm://0"; + String connectionTTL = "1000"; + String preAcknowledge = "true"; + + properties.setProperty("brokerURL", brokerURL); + properties.setProperty("connectionTTL", connectionTTL); + properties.setProperty("preAcknowledge", preAcknowledge); + + Reference reference = from(properties); + ActiveMQConnectionFactory object = getObject(reference, ActiveMQConnectionFactory.class); + + assertEquals(Long.parseLong(connectionTTL), object.getConnectionTTL()); + assertEquals(Boolean.parseBoolean(preAcknowledge), object.isPreAcknowledge()); + + } + + private T getObject(Reference reference, Class tClass) throws Exception { + String factoryName = reference.getFactoryClassName(); + Class factoryClass = Class.forName(factoryName); + ObjectFactory factory = (ObjectFactory) factoryClass.newInstance(); + Object o = factory.getObjectInstance(reference, null, null, null); + if (tClass.isAssignableFrom(tClass)) { + return tClass.cast(o); + } else { + throw new IllegalStateException("Expected class, " + tClass.getName()); + } + } + + public Reference from(Properties properties) { + String type = (String) properties.remove("type"); + String factory = (String) properties.remove("factory"); + Reference result = new Reference(type, factory, null); + for (Enumeration iter = properties.propertyNames(); iter.hasMoreElements();) { + String key = (String)iter.nextElement(); + result.add(new StringRefAddr(key, properties.getProperty(key))); + } + return result; + } +} diff --git a/tests/unit-tests/src/test/java/org/apache/activemq/artemis/tests/unit/ra/ConnectionFactoryPropertiesTest.java b/tests/unit-tests/src/test/java/org/apache/activemq/artemis/tests/unit/ra/ConnectionFactoryPropertiesTest.java index b3ed958e5c..3901e1b43f 100644 --- a/tests/unit-tests/src/test/java/org/apache/activemq/artemis/tests/unit/ra/ConnectionFactoryPropertiesTest.java +++ b/tests/unit-tests/src/test/java/org/apache/activemq/artemis/tests/unit/ra/ConnectionFactoryPropertiesTest.java @@ -43,6 +43,9 @@ public class ConnectionFactoryPropertiesTest extends ActiveMQTestBase { UNSUPPORTED_CF_PROPERTIES.add("discoveryGroupName"); UNSUPPORTED_CF_PROPERTIES.add("incomingInterceptorList"); UNSUPPORTED_CF_PROPERTIES.add("outgoingInterceptorList"); + UNSUPPORTED_CF_PROPERTIES.add("user"); + UNSUPPORTED_CF_PROPERTIES.add("userName"); + UNSUPPORTED_CF_PROPERTIES.add("password"); UNSUPPORTED_RA_PROPERTIES = new TreeSet<>(); UNSUPPORTED_RA_PROPERTIES.add("HA"); @@ -62,6 +65,7 @@ public class ConnectionFactoryPropertiesTest extends ActiveMQTestBase { UNSUPPORTED_RA_PROPERTIES.add("useMaskedPassword"); UNSUPPORTED_RA_PROPERTIES.add("useAutoRecovery"); UNSUPPORTED_RA_PROPERTIES.add("useLocalTx"); + UNSUPPORTED_RA_PROPERTIES.add("user"); UNSUPPORTED_RA_PROPERTIES.add("userName"); UNSUPPORTED_RA_PROPERTIES.add("jgroupsChannelLocatorClass"); UNSUPPORTED_RA_PROPERTIES.add("jgroupsChannelRefName"); diff --git a/tests/unit-tests/src/test/java/org/apache/activemq/artemis/tests/unit/jms/referenceable/DestinationObjectFactoryTest.java b/tests/unit-tests/src/test/java/org/apache/activemq/artemis/tests/unit/ra/referenceable/DestinationObjectFactoryTest.java similarity index 88% rename from tests/unit-tests/src/test/java/org/apache/activemq/artemis/tests/unit/jms/referenceable/DestinationObjectFactoryTest.java rename to tests/unit-tests/src/test/java/org/apache/activemq/artemis/tests/unit/ra/referenceable/DestinationObjectFactoryTest.java index 7bbbf31c75..fedcfd90e7 100644 --- a/tests/unit-tests/src/test/java/org/apache/activemq/artemis/tests/unit/jms/referenceable/DestinationObjectFactoryTest.java +++ b/tests/unit-tests/src/test/java/org/apache/activemq/artemis/tests/unit/ra/referenceable/DestinationObjectFactoryTest.java @@ -14,13 +14,13 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.apache.activemq.artemis.tests.unit.jms.referenceable; +package org.apache.activemq.artemis.tests.unit.ra.referenceable; import javax.naming.Reference; +import javax.naming.spi.ObjectFactory; import org.apache.activemq.artemis.api.jms.ActiveMQJMSClient; import org.apache.activemq.artemis.jms.client.ActiveMQDestination; -import org.apache.activemq.artemis.jms.referenceable.DestinationObjectFactory; import org.apache.activemq.artemis.tests.util.ActiveMQTestBase; import org.apache.activemq.artemis.utils.RandomUtil; import org.junit.Assert; @@ -41,8 +41,9 @@ public class DestinationObjectFactoryTest extends ActiveMQTestBase { public void testReference() throws Exception { ActiveMQDestination queue = (ActiveMQDestination) ActiveMQJMSClient.createQueue(RandomUtil.randomString()); Reference reference = queue.getReference(); - - DestinationObjectFactory factory = new DestinationObjectFactory(); + String factoryName = reference.getFactoryClassName(); + Class factoryClass = Class.forName(factoryName); + ObjectFactory factory = (ObjectFactory) factoryClass.newInstance(); Object object = factory.getObjectInstance(reference, null, null, null); Assert.assertNotNull(object); Assert.assertTrue(object instanceof ActiveMQDestination);