This is an automated email from the ASF dual-hosted git repository. dfoulks pushed a commit to branch main in repository https://gitbox.apache.org/repos/asf/activemq-openwire.git
commit 71efcd78abba5994df861eb93386623b1fa8683b Author: Timothy Bish <[email protected]> AuthorDate: Fri Dec 4 18:10:18 2015 -0500 https://issues.apache.org/jira/browse/OPENWIRE-11 Initial work to remove JMS dependency. --- openwire-core/pom.xml | 4 - .../apache/activemq/openwire/commands/Message.java | 28 ++-- .../openwire/commands/OpenWireBlobMessage.java | 27 +--- .../openwire/commands/OpenWireBytesMessage.java | 15 +- .../openwire/commands/OpenWireDestination.java | 59 +------- .../openwire/commands/OpenWireMapMessage.java | 37 +++-- .../openwire/commands/OpenWireMessage.java | 78 +++++----- .../openwire/commands/OpenWireObjectMessage.java | 25 ++-- .../activemq/openwire/commands/OpenWireQueue.java | 12 +- .../openwire/commands/OpenWireStreamMessage.java | 32 ++--- .../openwire/commands/OpenWireTempQueue.java | 17 +-- .../openwire/commands/OpenWireTempTopic.java | 16 +-- .../openwire/commands/OpenWireTextMessage.java | 28 ++-- .../activemq/openwire/commands/OpenWireTopic.java | 11 +- .../DefaultUnresolvedDestinationTransformer.java | 71 --------- .../activemq/openwire/utils/ExceptionSupport.java | 103 ------------- .../openwire/utils/IOExceptionSupport.java | 57 ++++++++ .../utils/UnresolvedDestinationTransformer.java | 57 -------- .../openwire/commands/OpenWireDestinationTest.java | 41 +----- .../openwire/commands/OpenWireMapMessageTest.java | 32 ++--- .../openwire/commands/OpenWireMessageTest.java | 160 ++++++++++----------- .../commands/OpenWireObjectMessageTest.java | 30 ++-- .../openwire/commands/OpenWireTextMessageTest.java | 23 +-- pom.xml | 5 - 24 files changed, 281 insertions(+), 687 deletions(-) diff --git a/openwire-core/pom.xml b/openwire-core/pom.xml index 62077dd..75549e7 100644 --- a/openwire-core/pom.xml +++ b/openwire-core/pom.xml @@ -48,10 +48,6 @@ <groupId>org.fusesource.hawtbuf</groupId> <artifactId>hawtbuf</artifactId> </dependency> - <dependency> - <groupId>org.apache.geronimo.specs</groupId> - <artifactId>geronimo-jms_1.1_spec</artifactId> - </dependency> <!-- =================================== --> <!-- Testing Dependencies --> diff --git a/openwire-core/src/main/java/org/apache/activemq/openwire/commands/Message.java b/openwire-core/src/main/java/org/apache/activemq/openwire/commands/Message.java index 3c6c57b..132ca54 100644 --- a/openwire-core/src/main/java/org/apache/activemq/openwire/commands/Message.java +++ b/openwire-core/src/main/java/org/apache/activemq/openwire/commands/Message.java @@ -28,13 +28,11 @@ import java.util.Map; import java.util.zip.DeflaterOutputStream; import java.util.zip.InflaterInputStream; -import javax.jms.JMSException; - import org.apache.activemq.openwire.annotations.OpenWireExtension; import org.apache.activemq.openwire.annotations.OpenWireProperty; import org.apache.activemq.openwire.annotations.OpenWireType; import org.apache.activemq.openwire.codec.OpenWireFormat; -import org.apache.activemq.openwire.utils.ExceptionSupport; +import org.apache.activemq.openwire.utils.IOExceptionSupport; import org.apache.activemq.openwire.utils.OpenWireMarshallingSupport; import org.fusesource.hawtbuf.Buffer; import org.fusesource.hawtbuf.ByteArrayInputStream; @@ -43,8 +41,6 @@ import org.fusesource.hawtbuf.UTF8Buffer; /** * Represents an ActiveMQ message - * - * @openwire:marshaller */ @OpenWireType(typeCode = 0, marshalAware = true) public abstract class Message extends BaseCommand implements MarshallAware { @@ -153,12 +149,12 @@ public abstract class Message extends BaseCommand implements MarshallAware { protected Map<String, Object> properties; public abstract Message copy(); - public abstract void clearBody() throws JMSException; + public abstract void clearBody() throws IOException; public abstract void storeContent(); public abstract void storeContentAndClear(); // useful to reduce the memory footprint of a persisted message - public void clearMarshalledState() throws JMSException { + public void clearMarshalledState() throws IOException { properties = null; } @@ -216,20 +212,20 @@ public abstract class Message extends BaseCommand implements MarshallAware { return Collections.unmodifiableMap(properties); } - public void clearProperties() throws JMSException { + public void clearProperties() throws IOException { marshalledProperties = null; properties = null; } - public Object getProperty(String name) throws JMSException { + public Object getProperty(String name) throws IOException { if (properties == null) { if (marshalledProperties == null) { return null; } try { properties = unmarsallProperties(marshalledProperties); - } catch (IOException e) { - throw ExceptionSupport.create("Error during properties unmarshal, reason: " + e.getMessage(), e); + } catch (Exception e) { + throw IOExceptionSupport.create("Error during properties unmarshal, reason: " + e.getMessage(), e); } } Object result = properties.get(name); @@ -240,25 +236,25 @@ public abstract class Message extends BaseCommand implements MarshallAware { return result; } - public void setProperty(String name, Object value) throws JMSException { + public void setProperty(String name, Object value) throws IOException { lazyCreateProperties(); properties.put(name, value); } - public void removeProperty(String name) throws JMSException { + public void removeProperty(String name) throws IOException { lazyCreateProperties(); properties.remove(name); } - protected void lazyCreateProperties() throws JMSException { + protected void lazyCreateProperties() throws IOException { if (properties == null) { if (marshalledProperties == null) { properties = new HashMap<String, Object>(); } else { try { properties = unmarsallProperties(marshalledProperties); - } catch (IOException e) { - throw ExceptionSupport.create( + } catch (Exception e) { + throw IOExceptionSupport.create( "Error during properties unmarshal, reason: " + e.getMessage(), e); } marshalledProperties = null; diff --git a/openwire-core/src/main/java/org/apache/activemq/openwire/commands/OpenWireBlobMessage.java b/openwire-core/src/main/java/org/apache/activemq/openwire/commands/OpenWireBlobMessage.java index 561793e..d8636ad 100644 --- a/openwire-core/src/main/java/org/apache/activemq/openwire/commands/OpenWireBlobMessage.java +++ b/openwire-core/src/main/java/org/apache/activemq/openwire/commands/OpenWireBlobMessage.java @@ -17,20 +17,15 @@ package org.apache.activemq.openwire.commands; import java.io.IOException; -import java.io.InputStream; import java.net.MalformedURLException; import java.net.URL; -import javax.jms.JMSException; - -import org.apache.activemq.openwire.annotations.OpenWireType; import org.apache.activemq.openwire.annotations.OpenWireExtension; import org.apache.activemq.openwire.annotations.OpenWireProperty; +import org.apache.activemq.openwire.annotations.OpenWireType; /** * An implementation of ActiveMQ's BlobMessage for out of band BLOB transfer - * - * openwire:marshaller code="29" */ @OpenWireType(typeCode = 29, version = 3) public class OpenWireBlobMessage extends OpenWireMessage { @@ -126,16 +121,12 @@ public class OpenWireBlobMessage extends OpenWireMessage { this.deletedByBroker = deletedByBroker; } - public InputStream getInputStream() throws IOException, JMSException { - return null; - } - - public URL getURL() throws JMSException { + public URL getURL() throws IOException { if (url == null && remoteBlobUrl != null) { try { url = new URL(remoteBlobUrl); } catch (MalformedURLException e) { - throw new JMSException(e.getMessage()); + throw new IOException(e.getMessage()); } } return url; @@ -145,16 +136,4 @@ public class OpenWireBlobMessage extends OpenWireMessage { this.url = url; remoteBlobUrl = url != null ? url.toExternalForm() : null; } - - @Override - public void onSend() throws JMSException { - super.onSend(); - - // lets ensure we upload the BLOB first out of band before we send the - // message - // TODO - Lets support this later. - } - - public void deleteFile() throws IOException, JMSException { - } } diff --git a/openwire-core/src/main/java/org/apache/activemq/openwire/commands/OpenWireBytesMessage.java b/openwire-core/src/main/java/org/apache/activemq/openwire/commands/OpenWireBytesMessage.java index 33f922c..1adbb0c 100644 --- a/openwire-core/src/main/java/org/apache/activemq/openwire/commands/OpenWireBytesMessage.java +++ b/openwire-core/src/main/java/org/apache/activemq/openwire/commands/OpenWireBytesMessage.java @@ -21,9 +21,6 @@ import java.util.Arrays; import java.util.zip.Deflater; import java.util.zip.Inflater; -import javax.jms.JMSException; -import javax.jms.MessageNotReadableException; - import org.apache.activemq.openwire.annotations.OpenWireType; import org.fusesource.hawtbuf.Buffer; import org.fusesource.hawtbuf.BufferEditor; @@ -70,12 +67,10 @@ public class OpenWireBytesMessage extends OpenWireMessage { * of where the pointer for reading the message is currently located. * * @return number of bytes in the message - * @throws JMSException if the JMS provider fails to read the message due to - * some internal error. - * @throws MessageNotReadableException if the message is in write-only mode. - * @since 1.1 + * + * @throws IOException if there is an error in retrieving the body length value. */ - public long getBodyLength() throws JMSException { + public long getBodyLength() throws IOException { if (compressed) { return getBodyBytes().length; } else if (content != null) { @@ -96,9 +91,9 @@ public class OpenWireBytesMessage extends OpenWireMessage { * * @return a copy of the message contents, uncompressed as needed. * - * @throws JMSException if an error occurs while accessing the message payload. + * @throws IOException if an error occurs while accessing the message payload. */ - public byte[] getBodyBytes() throws JMSException { + public byte[] getBodyBytes() throws IOException { Buffer data = getPayload(); if (data == null) { data = new Buffer(new byte[] {}, 0, 0); diff --git a/openwire-core/src/main/java/org/apache/activemq/openwire/commands/OpenWireDestination.java b/openwire-core/src/main/java/org/apache/activemq/openwire/commands/OpenWireDestination.java index 04bb1f3..91c5d74 100644 --- a/openwire-core/src/main/java/org/apache/activemq/openwire/commands/OpenWireDestination.java +++ b/openwire-core/src/main/java/org/apache/activemq/openwire/commands/OpenWireDestination.java @@ -26,27 +26,16 @@ import java.util.Map; import java.util.Set; import java.util.StringTokenizer; -import javax.jms.Destination; -import javax.jms.JMSException; -import javax.jms.Queue; -import javax.jms.TemporaryQueue; -import javax.jms.TemporaryTopic; -import javax.jms.Topic; - -import org.apache.activemq.openwire.annotations.OpenWireType; import org.apache.activemq.openwire.annotations.OpenWireExtension; import org.apache.activemq.openwire.annotations.OpenWireProperty; -import org.apache.activemq.openwire.utils.DefaultUnresolvedDestinationTransformer; -import org.apache.activemq.openwire.utils.UnresolvedDestinationTransformer; +import org.apache.activemq.openwire.annotations.OpenWireType; /** * Base Destination class used to provide most of the utilities necessary to deal * with incoming and outgoing destination processing. - * - * @openwire:marshaller */ @OpenWireType(typeCode = 0) -public abstract class OpenWireDestination implements Destination, DataStructure, Comparable<OpenWireDestination> { +public abstract class OpenWireDestination implements DataStructure, Comparable<OpenWireDestination> { public static final String PATH_SEPERATOR = "."; public static final char COMPOSITE_SEPERATOR = ','; @@ -82,8 +71,6 @@ public abstract class OpenWireDestination implements Destination, DataStructure, @OpenWireExtension(serialized = true) protected Map<String, String> options; - protected static UnresolvedDestinationTransformer unresolvableDestinationTransformer = new DefaultUnresolvedDestinationTransformer(); - public OpenWireDestination() { } @@ -122,40 +109,6 @@ public abstract class OpenWireDestination implements Destination, DataStructure, } } - public static OpenWireDestination transform(Destination dest) throws JMSException { - if (dest == null) { - return null; - } - if (dest instanceof OpenWireDestination) { - return (OpenWireDestination)dest; - } - - if (dest instanceof Queue && dest instanceof Topic) { - String queueName = ((Queue) dest).getQueueName(); - String topicName = ((Topic) dest).getTopicName(); - if (queueName != null && topicName == null) { - return new OpenWireQueue(queueName); - } else if (queueName == null && topicName != null) { - return new OpenWireTopic(topicName); - } else { - return unresolvableDestinationTransformer.transform(dest); - } - } - if (dest instanceof TemporaryQueue) { - return new OpenWireTempQueue(((TemporaryQueue)dest).getQueueName()); - } - if (dest instanceof TemporaryTopic) { - return new OpenWireTempTopic(((TemporaryTopic)dest).getTopicName()); - } - if (dest instanceof Queue) { - return new OpenWireQueue(((Queue)dest).getQueueName()); - } - if (dest instanceof Topic) { - return new OpenWireTopic(((Topic)dest).getTopicName()); - } - throw new JMSException("Could not transform the destination into a ActiveMQ destination: " + dest); - } - public static int compare(OpenWireDestination destination, OpenWireDestination destination2) { if (destination == destination2) { return 0; @@ -379,14 +332,6 @@ public abstract class OpenWireDestination implements Destination, DataStructure, return isPattern; } - public static UnresolvedDestinationTransformer getUnresolvableDestinationTransformer() { - return unresolvableDestinationTransformer; - } - - public static void setUnresolvableDestinationTransformer(UnresolvedDestinationTransformer unresolvableDestinationTransformer) { - OpenWireDestination.unresolvableDestinationTransformer = unresolvableDestinationTransformer; - } - private static Map<String, String> parseQuery(String uri) throws Exception { if (uri != null) { Map<String, String> rc = new HashMap<String, String>(); diff --git a/openwire-core/src/main/java/org/apache/activemq/openwire/commands/OpenWireMapMessage.java b/openwire-core/src/main/java/org/apache/activemq/openwire/commands/OpenWireMapMessage.java index 656bfce..fbc5fa5 100644 --- a/openwire-core/src/main/java/org/apache/activemq/openwire/commands/OpenWireMapMessage.java +++ b/openwire-core/src/main/java/org/apache/activemq/openwire/commands/OpenWireMapMessage.java @@ -29,14 +29,10 @@ import java.util.Map; import java.util.zip.DeflaterOutputStream; import java.util.zip.InflaterInputStream; -import javax.jms.JMSException; -import javax.jms.MessageFormatException; -import javax.jms.MessageNotWriteableException; - -import org.apache.activemq.openwire.annotations.OpenWireType; import org.apache.activemq.openwire.annotations.OpenWireExtension; +import org.apache.activemq.openwire.annotations.OpenWireType; import org.apache.activemq.openwire.codec.OpenWireFormat; -import org.apache.activemq.openwire.utils.ExceptionSupport; +import org.apache.activemq.openwire.utils.IOExceptionSupport; import org.apache.activemq.openwire.utils.OpenWireMarshallingSupport; import org.fusesource.hawtbuf.Buffer; import org.fusesource.hawtbuf.ByteArrayInputStream; @@ -81,7 +77,7 @@ public class OpenWireMapMessage extends OpenWireMessage { } @Override - public void clearMarshalledState() throws JMSException { + public void clearMarshalledState() throws IOException { super.clearMarshalledState(); map.clear(); } @@ -115,10 +111,9 @@ public class OpenWireMapMessage extends OpenWireMessage { /** * Builds the message body from data * - * @throws JMSException * @throws IOException */ - private void loadContent() throws JMSException { + private void loadContent() throws IOException { try { if (getContent() != null && map.isEmpty()) { Buffer content = getContent(); @@ -130,8 +125,8 @@ public class OpenWireMapMessage extends OpenWireMessage { map = OpenWireMarshallingSupport.unmarshalPrimitiveMap(dataIn); dataIn.close(); } - } catch (IOException e) { - throw ExceptionSupport.create(e); + } catch (Exception e) { + throw IOExceptionSupport.create(e); } } @@ -154,7 +149,7 @@ public class OpenWireMapMessage extends OpenWireMessage { * message. */ @Override - public void clearBody() throws JMSException { + public void clearBody() throws IOException { super.clearBody(); map.clear(); } @@ -180,7 +175,7 @@ public class OpenWireMapMessage extends OpenWireMessage { * @throws JMSException if the JMS provider fails to read the message due to * some internal error. */ - public Object getObject(String name) throws JMSException { + public Object getObject(String name) throws IOException { initializeReading(); Object result = getContentMap().get(name); if (result instanceof UTF8Buffer) { @@ -207,7 +202,7 @@ public class OpenWireMapMessage extends OpenWireMessage { * empty string. * @throws MessageFormatException if the object is invalid. */ - public void setObject(String name, Object value) throws JMSException { + public void setObject(String name, Object value) throws IOException { initializeWriting(); if (value != null) { // byte[] not allowed on properties @@ -231,7 +226,7 @@ public class OpenWireMapMessage extends OpenWireMessage { * @throws IllegalArgumentException if the name is null or if the name is an * empty string. */ - public void removeObject(String name) throws JMSException { + public void removeObject(String name) throws IOException { initializeWriting(); if (name == null || name.trim().isEmpty()) { throw new IllegalArgumentException("map element name cannot be null or empty."); @@ -247,7 +242,7 @@ public class OpenWireMapMessage extends OpenWireMessage { * @return an enumeration of all the names in this <CODE>MapMessage</CODE> * @throws JMSException */ - public Enumeration<String> getMapNames() throws JMSException { + public Enumeration<String> getMapNames() throws IOException { return Collections.enumeration(getContentMap().keySet()); } @@ -260,15 +255,15 @@ public class OpenWireMapMessage extends OpenWireMessage { * @throws JMSException if the JMS provider fails to determine if the item * exists due to some internal error. */ - public boolean itemExists(String name) throws JMSException { + public boolean itemExists(String name) throws IOException { return getContentMap().containsKey(name); } - private void initializeReading() throws JMSException { + private void initializeReading() throws IOException { loadContent(); } - private void initializeWriting() throws MessageNotWriteableException { + private void initializeWriting() throws IOException { setContent(null); } @@ -283,12 +278,12 @@ public class OpenWireMapMessage extends OpenWireMessage { return super.toString() + " OpenWireMapMessage{ " + "theTable = " + map + " }"; } - protected Map<String, Object> getContentMap() throws JMSException { + protected Map<String, Object> getContentMap() throws IOException { initializeReading(); return map; } - protected void put(String name, Object value) throws JMSException { + protected void put(String name, Object value) throws IOException { if (name == null) { throw new IllegalArgumentException("The name of the property cannot be null."); } diff --git a/openwire-core/src/main/java/org/apache/activemq/openwire/commands/OpenWireMessage.java b/openwire-core/src/main/java/org/apache/activemq/openwire/commands/OpenWireMessage.java index ce39730..e2b6a1f 100644 --- a/openwire-core/src/main/java/org/apache/activemq/openwire/commands/OpenWireMessage.java +++ b/openwire-core/src/main/java/org/apache/activemq/openwire/commands/OpenWireMessage.java @@ -23,12 +23,9 @@ import java.util.List; import java.util.Map; import java.util.Vector; -import javax.jms.JMSException; -import javax.jms.MessageFormatException; - -import org.apache.activemq.openwire.annotations.OpenWireType; import org.apache.activemq.openwire.annotations.OpenWireExtension; -import org.apache.activemq.openwire.utils.ExceptionSupport; +import org.apache.activemq.openwire.annotations.OpenWireType; +import org.apache.activemq.openwire.utils.IOExceptionSupport; import org.fusesource.hawtbuf.Buffer; import org.fusesource.hawtbuf.UTF8Buffer; @@ -100,7 +97,7 @@ public class OpenWireMessage extends Message { } @Override - public void clearBody() throws JMSException { + public void clearBody() throws IOException { setContent(null); } @@ -112,11 +109,11 @@ public class OpenWireMessage extends Message { return messageId.toString(); } - public byte[] getCorrelationIdAsBytes() throws JMSException { + public byte[] getCorrelationIdAsBytes() throws IOException { return encodeString(this.getCorrelationId()); } - public void setCorrelationIdAsBytes(byte[] correlationId) throws JMSException { + public void setCorrelationIdAsBytes(byte[] correlationId) throws IOException { this.setCorrelationId(decodeString(correlationId)); } @@ -142,15 +139,15 @@ public class OpenWireMessage extends Message { * * @throws JMSException if an error occurs while accessing the message payload. */ - public Buffer getPayload() throws JMSException { + public Buffer getPayload() throws IOException { Buffer data = getContent(); if (data == null) { data = new Buffer(new byte[] {}, 0, 0); } else if (isCompressed()) { try { return decompress(); - } catch (IOException e) { - throw ExceptionSupport.create(e); + } catch (Exception e) { + throw IOExceptionSupport.create(e); } } @@ -167,9 +164,9 @@ public class OpenWireMessage extends Message { * @param bytes * the new byte array to use to fill the message body. * - * @throws JMSException if an error occurs while accessing the message payload. + * @throws IOException if an error occurs while accessing the message payload. */ - public void setPayload(byte[] bytes) throws JMSException { + public void setPayload(byte[] bytes) throws IOException { setPayload(new Buffer(bytes)); } @@ -185,14 +182,14 @@ public class OpenWireMessage extends Message { * * @throws JMSException if an error occurs while accessing the message payload. */ - public void setPayload(Buffer buffer) throws JMSException { + public void setPayload(Buffer buffer) throws IOException { try { setContent(buffer); if (isUseCompression()) { doCompress(); } - } catch (IOException ioe) { - throw ExceptionSupport.create(ioe); + } catch (Exception ex) { + throw IOExceptionSupport.create(ex); } } @@ -203,9 +200,9 @@ public class OpenWireMessage extends Message { * @param value * the string Message ID value to assign to this message. * - * @throws JMSException if an error occurs while parsing the String to a MessageID + * @throws IOException if an error occurs while parsing the String to a MessageID */ - public void setMessageId(String value) throws JMSException { + public void setMessageId(String value) throws IOException { if (value != null) { try { MessageId id = new MessageId(value); @@ -231,36 +228,36 @@ public class OpenWireMessage extends Message { * * @throws JMSException if an error occurs while setting this MessageId */ - public void setMessageId(ProducerId producerId, long producerSequenceId) throws JMSException { + public void setMessageId(ProducerId producerId, long producerSequenceId) throws IOException { MessageId id = null; try { id = new MessageId(producerId, producerSequenceId); this.setMessageId(id); } catch (Throwable e) { - throw ExceptionSupport.create("Invalid message id '" + id + "', reason: " + e.getMessage(), e); + throw IOExceptionSupport.create("Invalid message id '" + id + "', reason: " + e.getMessage(), e); } } - public boolean propertyExists(String name) throws JMSException { + public boolean propertyExists(String name) throws IOException { try { return (this.getProperties().containsKey(name) || getProperty(name)!= null); - } catch (IOException e) { - throw ExceptionSupport.create(e); + } catch (Exception e) { + throw IOExceptionSupport.create(e); } } @SuppressWarnings("rawtypes") - public Enumeration getPropertyNames() throws JMSException { + public Enumeration getPropertyNames() throws IOException { try { Vector<String> result = new Vector<String>(this.getProperties().keySet()); return result.elements(); - } catch (IOException e) { - throw ExceptionSupport.create(e); + } catch (Exception e) { + throw IOExceptionSupport.create(e); } } @Override - public void setProperty(String name, Object value) throws JMSException { + public void setProperty(String name, Object value) throws IOException { setProperty(name, value, true); } @@ -276,7 +273,7 @@ public class OpenWireMessage extends Message { * * @throws JMSException if an error occurs while setting the properties. */ - public void setProperties(Map<String, ?> properties) throws JMSException { + public void setProperties(Map<String, ?> properties) throws IOException { for (Map.Entry<String, ?> entry : properties.entrySet()) { setProperty(entry.getKey(), entry.getValue()); } @@ -295,9 +292,9 @@ public class OpenWireMessage extends Message { * @param checkValid * indicates if a type validity check should be performed on the given object. * - * @throws JMSException if an error occurs while attempting to set the property value. + * @throws IOException if an error occurs while attempting to set the property value. */ - public void setProperty(String name, Object value, boolean checkValid) throws JMSException { + public void setProperty(String name, Object value, boolean checkValid) throws IOException { if (name == null || name.equals("")) { throw new IllegalArgumentException("Property name cannot be empty or null"); } @@ -367,45 +364,48 @@ public class OpenWireMessage extends Message { * Method that allows an application to inform the Message instance that it is * about to be sent and that it should prepare its internal state for dispatch. * - * @throws JMSException if an error occurs or Message state is invalid. + * @throws IOException if an error occurs or Message state is invalid. */ - public void onSend() throws JMSException { + public void onSend() throws IOException { } - protected void checkValidObject(Object value) throws MessageFormatException { + protected void checkValidObject(Object value) throws IOException { + + // TODO - We can probably remove these nested enabled check, the provider should + // do this since we are just a codec. boolean valid = value instanceof Boolean || value instanceof Byte || value instanceof Short || value instanceof Integer || value instanceof Long; valid = valid || value instanceof Float || value instanceof Double || value instanceof Character || value instanceof String || value == null; if (!valid) { if (isNestedMapAndListAllowed()) { if (!(value instanceof Map || value instanceof List)) { - throw new MessageFormatException("Only objectified primitive objects, String, Map and List types are allowed but was: " + value + " type: " + value.getClass()); + throw new IllegalArgumentException("Only objectified primitive objects, String, Map and List types are allowed but was: " + value + " type: " + value.getClass()); } } else { - throw new MessageFormatException("Only objectified primitive objects and String types are allowed but was: " + value + " type: " + value.getClass()); + throw new IllegalArgumentException("Only objectified primitive objects and String types are allowed but was: " + value + " type: " + value.getClass()); } } } - protected static String decodeString(byte[] data) throws JMSException { + protected static String decodeString(byte[] data) throws IOException { try { if (data == null) { return null; } return new String(data, "UTF-8"); } catch (UnsupportedEncodingException e) { - throw new JMSException("Invalid UTF-8 encoding: " + e.getMessage()); + throw IOExceptionSupport.create("Invalid UTF-8 encoding: " + e.getMessage(), e); } } - protected static byte[] encodeString(String data) throws JMSException { + protected static byte[] encodeString(String data) throws IOException { try { if (data == null) { return null; } return data.getBytes("UTF-8"); } catch (UnsupportedEncodingException e) { - throw new JMSException("Invalid UTF-8 encoding: " + e.getMessage()); + throw IOExceptionSupport.create("Invalid UTF-8 encoding: " + e.getMessage(), e); } } } diff --git a/openwire-core/src/main/java/org/apache/activemq/openwire/commands/OpenWireObjectMessage.java b/openwire-core/src/main/java/org/apache/activemq/openwire/commands/OpenWireObjectMessage.java index 8480234..3214556 100644 --- a/openwire-core/src/main/java/org/apache/activemq/openwire/commands/OpenWireObjectMessage.java +++ b/openwire-core/src/main/java/org/apache/activemq/openwire/commands/OpenWireObjectMessage.java @@ -27,12 +27,10 @@ import java.io.Serializable; import java.util.zip.DeflaterOutputStream; import java.util.zip.InflaterInputStream; -import javax.jms.JMSException; - -import org.apache.activemq.openwire.annotations.OpenWireType; import org.apache.activemq.openwire.annotations.OpenWireExtension; +import org.apache.activemq.openwire.annotations.OpenWireType; import org.apache.activemq.openwire.codec.OpenWireFormat; -import org.apache.activemq.openwire.utils.ExceptionSupport; +import org.apache.activemq.openwire.utils.IOExceptionSupport; import org.apache.activemq.openwire.utils.ObjectMessageInputStream; import org.fusesource.hawtbuf.Buffer; import org.fusesource.hawtbuf.ByteArrayInputStream; @@ -111,11 +109,10 @@ public class OpenWireObjectMessage extends OpenWireMessage { * message body in the same state as an empty body in a newly created * message. * - * @throws JMSException if the JMS provider fails to clear the message body - * due to some internal error. + * @throws IOException if an error occurs removing the body. */ @Override - public void clearBody() throws JMSException { + public void clearBody() throws IOException { super.clearBody(); this.object = null; } @@ -134,7 +131,7 @@ public class OpenWireObjectMessage extends OpenWireMessage { * @throws javax.jms.MessageNotWriteableException if the message is in * read-only mode. */ - public void setObject(Serializable newObject) throws JMSException { + public void setObject(Serializable newObject) throws IOException { this.object = newObject; setContent(null); storeContent(); @@ -147,7 +144,7 @@ public class OpenWireObjectMessage extends OpenWireMessage { * @return the serializable object containing this message's data * @throws JMSException */ - public Serializable getObject() throws JMSException { + public Serializable getObject() throws IOException { if (object == null && getContent() != null) { try { Buffer content = getContent(); @@ -160,13 +157,13 @@ public class OpenWireObjectMessage extends OpenWireMessage { try { object = (Serializable)objIn.readObject(); } catch (ClassNotFoundException ce) { - throw ExceptionSupport.create("Failed to build body from content. Serializable class not available to broker. Reason: " + ce, ce); + throw IOExceptionSupport.create("Failed to build body from content. Serializable class not available to broker. Reason: " + ce, ce); } finally { dataIn.close(); objIn.close(); } - } catch (IOException e) { - throw ExceptionSupport.create("Failed to build body from bytes. Reason: " + e, e); + } catch (Exception e) { + throw IOExceptionSupport.create("Failed to build body from bytes. Reason: " + e, e); } } return this.object; @@ -179,7 +176,7 @@ public class OpenWireObjectMessage extends OpenWireMessage { } @Override - public void clearMarshalledState() throws JMSException { + public void clearMarshalledState() throws IOException { super.clearMarshalledState(); this.object = null; } @@ -194,7 +191,7 @@ public class OpenWireObjectMessage extends OpenWireMessage { public String toString() { try { getObject(); - } catch (JMSException e) { + } catch (IOException e) { } return super.toString(); } diff --git a/openwire-core/src/main/java/org/apache/activemq/openwire/commands/OpenWireQueue.java b/openwire-core/src/main/java/org/apache/activemq/openwire/commands/OpenWireQueue.java index ab03b58..543b723 100644 --- a/openwire-core/src/main/java/org/apache/activemq/openwire/commands/OpenWireQueue.java +++ b/openwire-core/src/main/java/org/apache/activemq/openwire/commands/OpenWireQueue.java @@ -16,17 +16,10 @@ */ package org.apache.activemq.openwire.commands; -import javax.jms.JMSException; -import javax.jms.Queue; - import org.apache.activemq.openwire.annotations.OpenWireType; - -/** - * @openwire:marshaller code="100" - */ @OpenWireType(typeCode = 100) -public class OpenWireQueue extends OpenWireDestination implements Queue { +public class OpenWireQueue extends OpenWireDestination { public static final byte DATA_STRUCTURE_TYPE = CommandTypes.OPENWIRE_QUEUE; @@ -57,8 +50,7 @@ public class OpenWireQueue extends OpenWireDestination implements Queue { return QUEUE_QUALIFIED_PREFIX; } - @Override - public String getQueueName() throws JMSException { + public String getQueueName() { return getPhysicalName(); } } diff --git a/openwire-core/src/main/java/org/apache/activemq/openwire/commands/OpenWireStreamMessage.java b/openwire-core/src/main/java/org/apache/activemq/openwire/commands/OpenWireStreamMessage.java index d848e0e..82db2e4 100644 --- a/openwire-core/src/main/java/org/apache/activemq/openwire/commands/OpenWireStreamMessage.java +++ b/openwire-core/src/main/java/org/apache/activemq/openwire/commands/OpenWireStreamMessage.java @@ -24,18 +24,13 @@ import java.util.ArrayList; import java.util.Collections; import java.util.List; -import javax.jms.JMSException; - import org.apache.activemq.openwire.annotations.OpenWireType; -import org.apache.activemq.openwire.utils.ExceptionSupport; +import org.apache.activemq.openwire.utils.IOExceptionSupport; import org.apache.activemq.openwire.utils.OpenWireMarshallingSupport; import org.fusesource.hawtbuf.Buffer; import org.fusesource.hawtbuf.DataByteArrayInputStream; import org.fusesource.hawtbuf.DataByteArrayOutputStream; -/** - * openwire:marshaller code="27" - */ @OpenWireType(typeCode = 27) public class OpenWireStreamMessage extends OpenWireMessage { @@ -54,7 +49,7 @@ public class OpenWireStreamMessage extends OpenWireMessage { } @Override - public void onSend() throws JMSException { + public void onSend() throws IOException { super.onSend(); storeContent(); } @@ -79,7 +74,7 @@ public class OpenWireStreamMessage extends OpenWireMessage { * * @throws JMSException if an error occurs while reading the message. */ - public List<Object> readStreamToList() throws JMSException { + public List<Object> readStreamToList() throws IOException { if (!hasContent()) { return Collections.emptyList(); } @@ -93,8 +88,8 @@ public class OpenWireStreamMessage extends OpenWireMessage { result.add(readNextElement(dataIn)); } catch (EOFException ex) { break; - } catch (IOException e) { - throw ExceptionSupport.create(e); + } catch (Exception e) { + throw IOExceptionSupport.create(e); } } @@ -159,24 +154,17 @@ public class OpenWireStreamMessage extends OpenWireMessage { * @param elements * the list of elements to store into the list. * - * @throws JMSException if an error occurs while writing the elements to the message. + * @throws IOException if an error occurs while writing the elements to the message. */ - public void writeListToStream(List<Object> elements) throws JMSException { + public void writeListToStream(List<Object> elements) throws IOException { if (elements != null && !elements.isEmpty()) { DataByteArrayOutputStream output = new DataByteArrayOutputStream(); for (Object value : elements) { - try { - writeElement(value, output); - } catch (IOException e) { - throw ExceptionSupport.create(e); - } - } - try { - output.close(); - } catch (IOException e) { - throw ExceptionSupport.create(e); + writeElement(value, output); } + output.close(); + setPayload(output.toBuffer()); } } diff --git a/openwire-core/src/main/java/org/apache/activemq/openwire/commands/OpenWireTempQueue.java b/openwire-core/src/main/java/org/apache/activemq/openwire/commands/OpenWireTempQueue.java index b3cbed0..0ec09d2 100644 --- a/openwire-core/src/main/java/org/apache/activemq/openwire/commands/OpenWireTempQueue.java +++ b/openwire-core/src/main/java/org/apache/activemq/openwire/commands/OpenWireTempQueue.java @@ -16,19 +16,13 @@ */ package org.apache.activemq.openwire.commands; -import javax.jms.JMSException; -import javax.jms.TemporaryQueue; - import org.apache.activemq.openwire.annotations.OpenWireType; - /** - * Represents an ActiveMQ Temporary Queue. - * - * @openwire:marshaller code="102" + * Represents an OpenWire Temporary Queue. */ @OpenWireType(typeCode = 102) -public class OpenWireTempQueue extends OpenWireTempDestination implements TemporaryQueue { +public class OpenWireTempQueue extends OpenWireTempDestination { public static final byte DATA_STRUCTURE_TYPE = CommandTypes.OPENWIRE_TEMP_QUEUE; @@ -63,12 +57,7 @@ public class OpenWireTempQueue extends OpenWireTempDestination implements Tempor return TEMP_QUEUE_QUALIFED_PREFIX; } - @Override - public String getQueueName() throws JMSException { + public String getQueueName() { return getPhysicalName(); } - - @Override - public void delete() throws JMSException { - } } diff --git a/openwire-core/src/main/java/org/apache/activemq/openwire/commands/OpenWireTempTopic.java b/openwire-core/src/main/java/org/apache/activemq/openwire/commands/OpenWireTempTopic.java index 05a5fe3..ceef32b 100644 --- a/openwire-core/src/main/java/org/apache/activemq/openwire/commands/OpenWireTempTopic.java +++ b/openwire-core/src/main/java/org/apache/activemq/openwire/commands/OpenWireTempTopic.java @@ -16,16 +16,10 @@ */ package org.apache.activemq.openwire.commands; -import javax.jms.JMSException; -import javax.jms.TemporaryTopic; - import org.apache.activemq.openwire.annotations.OpenWireType; -/** - * @openwire:marshaller code="103" - */ @OpenWireType(typeCode = 103) -public class OpenWireTempTopic extends OpenWireTempDestination implements TemporaryTopic { +public class OpenWireTempTopic extends OpenWireTempDestination { public static final byte DATA_STRUCTURE_TYPE = CommandTypes.OPENWIRE_TEMP_TOPIC; @@ -60,13 +54,7 @@ public class OpenWireTempTopic extends OpenWireTempDestination implements Tempor return TEMP_TOPIC_QUALIFED_PREFIX; } - @Override - public String getTopicName() throws JMSException { + public String getTopicName() { return getPhysicalName(); } - - @Override - public void delete() throws JMSException { - - } } diff --git a/openwire-core/src/main/java/org/apache/activemq/openwire/commands/OpenWireTextMessage.java b/openwire-core/src/main/java/org/apache/activemq/openwire/commands/OpenWireTextMessage.java index de9d964..1003148 100644 --- a/openwire-core/src/main/java/org/apache/activemq/openwire/commands/OpenWireTextMessage.java +++ b/openwire-core/src/main/java/org/apache/activemq/openwire/commands/OpenWireTextMessage.java @@ -22,21 +22,15 @@ import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; -import javax.jms.JMSException; -import javax.jms.MessageNotWriteableException; - -import org.apache.activemq.openwire.annotations.OpenWireType; import org.apache.activemq.openwire.annotations.OpenWireExtension; +import org.apache.activemq.openwire.annotations.OpenWireType; import org.apache.activemq.openwire.codec.OpenWireFormat; -import org.apache.activemq.openwire.utils.ExceptionSupport; +import org.apache.activemq.openwire.utils.IOExceptionSupport; import org.apache.activemq.openwire.utils.OpenWireMarshallingSupport; import org.fusesource.hawtbuf.Buffer; import org.fusesource.hawtbuf.ByteArrayInputStream; import org.fusesource.hawtbuf.ByteArrayOutputStream; -/** - * openwire:marshaller code="28" - */ @OpenWireType(typeCode = 28) public class OpenWireTextMessage extends OpenWireMessage { @@ -67,12 +61,12 @@ public class OpenWireTextMessage extends OpenWireMessage { return "jms/text-message"; } - public void setText(String text) throws MessageNotWriteableException { + public void setText(String text) { this.text = text; setContent(null); } - public String getText() throws JMSException { + public String getText() throws IOException { if (text == null && getContent() != null) { text = decodeContent(); setContent(null); @@ -80,7 +74,7 @@ public class OpenWireTextMessage extends OpenWireMessage { return text; } - private String decodeContent() throws JMSException { + private String decodeContent() throws IOException { String text = null; if (hasContent()) { InputStream is = null; @@ -89,8 +83,8 @@ public class OpenWireTextMessage extends OpenWireMessage { DataInputStream dataIn = new DataInputStream(is); text = OpenWireMarshallingSupport.readUTF8(dataIn); dataIn.close(); - } catch (IOException ioe) { - throw ExceptionSupport.create(ioe); + } catch (Exception ex) { + throw IOExceptionSupport.create(ex); } finally { if (is != null) { try { @@ -134,7 +128,7 @@ public class OpenWireTextMessage extends OpenWireMessage { } @Override - public void clearMarshalledState() throws JMSException { + public void clearMarshalledState() throws IOException { super.clearMarshalledState(); this.text = null; } @@ -147,11 +141,11 @@ public class OpenWireTextMessage extends OpenWireMessage { * message body in the same state as an empty body in a newly created * message. * - * @throws JMSException if the JMS provider fails to clear the message body + * @throws IOException if the JMS provider fails to clear the message body * due to some internal error. */ @Override - public void clearBody() throws JMSException { + public void clearBody() throws IOException { super.clearBody(); this.text = null; } @@ -174,7 +168,7 @@ public class OpenWireTextMessage extends OpenWireMessage { if( text == null ) { try { text = decodeContent(); - } catch (JMSException ex) { + } catch (IOException ex) { } } if (text != null) { diff --git a/openwire-core/src/main/java/org/apache/activemq/openwire/commands/OpenWireTopic.java b/openwire-core/src/main/java/org/apache/activemq/openwire/commands/OpenWireTopic.java index 2bf503f..961e7ce 100644 --- a/openwire-core/src/main/java/org/apache/activemq/openwire/commands/OpenWireTopic.java +++ b/openwire-core/src/main/java/org/apache/activemq/openwire/commands/OpenWireTopic.java @@ -16,16 +16,10 @@ */ package org.apache.activemq.openwire.commands; -import javax.jms.JMSException; -import javax.jms.Topic; - import org.apache.activemq.openwire.annotations.OpenWireType; -/** - * @openwire:marshaller code="101" - */ @OpenWireType(typeCode = 101) -public class OpenWireTopic extends OpenWireDestination implements Topic { +public class OpenWireTopic extends OpenWireDestination { public static final byte DATA_STRUCTURE_TYPE = CommandTypes.OPENWIRE_TOPIC; @@ -46,8 +40,7 @@ public class OpenWireTopic extends OpenWireDestination implements Topic { return true; } - @Override - public String getTopicName() throws JMSException { + public String getTopicName() { return getPhysicalName(); } diff --git a/openwire-core/src/main/java/org/apache/activemq/openwire/utils/DefaultUnresolvedDestinationTransformer.java b/openwire-core/src/main/java/org/apache/activemq/openwire/utils/DefaultUnresolvedDestinationTransformer.java deleted file mode 100644 index e7c6bec..0000000 --- a/openwire-core/src/main/java/org/apache/activemq/openwire/utils/DefaultUnresolvedDestinationTransformer.java +++ /dev/null @@ -1,71 +0,0 @@ -/** - * 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.openwire.utils; - -import java.lang.reflect.Method; - -import javax.jms.Destination; -import javax.jms.JMSException; -import javax.jms.Queue; -import javax.jms.Topic; - -import org.apache.activemq.openwire.commands.OpenWireDestination; -import org.apache.activemq.openwire.commands.OpenWireQueue; -import org.apache.activemq.openwire.commands.OpenWireTopic; - -/** - * A default implementation of the resolver that attempts to find an isQueue or isTopic method - * on the foreign destination to determine the correct type. - */ -public class DefaultUnresolvedDestinationTransformer implements UnresolvedDestinationTransformer { - - @Override - public OpenWireDestination transform(Destination dest) throws JMSException { - String queueName = ((Queue) dest).getQueueName(); - String topicName = ((Topic) dest).getTopicName(); - - if (queueName == null && topicName == null) { - throw new JMSException("Unresolvable destination: Both queue and topic names are null: " + dest); - } - - try { - Method isQueueMethod = dest.getClass().getMethod("isQueue"); - Method isTopicMethod = dest.getClass().getMethod("isTopic"); - - if (isQueueMethod == null && isTopicMethod == null) { - throw new JMSException("Unresolvable destination: Neither isQueue nor isTopic methods present: " + dest); - } - - Boolean isQueue = (Boolean) isQueueMethod.invoke(dest); - Boolean isTopic = (Boolean) isTopicMethod.invoke(dest); - if (isQueue) { - return new OpenWireQueue(queueName); - } else if (isTopic) { - return new OpenWireTopic(topicName); - } else { - throw new JMSException("Unresolvable destination: Neither Queue nor Topic: " + dest); - } - } catch (Exception e) { - throw new JMSException("Unresolvable destination: " + e.getMessage() + ": " + dest); - } - } - - @Override - public OpenWireDestination transform(String dest) throws JMSException { - return new OpenWireQueue(dest); - } -} diff --git a/openwire-core/src/main/java/org/apache/activemq/openwire/utils/ExceptionSupport.java b/openwire-core/src/main/java/org/apache/activemq/openwire/utils/ExceptionSupport.java deleted file mode 100644 index 3f113b1..0000000 --- a/openwire-core/src/main/java/org/apache/activemq/openwire/utils/ExceptionSupport.java +++ /dev/null @@ -1,103 +0,0 @@ -/** - * 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.openwire.utils; - -import javax.jms.JMSException; -import javax.jms.MessageEOFException; -import javax.jms.MessageFormatException; - -/** - * Exception support class. - * - * Factory class for creating JMSException instances based on String messages or by - * wrapping other non-JMS exception. - * - * @since 1.0 - */ -public final class ExceptionSupport { - - private ExceptionSupport() {} - - public static JMSException create(String msg, Throwable cause) { - JMSException exception = new JMSException(msg); - exception.initCause(cause); - return exception; - } - - public static JMSException create(String msg, Exception cause) { - JMSException exception = new JMSException(msg); - exception.setLinkedException(cause); - exception.initCause(cause); - return exception; - } - - public static JMSException create(Throwable cause) { - if (cause instanceof JMSException) { - return (JMSException) cause; - } - if (cause.getCause() instanceof JMSException) { - return (JMSException) cause.getCause(); - } - - String msg = cause.getMessage(); - if (msg == null || msg.length() == 0) { - msg = cause.toString(); - } - JMSException exception = new JMSException(msg); - exception.initCause(cause); - return exception; - } - - public static JMSException create(Exception cause) { - if (cause instanceof JMSException) { - return (JMSException) cause; - } - if (cause.getCause() instanceof JMSException) { - return (JMSException) cause.getCause(); - } - - String msg = cause.getMessage(); - if (msg == null || msg.length() == 0) { - msg = cause.toString(); - } - JMSException exception = new JMSException(msg); - exception.setLinkedException(cause); - exception.initCause(cause); - return exception; - } - - public static MessageEOFException createMessageEOFException(Exception cause) { - String msg = cause.getMessage(); - if (msg == null || msg.length() == 0) { - msg = cause.toString(); - } - MessageEOFException exception = new MessageEOFException(msg); - exception.setLinkedException(cause); - exception.initCause(cause); - return exception; - } - - public static MessageFormatException createMessageFormatException(Throwable cause) { - String msg = cause.getMessage(); - if (msg == null || msg.length() == 0) { - msg = cause.toString(); - } - MessageFormatException exception = new MessageFormatException(msg); - exception.initCause(cause); - return exception; - } -} diff --git a/openwire-core/src/main/java/org/apache/activemq/openwire/utils/IOExceptionSupport.java b/openwire-core/src/main/java/org/apache/activemq/openwire/utils/IOExceptionSupport.java new file mode 100644 index 0000000..7062960 --- /dev/null +++ b/openwire-core/src/main/java/org/apache/activemq/openwire/utils/IOExceptionSupport.java @@ -0,0 +1,57 @@ +/** + * 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.openwire.utils; + +import java.io.IOException; + +/** + * Exception support class. + * + * Factory class for creating IOException instances based on String messages or by + * wrapping other causal exceptions. + * + * @since 1.0 + */ +public final class IOExceptionSupport { + + private IOExceptionSupport() {} + + public static IOException create(String msg, Throwable cause) { + IOException exception = new IOException(msg); + exception.initCause(cause); + return exception; + } + + public static IOException create(Throwable cause) { + if (cause instanceof IOException) { + return (IOException) cause; + } + + if (cause.getCause() instanceof IOException) { + return (IOException) cause.getCause(); + } + + String msg = cause.getMessage(); + if (msg == null || msg.length() == 0) { + msg = cause.toString(); + } + + IOException exception = new IOException(msg); + exception.initCause(cause); + return exception; + } +} diff --git a/openwire-core/src/main/java/org/apache/activemq/openwire/utils/UnresolvedDestinationTransformer.java b/openwire-core/src/main/java/org/apache/activemq/openwire/utils/UnresolvedDestinationTransformer.java deleted file mode 100644 index 252c758..0000000 --- a/openwire-core/src/main/java/org/apache/activemq/openwire/utils/UnresolvedDestinationTransformer.java +++ /dev/null @@ -1,57 +0,0 @@ -/** - * 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.openwire.utils; - -import javax.jms.Destination; -import javax.jms.JMSException; - -import org.apache.activemq.openwire.commands.OpenWireDestination; - -/** - * Allows for the configuration of a user defined Destination transformer that will - * be called when it cannot be logically determined what type of Destination is - * being converted to an OpenWireDestination. This can happen for instance when a - * JMS Provider's Destination implements both Topic and Queue from the same root - * Destination object. - */ -public interface UnresolvedDestinationTransformer { - - /** - * Given the JMS Destination convert it to the correct OpenWire destination - * - * @param destination - * the foreign destination to convert to the proper OpenWire type. - * - * @return an OpenWireDestination instance of the correct type. - * - * @throws JMSException if an error occurs while converting the Destination type. - */ - public OpenWireDestination transform(Destination destination) throws JMSException; - - /** - * Given the name of a JMS Destination convert it to the correct OpenWire destination. - * - * @param destination - * the name of a destination to convert to the proper OpenWire type. - * - * @return an OpenWireDestination instance of the correct type. - * - * @throws JMSException if an error occurs while converting the Destination type. - */ - public OpenWireDestination transform(String destination) throws JMSException; - -} diff --git a/openwire-core/src/test/java/org/apache/activemq/openwire/commands/OpenWireDestinationTest.java b/openwire-core/src/test/java/org/apache/activemq/openwire/commands/OpenWireDestinationTest.java index e69eaf8..ed13440 100644 --- a/openwire-core/src/test/java/org/apache/activemq/openwire/commands/OpenWireDestinationTest.java +++ b/openwire-core/src/test/java/org/apache/activemq/openwire/commands/OpenWireDestinationTest.java @@ -18,7 +18,6 @@ package org.apache.activemq.openwire.commands; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; import java.io.IOException; @@ -29,17 +28,6 @@ import java.util.Map; import java.util.SortedSet; import java.util.TreeSet; -import javax.jms.JMSException; -import javax.jms.Queue; -import javax.jms.TemporaryQueue; -import javax.jms.TemporaryTopic; -import javax.jms.Topic; - -import org.apache.activemq.openwire.commands.OpenWireDestination; -import org.apache.activemq.openwire.commands.OpenWireQueue; -import org.apache.activemq.openwire.commands.OpenWireTempQueue; -import org.apache.activemq.openwire.commands.OpenWireTempTopic; -import org.apache.activemq.openwire.commands.OpenWireTopic; import org.junit.Test; /** @@ -58,7 +46,7 @@ public class OpenWireDestinationTest { assertEquals("Sorted order", expected, actual); } - class CombyDest implements Queue, Topic, TemporaryQueue, TemporaryTopic { + class CombyDest { private final String qName; private final String topicName; @@ -68,39 +56,16 @@ public class OpenWireDestinationTest { this.topicName = topicName; } - @Override - public void delete() throws JMSException {} - - @Override - public String getTopicName() throws JMSException { + public String getTopicName() { return topicName; } - @Override - public String getQueueName() throws JMSException { + public String getQueueName() { return qName; } } @Test - public void testTransformPollymorphic() throws Exception { - OpenWireQueue queue = new OpenWireQueue("TEST"); - assertEquals(OpenWireDestination.transform(queue), queue); - assertTrue("is a q", OpenWireDestination.transform(new CombyDest(null, "Topic")) instanceof OpenWireTopic); - assertTrue("is a q", OpenWireDestination.transform(new CombyDest("Q", null)) instanceof OpenWireQueue); - try { - OpenWireDestination.transform(new CombyDest(null, null)); - fail("expect ex as cannot disambiguate"); - } catch (JMSException expected) { - } - try { - OpenWireDestination.transform(new CombyDest("Q", "T")); - fail("expect ex as cannot disambiguate"); - } catch (JMSException expected) { - } - } - - @Test public void testEmptyQueueName() { try { new OpenWireQueue(""); diff --git a/openwire-core/src/test/java/org/apache/activemq/openwire/commands/OpenWireMapMessageTest.java b/openwire-core/src/test/java/org/apache/activemq/openwire/commands/OpenWireMapMessageTest.java index 0a7e66a..ba4d2c2 100644 --- a/openwire-core/src/test/java/org/apache/activemq/openwire/commands/OpenWireMapMessageTest.java +++ b/openwire-core/src/test/java/org/apache/activemq/openwire/commands/OpenWireMapMessageTest.java @@ -27,10 +27,6 @@ import java.util.Collections; import java.util.Enumeration; import java.util.List; -import javax.jms.JMSException; -import javax.jms.MessageFormatException; - -import org.apache.activemq.openwire.commands.OpenWireMapMessage; import org.junit.Rule; import org.junit.Test; import org.junit.rules.TestName; @@ -45,7 +41,7 @@ public class OpenWireMapMessageTest { public TestName name = new TestName(); @Test - public void testBytesConversion() throws JMSException, IOException { + public void testBytesConversion() throws Exception { OpenWireMapMessage msg = new OpenWireMapMessage(); msg.setObject("boolean", true); msg.setObject("byte", (byte) 1); @@ -68,7 +64,7 @@ public class OpenWireMapMessageTest { msg.setObject("bigString", bigString); - msg = (OpenWireMapMessage) msg.copy(); + msg = msg.copy(); assertEquals(msg.getObject("boolean"), true); assertEquals(msg.getObject("byte"), (byte) 1); @@ -85,7 +81,7 @@ public class OpenWireMapMessageTest { } @Test - public void testGetObject() throws JMSException { + public void testGetObject() throws Exception { OpenWireMapMessage msg = new OpenWireMapMessage(); Boolean booleanValue = Boolean.TRUE; Byte byteValue = Byte.valueOf("1"); @@ -109,13 +105,13 @@ public class OpenWireMapMessageTest { msg.setObject("long", longValue); msg.setObject("short", shortValue); msg.setObject("string", stringValue); - } catch (MessageFormatException mfe) { - LOG.warn("Caught: " + mfe); - mfe.printStackTrace(); + } catch (IOException ioe) { + LOG.warn("Caught: " + ioe); + ioe.printStackTrace(); fail("object formats should be correct"); } - msg = (OpenWireMapMessage) msg.copy(); + msg = msg.copy(); assertTrue(msg.getObject("boolean") instanceof Boolean); assertEquals(msg.getObject("boolean"), booleanValue); @@ -143,12 +139,12 @@ public class OpenWireMapMessageTest { try { msg.setObject("object", new Object()); fail("should have thrown exception"); - } catch (MessageFormatException e) { + } catch (IllegalArgumentException e) { } } @Test - public void testGetMapNames() throws JMSException { + public void testGetMapNames() throws Exception { OpenWireMapMessage msg = new OpenWireMapMessage(); msg.setObject("boolean", true); msg.setObject("byte", (byte) 1); @@ -162,7 +158,7 @@ public class OpenWireMapMessageTest { msg.setObject("short", (short) 1); msg.setObject("string", "string"); - msg = (OpenWireMapMessage) msg.copy(); + msg = msg.copy(); Enumeration<String> mapNamesEnum = msg.getMapNames(); List<String> mapNamesList = Collections.list(mapNamesEnum); @@ -182,19 +178,19 @@ public class OpenWireMapMessageTest { } @Test - public void testItemExists() throws JMSException { + public void testItemExists() throws Exception { OpenWireMapMessage mapMessage = new OpenWireMapMessage(); mapMessage.setObject("exists", "test"); - mapMessage = (OpenWireMapMessage) mapMessage.copy(); + mapMessage = mapMessage.copy(); assertTrue(mapMessage.itemExists("exists")); assertFalse(mapMessage.itemExists("doesntExist")); } @Test - public void testClearBody() throws JMSException { + public void testClearBody() throws Exception { OpenWireMapMessage mapMessage = new OpenWireMapMessage(); mapMessage.setObject("String", "String"); mapMessage.clearBody(); @@ -204,7 +200,7 @@ public class OpenWireMapMessageTest { mapMessage.clearBody(); mapMessage.setObject("String", "String"); - mapMessage = (OpenWireMapMessage) mapMessage.copy(); + mapMessage = mapMessage.copy(); mapMessage.getObject("String"); } diff --git a/openwire-core/src/test/java/org/apache/activemq/openwire/commands/OpenWireMessageTest.java b/openwire-core/src/test/java/org/apache/activemq/openwire/commands/OpenWireMessageTest.java index b6263c7..30f8084 100644 --- a/openwire-core/src/test/java/org/apache/activemq/openwire/commands/OpenWireMessageTest.java +++ b/openwire-core/src/test/java/org/apache/activemq/openwire/commands/OpenWireMessageTest.java @@ -26,18 +26,7 @@ import static org.junit.Assert.fail; import java.io.IOException; import java.util.Map; -import javax.jms.DeliveryMode; -import javax.jms.JMSException; -import javax.jms.Message; - import org.apache.activemq.openwire.codec.OpenWireFormat; -import org.apache.activemq.openwire.commands.CommandTypes; -import org.apache.activemq.openwire.commands.OpenWireBytesMessage; -import org.apache.activemq.openwire.commands.OpenWireDestination; -import org.apache.activemq.openwire.commands.OpenWireMessage; -import org.apache.activemq.openwire.commands.OpenWireObjectMessage; -import org.apache.activemq.openwire.commands.OpenWireTempTopic; -import org.apache.activemq.openwire.commands.OpenWireTopic; import org.fusesource.hawtbuf.Buffer; import org.junit.Before; import org.junit.Test; @@ -50,7 +39,7 @@ public class OpenWireMessageTest { protected boolean readOnlyMessage; - private String jmsMessageID; + private MessageId myMessageID; private String jmsCorrelationID; private OpenWireDestination jmsDestination; private OpenWireDestination jmsReplyTo; @@ -64,11 +53,11 @@ public class OpenWireMessageTest { @Before public void setUp() throws Exception { - this.jmsMessageID = "ID:TEST-ID:0:0:0:1"; + this.myMessageID = new MessageId("ID:TEST-ID:0:0:0:1"); this.jmsCorrelationID = "testcorrelationid"; this.jmsDestination = new OpenWireTopic("test.topic"); this.jmsReplyTo = new OpenWireTempTopic("test.replyto.topic:001"); - this.jmsDeliveryMode = Message.DEFAULT_DELIVERY_MODE; + this.jmsDeliveryMode = 1; this.jmsRedelivered = true; this.jmsType = "test type"; this.jmsExpiration = 100000; @@ -87,12 +76,12 @@ public class OpenWireMessageTest { assertEquals(msg.getDataStructureType(), CommandTypes.OPENWIRE_MESSAGE); } -// @Test -// public void testHashCode() throws Exception { -// OpenWireMessage msg = new OpenWireMessage(); -// msg.setMessageId(this.jmsMessageID); -// assertTrue(msg.getMessageId().hashCode() == jmsMessageID.hashCode()); -// } + @Test + public void testHashCode() throws Exception { + OpenWireMessage msg = new OpenWireMessage(); + msg.setMessageId(this.myMessageID); + assertEquals(msg.getMessageId().hashCode(), myMessageID.hashCode()); + } @Test public void testSetToForeignJMSID() throws Exception { @@ -104,67 +93,66 @@ public class OpenWireMessageTest { public void testEqualsObject() throws Exception { OpenWireMessage msg1 = new OpenWireMessage(); OpenWireMessage msg2 = new OpenWireMessage(); - msg1.setMessageId(this.jmsMessageID); + msg1.setMessageId(this.myMessageID); assertTrue(!msg1.equals(msg2)); - msg2.setMessageId(this.jmsMessageID); + msg2.setMessageId(this.myMessageID); assertTrue(msg1.equals(msg2)); } @Test public void testShallowCopy() throws Exception { OpenWireMessage msg1 = new OpenWireMessage(); - msg1.setMessageId(jmsMessageID); + msg1.setMessageId(myMessageID); OpenWireMessage msg2 = msg1.copy(); assertTrue(msg1 != msg2 && msg1.equals(msg2)); } -// @Test -// public void testCopy() throws Exception { -// this.jmsMessageID = "testid"; -// this.jmsCorrelationID = "testcorrelationid"; -// this.jmsDestination = new OpenWireTopic("test.topic"); -// this.jmsReplyTo = new OpenWireTempTopic("test.replyto.topic:001"); -// this.jmsDeliveryMode = Message.DEFAULT_DELIVERY_MODE; -// this.jmsRedelivered = true; -// this.jmsType = "test type"; -// this.jmsExpiration = 100000; -// this.jmsPriority = 5; -// this.jmsTimestamp = System.currentTimeMillis(); -// this.readOnlyMessage = false; -// -// OpenWireMessage msg1 = new OpenWireMessage(); -// msg1.setMessageId(this.jmsMessageID); -// msg1.setCorrelationId(this.jmsCorrelationID); -// msg1.setDestination(this.jmsDestination); -// msg1.setReplyTo(this.jmsReplyTo); -// msg1.setPersistent(this.jmsDeliveryMode == DeliveryMode.PERSISTENT); -// msg1.setRedelivered(this.jmsRedelivered); -// msg1.setType(this.jmsType); -// msg1.setExpiration(this.jmsExpiration); -// msg1.setPriority((byte) this.jmsPriority); -// msg1.setTimestamp(this.jmsTimestamp); -// msg1.setReadOnlyProperties(true); -// OpenWireMessage msg2 = new OpenWireMessage(); -// msg1.copy(msg2); -// assertEquals(msg1.getMessageId(), msg2.getMessageId()); -// assertTrue(msg1.getCorrelationId().equals(msg2.getCorrelationId())); -// assertTrue(msg1.getDestination().equals(msg2.getDestination())); -// assertTrue(msg1.getReplyTo().equals(msg2.getReplyTo())); -// assertTrue(msg1.isPersistent() == msg2.isPersistent()); -// assertTrue(msg1.isRedelivered() == msg2.isRedelivered()); -// assertTrue(msg1.getType().equals(msg2.getType())); -// assertTrue(msg1.getExpiration() == msg2.getExpiration()); -// assertTrue(msg1.getPriority() == msg2.getPriority()); -// assertTrue(msg1.getTimestamp() == msg2.getTimestamp()); -// -// LOG.info("Message is: " + msg1); -// } + @Test + public void testCopy() throws Exception { + this.myMessageID = new MessageId("ID:TEST-ID:0:0:0:2"); + this.jmsCorrelationID = "testcorrelationid"; + this.jmsDestination = new OpenWireTopic("test.topic"); + this.jmsReplyTo = new OpenWireTempTopic("test.replyto.topic:001"); + this.jmsDeliveryMode = 1; + this.jmsRedelivered = true; + this.jmsType = "test type"; + this.jmsExpiration = 100000; + this.jmsPriority = 5; + this.jmsTimestamp = System.currentTimeMillis(); + this.readOnlyMessage = false; + + OpenWireMessage msg1 = new OpenWireMessage(); + msg1.setMessageId(this.myMessageID); + msg1.setCorrelationId(this.jmsCorrelationID); + msg1.setDestination(this.jmsDestination); + msg1.setReplyTo(this.jmsReplyTo); + msg1.setPersistent(this.jmsDeliveryMode == 1); + msg1.setRedelivered(this.jmsRedelivered); + msg1.setType(this.jmsType); + msg1.setExpiration(this.jmsExpiration); + msg1.setPriority((byte) this.jmsPriority); + msg1.setTimestamp(this.jmsTimestamp); + OpenWireMessage msg2 = new OpenWireMessage(); + msg1.copy(msg2); + assertEquals(msg1.getMessageId(), msg2.getMessageId()); + assertTrue(msg1.getCorrelationId().equals(msg2.getCorrelationId())); + assertTrue(msg1.getDestination().equals(msg2.getDestination())); + assertTrue(msg1.getReplyTo().equals(msg2.getReplyTo())); + assertTrue(msg1.isPersistent() == msg2.isPersistent()); + assertTrue(msg1.isRedelivered() == msg2.isRedelivered()); + assertTrue(msg1.getType().equals(msg2.getType())); + assertTrue(msg1.getExpiration() == msg2.getExpiration()); + assertTrue(msg1.getPriority() == msg2.getPriority()); + assertTrue(msg1.getTimestamp() == msg2.getTimestamp()); + + LOG.info("Message is: " + msg1); + } @Test public void testGetAndSetMessageId() throws Exception { OpenWireMessage msg = new OpenWireMessage(); - msg.setMessageId(this.jmsMessageID); - assertEquals(msg.getMessageId().toString(), this.jmsMessageID); + msg.setMessageId(this.myMessageID); + assertEquals(msg.getMessageId().toString(), this.myMessageID.toString()); } @Test @@ -201,7 +189,7 @@ public class OpenWireMessageTest { } @Test - public void testGetAndSetJMSReplyTo() throws JMSException { + public void testGetAndSetJMSReplyTo() throws Exception { OpenWireMessage msg = new OpenWireMessage(); msg.setReplyTo(this.jmsReplyTo); assertTrue(msg.getReplyTo().equals(this.jmsReplyTo)); @@ -217,7 +205,7 @@ public class OpenWireMessageTest { @Test public void testGetAndSetPersistentFlag() { OpenWireMessage msg = new OpenWireMessage(); - boolean persistent = this.jmsDeliveryMode == DeliveryMode.PERSISTENT; + boolean persistent = this.jmsDeliveryMode == 1; msg.setPersistent(persistent); assertTrue(msg.isPersistent() == persistent); } @@ -257,11 +245,11 @@ public class OpenWireMessageTest { } @Test - public void testClearProperties() throws JMSException { + public void testClearProperties() throws Exception { OpenWireMessage msg = new OpenWireMessage(); msg.setProperty("test", "test"); msg.setContent(new Buffer(new byte[1], 0, 0)); - msg.setMessageId(this.jmsMessageID); + msg.setMessageId(this.myMessageID); msg.clearProperties(); assertNull(msg.getProperty("test")); assertNotNull(msg.getMessageId()); @@ -269,7 +257,7 @@ public class OpenWireMessageTest { } @Test - public void testPropertyExists() throws JMSException { + public void testPropertyExists() throws Exception { OpenWireMessage msg = new OpenWireMessage(); msg.setProperty("test", "test"); assertTrue(msg.propertyExists("test")); @@ -279,7 +267,7 @@ public class OpenWireMessageTest { } @Test - public void testGetBooleanProperty() throws JMSException { + public void testGetBooleanProperty() throws Exception { OpenWireMessage msg = new OpenWireMessage(); String name = "booleanProperty"; msg.setProperty(name, true); @@ -287,7 +275,7 @@ public class OpenWireMessageTest { } @Test - public void testGetByteProperty() throws JMSException { + public void testGetByteProperty() throws Exception { OpenWireMessage msg = new OpenWireMessage(); String name = "byteProperty"; msg.setProperty(name, (byte) 1); @@ -295,7 +283,7 @@ public class OpenWireMessageTest { } @Test - public void testGetShortProperty() throws JMSException { + public void testGetShortProperty() throws Exception { OpenWireMessage msg = new OpenWireMessage(); String name = "shortProperty"; msg.setProperty(name, (short) 1); @@ -303,7 +291,7 @@ public class OpenWireMessageTest { } @Test - public void testGetIntProperty() throws JMSException { + public void testGetIntProperty() throws Exception { OpenWireMessage msg = new OpenWireMessage(); String name = "intProperty"; msg.setProperty(name, 1); @@ -311,7 +299,7 @@ public class OpenWireMessageTest { } @Test - public void testGetLongProperty() throws JMSException { + public void testGetLongProperty() throws Exception { OpenWireMessage msg = new OpenWireMessage(); String name = "longProperty"; msg.setProperty(name, 1L); @@ -319,7 +307,7 @@ public class OpenWireMessageTest { } @Test - public void testGetFloatProperty() throws JMSException { + public void testGetFloatProperty() throws Exception { OpenWireMessage msg = new OpenWireMessage(); String name = "floatProperty"; msg.setProperty(name, 1.3f); @@ -327,7 +315,7 @@ public class OpenWireMessageTest { } @Test - public void testGetDoubleProperty() throws JMSException { + public void testGetDoubleProperty() throws Exception { OpenWireMessage msg = new OpenWireMessage(); String name = "doubleProperty"; msg.setProperty(name, 1.3d); @@ -335,7 +323,7 @@ public class OpenWireMessageTest { } @Test - public void testGetStringProperty() throws JMSException { + public void testGetStringProperty() throws Exception { OpenWireMessage msg = new OpenWireMessage(); String name = "stringProperty"; msg.setProperty(name, name); @@ -343,7 +331,7 @@ public class OpenWireMessageTest { } @Test - public void testgetProperty() throws JMSException { + public void testgetProperty() throws Exception { OpenWireMessage msg = new OpenWireMessage(); String name = "floatProperty"; msg.setProperty(name, 1.3f); @@ -382,7 +370,7 @@ public class OpenWireMessageTest { roundTripProperties(message); } - private void roundTripProperties(OpenWireObjectMessage message) throws IOException, JMSException { + private void roundTripProperties(OpenWireObjectMessage message) throws IOException, Exception { OpenWireObjectMessage copy = new OpenWireObjectMessage(); for (Map.Entry<String, Object> prop : message.getProperties().entrySet()) { LOG.debug("{} -> {}", prop.getKey(), prop.getValue().getClass()); @@ -401,7 +389,7 @@ public class OpenWireMessageTest { } @Test - public void testSetNullProperty() throws JMSException { + public void testSetNullProperty() throws Exception { OpenWireMessage msg = new OpenWireMessage(); String name = "cheese"; msg.setProperty(name, "Cheddar"); @@ -412,7 +400,7 @@ public class OpenWireMessageTest { } @Test - public void testSetNullPropertyName() throws JMSException { + public void testSetNullPropertyName() throws Exception { OpenWireMessage msg = new OpenWireMessage(); try { @@ -424,7 +412,7 @@ public class OpenWireMessageTest { } @Test - public void testSetEmptyPropertyName() throws JMSException { + public void testSetEmptyPropertyName() throws Exception { OpenWireMessage msg = new OpenWireMessage(); try { @@ -436,7 +424,7 @@ public class OpenWireMessageTest { } @Test - public void testGetAndSetDeliveryCount() throws JMSException { + public void testGetAndSetDeliveryCount() throws Exception { OpenWireMessage msg = new OpenWireMessage(); msg.setRedeliveryCounter(1); int count = msg.getRedeliveryCounter(); @@ -444,7 +432,7 @@ public class OpenWireMessageTest { } @Test - public void testClearBody() throws JMSException { + public void testClearBody() throws Exception { OpenWireBytesMessage message = new OpenWireBytesMessage(); message.clearBody(); assertNull(message.getContent()); diff --git a/openwire-core/src/test/java/org/apache/activemq/openwire/commands/OpenWireObjectMessageTest.java b/openwire-core/src/test/java/org/apache/activemq/openwire/commands/OpenWireObjectMessageTest.java index 5363df8..895aeec 100644 --- a/openwire-core/src/test/java/org/apache/activemq/openwire/commands/OpenWireObjectMessageTest.java +++ b/openwire-core/src/test/java/org/apache/activemq/openwire/commands/OpenWireObjectMessageTest.java @@ -19,33 +19,25 @@ package org.apache.activemq.openwire.commands; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNull; import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; import java.io.IOException; -import javax.jms.JMSException; -import javax.jms.MessageNotWriteableException; - -import org.apache.activemq.openwire.commands.OpenWireObjectMessage; import org.junit.Test; -/** - * - */ public class OpenWireObjectMessageTest { @Test - public void testBytes() throws JMSException, IOException { + public void testBytes() throws Exception, IOException { OpenWireObjectMessage msg = new OpenWireObjectMessage(); String str = "testText"; msg.setObject(str); - msg = (OpenWireObjectMessage) msg.copy(); + msg = msg.copy(); assertEquals(msg.getObject(), str); } @Test - public void testSetObject() throws JMSException { + public void testSetObject() throws Exception { OpenWireObjectMessage msg = new OpenWireObjectMessage(); String str = "testText"; msg.setObject(str); @@ -53,16 +45,12 @@ public class OpenWireObjectMessageTest { } @Test - public void testClearBody() throws JMSException { + public void testClearBody() throws Exception { OpenWireObjectMessage objectMessage = new OpenWireObjectMessage(); - try { - objectMessage.setObject("String"); - objectMessage.clearBody(); - assertNull(objectMessage.getObject()); - objectMessage.setObject("String"); - objectMessage.getObject(); - } catch (MessageNotWriteableException mnwe) { - fail("should be writeable"); - } + objectMessage.setObject("String"); + objectMessage.clearBody(); + assertNull(objectMessage.getObject()); + objectMessage.setObject("String"); + objectMessage.getObject(); } } diff --git a/openwire-core/src/test/java/org/apache/activemq/openwire/commands/OpenWireTextMessageTest.java b/openwire-core/src/test/java/org/apache/activemq/openwire/commands/OpenWireTextMessageTest.java index d4a3811..45a4487 100644 --- a/openwire-core/src/test/java/org/apache/activemq/openwire/commands/OpenWireTextMessageTest.java +++ b/openwire-core/src/test/java/org/apache/activemq/openwire/commands/OpenWireTextMessageTest.java @@ -19,15 +19,10 @@ package org.apache.activemq.openwire.commands; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNull; import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; import java.io.DataOutputStream; import java.io.IOException; -import javax.jms.JMSException; -import javax.jms.MessageNotReadableException; -import javax.jms.MessageNotWriteableException; - import org.apache.activemq.openwire.utils.MarshallingSupport; import org.fusesource.hawtbuf.Buffer; import org.fusesource.hawtbuf.ByteArrayOutputStream; @@ -45,7 +40,7 @@ public class OpenWireTextMessageTest { } @Test - public void testShallowCopy() throws JMSException { + public void testShallowCopy() throws Exception { OpenWireTextMessage msg = new OpenWireTextMessage(); String string = "str"; msg.setText(string); @@ -60,13 +55,13 @@ public class OpenWireTextMessageTest { try { msg.setText(str); assertEquals(msg.getText(), str); - } catch (JMSException e) { + } catch (Exception e) { e.printStackTrace(); } } @Test - public void testGetBytes() throws JMSException, IOException { + public void testGetBytes() throws Exception, IOException { OpenWireTextMessage msg = new OpenWireTextMessage(); String str = "testText"; msg.setText(str); @@ -80,19 +75,13 @@ public class OpenWireTextMessageTest { } @Test - public void testClearBody() throws JMSException, IOException { + public void testClearBody() throws Exception, IOException { OpenWireTextMessage textMessage = new OpenWireTextMessage(); textMessage.setText("string"); textMessage.clearBody(); assertNull(textMessage.getText()); - try { - textMessage.setText("String"); - textMessage.getText(); - } catch (MessageNotWriteableException mnwe) { - fail("should be writeable"); - } catch (MessageNotReadableException mnre) { - fail("should be readable"); - } + textMessage.setText("String"); + textMessage.getText(); } @Test diff --git a/pom.xml b/pom.xml index 5135a68..85b0bec 100644 --- a/pom.xml +++ b/pom.xml @@ -144,11 +144,6 @@ <version>${reflections-version}</version> </dependency> <dependency> - <groupId>org.apache.geronimo.specs</groupId> - <artifactId>geronimo-jms_1.1_spec</artifactId> - <version>1.1.1</version> - </dependency> - <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>${junit-version}</version>
