From 5079ad10199b6b376abd5d872711a59e0a2492bf Mon Sep 17 00:00:00 2001 From: Clebert Suconic Date: Wed, 10 Feb 2021 17:51:10 +0100 Subject: [PATCH] [ARTEMIS-3113]: Artemis AMQP shouldn't depend on JMS. * removing the JMS dependency on AMQP module * fixing destinations usage. Jira: https://issues.apache.org/jira/browse/ARTEMIS-3113 --- .../artemis/utils/DestinationUtil.java | 56 +++++ .../jms/client/ActiveMQDestination.java | 23 +- .../artemis-amqp-protocol/pom.xml | 9 +- .../amqp/broker/ProtonProtocolManager.java | 4 +- .../amqp/converter/AMQPMessageSupport.java | 86 +++---- .../amqp/converter/AmqpCoreConverter.java | 40 ++-- .../amqp/converter/CoreAmqpConverter.java | 34 ++- .../protocol/amqp/converter/JMSConstants.java | 26 +++ .../converter/jms/ServerJMSBytesMessage.java | 88 +++---- .../converter/jms/ServerJMSMapMessage.java | 107 ++++----- .../amqp/converter/jms/ServerJMSMessage.java | 217 +++++++----------- .../converter/jms/ServerJMSObjectMessage.java | 11 +- .../converter/jms/ServerJMSStreamMessage.java | 130 ++++------- .../converter/jms/ServerJMSTextMessage.java | 11 +- .../proton/ProtonServerSenderContext.java | 4 +- .../amqp/converter/TestConversions.java | 2 +- .../JMSMappingInboundTransformerTest.java | 87 +++---- .../JMSMappingOutboundTransformerTest.java | 33 +-- 18 files changed, 411 insertions(+), 557 deletions(-) create mode 100644 artemis-commons/src/main/java/org/apache/activemq/artemis/utils/DestinationUtil.java create mode 100644 artemis-protocols/artemis-amqp-protocol/src/main/java/org/apache/activemq/artemis/protocol/amqp/converter/JMSConstants.java diff --git a/artemis-commons/src/main/java/org/apache/activemq/artemis/utils/DestinationUtil.java b/artemis-commons/src/main/java/org/apache/activemq/artemis/utils/DestinationUtil.java new file mode 100644 index 0000000000..5bf05e4ce1 --- /dev/null +++ b/artemis-commons/src/main/java/org/apache/activemq/artemis/utils/DestinationUtil.java @@ -0,0 +1,56 @@ +/* + * 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.utils; + +import org.apache.activemq.artemis.api.core.SimpleString; + +public class DestinationUtil { + + private static final char SEPARATOR = '.'; + + private static String escape(final String input) { + if (input == null) { + return ""; + } + return input.replace("\\", "\\\\").replace(".", "\\."); + } + + public static SimpleString createQueueNameForSubscription(final boolean isDurable, + final String clientID, + final String subscriptionName) { + final String queueName; + if (clientID != null) { + if (isDurable) { + queueName = escape(clientID) + SEPARATOR + + escape(subscriptionName); + } else { + queueName = "nonDurable" + SEPARATOR + + escape(clientID) + SEPARATOR + + escape(subscriptionName); + } + } else { + if (isDurable) { + queueName = escape(subscriptionName); + } else { + queueName = "nonDurable" + SEPARATOR + + escape(subscriptionName); + } + } + return SimpleString.toSimpleString(queueName); + } + +} 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 fbc542dc06..a5a0f227da 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 @@ -31,6 +31,7 @@ import org.apache.activemq.artemis.api.core.RoutingType; import org.apache.activemq.artemis.api.core.SimpleString; import org.apache.activemq.artemis.core.protocol.core.impl.PacketImpl; import org.apache.activemq.artemis.jndi.JNDIStorable; +import org.apache.activemq.artemis.utils.DestinationUtil; /** * ActiveMQ Artemis implementation of a JMS Destination. @@ -42,6 +43,8 @@ public class ActiveMQDestination extends JNDIStorable implements Destination, Se private static final long serialVersionUID = 5027962425462382883L; + // INFO: These variables are duplicated as part of AMQPMessageSupport in artemis-amqp-protocols + // The duplication there is to avoid a dependency on this module from a server's module public static final String QUEUE_QUALIFIED_PREFIX = "queue://"; public static final String TOPIC_QUALIFIED_PREFIX = "topic://"; public static final String TEMP_QUEUE_QUALIFED_PREFIX = "temp-queue://"; @@ -167,25 +170,7 @@ public class ActiveMQDestination extends JNDIStorable implements Destination, Se public static SimpleString createQueueNameForSubscription(final boolean isDurable, final String clientID, final String subscriptionName) { - final String queueName; - if (clientID != null) { - if (isDurable) { - queueName = ActiveMQDestination.escape(clientID) + SEPARATOR + - ActiveMQDestination.escape(subscriptionName); - } else { - queueName = "nonDurable" + SEPARATOR + - ActiveMQDestination.escape(clientID) + SEPARATOR + - ActiveMQDestination.escape(subscriptionName); - } - } else { - if (isDurable) { - queueName = ActiveMQDestination.escape(subscriptionName); - } else { - queueName = "nonDurable" + SEPARATOR + - ActiveMQDestination.escape(subscriptionName); - } - } - return SimpleString.toSimpleString(queueName); + return DestinationUtil.createQueueNameForSubscription(isDurable, clientID, subscriptionName); } public static String createQueueNameForSharedSubscription(final boolean isDurable, diff --git a/artemis-protocols/artemis-amqp-protocol/pom.xml b/artemis-protocols/artemis-amqp-protocol/pom.xml index 6eacbfb543..cc8e53a034 100644 --- a/artemis-protocols/artemis-amqp-protocol/pom.xml +++ b/artemis-protocols/artemis-amqp-protocol/pom.xml @@ -33,11 +33,11 @@ - + org.apache.activemq artemis-selector @@ -110,11 +110,6 @@ commons-collections test - - org.apache.geronimo.specs - geronimo-jms_2.0_spec - provided - junit junit diff --git a/artemis-protocols/artemis-amqp-protocol/src/main/java/org/apache/activemq/artemis/protocol/amqp/broker/ProtonProtocolManager.java b/artemis-protocols/artemis-amqp-protocol/src/main/java/org/apache/activemq/artemis/protocol/amqp/broker/ProtonProtocolManager.java index 4940819d64..57a53ac938 100644 --- a/artemis-protocols/artemis-amqp-protocol/src/main/java/org/apache/activemq/artemis/protocol/amqp/broker/ProtonProtocolManager.java +++ b/artemis-protocols/artemis-amqp-protocol/src/main/java/org/apache/activemq/artemis/protocol/amqp/broker/ProtonProtocolManager.java @@ -32,7 +32,6 @@ import org.apache.activemq.artemis.core.remoting.impl.netty.NettyServerConnectio import org.apache.activemq.artemis.core.server.ActiveMQServer; import org.apache.activemq.artemis.core.server.management.Notification; import org.apache.activemq.artemis.core.server.management.NotificationListener; -import org.apache.activemq.artemis.jms.client.ActiveMQDestination; import org.apache.activemq.artemis.protocol.amqp.client.ProtonClientProtocolManager; import org.apache.activemq.artemis.protocol.amqp.proton.AMQPConnectionContext; import org.apache.activemq.artemis.protocol.amqp.proton.AMQPConstants; @@ -47,6 +46,7 @@ import org.apache.activemq.artemis.spi.core.remoting.Acceptor; import org.apache.activemq.artemis.spi.core.remoting.Connection; import io.netty.channel.ChannelPipeline; +import org.apache.activemq.artemis.protocol.amqp.converter.AMQPMessageSupport; import org.jboss.logging.Logger; /** @@ -102,7 +102,7 @@ public class ProtonProtocolManager extends AbstractProtocolManager content, CoreMessageObjectPools coreMessageObjectPools) throws JMSException { + public static ServerJMSMapMessage createMapMessage(long id, Map content, CoreMessageObjectPools coreMessageObjectPools) throws Exception { ServerJMSMapMessage message = createMapMessage(id, coreMessageObjectPools); final Set> set = content.entrySet(); for (Map.Entry entry : set) { @@ -396,7 +364,8 @@ public final class AMQPMessageSupport { } - public static byte destinationType(Destination destination) { + // IMPORTANT-TODO: HOW TO GET THIS? + /*public static byte destinationType(Destination destination) { if (destination instanceof Queue) { if (destination instanceof TemporaryQueue) { return TEMP_QUEUE_TYPE; @@ -411,22 +380,27 @@ public final class AMQPMessageSupport { } } + return QUEUE_TYPE; + } */ + + public static byte destinationType(String destination) { + if (destination.startsWith(QUEUE_QUALIFIED_PREFIX)) { + return QUEUE_TYPE; + } + if (destination.startsWith(TOPIC_QUALIFIED_PREFIX)) { + return TOPIC_TYPE; + } + if (destination.startsWith(TEMP_QUEUE_QUALIFED_PREFIX)) { + return TEMP_QUEUE_TYPE; + } + if (destination.startsWith(TEMP_TOPIC_QUALIFED_PREFIX)) { + return TEMP_TOPIC_TYPE; + } return QUEUE_TYPE; } - public static Destination destination(byte destinationType, String address) { - switch (destinationType) { - case TEMP_QUEUE_TYPE: - return new ActiveMQTemporaryQueue(address, null); - case TEMP_TOPIC_TYPE: - return new ActiveMQTemporaryTopic(address, null); - case TOPIC_TYPE: - return new ActiveMQTopic(address); - case QUEUE_TYPE: - return new ActiveMQQueue(address); - default: - return new ActiveMQQueue(address); - } + public static String destination(byte destinationType, String address) { + return address; } } diff --git a/artemis-protocols/artemis-amqp-protocol/src/main/java/org/apache/activemq/artemis/protocol/amqp/converter/AmqpCoreConverter.java b/artemis-protocols/artemis-amqp-protocol/src/main/java/org/apache/activemq/artemis/protocol/amqp/converter/AmqpCoreConverter.java index 564291f88d..264f794ef8 100644 --- a/artemis-protocols/artemis-amqp-protocol/src/main/java/org/apache/activemq/artemis/protocol/amqp/converter/AmqpCoreConverter.java +++ b/artemis-protocols/artemis-amqp-protocol/src/main/java/org/apache/activemq/artemis/protocol/amqp/converter/AmqpCoreConverter.java @@ -39,7 +39,11 @@ import static org.apache.activemq.artemis.protocol.amqp.converter.AMQPMessageSup import static org.apache.activemq.artemis.protocol.amqp.converter.AMQPMessageSupport.JMS_AMQP_ORIGINAL_ENCODING; import static org.apache.activemq.artemis.protocol.amqp.converter.AMQPMessageSupport.JMS_AMQP_REPLYTO_GROUP_ID; import static org.apache.activemq.artemis.protocol.amqp.converter.AMQPMessageSupport.OCTET_STREAM_CONTENT_TYPE; +import static org.apache.activemq.artemis.protocol.amqp.converter.AMQPMessageSupport.QUEUE_QUALIFIED_PREFIX; import static org.apache.activemq.artemis.protocol.amqp.converter.AMQPMessageSupport.SERIALIZED_JAVA_OBJECT_CONTENT_TYPE; +import static org.apache.activemq.artemis.protocol.amqp.converter.AMQPMessageSupport.TEMP_QUEUE_QUALIFED_PREFIX; +import static org.apache.activemq.artemis.protocol.amqp.converter.AMQPMessageSupport.TEMP_TOPIC_QUALIFED_PREFIX; +import static org.apache.activemq.artemis.protocol.amqp.converter.AMQPMessageSupport.TOPIC_QUALIFIED_PREFIX; import static org.apache.activemq.artemis.protocol.amqp.converter.AMQPMessageSupport.createBytesMessage; import static org.apache.activemq.artemis.protocol.amqp.converter.AMQPMessageSupport.createMapMessage; import static org.apache.activemq.artemis.protocol.amqp.converter.AMQPMessageSupport.createMessage; @@ -60,13 +64,9 @@ import java.util.Map; import java.util.Set; import java.util.UUID; -import javax.jms.DeliveryMode; -import javax.jms.JMSException; - import org.apache.activemq.artemis.api.core.ActiveMQPropertyConversionException; import org.apache.activemq.artemis.api.core.ICoreMessage; import org.apache.activemq.artemis.core.persistence.CoreMessageObjectPools; -import org.apache.activemq.artemis.jms.client.ActiveMQDestination; import org.apache.activemq.artemis.protocol.amqp.broker.AMQPMessage; import org.apache.activemq.artemis.protocol.amqp.converter.jms.ServerJMSMessage; import org.apache.activemq.artemis.protocol.amqp.converter.jms.ServerJMSStreamMessage; @@ -98,12 +98,14 @@ import org.apache.qpid.proton.codec.WritableBuffer; import io.netty.buffer.ByteBuf; import io.netty.buffer.PooledByteBufAllocator; +import static org.apache.activemq.artemis.protocol.amqp.converter.JMSConstants.DeliveryMode_NON_PERSISTENT; +import static org.apache.activemq.artemis.protocol.amqp.converter.JMSConstants.DeliveryMode_PERSISTENT; +import static org.apache.activemq.artemis.protocol.amqp.converter.JMSConstants.MESSAGE_DEFAULT_PRIORITY; /** * This class was created just to separate concerns on AMQPConverter. * For better organization of the code. * */ public class AmqpCoreConverter { - public static ICoreMessage toCore(AMQPMessage message, CoreMessageObjectPools coreMessageObjectPools) throws Exception { return message.toCore(coreMessageObjectPools); } @@ -215,7 +217,7 @@ public class AmqpCoreConverter { // If the JMS expiration has not yet been set... if (header != null && result.getJMSExpiration() == 0) { // Then lets try to set it based on the message TTL. - long ttl = javax.jms.Message.DEFAULT_TIME_TO_LIVE; + long ttl = JMSConstants.MESSAGE_DEFAULT_TIME_TO_LIVE; if (header.getTtl() != null) { ttl = header.getTtl().longValue(); } @@ -242,16 +244,16 @@ public class AmqpCoreConverter { if (header.getDurable() != null) { jms.setBooleanProperty(JMS_AMQP_HEADER_DURABLE, true); - jms.setJMSDeliveryMode(header.getDurable().booleanValue() ? DeliveryMode.PERSISTENT : DeliveryMode.NON_PERSISTENT); + jms.setJMSDeliveryMode(header.getDurable().booleanValue() ? DeliveryMode_PERSISTENT : DeliveryMode_NON_PERSISTENT); } else { - jms.setJMSDeliveryMode(DeliveryMode.NON_PERSISTENT); + jms.setJMSDeliveryMode(DeliveryMode_NON_PERSISTENT); } if (header.getPriority() != null) { jms.setBooleanProperty(JMS_AMQP_HEADER_PRIORITY, true); jms.setJMSPriority(header.getPriority().intValue()); } else { - jms.setJMSPriority(javax.jms.Message.DEFAULT_PRIORITY); + jms.setJMSPriority(MESSAGE_DEFAULT_PRIORITY); } if (header.getFirstAcquirer() != null) { @@ -264,8 +266,8 @@ public class AmqpCoreConverter { jms.setLongProperty("JMSXDeliveryCount", header.getDeliveryCount().longValue() + 1); } } else { - jms.setJMSPriority((byte) javax.jms.Message.DEFAULT_PRIORITY); - jms.setJMSDeliveryMode(DeliveryMode.NON_PERSISTENT); + jms.setJMSPriority((byte) MESSAGE_DEFAULT_PRIORITY); + jms.setJMSDeliveryMode(DeliveryMode_NON_PERSISTENT); } return jms; @@ -337,7 +339,7 @@ public class AmqpCoreConverter { } if (properties.getTo() != null) { byte queueType = parseQueueAnnotation(annotations, AMQPMessageSupport.JMS_DEST_TYPE_MSG_ANNOTATION); - jms.setJMSDestination(AMQPMessageSupport.destination(queueType, properties.getTo())); + jms.setJMSDestination(properties.getTo()); } if (properties.getSubject() != null) { jms.setJMSType(properties.getSubject()); @@ -347,19 +349,19 @@ public class AmqpCoreConverter { switch (value) { case AMQPMessageSupport.QUEUE_TYPE: - org.apache.activemq.artemis.reader.MessageUtil.setJMSReplyTo(jms.getInnerMessage(), ActiveMQDestination.QUEUE_QUALIFIED_PREFIX + properties.getReplyTo()); + org.apache.activemq.artemis.reader.MessageUtil.setJMSReplyTo(jms.getInnerMessage(), QUEUE_QUALIFIED_PREFIX + properties.getReplyTo()); break; case AMQPMessageSupport.TEMP_QUEUE_TYPE: - org.apache.activemq.artemis.reader.MessageUtil.setJMSReplyTo(jms.getInnerMessage(), ActiveMQDestination.TEMP_QUEUE_QUALIFED_PREFIX + properties.getReplyTo()); + org.apache.activemq.artemis.reader.MessageUtil.setJMSReplyTo(jms.getInnerMessage(), TEMP_QUEUE_QUALIFED_PREFIX + properties.getReplyTo()); break; case AMQPMessageSupport.TOPIC_TYPE: - org.apache.activemq.artemis.reader.MessageUtil.setJMSReplyTo(jms.getInnerMessage(), ActiveMQDestination.TOPIC_QUALIFIED_PREFIX + properties.getReplyTo()); + org.apache.activemq.artemis.reader.MessageUtil.setJMSReplyTo(jms.getInnerMessage(), TOPIC_QUALIFIED_PREFIX + properties.getReplyTo()); break; case AMQPMessageSupport.TEMP_TOPIC_TYPE: - org.apache.activemq.artemis.reader.MessageUtil.setJMSReplyTo(jms.getInnerMessage(), ActiveMQDestination.TEMP_TOPIC_QUALIFED_PREFIX + properties.getReplyTo()); + org.apache.activemq.artemis.reader.MessageUtil.setJMSReplyTo(jms.getInnerMessage(), TEMP_TOPIC_QUALIFED_PREFIX + properties.getReplyTo()); break; default: - org.apache.activemq.artemis.reader.MessageUtil.setJMSReplyTo(jms.getInnerMessage(), ActiveMQDestination.QUEUE_QUALIFIED_PREFIX + properties.getReplyTo()); + org.apache.activemq.artemis.reader.MessageUtil.setJMSReplyTo(jms.getInnerMessage(), QUEUE_QUALIFIED_PREFIX + properties.getReplyTo()); break; } } @@ -425,7 +427,7 @@ public class AmqpCoreConverter { return jms; } - private static void encodeUnsupportedMessagePropertyType(ServerJMSMessage jms, String key, Object value) throws JMSException { + private static void encodeUnsupportedMessagePropertyType(ServerJMSMessage jms, String key, Object value) throws Exception { final ByteBuf buffer = PooledByteBufAllocator.DEFAULT.heapBuffer(); final EncoderImpl encoder = TLSEncode.getEncoder(); @@ -444,7 +446,7 @@ public class AmqpCoreConverter { } } - private static void setProperty(javax.jms.Message msg, String key, Object value) throws JMSException { + private static void setProperty(ServerJMSMessage msg, String key, Object value) throws Exception { if (value instanceof UnsignedLong) { long v = ((UnsignedLong) value).longValue(); msg.setLongProperty(key, v); diff --git a/artemis-protocols/artemis-amqp-protocol/src/main/java/org/apache/activemq/artemis/protocol/amqp/converter/CoreAmqpConverter.java b/artemis-protocols/artemis-amqp-protocol/src/main/java/org/apache/activemq/artemis/protocol/amqp/converter/CoreAmqpConverter.java index 0353093529..3725a3069b 100644 --- a/artemis-protocols/artemis-amqp-protocol/src/main/java/org/apache/activemq/artemis/protocol/amqp/converter/CoreAmqpConverter.java +++ b/artemis-protocols/artemis-amqp-protocol/src/main/java/org/apache/activemq/artemis/protocol/amqp/converter/CoreAmqpConverter.java @@ -45,10 +45,9 @@ import static org.apache.activemq.artemis.protocol.amqp.converter.AMQPMessageSup import static org.apache.activemq.artemis.protocol.amqp.converter.AMQPMessageSupport.JMS_AMQP_PREFIX; import static org.apache.activemq.artemis.protocol.amqp.converter.AMQPMessageSupport.JMS_AMQP_PROPERTIES; import static org.apache.activemq.artemis.protocol.amqp.converter.AMQPMessageSupport.JMS_AMQP_REPLYTO_GROUP_ID; +import static org.apache.activemq.artemis.protocol.amqp.converter.AMQPMessageSupport.SERIALIZED_JAVA_OBJECT_CONTENT_TYPE; import static org.apache.activemq.artemis.protocol.amqp.converter.AMQPMessageSupport.JMS_DEST_TYPE_MSG_ANNOTATION; import static org.apache.activemq.artemis.protocol.amqp.converter.AMQPMessageSupport.JMS_REPLY_TO_TYPE_MSG_ANNOTATION; -import static org.apache.activemq.artemis.protocol.amqp.converter.AMQPMessageSupport.SERIALIZED_JAVA_OBJECT_CONTENT_TYPE; -import static org.apache.activemq.artemis.protocol.amqp.converter.AMQPMessageSupport.toAddress; import java.nio.charset.StandardCharsets; import java.util.ArrayList; @@ -59,11 +58,6 @@ import java.util.LinkedHashMap; import java.util.Map; import java.util.Set; -import javax.jms.Destination; -import javax.jms.JMSException; -import javax.jms.MessageEOFException; -import javax.jms.TextMessage; - import org.apache.activemq.artemis.api.core.ActiveMQBuffer; import org.apache.activemq.artemis.api.core.ICoreMessage; import org.apache.activemq.artemis.api.core.Message; @@ -149,7 +143,7 @@ public class CoreAmqpConverter { header.setDurable(true); } byte priority = (byte) message.getJMSPriority(); - if (priority != javax.jms.Message.DEFAULT_PRIORITY) { + if (priority != JMSConstants.MESSAGE_DEFAULT_PRIORITY) { if (header == null) { header = new Header(); } @@ -171,15 +165,15 @@ public class CoreAmqpConverter { properties.setMessageId("ID:" + message.getInnerMessage().getUserID().toString()); } } - Destination destination = message.getJMSDestination(); + SimpleString destination = message.getJMSDestination(); if (destination != null) { - properties.setTo(toAddress(destination)); - maMap.put(JMS_DEST_TYPE_MSG_ANNOTATION, AMQPMessageSupport.destinationType(destination)); + properties.setTo(destination.toString()); + maMap.put(JMS_DEST_TYPE_MSG_ANNOTATION, AMQPMessageSupport.destinationType(destination.toString())); } - Destination replyTo = message.getJMSReplyTo(); + SimpleString replyTo = message.getJMSReplyTo(); if (replyTo != null) { - properties.setReplyTo(toAddress(replyTo)); - maMap.put(JMS_REPLY_TO_TYPE_MSG_ANNOTATION, AMQPMessageSupport.destinationType(replyTo)); + properties.setReplyTo(replyTo.toString()); + maMap.put(JMS_REPLY_TO_TYPE_MSG_ANNOTATION, AMQPMessageSupport.destinationType(replyTo.toString())); } Object correlationID = message.getInnerMessage().getCorrelationID(); @@ -393,7 +387,7 @@ public class CoreAmqpConverter { return decodedType; } - private static Section convertBody(ServerJMSMessage message, Map maMap, Properties properties) throws JMSException { + private static Section convertBody(ServerJMSMessage message, Map maMap, Properties properties) throws Exception { Section body = null; short orignalEncoding = AMQP_UNKNOWN; @@ -425,7 +419,7 @@ public class CoreAmqpConverter { break; } } else if (message instanceof ServerJMSTextMessage) { - String text = (((TextMessage) message).getText()); + String text = (((ServerJMSTextMessage) message).getText()); switch (orignalEncoding) { case AMQP_NULL: @@ -456,7 +450,7 @@ public class CoreAmqpConverter { while (true) { list.add(m.readObject()); } - } catch (MessageEOFException e) { + } catch (Exception e) { } switch (orignalEncoding) { @@ -521,7 +515,7 @@ public class CoreAmqpConverter { return body; } - private static Binary getBinaryFromMessageBody(ServerJMSBytesMessage message) throws JMSException { + private static Binary getBinaryFromMessageBody(ServerJMSBytesMessage message) throws Exception { byte[] data = new byte[(int) message.getBodyLength()]; message.readBytes(data); message.reset(); // Need to reset after readBytes or future readBytes @@ -529,11 +523,11 @@ public class CoreAmqpConverter { return new Binary(data); } - private static Binary getBinaryFromMessageBody(ServerJMSObjectMessage message) throws JMSException { + private static Binary getBinaryFromMessageBody(ServerJMSObjectMessage message) throws Exception { return message.getSerializedForm(); } - private static Map getMapFromMessageBody(ServerJMSMapMessage message) throws JMSException { + private static Map getMapFromMessageBody(ServerJMSMapMessage message) throws Exception { final HashMap map = new LinkedHashMap<>(); @SuppressWarnings("unchecked") diff --git a/artemis-protocols/artemis-amqp-protocol/src/main/java/org/apache/activemq/artemis/protocol/amqp/converter/JMSConstants.java b/artemis-protocols/artemis-amqp-protocol/src/main/java/org/apache/activemq/artemis/protocol/amqp/converter/JMSConstants.java new file mode 100644 index 0000000000..fdd5537ab4 --- /dev/null +++ b/artemis-protocols/artemis-amqp-protocol/src/main/java/org/apache/activemq/artemis/protocol/amqp/converter/JMSConstants.java @@ -0,0 +1,26 @@ +/* + * 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.protocol.amqp.converter; + +public class JMSConstants { + public static final int DeliveryMode_NON_PERSISTENT = 1; + public static final int DeliveryMode_PERSISTENT = 2; + + public static final long MESSAGE_DEFAULT_TIME_TO_LIVE = 0; + + public static final int MESSAGE_DEFAULT_PRIORITY = 4; +} diff --git a/artemis-protocols/artemis-amqp-protocol/src/main/java/org/apache/activemq/artemis/protocol/amqp/converter/jms/ServerJMSBytesMessage.java b/artemis-protocols/artemis-amqp-protocol/src/main/java/org/apache/activemq/artemis/protocol/amqp/converter/jms/ServerJMSBytesMessage.java index f7f2a0de49..1fbe469040 100644 --- a/artemis-protocols/artemis-amqp-protocol/src/main/java/org/apache/activemq/artemis/protocol/amqp/converter/jms/ServerJMSBytesMessage.java +++ b/artemis-protocols/artemis-amqp-protocol/src/main/java/org/apache/activemq/artemis/protocol/amqp/converter/jms/ServerJMSBytesMessage.java @@ -16,9 +16,6 @@ */ package org.apache.activemq.artemis.protocol.amqp.converter.jms; -import javax.jms.BytesMessage; -import javax.jms.JMSException; - import org.apache.activemq.artemis.api.core.ICoreMessage; import static org.apache.activemq.artemis.reader.BytesMessageUtil.bytesMessageReset; @@ -46,142 +43,116 @@ import static org.apache.activemq.artemis.reader.BytesMessageUtil.bytesWriteObje import static org.apache.activemq.artemis.reader.BytesMessageUtil.bytesWriteShort; import static org.apache.activemq.artemis.reader.BytesMessageUtil.bytesWriteUTF; -public class ServerJMSBytesMessage extends ServerJMSMessage implements BytesMessage { +public class ServerJMSBytesMessage extends ServerJMSMessage { public ServerJMSBytesMessage(ICoreMessage message) { super(message); } - @Override - public long getBodyLength() throws JMSException { + public long getBodyLength() throws Exception { return message.getBodyBufferSize(); } - @Override - public boolean readBoolean() throws JMSException { + public boolean readBoolean() throws Exception { return bytesReadBoolean(getReadBodyBuffer()); } - @Override - public byte readByte() throws JMSException { + public byte readByte() throws Exception { return bytesReadByte(getReadBodyBuffer()); } - @Override - public int readUnsignedByte() throws JMSException { + public int readUnsignedByte() throws Exception { return bytesReadUnsignedByte(getReadBodyBuffer()); } - @Override - public short readShort() throws JMSException { + public short readShort() throws Exception { return bytesReadShort(getReadBodyBuffer()); } - @Override - public int readUnsignedShort() throws JMSException { + public int readUnsignedShort() throws Exception { return bytesReadUnsignedShort(getReadBodyBuffer()); } - @Override - public char readChar() throws JMSException { + public char readChar() throws Exception { return bytesReadChar(getReadBodyBuffer()); } - @Override - public int readInt() throws JMSException { + public int readInt() throws Exception { return bytesReadInt(getReadBodyBuffer()); } - @Override - public long readLong() throws JMSException { + public long readLong() throws Exception { return bytesReadLong(getReadBodyBuffer()); } - @Override - public float readFloat() throws JMSException { + public float readFloat() throws Exception { return bytesReadFloat(getReadBodyBuffer()); } - @Override - public double readDouble() throws JMSException { + public double readDouble() throws Exception { return bytesReadDouble(getReadBodyBuffer()); } - @Override - public String readUTF() throws JMSException { + public String readUTF() throws Exception { return bytesReadUTF(getReadBodyBuffer()); } - @Override - public int readBytes(byte[] value) throws JMSException { + public int readBytes(byte[] value) throws Exception { return bytesReadBytes(getReadBodyBuffer(), value); } - @Override - public int readBytes(byte[] value, int length) throws JMSException { + public int readBytes(byte[] value, int length) throws Exception { return bytesReadBytes(getReadBodyBuffer(), value, length); } - @Override - public void writeBoolean(boolean value) throws JMSException { + public void writeBoolean(boolean value) throws Exception { bytesWriteBoolean(getWriteBodyBuffer(), value); } - @Override - public void writeByte(byte value) throws JMSException { + public void writeByte(byte value) throws Exception { bytesWriteByte(getWriteBodyBuffer(), value); } - @Override - public void writeShort(short value) throws JMSException { + public void writeShort(short value) throws Exception { bytesWriteShort(getWriteBodyBuffer(), value); } - @Override - public void writeChar(char value) throws JMSException { + public void writeChar(char value) throws Exception { bytesWriteChar(getWriteBodyBuffer(), value); } - @Override - public void writeInt(int value) throws JMSException { + public void writeInt(int value) throws Exception { bytesWriteInt(getWriteBodyBuffer(), value); } - @Override - public void writeLong(long value) throws JMSException { + public void writeLong(long value) throws Exception { bytesWriteLong(getWriteBodyBuffer(), value); } - @Override - public void writeFloat(float value) throws JMSException { + public void writeFloat(float value) throws Exception { bytesWriteFloat(getWriteBodyBuffer(), value); } - @Override - public void writeDouble(double value) throws JMSException { + public void writeDouble(double value) throws Exception { bytesWriteDouble(getWriteBodyBuffer(), value); } - @Override - public void writeUTF(String value) throws JMSException { + public void writeUTF(String value) throws Exception { bytesWriteUTF(getWriteBodyBuffer(), value); } - @Override - public void writeBytes(byte[] value) throws JMSException { + public void writeBytes(byte[] value) throws Exception { bytesWriteBytes(getWriteBodyBuffer(), value); } - @Override - public void writeBytes(byte[] value, int offset, int length) throws JMSException { + public void writeBytes(byte[] value, int offset, int length) throws Exception { bytesWriteBytes(getWriteBodyBuffer(), value, offset, length); } - @Override - public void writeObject(Object value) throws JMSException { + public void writeObject(Object value) throws Exception { if (!bytesWriteObject(getWriteBodyBuffer(), value)) { - throw new JMSException("Can't make conversion of " + value + " to any known type"); + throw new Exception("Can't make conversion of " + value + " to any known type"); } } @@ -198,8 +169,7 @@ public class ServerJMSBytesMessage extends ServerJMSMessage implements BytesMess } - @Override - public void reset() throws JMSException { + public void reset() throws Exception { if (!message.isLargeMessage()) { bytesMessageReset(getReadBodyBuffer()); bytesMessageReset(getWriteBodyBuffer()); diff --git a/artemis-protocols/artemis-amqp-protocol/src/main/java/org/apache/activemq/artemis/protocol/amqp/converter/jms/ServerJMSMapMessage.java b/artemis-protocols/artemis-amqp-protocol/src/main/java/org/apache/activemq/artemis/protocol/amqp/converter/jms/ServerJMSMapMessage.java index 9ee86af41a..db8785caa1 100644 --- a/artemis-protocols/artemis-amqp-protocol/src/main/java/org/apache/activemq/artemis/protocol/amqp/converter/jms/ServerJMSMapMessage.java +++ b/artemis-protocols/artemis-amqp-protocol/src/main/java/org/apache/activemq/artemis/protocol/amqp/converter/jms/ServerJMSMapMessage.java @@ -16,9 +16,7 @@ */ package org.apache.activemq.artemis.protocol.amqp.converter.jms; -import javax.jms.JMSException; -import javax.jms.MapMessage; -import javax.jms.MessageFormatException; + import java.util.Collections; import java.util.Enumeration; @@ -38,7 +36,7 @@ import static org.apache.activemq.artemis.reader.MapMessageUtil.writeBodyMap; /** * ActiveMQ Artemis implementation of a JMS MapMessage. */ -public final class ServerJMSMapMessage extends ServerJMSMessage implements MapMessage { +public final class ServerJMSMapMessage extends ServerJMSMessage { // Constants ----------------------------------------------------- public static final byte TYPE = Message.MAP_TYPE; @@ -61,68 +59,56 @@ public final class ServerJMSMapMessage extends ServerJMSMessage implements MapMe // MapMessage implementation ------------------------------------- - @Override - public void setBoolean(final String name, final boolean value) throws JMSException { + public void setBoolean(final String name, final boolean value) throws Exception { map.putBooleanProperty(new SimpleString(name), value); } - @Override - public void setByte(final String name, final byte value) throws JMSException { + public void setByte(final String name, final byte value) throws Exception { map.putByteProperty(new SimpleString(name), value); } - @Override - public void setShort(final String name, final short value) throws JMSException { + public void setShort(final String name, final short value) throws Exception { map.putShortProperty(new SimpleString(name), value); } - @Override - public void setChar(final String name, final char value) throws JMSException { + public void setChar(final String name, final char value) throws Exception { map.putCharProperty(new SimpleString(name), value); } - @Override - public void setInt(final String name, final int value) throws JMSException { + public void setInt(final String name, final int value) throws Exception { map.putIntProperty(new SimpleString(name), value); } - @Override - public void setLong(final String name, final long value) throws JMSException { + public void setLong(final String name, final long value) throws Exception { map.putLongProperty(new SimpleString(name), value); } - @Override - public void setFloat(final String name, final float value) throws JMSException { + public void setFloat(final String name, final float value) throws Exception { map.putFloatProperty(new SimpleString(name), value); } - @Override - public void setDouble(final String name, final double value) throws JMSException { + public void setDouble(final String name, final double value) throws Exception { map.putDoubleProperty(new SimpleString(name), value); } - @Override - public void setString(final String name, final String value) throws JMSException { + public void setString(final String name, final String value) throws Exception { map.putSimpleStringProperty(new SimpleString(name), value == null ? null : new SimpleString(value)); } - @Override - public void setBytes(final String name, final byte[] value) throws JMSException { + public void setBytes(final String name, final byte[] value) throws Exception { map.putBytesProperty(new SimpleString(name), value); } - @Override - public void setBytes(final String name, final byte[] value, final int offset, final int length) throws JMSException { + public void setBytes(final String name, final byte[] value, final int offset, final int length) throws Exception { if (offset + length > value.length) { - throw new JMSException("Invalid offset/length"); + throw new Exception("Invalid offset/length"); } byte[] newBytes = new byte[length]; System.arraycopy(value, offset, newBytes, 0, length); map.putBytesProperty(new SimpleString(name), newBytes); } - @Override - public void setObject(final String name, final Object value) throws JMSException { + public void setObject(final String name, final Object value) throws Exception { try { // primitives and String Object val = value; @@ -137,84 +123,75 @@ public final class ServerJMSMapMessage extends ServerJMSMessage implements MapMe } TypedProperties.setObjectProperty(new SimpleString(name), val, map); } catch (ActiveMQPropertyConversionException e) { - throw new MessageFormatException(e.getMessage()); + throw new RuntimeException(e.getMessage()); } } - @Override - public boolean getBoolean(final String name) throws JMSException { + public boolean getBoolean(final String name) throws Exception { try { return map.getBooleanProperty(new SimpleString(name)); } catch (ActiveMQPropertyConversionException e) { - throw new MessageFormatException(e.getMessage()); + throw new RuntimeException(e.getMessage()); } } - @Override - public byte getByte(final String name) throws JMSException { + public byte getByte(final String name) throws Exception { try { return map.getByteProperty(new SimpleString(name)); } catch (ActiveMQPropertyConversionException e) { - throw new MessageFormatException(e.getMessage()); + throw new RuntimeException(e.getMessage()); } } - @Override - public short getShort(final String name) throws JMSException { + public short getShort(final String name) throws Exception { try { return map.getShortProperty(new SimpleString(name)); } catch (ActiveMQPropertyConversionException e) { - throw new MessageFormatException(e.getMessage()); + throw new RuntimeException(e.getMessage()); } } - @Override - public char getChar(final String name) throws JMSException { + public char getChar(final String name) throws Exception { try { return map.getCharProperty(new SimpleString(name)); } catch (ActiveMQPropertyConversionException e) { - throw new MessageFormatException(e.getMessage()); + throw new RuntimeException(e.getMessage()); } } - @Override - public int getInt(final String name) throws JMSException { + public int getInt(final String name) throws Exception { try { return map.getIntProperty(new SimpleString(name)); } catch (ActiveMQPropertyConversionException e) { - throw new MessageFormatException(e.getMessage()); + throw new RuntimeException(e.getMessage()); } } - @Override - public long getLong(final String name) throws JMSException { + public long getLong(final String name) throws Exception { try { return map.getLongProperty(new SimpleString(name)); } catch (ActiveMQPropertyConversionException e) { - throw new MessageFormatException(e.getMessage()); + throw new RuntimeException(e.getMessage()); } } - @Override - public float getFloat(final String name) throws JMSException { + public float getFloat(final String name) throws Exception { try { return map.getFloatProperty(new SimpleString(name)); } catch (ActiveMQPropertyConversionException e) { - throw new MessageFormatException(e.getMessage()); + throw new RuntimeException(e.getMessage()); } } - @Override - public double getDouble(final String name) throws JMSException { + public double getDouble(final String name) throws Exception { try { return map.getDoubleProperty(new SimpleString(name)); } catch (ActiveMQPropertyConversionException e) { - throw new MessageFormatException(e.getMessage()); + throw new RuntimeException(e.getMessage()); } } - @Override - public String getString(final String name) throws JMSException { + public String getString(final String name) throws Exception { try { SimpleString str = map.getSimpleStringProperty(new SimpleString(name)); if (str == null) { @@ -223,21 +200,19 @@ public final class ServerJMSMapMessage extends ServerJMSMessage implements MapMe return str.toString(); } } catch (ActiveMQPropertyConversionException e) { - throw new MessageFormatException(e.getMessage()); + throw new RuntimeException(e.getMessage()); } } - @Override - public byte[] getBytes(final String name) throws JMSException { + public byte[] getBytes(final String name) throws Exception { try { return map.getBytesProperty(new SimpleString(name)); } catch (ActiveMQPropertyConversionException e) { - throw new MessageFormatException(e.getMessage()); + throw new RuntimeException(e.getMessage()); } } - @Override - public Object getObject(final String name) throws JMSException { + public Object getObject(final String name) throws Exception { Object val = map.getProperty(new SimpleString(name)); if (val instanceof SimpleString) { @@ -247,18 +222,16 @@ public final class ServerJMSMapMessage extends ServerJMSMessage implements MapMe return val; } - @Override - public Enumeration getMapNames() throws JMSException { + public Enumeration getMapNames() throws Exception { return Collections.enumeration(map.getMapNames()); } - @Override - public boolean itemExists(final String name) throws JMSException { + public boolean itemExists(final String name) throws Exception { return map.containsProperty(new SimpleString(name)); } @Override - public void clearBody() throws JMSException { + public void clearBody() throws Exception { super.clearBody(); map.clear(); 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 ea719f4622..37753224b1 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 @@ -16,17 +16,13 @@ */ package org.apache.activemq.artemis.protocol.amqp.converter.jms; -import javax.jms.DeliveryMode; -import javax.jms.Destination; -import javax.jms.JMSException; -import javax.jms.Message; + import java.util.Collections; import java.util.Enumeration; import org.apache.activemq.artemis.api.core.ActiveMQBuffer; import org.apache.activemq.artemis.api.core.ICoreMessage; import org.apache.activemq.artemis.api.core.SimpleString; -import org.apache.activemq.artemis.jms.client.ActiveMQDestination; import org.apache.activemq.artemis.reader.MessageUtil; import static org.apache.activemq.artemis.api.core.FilterConstants.NATIVE_MESSAGE_ID; @@ -36,7 +32,10 @@ import static org.apache.activemq.artemis.api.core.Message.OBJECT_TYPE; import static org.apache.activemq.artemis.api.core.Message.STREAM_TYPE; import static org.apache.activemq.artemis.api.core.Message.TEXT_TYPE; -public class ServerJMSMessage implements Message { +import static org.apache.activemq.artemis.protocol.amqp.converter.JMSConstants.DeliveryMode_NON_PERSISTENT; +import static org.apache.activemq.artemis.protocol.amqp.converter.JMSConstants.DeliveryMode_PERSISTENT; + +public class ServerJMSMessage { protected final ICoreMessage message; private ActiveMQBuffer readBodyBuffer; @@ -68,6 +67,7 @@ public class ServerJMSMessage implements Message { /** * When reading we use a protected copy so multi-threads can work fine + * @return */ protected ActiveMQBuffer getReadBodyBuffer() { if (readBodyBuffer == null) { @@ -79,52 +79,46 @@ public class ServerJMSMessage implements Message { /** * When writing on the conversion we use the buffer directly + * @return */ protected ActiveMQBuffer getWriteBodyBuffer() { readBodyBuffer = null; // it invalidates this buffer if anything is written return message.getBodyBuffer(); } - @Override - public final String getJMSMessageID() throws JMSException { + public final String getJMSMessageID() throws Exception { if (message.containsProperty(NATIVE_MESSAGE_ID)) { return getStringProperty(NATIVE_MESSAGE_ID); } return null; } - @Override - public final void setJMSMessageID(String id) throws JMSException { + public final void setJMSMessageID(String id) throws Exception { if (id != null) { message.putStringProperty(NATIVE_MESSAGE_ID, id); } } - @Override - public final long getJMSTimestamp() throws JMSException { + public final long getJMSTimestamp() throws Exception { return message.getTimestamp(); } - @Override - public final void setJMSTimestamp(long timestamp) throws JMSException { + public final void setJMSTimestamp(long timestamp) throws Exception { message.setTimestamp(timestamp); } - @Override - public final byte[] getJMSCorrelationIDAsBytes() throws JMSException { + public final byte[] getJMSCorrelationIDAsBytes() throws Exception { return MessageUtil.getJMSCorrelationIDAsBytes(message); } - @Override - public final void setJMSCorrelationIDAsBytes(byte[] correlationID) throws JMSException { + public final void setJMSCorrelationIDAsBytes(byte[] correlationID) throws Exception { if (correlationID == null || correlationID.length == 0) { - throw new JMSException("Please specify a non-zero length byte[]"); + throw new Exception("Please specify a non-zero length byte[]"); } message.setCorrelationID(correlationID); } - @Override - public final String getJMSCorrelationID() throws JMSException { + public final String getJMSCorrelationID() throws Exception { Object correlationID = message.getCorrelationID(); if (correlationID instanceof String) { @@ -137,226 +131,178 @@ public class ServerJMSMessage implements Message { } } - @Override - public final void setJMSCorrelationID(String correlationID) throws JMSException { + public final void setJMSCorrelationID(String correlationID) throws Exception { message.setCorrelationID(correlationID); } - @Override - public final Destination getJMSReplyTo() throws JMSException { - SimpleString reply = MessageUtil.getJMSReplyTo(message); - if (reply != null) { - return ActiveMQDestination.fromPrefixedName(reply.toString()); - } else { - return null; + public final SimpleString getJMSReplyTo() throws Exception { + return MessageUtil.getJMSReplyTo(message); + } + + public final void setJMSReplyTo(String replyTo) throws Exception { + MessageUtil.setJMSReplyTo(message, SimpleString.toSimpleString(replyTo)); + } + + public SimpleString getJMSDestination() throws Exception { + return message.getAddressSimpleString(); + } + + public final void setJMSDestination(String destination) throws Exception { + message.setAddress(destination); + } + + public final int getJMSDeliveryMode() throws Exception { + return message.isDurable() ? DeliveryMode_PERSISTENT : DeliveryMode_NON_PERSISTENT; + } + + public final void setJMSDeliveryMode(int deliveryMode) throws Exception { + switch (deliveryMode) { + case DeliveryMode_PERSISTENT: + message.setDurable(true); + break; + case DeliveryMode_NON_PERSISTENT: + message.setDurable(false); + break; + default: + throw new Exception("Invalid mode " + deliveryMode); } } - @Override - public final void setJMSReplyTo(Destination replyTo) throws JMSException { - MessageUtil.setJMSReplyTo(message, replyTo == null ? null : ((ActiveMQDestination) replyTo).getSimpleAddress()); - } - - @Override - public Destination getJMSDestination() throws JMSException { - return ActiveMQDestination.createDestination(message.getRoutingType(), message.getAddressSimpleString()); - } - - @Override - public final void setJMSDestination(Destination destination) throws JMSException { - if (destination == null) { - message.setAddress((SimpleString) null); - } else { - message.setAddress(((ActiveMQDestination) destination).getSimpleAddress()); - } - - } - - @Override - public final int getJMSDeliveryMode() throws JMSException { - return message.isDurable() ? DeliveryMode.PERSISTENT : DeliveryMode.NON_PERSISTENT; - } - - @Override - public final void setJMSDeliveryMode(int deliveryMode) throws JMSException { - if (deliveryMode == DeliveryMode.PERSISTENT) { - message.setDurable(true); - } else if (deliveryMode == DeliveryMode.NON_PERSISTENT) { - message.setDurable(false); - } else { - throw new JMSException("Invalid mode " + deliveryMode); - } - } - - @Override - public final boolean getJMSRedelivered() throws JMSException { + public final boolean getJMSRedelivered() throws Exception { return false; } - @Override - public final void setJMSRedelivered(boolean redelivered) throws JMSException { + public final void setJMSRedelivered(boolean redelivered) throws Exception { // no op } - @Override - public final String getJMSType() throws JMSException { + public final String getJMSType() throws Exception { return MessageUtil.getJMSType(message); } - @Override - public final void setJMSType(String type) throws JMSException { + public final void setJMSType(String type) throws Exception { MessageUtil.setJMSType(message, type); } - @Override - public final long getJMSExpiration() throws JMSException { + public final long getJMSExpiration() throws Exception { return message.getExpiration(); } - @Override - public final void setJMSExpiration(long expiration) throws JMSException { + public final void setJMSExpiration(long expiration) throws Exception { message.setExpiration(expiration); } - @Override - public final long getJMSDeliveryTime() throws JMSException { + public final long getJMSDeliveryTime() throws Exception { // no op return 0; } - @Override - public final void setJMSDeliveryTime(long deliveryTime) throws JMSException { + public final void setJMSDeliveryTime(long deliveryTime) throws Exception { // no op } - @Override - public final int getJMSPriority() throws JMSException { + public final int getJMSPriority() throws Exception { return message.getPriority(); } - @Override - public final void setJMSPriority(int priority) throws JMSException { + public final void setJMSPriority(int priority) throws Exception { message.setPriority((byte) priority); } - @Override - public final void clearProperties() throws JMSException { + public final void clearProperties() throws Exception { MessageUtil.clearProperties(message); } - @Override - public final boolean propertyExists(String name) throws JMSException { + public final boolean propertyExists(String name) throws Exception { return MessageUtil.propertyExists(message, name); } - @Override - public final boolean getBooleanProperty(String name) throws JMSException { + public final boolean getBooleanProperty(String name) throws Exception { return message.getBooleanProperty(name); } - @Override - public final byte getByteProperty(String name) throws JMSException { + public final byte getByteProperty(String name) throws Exception { return message.getByteProperty(name); } - @Override - public final short getShortProperty(String name) throws JMSException { + public final short getShortProperty(String name) throws Exception { return message.getShortProperty(name); } - @Override - public final int getIntProperty(String name) throws JMSException { + public final int getIntProperty(String name) throws Exception { return MessageUtil.getIntProperty(message, name); } - @Override - public final long getLongProperty(String name) throws JMSException { + public final long getLongProperty(String name) throws Exception { return MessageUtil.getLongProperty(message, name); } - @Override - public final float getFloatProperty(String name) throws JMSException { + public final float getFloatProperty(String name) throws Exception { return message.getFloatProperty(name); } - @Override - public final double getDoubleProperty(String name) throws JMSException { + public final double getDoubleProperty(String name) throws Exception { return message.getDoubleProperty(name); } - @Override - public final String getStringProperty(String name) throws JMSException { + public final String getStringProperty(String name) throws Exception { return MessageUtil.getStringProperty(message, name); } - @Override - public final Object getObjectProperty(String name) throws JMSException { + public final Object getObjectProperty(String name) throws Exception { return MessageUtil.getObjectProperty(message, name); } - @Override - public final Enumeration getPropertyNames() throws JMSException { + public final Enumeration getPropertyNames() throws Exception { return Collections.enumeration(MessageUtil.getPropertyNames(message)); } - @Override - public final void setBooleanProperty(String name, boolean value) throws JMSException { + public final void setBooleanProperty(String name, boolean value) throws Exception { message.putBooleanProperty(name, value); } - @Override - public final void setByteProperty(String name, byte value) throws JMSException { + public final void setByteProperty(String name, byte value) throws Exception { message.putByteProperty(name, value); } - @Override - public final void setShortProperty(String name, short value) throws JMSException { + public final void setShortProperty(String name, short value) throws Exception { message.putShortProperty(name, value); } - @Override - public final void setIntProperty(String name, int value) throws JMSException { + public final void setIntProperty(String name, int value) throws Exception { MessageUtil.setIntProperty(message, name, value); } - @Override - public final void setLongProperty(String name, long value) throws JMSException { + public final void setLongProperty(String name, long value) throws Exception { MessageUtil.setLongProperty(message, name, value); } - @Override - public final void setFloatProperty(String name, float value) throws JMSException { + public final void setFloatProperty(String name, float value) throws Exception { message.putFloatProperty(name, value); } - @Override - public final void setDoubleProperty(String name, double value) throws JMSException { + public final void setDoubleProperty(String name, double value) throws Exception { message.putDoubleProperty(name, value); } - @Override - public final void setStringProperty(String name, String value) throws JMSException { + public final void setStringProperty(String name, String value) throws Exception { MessageUtil.setStringProperty(message, name, value); } - @Override - public final void setObjectProperty(String name, Object value) throws JMSException { + public final void setObjectProperty(String name, Object value) throws Exception { MessageUtil.setObjectProperty(message, name, value); } - @Override - public final void acknowledge() throws JMSException { + public final void acknowledge() throws Exception { // no op } - @Override - public void clearBody() throws JMSException { + public void clearBody() throws Exception { message.getBodyBuffer().clear(); } - @Override - public final T getBody(Class c) throws JMSException { + public final T getBody(Class c) throws Exception { // no op.. jms2 not used on the conversion return null; } @@ -376,8 +322,7 @@ public class ServerJMSMessage implements Message { } } - @Override - public final boolean isBodyAssignableTo(Class c) throws JMSException { + public final boolean isBodyAssignableTo(Class c) throws Exception { // no op.. jms2 not used on the conversion return false; } diff --git a/artemis-protocols/artemis-amqp-protocol/src/main/java/org/apache/activemq/artemis/protocol/amqp/converter/jms/ServerJMSObjectMessage.java b/artemis-protocols/artemis-amqp-protocol/src/main/java/org/apache/activemq/artemis/protocol/amqp/converter/jms/ServerJMSObjectMessage.java index 1281f2ba20..4dbc3e7fdc 100644 --- a/artemis-protocols/artemis-amqp-protocol/src/main/java/org/apache/activemq/artemis/protocol/amqp/converter/jms/ServerJMSObjectMessage.java +++ b/artemis-protocols/artemis-amqp-protocol/src/main/java/org/apache/activemq/artemis/protocol/amqp/converter/jms/ServerJMSObjectMessage.java @@ -18,15 +18,12 @@ package org.apache.activemq.artemis.protocol.amqp.converter.jms; import java.io.Serializable; -import javax.jms.JMSException; -import javax.jms.ObjectMessage; - import org.apache.activemq.artemis.api.core.ActiveMQBuffer; import org.apache.activemq.artemis.api.core.ICoreMessage; import org.apache.activemq.artemis.api.core.Message; import org.apache.qpid.proton.amqp.Binary; -public class ServerJMSObjectMessage extends ServerJMSMessage implements ObjectMessage { +public class ServerJMSObjectMessage extends ServerJMSMessage { public static final byte TYPE = Message.OBJECT_TYPE; @@ -36,13 +33,11 @@ public class ServerJMSObjectMessage extends ServerJMSMessage implements ObjectMe super(message); } - @Override - public void setObject(Serializable object) throws JMSException { + public void setObject(Serializable object) throws Exception { throw new UnsupportedOperationException("Cannot set Object on this internal message"); } - @Override - public Serializable getObject() throws JMSException { + public Serializable getObject() throws Exception { throw new UnsupportedOperationException("Cannot set Object on this internal message"); } diff --git a/artemis-protocols/artemis-amqp-protocol/src/main/java/org/apache/activemq/artemis/protocol/amqp/converter/jms/ServerJMSStreamMessage.java b/artemis-protocols/artemis-amqp-protocol/src/main/java/org/apache/activemq/artemis/protocol/amqp/converter/jms/ServerJMSStreamMessage.java index 9aaf4c3fb6..8a72345a10 100644 --- a/artemis-protocols/artemis-amqp-protocol/src/main/java/org/apache/activemq/artemis/protocol/amqp/converter/jms/ServerJMSStreamMessage.java +++ b/artemis-protocols/artemis-amqp-protocol/src/main/java/org/apache/activemq/artemis/protocol/amqp/converter/jms/ServerJMSStreamMessage.java @@ -16,11 +16,6 @@ */ package org.apache.activemq.artemis.protocol.amqp.converter.jms; -import javax.jms.JMSException; -import javax.jms.MessageEOFException; -import javax.jms.MessageFormatException; -import javax.jms.StreamMessage; - import org.apache.activemq.artemis.api.core.ICoreMessage; import org.apache.activemq.artemis.api.core.Message; import org.apache.activemq.artemis.api.core.Pair; @@ -38,7 +33,7 @@ import static org.apache.activemq.artemis.reader.StreamMessageUtil.streamReadObj import static org.apache.activemq.artemis.reader.StreamMessageUtil.streamReadShort; import static org.apache.activemq.artemis.reader.StreamMessageUtil.streamReadString; -public final class ServerJMSStreamMessage extends ServerJMSMessage implements StreamMessage { +public final class ServerJMSStreamMessage extends ServerJMSMessage { public static final byte TYPE = Message.STREAM_TYPE; @@ -50,110 +45,101 @@ public final class ServerJMSStreamMessage extends ServerJMSMessage implements St // StreamMessage implementation ---------------------------------- - @Override - public boolean readBoolean() throws JMSException { + public boolean readBoolean() throws Exception { try { return streamReadBoolean(getReadBodyBuffer()); } catch (IllegalStateException e) { - throw new MessageFormatException(e.getMessage()); + throw new RuntimeException(e.getMessage()); } catch (IndexOutOfBoundsException e) { - throw new MessageEOFException(""); + throw new RuntimeException(""); } } - @Override - public byte readByte() throws JMSException { + public byte readByte() throws Exception { try { return streamReadByte(getReadBodyBuffer()); } catch (IllegalStateException e) { - throw new MessageFormatException(e.getMessage()); + throw new RuntimeException(e.getMessage()); } catch (IndexOutOfBoundsException e) { - throw new MessageEOFException(""); + throw new RuntimeException(""); } } - @Override - public short readShort() throws JMSException { + public short readShort() throws Exception { try { return streamReadShort(getReadBodyBuffer()); } catch (IllegalStateException e) { - throw new MessageFormatException(e.getMessage()); + throw new RuntimeException(e.getMessage()); } catch (IndexOutOfBoundsException e) { - throw new MessageEOFException(""); + throw new RuntimeException(""); } } - @Override - public char readChar() throws JMSException { + public char readChar() throws Exception { try { return streamReadChar(getReadBodyBuffer()); } catch (IllegalStateException e) { - throw new MessageFormatException(e.getMessage()); + throw new RuntimeException(e.getMessage()); } catch (IndexOutOfBoundsException e) { - throw new MessageEOFException(""); + throw new RuntimeException(""); } } - @Override - public int readInt() throws JMSException { + public int readInt() throws Exception { try { return streamReadInteger(getReadBodyBuffer()); } catch (IllegalStateException e) { - throw new MessageFormatException(e.getMessage()); + throw new RuntimeException(e.getMessage()); } catch (IndexOutOfBoundsException e) { - throw new MessageEOFException(""); + throw new RuntimeException(""); } } - @Override - public long readLong() throws JMSException { + public long readLong() throws Exception { try { return streamReadLong(getReadBodyBuffer()); } catch (IllegalStateException e) { - throw new MessageFormatException(e.getMessage()); + throw new RuntimeException(e.getMessage()); } catch (IndexOutOfBoundsException e) { - throw new MessageEOFException(""); + throw new RuntimeException(""); } } - @Override - public float readFloat() throws JMSException { + public float readFloat() throws Exception { try { return streamReadFloat(getReadBodyBuffer()); } catch (IllegalStateException e) { - throw new MessageFormatException(e.getMessage()); + throw new RuntimeException(e.getMessage()); } catch (IndexOutOfBoundsException e) { - throw new MessageEOFException(""); + throw new RuntimeException(""); } } - @Override - public double readDouble() throws JMSException { + public double readDouble() throws Exception { try { return streamReadDouble(getReadBodyBuffer()); } catch (IllegalStateException e) { - throw new MessageFormatException(e.getMessage()); + throw new RuntimeException(e.getMessage()); } catch (IndexOutOfBoundsException e) { - throw new MessageEOFException(""); + throw new RuntimeException(""); } } - @Override - public String readString() throws JMSException { + public String readString() throws Exception { try { return streamReadString(getReadBodyBuffer()); } catch (IllegalStateException e) { - throw new MessageFormatException(e.getMessage()); + throw new RuntimeException(e.getMessage()); } catch (IndexOutOfBoundsException e) { - throw new MessageEOFException(""); + throw new RuntimeException(""); } } @@ -162,8 +148,7 @@ public final class ServerJMSStreamMessage extends ServerJMSMessage implements St */ private int len = 0; - @Override - public int readBytes(final byte[] value) throws JMSException { + public int readBytes(final byte[] value) throws Exception { try { Pair pairRead = streamReadBytes(getReadBodyBuffer(), len, value); @@ -171,108 +156,95 @@ public final class ServerJMSStreamMessage extends ServerJMSMessage implements St len = pairRead.getA(); return pairRead.getB(); } catch (IllegalStateException e) { - throw new MessageFormatException(e.getMessage()); + throw new RuntimeException(e.getMessage()); } catch (IndexOutOfBoundsException e) { - throw new MessageEOFException(""); + throw new RuntimeException(""); } } - @Override - public Object readObject() throws JMSException { + public Object readObject() throws Exception { if (getReadBodyBuffer().readerIndex() >= getReadBodyBuffer().writerIndex()) { - throw new MessageEOFException(""); + throw new RuntimeException(""); } try { return streamReadObject(getReadBodyBuffer()); } catch (IllegalStateException e) { - throw new MessageFormatException(e.getMessage()); + throw new RuntimeException(e.getMessage()); } catch (IndexOutOfBoundsException e) { - throw new MessageEOFException(""); + throw new RuntimeException(""); } } - @Override - public void writeBoolean(final boolean value) throws JMSException { + public void writeBoolean(final boolean value) throws Exception { getWriteBodyBuffer().writeByte(DataConstants.BOOLEAN); getWriteBodyBuffer().writeBoolean(value); } - @Override - public void writeByte(final byte value) throws JMSException { + public void writeByte(final byte value) throws Exception { getWriteBodyBuffer().writeByte(DataConstants.BYTE); getWriteBodyBuffer().writeByte(value); } - @Override - public void writeShort(final short value) throws JMSException { + public void writeShort(final short value) throws Exception { getWriteBodyBuffer().writeByte(DataConstants.SHORT); getWriteBodyBuffer().writeShort(value); } - @Override - public void writeChar(final char value) throws JMSException { + public void writeChar(final char value) throws Exception { getWriteBodyBuffer().writeByte(DataConstants.CHAR); getWriteBodyBuffer().writeShort((short) value); } - @Override - public void writeInt(final int value) throws JMSException { + public void writeInt(final int value) throws Exception { getWriteBodyBuffer().writeByte(DataConstants.INT); getWriteBodyBuffer().writeInt(value); } - @Override - public void writeLong(final long value) throws JMSException { + public void writeLong(final long value) throws Exception { getWriteBodyBuffer().writeByte(DataConstants.LONG); getWriteBodyBuffer().writeLong(value); } - @Override - public void writeFloat(final float value) throws JMSException { + public void writeFloat(final float value) throws Exception { getWriteBodyBuffer().writeByte(DataConstants.FLOAT); getWriteBodyBuffer().writeInt(Float.floatToIntBits(value)); } - @Override - public void writeDouble(final double value) throws JMSException { + public void writeDouble(final double value) throws Exception { getWriteBodyBuffer().writeByte(DataConstants.DOUBLE); getWriteBodyBuffer().writeLong(Double.doubleToLongBits(value)); } - @Override - public void writeString(final String value) throws JMSException { + public void writeString(final String value) throws Exception { getWriteBodyBuffer().writeByte(DataConstants.STRING); getWriteBodyBuffer().writeNullableString(value); } - @Override - public void writeBytes(final byte[] value) throws JMSException { + public void writeBytes(final byte[] value) throws Exception { getWriteBodyBuffer().writeByte(DataConstants.BYTES); getWriteBodyBuffer().writeInt(value.length); getWriteBodyBuffer().writeBytes(value); } - @Override - public void writeBytes(final byte[] value, final int offset, final int length) throws JMSException { + public void writeBytes(final byte[] value, final int offset, final int length) throws Exception { getWriteBodyBuffer().writeByte(DataConstants.BYTES); getWriteBodyBuffer().writeInt(length); getWriteBodyBuffer().writeBytes(value, offset, length); } - @Override - public void writeObject(final Object value) throws JMSException { + public void writeObject(final Object value) throws Exception { if (value instanceof String) { writeString((String) value); } else if (value instanceof Boolean) { @@ -296,19 +268,18 @@ public final class ServerJMSStreamMessage extends ServerJMSMessage implements St } else if (value == null) { writeString(null); } else { - throw new MessageFormatException("Invalid object type: " + value.getClass()); + throw new RuntimeException("Invalid object type: " + value.getClass()); } } - @Override - public void reset() throws JMSException { + public void reset() throws Exception { getWriteBodyBuffer().resetReaderIndex(); } // ActiveMQRAMessage overrides ---------------------------------------- @Override - public void clearBody() throws JMSException { + public void clearBody() throws Exception { super.clearBody(); getWriteBodyBuffer().clear(); @@ -321,6 +292,7 @@ public final class ServerJMSStreamMessage extends ServerJMSMessage implements St /** * Encode the body into the internal message + * @throws java.lang.Exception */ @Override public void encode() throws Exception { diff --git a/artemis-protocols/artemis-amqp-protocol/src/main/java/org/apache/activemq/artemis/protocol/amqp/converter/jms/ServerJMSTextMessage.java b/artemis-protocols/artemis-amqp-protocol/src/main/java/org/apache/activemq/artemis/protocol/amqp/converter/jms/ServerJMSTextMessage.java index f770185940..4ef6a5356e 100644 --- a/artemis-protocols/artemis-amqp-protocol/src/main/java/org/apache/activemq/artemis/protocol/amqp/converter/jms/ServerJMSTextMessage.java +++ b/artemis-protocols/artemis-amqp-protocol/src/main/java/org/apache/activemq/artemis/protocol/amqp/converter/jms/ServerJMSTextMessage.java @@ -16,9 +16,6 @@ */ package org.apache.activemq.artemis.protocol.amqp.converter.jms; -import javax.jms.JMSException; -import javax.jms.TextMessage; - import org.apache.activemq.artemis.api.core.ICoreMessage; import org.apache.activemq.artemis.api.core.Message; import org.apache.activemq.artemis.api.core.SimpleString; @@ -31,7 +28,7 @@ import static org.apache.activemq.artemis.reader.TextMessageUtil.writeBodyText; *
* This class was ported from SpyTextMessage in JBossMQ. */ -public class ServerJMSTextMessage extends ServerJMSMessage implements TextMessage { +public class ServerJMSTextMessage extends ServerJMSMessage { // Constants ----------------------------------------------------- public static final byte TYPE = Message.TEXT_TYPE; @@ -55,8 +52,7 @@ public class ServerJMSTextMessage extends ServerJMSMessage implements TextMessag } // TextMessage implementation ------------------------------------ - @Override - public void setText(final String text) throws JMSException { + public void setText(final String text) throws Exception { if (text != null) { this.text = new SimpleString(text); } else { @@ -66,7 +62,6 @@ public class ServerJMSTextMessage extends ServerJMSMessage implements TextMessag writeBodyText(getWriteBodyBuffer(), this.text); } - @Override public String getText() { if (text != null) { return text.toString(); @@ -76,7 +71,7 @@ public class ServerJMSTextMessage extends ServerJMSMessage implements TextMessag } @Override - public void clearBody() throws JMSException { + public void clearBody() throws Exception { super.clearBody(); text = null; diff --git a/artemis-protocols/artemis-amqp-protocol/src/main/java/org/apache/activemq/artemis/protocol/amqp/proton/ProtonServerSenderContext.java b/artemis-protocols/artemis-amqp-protocol/src/main/java/org/apache/activemq/artemis/protocol/amqp/proton/ProtonServerSenderContext.java index fbe503bf3b..ffcf5af29a 100644 --- a/artemis-protocols/artemis-amqp-protocol/src/main/java/org/apache/activemq/artemis/protocol/amqp/proton/ProtonServerSenderContext.java +++ b/artemis-protocols/artemis-amqp-protocol/src/main/java/org/apache/activemq/artemis/protocol/amqp/proton/ProtonServerSenderContext.java @@ -42,7 +42,6 @@ import org.apache.activemq.artemis.core.server.MessageReference; import org.apache.activemq.artemis.core.server.QueueQueryResult; import org.apache.activemq.artemis.core.server.ServerConsumer; import org.apache.activemq.artemis.core.server.impl.ServerConsumerImpl; -import org.apache.activemq.artemis.jms.client.ActiveMQDestination; import org.apache.activemq.artemis.protocol.amqp.broker.AMQPLargeMessage; import org.apache.activemq.artemis.protocol.amqp.broker.AMQPMessage; import org.apache.activemq.artemis.protocol.amqp.broker.AMQPMessageBrokerAccessor; @@ -64,6 +63,7 @@ import org.apache.activemq.artemis.selector.filter.FilterException; import org.apache.activemq.artemis.selector.impl.SelectorParser; import org.apache.activemq.artemis.spi.core.remoting.ReadyListener; import org.apache.activemq.artemis.utils.CompositeAddress; +import org.apache.activemq.artemis.utils.DestinationUtil; import org.apache.qpid.proton.amqp.DescribedType; import org.apache.qpid.proton.amqp.Symbol; import org.apache.qpid.proton.amqp.messaging.Accepted; @@ -842,7 +842,7 @@ public class ProtonServerSenderContext extends ProtonInitializable implements Pr final boolean durable = !isVolatile; final String subscriptionName = pubId.contains("|") ? pubId.split("\\|")[0] : pubId; final String clientID = clientId == null || clientId.isEmpty() || global ? null : clientId; - return ActiveMQDestination.createQueueNameForSubscription(durable, clientID, subscriptionName); + return DestinationUtil.createQueueNameForSubscription(durable, clientID, subscriptionName); } else { String queue = clientId == null || clientId.isEmpty() || global ? pubId : clientId + "." + pubId; if (shared) { diff --git a/artemis-protocols/artemis-amqp-protocol/src/test/java/org/apache/activemq/artemis/protocol/amqp/converter/TestConversions.java b/artemis-protocols/artemis-amqp-protocol/src/test/java/org/apache/activemq/artemis/protocol/amqp/converter/TestConversions.java index cda1b3f578..b5d3ff8675 100644 --- a/artemis-protocols/artemis-amqp-protocol/src/test/java/org/apache/activemq/artemis/protocol/amqp/converter/TestConversions.java +++ b/artemis-protocols/artemis-amqp-protocol/src/test/java/org/apache/activemq/artemis/protocol/amqp/converter/TestConversions.java @@ -120,7 +120,7 @@ public class TestConversions extends Assert { Assert.assertArrayEquals(bodyBytes, newBodyBytes); } - private void verifyProperties(javax.jms.Message message) throws Exception { + private void verifyProperties(ServerJMSMessage message) throws Exception { assertEquals(true, message.getBooleanProperty("true")); assertEquals(false, message.getBooleanProperty("false")); assertEquals("bar", message.getStringProperty("foo")); diff --git a/artemis-protocols/artemis-amqp-protocol/src/test/java/org/apache/activemq/artemis/protocol/amqp/converter/message/JMSMappingInboundTransformerTest.java b/artemis-protocols/artemis-amqp-protocol/src/test/java/org/apache/activemq/artemis/protocol/amqp/converter/message/JMSMappingInboundTransformerTest.java index 0b8ac8d334..c93185e30b 100644 --- a/artemis-protocols/artemis-amqp-protocol/src/test/java/org/apache/activemq/artemis/protocol/amqp/converter/message/JMSMappingInboundTransformerTest.java +++ b/artemis-protocols/artemis-amqp-protocol/src/test/java/org/apache/activemq/artemis/protocol/amqp/converter/message/JMSMappingInboundTransformerTest.java @@ -29,12 +29,6 @@ import java.util.List; import java.util.Map; import java.util.UUID; -import javax.jms.Destination; -import javax.jms.Queue; -import javax.jms.TemporaryQueue; -import javax.jms.TemporaryTopic; -import javax.jms.TextMessage; -import javax.jms.Topic; import org.apache.activemq.artemis.api.core.ICoreMessage; import org.apache.activemq.artemis.protocol.amqp.broker.AMQPMessage; @@ -49,17 +43,17 @@ import org.apache.activemq.artemis.protocol.amqp.converter.jms.ServerJMSTextMess import org.apache.activemq.artemis.protocol.amqp.util.NettyReadable; import org.apache.activemq.artemis.protocol.amqp.util.NettyWritable; import org.apache.qpid.proton.amqp.Binary; -import org.apache.qpid.proton.amqp.Symbol; import org.apache.qpid.proton.amqp.messaging.AmqpSequence; import org.apache.qpid.proton.amqp.messaging.AmqpValue; import org.apache.qpid.proton.amqp.messaging.Data; -import org.apache.qpid.proton.amqp.messaging.MessageAnnotations; import org.apache.qpid.proton.message.Message; import org.apache.qpid.proton.message.impl.MessageImpl; import org.junit.Before; import org.junit.Test; import io.netty.buffer.Unpooled; +import org.apache.qpid.proton.amqp.Symbol; +import org.apache.qpid.proton.amqp.messaging.MessageAnnotations; public class JMSMappingInboundTransformerTest { @@ -85,7 +79,7 @@ public class JMSMappingInboundTransformerTest { ICoreMessage coreMessage = messageEncode.toCore(); - javax.jms.Message jmsMessage = ServerJMSMessage.wrapCoreMessage(coreMessage); + ServerJMSMessage jmsMessage = ServerJMSMessage.wrapCoreMessage(coreMessage); assertNotNull("Message should not be null", jmsMessage); assertEquals("Unexpected message class type", ServerJMSBytesMessage.class, jmsMessage.getClass()); @@ -102,7 +96,7 @@ public class JMSMappingInboundTransformerTest { public void testCreateBytesMessageFromNoBodySectionAndNoContentType() throws Exception { MessageImpl message = (MessageImpl) Message.Factory.create(); - javax.jms.Message jmsMessage = ServerJMSMessage.wrapCoreMessage(encodeAndCreateAMQPMessage(message).toCore()); + ServerJMSMessage jmsMessage = ServerJMSMessage.wrapCoreMessage(encodeAndCreateAMQPMessage(message).toCore()); assertNotNull("Message should not be null", jmsMessage); assertEquals("Unexpected message class type", ServerJMSBytesMessage.class, jmsMessage.getClass()); @@ -113,7 +107,7 @@ public class JMSMappingInboundTransformerTest { MessageImpl message = (MessageImpl) Message.Factory.create(); message.setContentType("text/plain"); - javax.jms.Message jmsMessage = ServerJMSMessage.wrapCoreMessage(encodeAndCreateAMQPMessage(message).toCore()); + ServerJMSMessage jmsMessage = ServerJMSMessage.wrapCoreMessage(encodeAndCreateAMQPMessage(message).toCore()); assertNotNull("Message should not be null", jmsMessage); assertEquals("Unexpected message class type", ServerJMSTextMessage.class, jmsMessage.getClass()); @@ -137,7 +131,7 @@ public class JMSMappingInboundTransformerTest { message.setContentType(AMQPMessageSupport.OCTET_STREAM_CONTENT_TYPE); AMQPStandardMessage amqp = encodeAndCreateAMQPMessage(message); - javax.jms.Message jmsMessage = ServerJMSMessage.wrapCoreMessage(amqp.toCore()); + ServerJMSMessage jmsMessage = ServerJMSMessage.wrapCoreMessage(amqp.toCore()); assertNotNull("Message should not be null", jmsMessage); assertEquals("Unexpected message class type", ServerJMSBytesMessage.class, jmsMessage.getClass()); @@ -158,7 +152,7 @@ public class JMSMappingInboundTransformerTest { message.setBody(new Data(binary)); message.setContentType("unknown-content-type"); - javax.jms.Message jmsMessage = ServerJMSMessage.wrapCoreMessage(encodeAndCreateAMQPMessage(message).toCore()); + ServerJMSMessage jmsMessage = ServerJMSMessage.wrapCoreMessage(encodeAndCreateAMQPMessage(message).toCore()); assertNotNull("Message should not be null", jmsMessage); assertEquals("Unexpected message class type", ServerJMSBytesMessage.class, jmsMessage.getClass()); @@ -179,20 +173,12 @@ public class JMSMappingInboundTransformerTest { assertNull(message.getContentType()); - javax.jms.Message jmsMessage = ServerJMSMessage.wrapCoreMessage(encodeAndCreateAMQPMessage(message).toCore()); + ServerJMSMessage jmsMessage = ServerJMSMessage.wrapCoreMessage(encodeAndCreateAMQPMessage(message).toCore()); assertNotNull("Message should not be null", jmsMessage); assertEquals("Unexpected message class type", ServerJMSBytesMessage.class, jmsMessage.getClass()); } - /** - * Test that receiving a data body containing nothing, but with the content type set to - * {@value AMQPMessageSupport#SERIALIZED_JAVA_OBJECT_CONTENT_TYPE} results in an - * ObjectMessage when not otherwise annotated to indicate the type of JMS message it is. - * - * @throws Exception - * if an error occurs during the test. - */ @Test public void testCreateObjectMessageFromDataWithContentTypeAndEmptyBinary() throws Exception { MessageImpl message = (MessageImpl) Message.Factory.create(); @@ -200,7 +186,7 @@ public class JMSMappingInboundTransformerTest { message.setBody(new Data(binary)); message.setContentType(AMQPMessageSupport.SERIALIZED_JAVA_OBJECT_CONTENT_TYPE.toString()); - javax.jms.Message jmsMessage = ServerJMSMessage.wrapCoreMessage(encodeAndCreateAMQPMessage(message).toCore()); + ServerJMSMessage jmsMessage = ServerJMSMessage.wrapCoreMessage(encodeAndCreateAMQPMessage(message).toCore()); assertNotNull("Message should not be null", jmsMessage); assertEquals("Unexpected message class type", ServerJMSObjectMessage.class, jmsMessage.getClass()); @@ -300,7 +286,7 @@ public class JMSMappingInboundTransformerTest { message.setBody(new Data(binary)); message.setContentType(contentType); - javax.jms.Message jmsMessage = ServerJMSMessage.wrapCoreMessage(encodeAndCreateAMQPMessage(message).toCore()); + ServerJMSMessage jmsMessage = ServerJMSMessage.wrapCoreMessage(encodeAndCreateAMQPMessage(message).toCore()); assertNotNull("Message should not be null", jmsMessage); if (StandardCharsets.UTF_8.equals(expectedCharset)) { @@ -324,7 +310,7 @@ public class JMSMappingInboundTransformerTest { MessageImpl message = (MessageImpl) Message.Factory.create(); message.setBody(new AmqpValue("content")); - javax.jms.Message jmsMessage = ServerJMSMessage.wrapCoreMessage(encodeAndCreateAMQPMessage(message).toCore()); + ServerJMSMessage jmsMessage = ServerJMSMessage.wrapCoreMessage(encodeAndCreateAMQPMessage(message).toCore()); assertNotNull("Message should not be null", jmsMessage); assertEquals("Unexpected message class type", ServerJMSTextMessage.class, jmsMessage.getClass()); @@ -342,7 +328,7 @@ public class JMSMappingInboundTransformerTest { MessageImpl message = (MessageImpl) Message.Factory.create(); message.setBody(new AmqpValue(null)); - javax.jms.Message jmsMessage = ServerJMSMessage.wrapCoreMessage(encodeAndCreateAMQPMessage(message).toCore()); + ServerJMSMessage jmsMessage = ServerJMSMessage.wrapCoreMessage(encodeAndCreateAMQPMessage(message).toCore()); assertNotNull("Message should not be null", jmsMessage); assertEquals("Unexpected message class type", ServerJMSTextMessage.class, jmsMessage.getClass()); @@ -362,7 +348,7 @@ public class JMSMappingInboundTransformerTest { message.setBody(new AmqpValue(new Binary(new byte[0]))); message.setContentType(AMQPMessageSupport.SERIALIZED_JAVA_OBJECT_CONTENT_TYPE.toString()); - javax.jms.Message jmsMessage = ServerJMSMessage.wrapCoreMessage(encodeAndCreateAMQPMessage(message).toCore()); + ServerJMSMessage jmsMessage = ServerJMSMessage.wrapCoreMessage(encodeAndCreateAMQPMessage(message).toCore()); assertNotNull("Message should not be null", jmsMessage); assertEquals("Unexpected message class type", ServerJMSObjectMessage.class, jmsMessage.getClass()); @@ -381,7 +367,7 @@ public class JMSMappingInboundTransformerTest { Map map = new HashMap<>(); message.setBody(new AmqpValue(map)); - javax.jms.Message jmsMessage = ServerJMSMessage.wrapCoreMessage(encodeAndCreateAMQPMessage(message).toCore()); + ServerJMSMessage jmsMessage = ServerJMSMessage.wrapCoreMessage(encodeAndCreateAMQPMessage(message).toCore()); assertNotNull("Message should not be null", jmsMessage); assertEquals("Unexpected message class type", ServerJMSMapMessage.class, jmsMessage.getClass()); @@ -400,7 +386,7 @@ public class JMSMappingInboundTransformerTest { List list = new ArrayList<>(); message.setBody(new AmqpValue(list)); - javax.jms.Message jmsMessage = ServerJMSMessage.wrapCoreMessage(encodeAndCreateAMQPMessage(message).toCore()); + ServerJMSMessage jmsMessage = ServerJMSMessage.wrapCoreMessage(encodeAndCreateAMQPMessage(message).toCore()); assertNotNull("Message should not be null", jmsMessage); assertEquals("Unexpected message class type", ServerJMSStreamMessage.class, jmsMessage.getClass()); @@ -419,7 +405,7 @@ public class JMSMappingInboundTransformerTest { List list = new ArrayList<>(); message.setBody(new AmqpSequence(list)); - javax.jms.Message jmsMessage = ServerJMSMessage.wrapCoreMessage(encodeAndCreateAMQPMessage(message).toCore()); + ServerJMSMessage jmsMessage = ServerJMSMessage.wrapCoreMessage(encodeAndCreateAMQPMessage(message).toCore()); assertNotNull("Message should not be null", jmsMessage); assertEquals("Unexpected message class type", ServerJMSStreamMessage.class, jmsMessage.getClass()); @@ -438,7 +424,7 @@ public class JMSMappingInboundTransformerTest { Binary binary = new Binary(new byte[0]); message.setBody(new AmqpValue(binary)); - javax.jms.Message jmsMessage = ServerJMSMessage.wrapCoreMessage(encodeAndCreateAMQPMessage(message).toCore()); + ServerJMSMessage jmsMessage = ServerJMSMessage.wrapCoreMessage(encodeAndCreateAMQPMessage(message).toCore()); assertNotNull("Message should not be null", jmsMessage); assertEquals("Unexpected message class type", ServerJMSBytesMessage.class, jmsMessage.getClass()); @@ -457,7 +443,7 @@ public class JMSMappingInboundTransformerTest { MessageImpl message = (MessageImpl) Message.Factory.create(); message.setBody(new AmqpValue(UUID.randomUUID())); - javax.jms.Message jmsMessage = ServerJMSMessage.wrapCoreMessage(encodeAndCreateAMQPMessage(message).toCore()); + ServerJMSMessage jmsMessage = ServerJMSMessage.wrapCoreMessage(encodeAndCreateAMQPMessage(message).toCore()); assertNotNull("Message should not be null", jmsMessage); assertEquals("Unexpected message class type", ServerJMSBytesMessage.class, jmsMessage.getClass()); @@ -472,10 +458,10 @@ public class JMSMappingInboundTransformerTest { ServerJMSTextMessage jmsMessage = (ServerJMSTextMessage)ServerJMSMessage.wrapCoreMessage(encodeAndCreateAMQPMessage(message).toCore()); jmsMessage.decode(); - assertTrue("Expected TextMessage", jmsMessage instanceof TextMessage); + assertTrue("Expected TextMessage", jmsMessage instanceof ServerJMSTextMessage); assertEquals("Unexpected message class type", ServerJMSTextMessage.class, jmsMessage.getClass()); - TextMessage textMessage = (TextMessage) jmsMessage; + ServerJMSTextMessage textMessage = jmsMessage; assertNotNull(textMessage.getText()); assertEquals(contentString, textMessage.getText()); @@ -485,30 +471,30 @@ public class JMSMappingInboundTransformerTest { @Test public void testTransformWithNoToTypeDestinationTypeAnnotation() throws Exception { - doTransformWithToTypeDestinationTypeAnnotationTestImpl(null, Destination.class); + doTransformWithToTypeDestinationTypeAnnotationTestImpl(null); } @Test public void testTransformWithQueueStringToTypeDestinationTypeAnnotation() throws Exception { - doTransformWithToTypeDestinationTypeAnnotationTestImpl("queue", Queue.class); + doTransformWithToTypeDestinationTypeAnnotationTestImpl("queue"); } @Test public void testTransformWithTemporaryQueueStringToTypeDestinationTypeAnnotation() throws Exception { - doTransformWithToTypeDestinationTypeAnnotationTestImpl("queue,temporary", TemporaryQueue.class); + doTransformWithToTypeDestinationTypeAnnotationTestImpl("queue,temporary"); } @Test public void testTransformWithTopicStringToTypeDestinationTypeAnnotation() throws Exception { - doTransformWithToTypeDestinationTypeAnnotationTestImpl("topic", Topic.class); + doTransformWithToTypeDestinationTypeAnnotationTestImpl("topic"); } @Test public void testTransformWithTemporaryTopicStringToTypeDestinationTypeAnnotation() throws Exception { - doTransformWithToTypeDestinationTypeAnnotationTestImpl("topic,temporary", TemporaryTopic.class); + doTransformWithToTypeDestinationTypeAnnotationTestImpl("topic,temporary"); } - private void doTransformWithToTypeDestinationTypeAnnotationTestImpl(Object toTypeAnnotationValue, Class expectedClass) + private void doTransformWithToTypeDestinationTypeAnnotationTestImpl(Object toTypeAnnotationValue) throws Exception { String toAddress = "toAddress"; @@ -522,38 +508,39 @@ public class JMSMappingInboundTransformerTest { message.setMessageAnnotations(ma); } - javax.jms.Message jmsMessage = ServerJMSMessage.wrapCoreMessage(encodeAndCreateAMQPMessage(message).toCore()); - assertTrue("Expected TextMessage", jmsMessage instanceof TextMessage); + ServerJMSMessage jmsMessage = ServerJMSMessage.wrapCoreMessage(encodeAndCreateAMQPMessage(message).toCore()); + assertTrue("Expected ServerJMSTextMessage", jmsMessage instanceof ServerJMSTextMessage); } // ----- ReplyTo Conversions ----------------------------------------------// + @Test public void testTransformWithNoReplyToTypeDestinationTypeAnnotation() throws Exception { - doTransformWithReplyToTypeDestinationTypeAnnotationTestImpl(null, Destination.class); + doTransformWithReplyToTypeDestinationTypeAnnotationTestImpl(null); } @Test public void testTransformWithQueueStringReplyToTypeDestinationTypeAnnotation() throws Exception { - doTransformWithReplyToTypeDestinationTypeAnnotationTestImpl("queue", Queue.class); + doTransformWithReplyToTypeDestinationTypeAnnotationTestImpl("queue"); } @Test public void testTransformWithTemporaryQueueStringReplyToTypeDestinationTypeAnnotation() throws Exception { - doTransformWithReplyToTypeDestinationTypeAnnotationTestImpl("queue,temporary", TemporaryQueue.class); + doTransformWithReplyToTypeDestinationTypeAnnotationTestImpl("queue,temporary"); } @Test public void testTransformWithTopicStringReplyToTypeDestinationTypeAnnotation() throws Exception { - doTransformWithReplyToTypeDestinationTypeAnnotationTestImpl("topic", Topic.class); + doTransformWithReplyToTypeDestinationTypeAnnotationTestImpl("topic"); } @Test public void testTransformWithTemporaryTopicStringReplyToTypeDestinationTypeAnnotation() throws Exception { - doTransformWithReplyToTypeDestinationTypeAnnotationTestImpl("topic,temporary", TemporaryTopic.class); + doTransformWithReplyToTypeDestinationTypeAnnotationTestImpl("topic,temporary"); } - private void doTransformWithReplyToTypeDestinationTypeAnnotationTestImpl(Object replyToTypeAnnotationValue, Class expectedClass) + private void doTransformWithReplyToTypeDestinationTypeAnnotationTestImpl(Object replyToTypeAnnotationValue) throws Exception { String replyToAddress = "replyToAddress"; @@ -567,8 +554,8 @@ public class JMSMappingInboundTransformerTest { message.setMessageAnnotations(ma); } - javax.jms.Message jmsMessage = ServerJMSMessage.wrapCoreMessage(encodeAndCreateAMQPMessage(message).toCore()); - assertTrue("Expected TextMessage", jmsMessage instanceof TextMessage); + ServerJMSMessage jmsMessage = ServerJMSMessage.wrapCoreMessage(encodeAndCreateAMQPMessage(message).toCore()); + assertTrue("Expected TextMessage", jmsMessage instanceof ServerJMSTextMessage); } private AMQPStandardMessage encodeAndCreateAMQPMessage(MessageImpl message) { diff --git a/artemis-protocols/artemis-amqp-protocol/src/test/java/org/apache/activemq/artemis/protocol/amqp/converter/message/JMSMappingOutboundTransformerTest.java b/artemis-protocols/artemis-amqp-protocol/src/test/java/org/apache/activemq/artemis/protocol/amqp/converter/message/JMSMappingOutboundTransformerTest.java index 069996a7d3..f3b688562f 100644 --- a/artemis-protocols/artemis-amqp-protocol/src/test/java/org/apache/activemq/artemis/protocol/amqp/converter/message/JMSMappingOutboundTransformerTest.java +++ b/artemis-protocols/artemis-amqp-protocol/src/test/java/org/apache/activemq/artemis/protocol/amqp/converter/message/JMSMappingOutboundTransformerTest.java @@ -40,15 +40,9 @@ import java.util.List; import java.util.Map; import java.util.UUID; -import javax.jms.Destination; -import javax.jms.JMSException; - import org.apache.activemq.artemis.core.buffers.impl.ResetLimitWrappedActiveMQBuffer; import org.apache.activemq.artemis.core.message.impl.CoreMessage; -import org.apache.activemq.artemis.jms.client.ActiveMQQueue; -import org.apache.activemq.artemis.jms.client.ActiveMQTemporaryQueue; -import org.apache.activemq.artemis.jms.client.ActiveMQTemporaryTopic; -import org.apache.activemq.artemis.jms.client.ActiveMQTopic; + import org.apache.activemq.artemis.protocol.amqp.broker.AMQPMessage; import org.apache.activemq.artemis.protocol.amqp.converter.AMQPConverter; import org.apache.activemq.artemis.protocol.amqp.converter.AMQPMessageSupport; @@ -473,7 +467,8 @@ public class JMSMappingOutboundTransformerTest { doTestConvertMessageWithJMSDestination(createDestination(QUEUE_TYPE), QUEUE_TYPE); } - private void doTestConvertMessageWithJMSDestination(Destination jmsDestination, Object expectedAnnotationValue) throws Exception { + + private void doTestConvertMessageWithJMSDestination(String jmsDestination, Object expectedAnnotationValue) throws Exception { ServerJMSTextMessage textMessage = createTextMessage(); textMessage.setText("myTextMessageContent"); textMessage.setJMSDestination(jmsDestination); @@ -490,7 +485,7 @@ public class JMSMappingOutboundTransformerTest { } if (jmsDestination != null) { - assertEquals("Unexpected 'to' address", AMQPMessageSupport.toAddress(jmsDestination), amqp.getAddress()); + assertEquals("Unexpected 'to' address", jmsDestination, amqp.getAddress()); } } @@ -506,7 +501,7 @@ public class JMSMappingOutboundTransformerTest { doTestConvertMessageWithJMSReplyTo(createDestination(QUEUE_TYPE), QUEUE_TYPE); } - private void doTestConvertMessageWithJMSReplyTo(Destination jmsReplyTo, Object expectedAnnotationValue) throws Exception { + private void doTestConvertMessageWithJMSReplyTo(String jmsReplyTo, Object expectedAnnotationValue) throws Exception { ServerJMSTextMessage textMessage = createTextMessage(); textMessage.setText("myTextMessageContent"); textMessage.setJMSReplyTo(jmsReplyTo); @@ -523,34 +518,24 @@ public class JMSMappingOutboundTransformerTest { } if (jmsReplyTo != null) { - assertEquals("Unexpected 'reply-to' address", AMQPMessageSupport.toAddress(jmsReplyTo).toString(), amqp.getReplyTo().toString()); + assertEquals("Unexpected 'reply-to' address", jmsReplyTo, amqp.getReplyTo().toString()); } } // ----- Utility Methods used for this Test -------------------------------// - private Destination createDestination(byte destType) { - Destination destination = null; + private String createDestination(byte destType) { String prefix = PrefixUtil.getURIPrefix(TEST_ADDRESS); String address = PrefixUtil.removePrefix(TEST_ADDRESS, prefix); switch (destType) { case QUEUE_TYPE: - destination = new ActiveMQQueue(address); - break; case TOPIC_TYPE: - destination = new ActiveMQTopic(address); - break; case TEMP_QUEUE_TYPE: - destination = new ActiveMQTemporaryQueue(address, null); - break; case TEMP_TOPIC_TYPE: - destination = new ActiveMQTemporaryTopic(address, null); - break; + return address; default: throw new IllegalArgumentException("Invliad Destination Type given/"); } - - return destination; } private ServerJMSMessage createMessage() { @@ -597,7 +582,7 @@ public class JMSMappingOutboundTransformerTest { try { result.setText(text); - } catch (JMSException e) { + } catch (Exception e) { } return result;