activemq-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tab...@apache.org
Subject [29/51] [partial] https://issues.apache.org/jira/browse/OPENWIRE-1
Date Thu, 24 Jul 2014 14:23:18 GMT
http://git-wip-us.apache.org/repos/asf/activemq-openwire/blob/7ae454fa/openwire-jms/src/main/java/org/apache/activemq/openwire/jms/OpenWireJMSStreamMessage.java
----------------------------------------------------------------------
diff --git a/openwire-jms/src/main/java/org/apache/activemq/openwire/jms/OpenWireJMSStreamMessage.java b/openwire-jms/src/main/java/org/apache/activemq/openwire/jms/OpenWireJMSStreamMessage.java
new file mode 100644
index 0000000..ae7793c
--- /dev/null
+++ b/openwire-jms/src/main/java/org/apache/activemq/openwire/jms/OpenWireJMSStreamMessage.java
@@ -0,0 +1,710 @@
+/**
+ * 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.jms;
+
+import java.io.DataInputStream;
+import java.io.DataOutputStream;
+import java.io.EOFException;
+import java.io.IOException;
+import java.io.InputStream;
+
+import javax.jms.JMSException;
+import javax.jms.MessageEOFException;
+import javax.jms.MessageFormatException;
+import javax.jms.MessageNotReadableException;
+import javax.jms.StreamMessage;
+
+import org.apache.activemq.openwire.commands.OpenWireStreamMessage;
+import org.apache.activemq.openwire.utils.ExceptionSupport;
+import org.apache.activemq.openwire.utils.OpenWireMarshallingSupport;
+import org.fusesource.hawtbuf.Buffer;
+import org.fusesource.hawtbuf.ByteArrayInputStream;
+import org.fusesource.hawtbuf.ByteArrayOutputStream;
+
+/**
+ * Wrapper class that provides StreamMessage compliant mappings to the OpenWireStreamMessage
+ */
+public class OpenWireJMSStreamMessage extends OpenWireJMSMessage implements StreamMessage {
+
+    private final OpenWireStreamMessage message;
+
+    protected transient DataOutputStream dataOut;
+    protected transient ByteArrayOutputStream bytesOut;
+    protected transient DataInputStream dataIn;
+    protected transient int remainingBytes = -1;
+
+    /**
+     * Creates a new instance that wraps a new OpenWireMessage instance.
+     */
+    public OpenWireJMSStreamMessage() {
+        this(new OpenWireStreamMessage());
+    }
+
+    /**
+     * Creates a new instance that wraps the given OpenWireMessage
+     *
+     * @param message
+     *        the OpenWireMessage to wrap.
+     */
+    public OpenWireJMSStreamMessage(OpenWireStreamMessage message) {
+        this.message = message;
+    }
+
+    @Override
+    public OpenWireJMSStreamMessage copy() throws JMSException {
+        OpenWireJMSStreamMessage other = new OpenWireJMSStreamMessage(message.copy());
+        copy(other);
+        return other;
+    }
+
+    private void copy(OpenWireJMSStreamMessage copy) throws JMSException {
+        storeContent();
+        super.copy(copy);
+        copy.dataOut = null;
+        copy.bytesOut = null;
+        copy.dataIn = null;
+    }
+
+    @Override
+    public void clearBody() throws JMSException {
+        super.clearBody();
+        message.clearBody();
+        dataOut = null;
+        dataIn = null;
+        bytesOut = null;
+        remainingBytes = -1;
+    }
+
+    @Override
+    public boolean readBoolean() throws JMSException {
+        initializeReading();
+        try {
+            this.dataIn.mark(10);
+            int type = this.dataIn.read();
+            if (type == -1) {
+                throw new MessageEOFException("reached end of data");
+            } else if (type == OpenWireMarshallingSupport.BOOLEAN_TYPE) {
+                return this.dataIn.readBoolean();
+            } else if (type == OpenWireMarshallingSupport.STRING_TYPE) {
+                return Boolean.valueOf(this.dataIn.readUTF()).booleanValue();
+            } else if (type == OpenWireMarshallingSupport.NULL) {
+                this.dataIn.reset();
+                throw new NullPointerException("Cannot convert NULL value to boolean.");
+            } else {
+                this.dataIn.reset();
+                throw new MessageFormatException(" not a boolean type");
+            }
+        } catch (EOFException e) {
+            throw ExceptionSupport.createMessageEOFException(e);
+        } catch (IOException e) {
+            throw ExceptionSupport.createMessageFormatException(e);
+        }
+    }
+
+    @Override
+    public byte readByte() throws JMSException {
+        initializeReading();
+        try {
+            this.dataIn.mark(10);
+            int type = this.dataIn.read();
+            if (type == -1) {
+                throw new MessageEOFException("reached end of data");
+            } else if (type == OpenWireMarshallingSupport.BYTE_TYPE) {
+                return this.dataIn.readByte();
+            } else if (type == OpenWireMarshallingSupport.STRING_TYPE) {
+                return Byte.valueOf(this.dataIn.readUTF()).byteValue();
+            } else if (type == OpenWireMarshallingSupport.NULL) {
+                this.dataIn.reset();
+                throw new NullPointerException("Cannot convert NULL value to byte.");
+            } else {
+                this.dataIn.reset();
+                throw new MessageFormatException(" not a byte type");
+            }
+        } catch (NumberFormatException mfe) {
+            try {
+                this.dataIn.reset();
+            } catch (IOException ioe) {
+                throw ExceptionSupport.create(ioe);
+            }
+            throw mfe;
+        } catch (EOFException e) {
+            throw ExceptionSupport.createMessageEOFException(e);
+        } catch (IOException e) {
+            throw ExceptionSupport.createMessageFormatException(e);
+        }
+    }
+
+    @Override
+    public short readShort() throws JMSException {
+        initializeReading();
+        try {
+            this.dataIn.mark(17);
+            int type = this.dataIn.read();
+            if (type == -1) {
+                throw new MessageEOFException("reached end of data");
+            } else if (type == OpenWireMarshallingSupport.SHORT_TYPE) {
+                return this.dataIn.readShort();
+            } else if (type == OpenWireMarshallingSupport.BYTE_TYPE) {
+                return this.dataIn.readByte();
+            } else if (type == OpenWireMarshallingSupport.STRING_TYPE) {
+                return Short.valueOf(this.dataIn.readUTF()).shortValue();
+            } else if (type == OpenWireMarshallingSupport.NULL) {
+                this.dataIn.reset();
+                throw new NullPointerException("Cannot convert NULL value to short.");
+            } else {
+                this.dataIn.reset();
+                throw new MessageFormatException(" not a short type");
+            }
+        } catch (NumberFormatException mfe) {
+            try {
+                this.dataIn.reset();
+            } catch (IOException ioe) {
+                throw ExceptionSupport.create(ioe);
+            }
+            throw mfe;
+        } catch (EOFException e) {
+            throw ExceptionSupport.createMessageEOFException(e);
+        } catch (IOException e) {
+            throw ExceptionSupport.createMessageFormatException(e);
+        }
+    }
+
+    @Override
+    public char readChar() throws JMSException {
+        initializeReading();
+        try {
+            this.dataIn.mark(17);
+            int type = this.dataIn.read();
+            if (type == -1) {
+                throw new MessageEOFException("reached end of data");
+            } else if (type == OpenWireMarshallingSupport.CHAR_TYPE) {
+                return this.dataIn.readChar();
+            } else if (type == OpenWireMarshallingSupport.NULL) {
+                this.dataIn.reset();
+                throw new NullPointerException("Cannot convert NULL value to char.");
+            } else {
+                this.dataIn.reset();
+                throw new MessageFormatException(" not a char type");
+            }
+        } catch (NumberFormatException mfe) {
+            try {
+                this.dataIn.reset();
+            } catch (IOException ioe) {
+                throw ExceptionSupport.create(ioe);
+            }
+            throw mfe;
+        } catch (EOFException e) {
+            throw ExceptionSupport.createMessageEOFException(e);
+        } catch (IOException e) {
+            throw ExceptionSupport.createMessageFormatException(e);
+        }
+    }
+
+    @Override
+    public int readInt() throws JMSException {
+        initializeReading();
+        try {
+            this.dataIn.mark(33);
+            int type = this.dataIn.read();
+            if (type == -1) {
+                throw new MessageEOFException("reached end of data");
+            } else if (type == OpenWireMarshallingSupport.INTEGER_TYPE) {
+                return this.dataIn.readInt();
+            } else if (type == OpenWireMarshallingSupport.SHORT_TYPE) {
+                return this.dataIn.readShort();
+            } else if (type == OpenWireMarshallingSupport.BYTE_TYPE) {
+                return this.dataIn.readByte();
+            } else if (type == OpenWireMarshallingSupport.STRING_TYPE) {
+                return Integer.valueOf(this.dataIn.readUTF()).intValue();
+            } else if (type == OpenWireMarshallingSupport.NULL) {
+                this.dataIn.reset();
+                throw new NullPointerException("Cannot convert NULL value to int.");
+            } else {
+                this.dataIn.reset();
+                throw new MessageFormatException(" not an int type");
+            }
+        } catch (NumberFormatException mfe) {
+            try {
+                this.dataIn.reset();
+            } catch (IOException ioe) {
+                throw ExceptionSupport.create(ioe);
+            }
+            throw mfe;
+        } catch (EOFException e) {
+            throw ExceptionSupport.createMessageEOFException(e);
+        } catch (IOException e) {
+            throw ExceptionSupport.createMessageFormatException(e);
+        }
+    }
+
+    @Override
+    public long readLong() throws JMSException {
+        initializeReading();
+        try {
+            this.dataIn.mark(65);
+            int type = this.dataIn.read();
+            if (type == -1) {
+                throw new MessageEOFException("reached end of data");
+            } else if (type == OpenWireMarshallingSupport.LONG_TYPE) {
+                return this.dataIn.readLong();
+            } else if (type == OpenWireMarshallingSupport.INTEGER_TYPE) {
+                return this.dataIn.readInt();
+            } else if (type == OpenWireMarshallingSupport.SHORT_TYPE) {
+                return this.dataIn.readShort();
+            } else if (type == OpenWireMarshallingSupport.BYTE_TYPE) {
+                return this.dataIn.readByte();
+            } else if (type == OpenWireMarshallingSupport.STRING_TYPE) {
+                return Long.valueOf(this.dataIn.readUTF()).longValue();
+            } else if (type == OpenWireMarshallingSupport.NULL) {
+                this.dataIn.reset();
+                throw new NullPointerException("Cannot convert NULL value to long.");
+            } else {
+                this.dataIn.reset();
+                throw new MessageFormatException(" not a long type");
+            }
+        } catch (NumberFormatException mfe) {
+            try {
+                this.dataIn.reset();
+            } catch (IOException ioe) {
+                throw ExceptionSupport.create(ioe);
+            }
+            throw mfe;
+        } catch (EOFException e) {
+            throw ExceptionSupport.createMessageEOFException(e);
+        } catch (IOException e) {
+            throw ExceptionSupport.createMessageFormatException(e);
+        }
+    }
+
+    @Override
+    public float readFloat() throws JMSException {
+        initializeReading();
+        try {
+            this.dataIn.mark(33);
+            int type = this.dataIn.read();
+            if (type == -1) {
+                throw new MessageEOFException("reached end of data");
+            } else if (type == OpenWireMarshallingSupport.FLOAT_TYPE) {
+                return this.dataIn.readFloat();
+            } else if (type == OpenWireMarshallingSupport.STRING_TYPE) {
+                return Float.valueOf(this.dataIn.readUTF()).floatValue();
+            } else if (type == OpenWireMarshallingSupport.NULL) {
+                this.dataIn.reset();
+                throw new NullPointerException("Cannot convert NULL value to float.");
+            } else {
+                this.dataIn.reset();
+                throw new MessageFormatException(" not a float type");
+            }
+        } catch (NumberFormatException mfe) {
+            try {
+                this.dataIn.reset();
+            } catch (IOException ioe) {
+                throw ExceptionSupport.create(ioe);
+            }
+            throw mfe;
+        } catch (EOFException e) {
+            throw ExceptionSupport.createMessageEOFException(e);
+        } catch (IOException e) {
+            throw ExceptionSupport.createMessageFormatException(e);
+        }
+    }
+
+    @Override
+    public double readDouble() throws JMSException {
+        initializeReading();
+        try {
+            this.dataIn.mark(65);
+            int type = this.dataIn.read();
+            if (type == -1) {
+                throw new MessageEOFException("reached end of data");
+            } else if (type == OpenWireMarshallingSupport.DOUBLE_TYPE) {
+                return this.dataIn.readDouble();
+            } else if (type == OpenWireMarshallingSupport.FLOAT_TYPE) {
+                return this.dataIn.readFloat();
+            } else if (type == OpenWireMarshallingSupport.STRING_TYPE) {
+                return Double.valueOf(this.dataIn.readUTF()).doubleValue();
+            } else if (type == OpenWireMarshallingSupport.NULL) {
+                this.dataIn.reset();
+                throw new NullPointerException("Cannot convert NULL value to double.");
+            } else {
+                this.dataIn.reset();
+                throw new MessageFormatException(" not a double type");
+            }
+        } catch (NumberFormatException mfe) {
+            try {
+                this.dataIn.reset();
+            } catch (IOException ioe) {
+                throw ExceptionSupport.create(ioe);
+            }
+            throw mfe;
+        } catch (EOFException e) {
+            throw ExceptionSupport.createMessageEOFException(e);
+        } catch (IOException e) {
+            throw ExceptionSupport.createMessageFormatException(e);
+        }
+    }
+
+    @Override
+    public String readString() throws JMSException {
+        initializeReading();
+        try {
+            this.dataIn.mark(65);
+            int type = this.dataIn.read();
+            if (type == -1) {
+                throw new MessageEOFException("reached end of data");
+            } else if (type == OpenWireMarshallingSupport.NULL) {
+                return null;
+            } else if (type == OpenWireMarshallingSupport.BIG_STRING_TYPE) {
+                return OpenWireMarshallingSupport.readUTF8(dataIn);
+            } else if (type == OpenWireMarshallingSupport.STRING_TYPE) {
+                return this.dataIn.readUTF();
+            } else if (type == OpenWireMarshallingSupport.LONG_TYPE) {
+                return new Long(this.dataIn.readLong()).toString();
+            } else if (type == OpenWireMarshallingSupport.INTEGER_TYPE) {
+                return new Integer(this.dataIn.readInt()).toString();
+            } else if (type == OpenWireMarshallingSupport.SHORT_TYPE) {
+                return new Short(this.dataIn.readShort()).toString();
+            } else if (type == OpenWireMarshallingSupport.BYTE_TYPE) {
+                return new Byte(this.dataIn.readByte()).toString();
+            } else if (type == OpenWireMarshallingSupport.FLOAT_TYPE) {
+                return new Float(this.dataIn.readFloat()).toString();
+            } else if (type == OpenWireMarshallingSupport.DOUBLE_TYPE) {
+                return new Double(this.dataIn.readDouble()).toString();
+            } else if (type == OpenWireMarshallingSupport.BOOLEAN_TYPE) {
+                return (this.dataIn.readBoolean() ? Boolean.TRUE : Boolean.FALSE).toString();
+            } else if (type == OpenWireMarshallingSupport.CHAR_TYPE) {
+                return new Character(this.dataIn.readChar()).toString();
+            } else {
+                this.dataIn.reset();
+                throw new MessageFormatException(" not a String type");
+            }
+        } catch (NumberFormatException mfe) {
+            try {
+                this.dataIn.reset();
+            } catch (IOException ioe) {
+                throw ExceptionSupport.create(ioe);
+            }
+            throw mfe;
+        } catch (EOFException e) {
+            throw ExceptionSupport.createMessageEOFException(e);
+        } catch (IOException e) {
+            throw ExceptionSupport.createMessageFormatException(e);
+        }
+    }
+
+    @Override
+    public int readBytes(byte[] value) throws JMSException {
+        initializeReading();
+        try {
+            if (value == null) {
+                throw new NullPointerException();
+            }
+
+            if (remainingBytes == -1) {
+                this.dataIn.mark(value.length + 1);
+                int type = this.dataIn.read();
+                if (type == -1) {
+                    throw new MessageEOFException("reached end of data");
+                }
+                if (type != OpenWireMarshallingSupport.BYTE_ARRAY_TYPE) {
+                    throw new MessageFormatException("Not a byte array");
+                }
+                remainingBytes = this.dataIn.readInt();
+            } else if (remainingBytes == 0) {
+                remainingBytes = -1;
+                return -1;
+            }
+
+            if (value.length <= remainingBytes) {
+                // small buffer
+                remainingBytes -= value.length;
+                this.dataIn.readFully(value);
+                return value.length;
+            } else {
+                // big buffer
+                int rc = this.dataIn.read(value, 0, remainingBytes);
+                remainingBytes = 0;
+                return rc;
+            }
+        } catch (EOFException e) {
+            JMSException jmsEx = new MessageEOFException(e.getMessage());
+            jmsEx.setLinkedException(e);
+            throw jmsEx;
+        } catch (IOException e) {
+            JMSException jmsEx = new MessageFormatException(e.getMessage());
+            jmsEx.setLinkedException(e);
+            throw jmsEx;
+        }
+    }
+
+    @Override
+    public Object readObject() throws JMSException {
+        initializeReading();
+        try {
+            this.dataIn.mark(65);
+            int type = this.dataIn.read();
+            if (type == -1) {
+                throw new MessageEOFException("reached end of data");
+            } else if (type == OpenWireMarshallingSupport.NULL) {
+                return null;
+            } else if (type == OpenWireMarshallingSupport.BIG_STRING_TYPE) {
+                return OpenWireMarshallingSupport.readUTF8(dataIn);
+            } else if (type == OpenWireMarshallingSupport.STRING_TYPE) {
+                return this.dataIn.readUTF();
+            } else if (type == OpenWireMarshallingSupport.LONG_TYPE) {
+                return Long.valueOf(this.dataIn.readLong());
+            } else if (type == OpenWireMarshallingSupport.INTEGER_TYPE) {
+                return Integer.valueOf(this.dataIn.readInt());
+            } else if (type == OpenWireMarshallingSupport.SHORT_TYPE) {
+                return Short.valueOf(this.dataIn.readShort());
+            } else if (type == OpenWireMarshallingSupport.BYTE_TYPE) {
+                return Byte.valueOf(this.dataIn.readByte());
+            } else if (type == OpenWireMarshallingSupport.FLOAT_TYPE) {
+                return new Float(this.dataIn.readFloat());
+            } else if (type == OpenWireMarshallingSupport.DOUBLE_TYPE) {
+                return new Double(this.dataIn.readDouble());
+            } else if (type == OpenWireMarshallingSupport.BOOLEAN_TYPE) {
+                return this.dataIn.readBoolean() ? Boolean.TRUE : Boolean.FALSE;
+            } else if (type == OpenWireMarshallingSupport.CHAR_TYPE) {
+                return Character.valueOf(this.dataIn.readChar());
+            } else if (type == OpenWireMarshallingSupport.BYTE_ARRAY_TYPE) {
+                int len = this.dataIn.readInt();
+                byte[] value = new byte[len];
+                this.dataIn.readFully(value);
+                return value;
+            } else {
+                this.dataIn.reset();
+                throw new MessageFormatException("unknown type");
+            }
+        } catch (NumberFormatException mfe) {
+            try {
+                this.dataIn.reset();
+            } catch (IOException ioe) {
+                throw ExceptionSupport.create(ioe);
+            }
+            throw mfe;
+        } catch (EOFException e) {
+            JMSException jmsEx = new MessageEOFException(e.getMessage());
+            jmsEx.setLinkedException(e);
+            throw jmsEx;
+        } catch (IOException e) {
+            JMSException jmsEx = new MessageFormatException(e.getMessage());
+            jmsEx.setLinkedException(e);
+            throw jmsEx;
+        }
+    }
+
+    @Override
+    public void writeBoolean(boolean value) throws JMSException {
+        initializeWriting();
+        try {
+            OpenWireMarshallingSupport.marshalBoolean(dataOut, value);
+        } catch (IOException ioe) {
+            throw ExceptionSupport.create(ioe);
+        }
+    }
+
+    @Override
+    public void writeByte(byte value) throws JMSException {
+        initializeWriting();
+        try {
+            OpenWireMarshallingSupport.marshalByte(dataOut, value);
+        } catch (IOException ioe) {
+            throw ExceptionSupport.create(ioe);
+        }
+    }
+
+    @Override
+    public void writeShort(short value) throws JMSException {
+        initializeWriting();
+        try {
+            OpenWireMarshallingSupport.marshalShort(dataOut, value);
+        } catch (IOException ioe) {
+            throw ExceptionSupport.create(ioe);
+        }
+    }
+
+    @Override
+    public void writeChar(char value) throws JMSException {
+        initializeWriting();
+        try {
+            OpenWireMarshallingSupport.marshalChar(dataOut, value);
+        } catch (IOException ioe) {
+            throw ExceptionSupport.create(ioe);
+        }
+    }
+
+    @Override
+    public void writeInt(int value) throws JMSException {
+        initializeWriting();
+        try {
+            OpenWireMarshallingSupport.marshalInt(dataOut, value);
+        } catch (IOException ioe) {
+            throw ExceptionSupport.create(ioe);
+        }
+    }
+
+    @Override
+    public void writeLong(long value) throws JMSException {
+        initializeWriting();
+        try {
+            OpenWireMarshallingSupport.marshalLong(dataOut, value);
+        } catch (IOException ioe) {
+            throw ExceptionSupport.create(ioe);
+        }
+    }
+
+    @Override
+    public void writeFloat(float value) throws JMSException {
+        initializeWriting();
+        try {
+            OpenWireMarshallingSupport.marshalFloat(dataOut, value);
+        } catch (IOException ioe) {
+            throw ExceptionSupport.create(ioe);
+        }
+    }
+
+    @Override
+    public void writeDouble(double value) throws JMSException {
+        initializeWriting();
+        try {
+            OpenWireMarshallingSupport.marshalDouble(dataOut, value);
+        } catch (IOException ioe) {
+            throw ExceptionSupport.create(ioe);
+        }
+    }
+
+    @Override
+    public void writeString(String value) throws JMSException {
+        initializeWriting();
+        try {
+            if (value == null) {
+                OpenWireMarshallingSupport.marshalNull(dataOut);
+            } else {
+                OpenWireMarshallingSupport.marshalString(dataOut, value);
+            }
+        } catch (IOException ioe) {
+            throw ExceptionSupport.create(ioe);
+        }
+    }
+
+    @Override
+    public void writeBytes(byte[] value) throws JMSException {
+        writeBytes(value, 0, value.length);
+    }
+
+    @Override
+    public void writeBytes(byte[] value, int offset, int length) throws JMSException {
+        initializeWriting();
+        try {
+            OpenWireMarshallingSupport.marshalByteArray(dataOut, value, offset, length);
+        } catch (IOException ioe) {
+            throw ExceptionSupport.create(ioe);
+        }
+    }
+
+    @Override
+    public void writeObject(Object value) throws JMSException {
+        initializeWriting();
+        if (value == null) {
+            try {
+                OpenWireMarshallingSupport.marshalNull(dataOut);
+            } catch (IOException ioe) {
+                throw ExceptionSupport.create(ioe);
+            }
+        } else if (value instanceof String) {
+            writeString(value.toString());
+        } else if (value instanceof Character) {
+            writeChar(((Character)value).charValue());
+        } else if (value instanceof Boolean) {
+            writeBoolean(((Boolean)value).booleanValue());
+        } else if (value instanceof Byte) {
+            writeByte(((Byte)value).byteValue());
+        } else if (value instanceof Short) {
+            writeShort(((Short)value).shortValue());
+        } else if (value instanceof Integer) {
+            writeInt(((Integer)value).intValue());
+        } else if (value instanceof Float) {
+            writeFloat(((Float)value).floatValue());
+        } else if (value instanceof Double) {
+            writeDouble(((Double)value).doubleValue());
+        } else if (value instanceof byte[]) {
+            writeBytes((byte[])value);
+        } else if (value instanceof Long) {
+            writeLong(((Long)value).longValue());
+        } else {
+            throw new MessageFormatException("Unsupported Object type: " + value.getClass());
+        }
+    }
+
+    @Override
+    public void reset() throws JMSException {
+        storeContent();
+        setReadOnlyBody(true);
+        this.bytesOut = null;
+        this.dataIn = null;
+        this.dataOut = null;
+        this.remainingBytes = -1;
+    }
+
+    private void initializeWriting() throws JMSException {
+        checkReadOnlyBody();
+        if (this.dataOut == null) {
+            this.bytesOut = new ByteArrayOutputStream();
+            this.dataOut = new DataOutputStream(bytesOut);
+        }
+
+        // For a message that already had a body and was sent we need to restore the content
+        // if the message is used again without having its clearBody method called.
+        if (message.hasContent()) {
+            Buffer content = message.getPayload();
+            try {
+                this.dataOut.write(content.getData(), content.getOffset(), content.getLength());
+            } catch (IOException e) {
+                throw ExceptionSupport.create(e);
+            }
+            message.setContent(null);
+        }
+    }
+
+    private void initializeReading() throws MessageNotReadableException {
+        checkWriteOnlyBody();
+        if (this.dataIn == null) {
+            Buffer data;
+            try {
+                data = message.getPayload();
+            } catch (JMSException e) {
+                throw new MessageNotReadableException("Failed to read content from message.");
+            }
+            InputStream is = new ByteArrayInputStream(data);
+            this.dataIn = new DataInputStream(is);
+        }
+    }
+
+    private void storeContent() throws JMSException {
+        if (dataOut != null) {
+            try {
+                dataOut.close();
+                message.setPayload(bytesOut.toBuffer());
+                bytesOut = null;
+                dataOut = null;
+            } catch (IOException ioe) {
+                throw new RuntimeException(ioe);
+            }
+        }
+    }
+}

http://git-wip-us.apache.org/repos/asf/activemq-openwire/blob/7ae454fa/openwire-jms/src/main/java/org/apache/activemq/openwire/jms/OpenWireJMSTextMessage.java
----------------------------------------------------------------------
diff --git a/openwire-jms/src/main/java/org/apache/activemq/openwire/jms/OpenWireJMSTextMessage.java b/openwire-jms/src/main/java/org/apache/activemq/openwire/jms/OpenWireJMSTextMessage.java
new file mode 100644
index 0000000..c81f601
--- /dev/null
+++ b/openwire-jms/src/main/java/org/apache/activemq/openwire/jms/OpenWireJMSTextMessage.java
@@ -0,0 +1,78 @@
+/**
+ * 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.jms;
+
+import javax.jms.JMSException;
+import javax.jms.TextMessage;
+
+import org.apache.activemq.openwire.commands.OpenWireTextMessage;
+
+/**
+ * A wrapper around an OpenWireTextMessage.
+ */
+public class OpenWireJMSTextMessage extends OpenWireJMSMessage implements TextMessage {
+
+    private final OpenWireTextMessage message;
+
+    /**
+     * Creates a new instance that wraps a new OpenWireJMSTextMessage instance.
+     */
+    public OpenWireJMSTextMessage() {
+        this(new OpenWireTextMessage());
+    }
+
+    /**
+     * Creates a new instance of an OpenWireJMSTextMessage that wraps the
+     * given OpenWireTextMessage instance.
+     *
+     * @param message
+     *        the message to wrap.
+     */
+    public OpenWireJMSTextMessage(OpenWireTextMessage message) {
+        super(message);
+        this.message = message;
+    }
+
+    @Override
+    public OpenWireJMSTextMessage copy() throws JMSException {
+        OpenWireJMSTextMessage other = new OpenWireJMSTextMessage(message.copy());
+        copy(other);
+        return other;
+    }
+
+    @Override
+    public void clearBody() throws JMSException {
+        super.clearBody();
+        message.clearBody();
+    }
+
+    @Override
+    public void setText(String text) throws JMSException {
+        checkReadOnlyBody();
+        message.setText(text);
+    }
+
+    @Override
+    public String getText() throws JMSException {
+        return message.getText();
+    }
+
+    @Override
+    public String toString() {
+        return this.message.toString();
+    }
+}

http://git-wip-us.apache.org/repos/asf/activemq-openwire/blob/7ae454fa/openwire-jms/src/main/java/org/apache/activemq/openwire/jms/utils/OpenWireMessagePropertyGetter.java
----------------------------------------------------------------------
diff --git a/openwire-jms/src/main/java/org/apache/activemq/openwire/jms/utils/OpenWireMessagePropertyGetter.java b/openwire-jms/src/main/java/org/apache/activemq/openwire/jms/utils/OpenWireMessagePropertyGetter.java
new file mode 100644
index 0000000..cec7354
--- /dev/null
+++ b/openwire-jms/src/main/java/org/apache/activemq/openwire/jms/utils/OpenWireMessagePropertyGetter.java
@@ -0,0 +1,339 @@
+/**
+ * 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.jms.utils;
+
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Set;
+
+import javax.jms.Destination;
+import javax.jms.JMSException;
+
+import org.apache.activemq.openwire.commands.OpenWireMessage;
+import org.apache.activemq.openwire.commands.TransactionId;
+
+/**
+ * Utility class used to intercept calls to Message property gets and map the
+ * correct OpenWire fields to the property name being queried.
+ */
+public class OpenWireMessagePropertyGetter {
+
+    private static final Map<String, PropertyGetter> PROPERTY_GETTERS = new HashMap<String, PropertyGetter>();
+
+    /**
+     * Interface for a Property Get intercepter object used to lookup JMS style
+     * properties that are part of the OpenWire Message object members or perform
+     * some needed conversion action before returned some named property.
+     */
+    public interface PropertyGetter {
+
+        /**
+         * Called when the names property is queried from an OpenWire Message object.
+         *
+         * @param message
+         *        The message being acted upon.
+         *
+         * @return the correct property value from the given Message.
+         */
+        Object getProperty(OpenWireMessage message);
+    }
+
+    static {
+        PROPERTY_GETTERS.put("JMSDestination", new PropertyGetter() {
+            @Override
+            public Object getProperty(OpenWireMessage message) {
+                Destination dest = message.getOriginalDestination();
+                if (dest == null) {
+                    dest = message.getDestination();
+                }
+                if (dest == null) {
+                    return null;
+                }
+                return dest.toString();
+            }
+        });
+        PROPERTY_GETTERS.put("JMSReplyTo", new PropertyGetter() {
+            @Override
+            public Object getProperty(OpenWireMessage message) {
+                if (message.getReplyTo() == null) {
+                    return null;
+                }
+                return message.getReplyTo().toString();
+            }
+        });
+        PROPERTY_GETTERS.put("JMSType", new PropertyGetter() {
+            @Override
+            public Object getProperty(OpenWireMessage message) {
+                return message.getType();
+            }
+        });
+        PROPERTY_GETTERS.put("JMSDeliveryMode", new PropertyGetter() {
+            @Override
+            public Object getProperty(OpenWireMessage message) {
+                return message.isPersistent() ? "PERSISTENT" : "NON_PERSISTENT";
+            }
+        });
+        PROPERTY_GETTERS.put("JMSPriority", new PropertyGetter() {
+            @Override
+            public Object getProperty(OpenWireMessage message) {
+                return Integer.valueOf(message.getPriority());
+            }
+        });
+        PROPERTY_GETTERS.put("JMSMessageID", new PropertyGetter() {
+            @Override
+            public Object getProperty(OpenWireMessage message) {
+                if (message.getMessageId() == null) {
+                    return null;
+                }
+                return message.getMessageId().toString();
+            }
+        });
+        PROPERTY_GETTERS.put("JMSTimestamp", new PropertyGetter() {
+            @Override
+            public Object getProperty(OpenWireMessage message) {
+                return Long.valueOf(message.getTimestamp());
+            }
+        });
+        PROPERTY_GETTERS.put("JMSCorrelationID", new PropertyGetter() {
+            @Override
+            public Object getProperty(OpenWireMessage message) {
+                return message.getCorrelationId();
+            }
+        });
+        PROPERTY_GETTERS.put("JMSExpiration", new PropertyGetter() {
+            @Override
+            public Object getProperty(OpenWireMessage message) {
+                return Long.valueOf(message.getExpiration());
+            }
+        });
+        PROPERTY_GETTERS.put("JMSRedelivered", new PropertyGetter() {
+            @Override
+            public Object getProperty(OpenWireMessage message) {
+                return Boolean.valueOf(message.isRedelivered());
+            }
+        });
+        PROPERTY_GETTERS.put("JMSXDeliveryCount", new PropertyGetter() {
+            @Override
+            public Object getProperty(OpenWireMessage message) {
+                return Integer.valueOf(message.getRedeliveryCounter() + 1);
+            }
+        });
+        PROPERTY_GETTERS.put("JMSXGroupID", new PropertyGetter() {
+            @Override
+            public Object getProperty(OpenWireMessage message) {
+                return message.getGroupId();
+            }
+        });
+        PROPERTY_GETTERS.put("JMSXUserID", new PropertyGetter() {
+            @Override
+            public Object getProperty(OpenWireMessage message) {
+                Object userId = message.getUserId();
+                if (userId == null) {
+                    try {
+                        userId = message.getProperty("JMSXUserID");
+                    } catch (JMSException e) {
+                    }
+                }
+
+                return userId;
+            }
+        });
+        PROPERTY_GETTERS.put("JMSXGroupSeq", new PropertyGetter() {
+            @Override
+            public Object getProperty(OpenWireMessage message) {
+                return new Integer(message.getGroupSequence());
+            }
+        });
+        PROPERTY_GETTERS.put("JMSXProducerTXID", new PropertyGetter() {
+            @Override
+            public Object getProperty(OpenWireMessage message) {
+                TransactionId txId = message.getOriginalTransactionId();
+                if (txId == null) {
+                    txId = message.getTransactionId();
+                }
+                if (txId == null) {
+                    return null;
+                }
+                return txId.toString();
+            }
+        });
+        PROPERTY_GETTERS.put("JMSActiveMQBrokerInTime", new PropertyGetter() {
+            @Override
+            public Object getProperty(OpenWireMessage message) {
+                return Long.valueOf(message.getBrokerInTime());
+            }
+        });
+        PROPERTY_GETTERS.put("JMSActiveMQBrokerOutTime", new PropertyGetter() {
+            @Override
+            public Object getProperty(OpenWireMessage message) {
+                return Long.valueOf(message.getBrokerOutTime());
+            }
+        });
+        PROPERTY_GETTERS.put("JMSActiveMQBrokerPath", new PropertyGetter() {
+            @Override
+            public Object getProperty(OpenWireMessage message) {
+                return Arrays.toString(message.getBrokerPath());
+            }
+        });
+        PROPERTY_GETTERS.put("JMSXGroupFirstForConsumer", new PropertyGetter() {
+            @Override
+            public Object getProperty(OpenWireMessage message) {
+                return Boolean.valueOf(message.isJMSXGroupFirstForConsumer());
+            }
+        });
+        PROPERTY_GETTERS.put("JMSXMimeType", new PropertyGetter() {
+            @Override
+            public Object getProperty(OpenWireMessage message) {
+                return String.valueOf(message.getMimeType());
+            }
+        });
+    }
+
+    /**
+     * For each of the currently configured message property intercepter instance a
+     * string key value is inserted into an Set and returned.
+     *
+     * @return a Set<String> containing the names of all intercepted properties.
+     */
+    public static Set<String> getPropertyNames() {
+        return PROPERTY_GETTERS.keySet();
+    }
+
+    /**
+     * Static get method that takes a property name and gets the value either via
+     * a registered property get object or through the OpenWireMessage getProperty
+     * method.
+     *
+     * @param message
+     *        the OpenWireMessage instance to read from
+     * @param name
+     *        the property name that is being requested.
+     *
+     * @return the correct value either mapped to an OpenWire attribute of a Message property.
+     *
+     * @throws JMSException if an error occurs while reading the defined property.
+     */
+    public static Object getProperty(OpenWireMessage message, String name) throws JMSException {
+        Object value = null;
+
+        PropertyGetter jmsPropertyExpression = PROPERTY_GETTERS.get(name);
+        if (jmsPropertyExpression != null) {
+            value = jmsPropertyExpression.getProperty(message);
+        } else {
+            value = message.getProperty(name);
+        }
+
+        return value;
+    }
+
+    /**
+     * Allows for the additional PropertyGetter instances to be added to the global set.
+     *
+     * @param propertyName
+     *        The name of the Message property that will be intercepted.
+     * @param getter
+     *        The PropertyGetter instance that should be used for the named property.
+     */
+    public static void addPropertyGetter(String propertyName, PropertyGetter getter) {
+        PROPERTY_GETTERS.put(propertyName, getter);
+    }
+
+    /**
+     * Given a property name, remove the configured getter that has been assigned to
+     * intercept the queries for that property value.
+     *
+     * @param propertyName
+     *        The name of the Property Getter to remove.
+     *
+     * @return true if a getter was removed from the global set.
+     */
+    public boolean removePropertyGetter(String propertyName) {
+        if (PROPERTY_GETTERS.remove(propertyName) != null) {
+            return true;
+        }
+
+        return false;
+    }
+
+    private final String name;
+    private final PropertyGetter jmsPropertyExpression;
+
+    /**
+     * Creates an new property getter instance that is assigned to read the named value.
+     *
+     * @param name
+     *        the property value that this getter is assigned to lookup.
+     */
+    public OpenWireMessagePropertyGetter(String name) {
+        this.name = name;
+        jmsPropertyExpression = PROPERTY_GETTERS.get(name);
+    }
+
+    /**
+     * Gets the correct property value from the OpenWireMessage instance based on
+     * the predefined property mappings.
+     *
+     * @param message
+     *        the OpenWireMessage whose property is being read.
+     *
+     * @return the correct value either mapped to an OpenWire attribute of a Message property.
+     *
+     * @throws JMSException if an error occurs while reading the defined property.
+     */
+    public Object get(OpenWireMessage message) throws JMSException {
+        if (jmsPropertyExpression != null) {
+            return jmsPropertyExpression.getProperty(message);
+        }
+
+        return message.getProperty(name);
+    }
+
+    /**
+     * @return the property name that is being intercepted for the OpenWireMessage.
+     */
+    public String getName() {
+        return name;
+    }
+
+    /**
+     * @see java.lang.Object#toString()
+     */
+    @Override
+    public String toString() {
+        return name;
+    }
+
+    /**
+     * @see java.lang.Object#hashCode()
+     */
+    @Override
+    public int hashCode() {
+        return name.hashCode();
+    }
+
+    /**
+     * @see java.lang.Object#equals(java.lang.Object)
+     */
+    @Override
+    public boolean equals(Object o) {
+        if (o == null || !this.getClass().equals(o.getClass())) {
+            return false;
+        }
+        return name.equals(((OpenWireMessagePropertyGetter) o).name);
+    }
+}

http://git-wip-us.apache.org/repos/asf/activemq-openwire/blob/7ae454fa/openwire-jms/src/main/java/org/apache/activemq/openwire/jms/utils/OpenWireMessagePropertySetter.java
----------------------------------------------------------------------
diff --git a/openwire-jms/src/main/java/org/apache/activemq/openwire/jms/utils/OpenWireMessagePropertySetter.java b/openwire-jms/src/main/java/org/apache/activemq/openwire/jms/utils/OpenWireMessagePropertySetter.java
new file mode 100644
index 0000000..d3f6854
--- /dev/null
+++ b/openwire-jms/src/main/java/org/apache/activemq/openwire/jms/utils/OpenWireMessagePropertySetter.java
@@ -0,0 +1,305 @@
+/**
+ * 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.jms.utils;
+
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Set;
+
+import javax.jms.DeliveryMode;
+import javax.jms.JMSException;
+import javax.jms.MessageFormatException;
+
+import org.apache.activemq.openwire.commands.OpenWireDestination;
+import org.apache.activemq.openwire.commands.OpenWireMessage;
+
+/**
+ * Utility class used to intercept calls to Message property sets and map the
+ * correct OpenWire fields to the property name being set.
+ */
+public class OpenWireMessagePropertySetter {
+
+    private static final Map<String, PropertySetter> PROPERTY_SETTERS = new HashMap<String, PropertySetter>();
+
+    /**
+     * Interface for a Property Set intercepter object used to write JMS style
+     * properties that are part of the OpenWire Message object members or perform
+     * some needed conversion action before some named property is set.
+     */
+    interface PropertySetter {
+
+        /**
+         * Called when the names property is assigned from an OpenWire Message object.
+         *
+         * @param message
+         *        The message instance being acted upon.
+         * @param value
+         *        The value to assign to the intercepted property.
+         *
+         * @throws MessageFormatException if an error occurs writing the property.
+s         */
+        void setProperty(OpenWireMessage message, Object value) throws MessageFormatException;
+    }
+
+    static {
+        PROPERTY_SETTERS.put("JMSXDeliveryCount", new PropertySetter() {
+            @Override
+            public void setProperty(OpenWireMessage message, Object value) throws MessageFormatException {
+                Integer rc = (Integer) TypeConversionSupport.convert(value, Integer.class);
+                if (rc == null) {
+                    throw new MessageFormatException("Property JMSXDeliveryCount cannot be set from a " + value.getClass().getName() + ".");
+                }
+                message.setRedeliveryCounter(rc.intValue() - 1);
+            }
+        });
+        PROPERTY_SETTERS.put("JMSXGroupID", new PropertySetter() {
+            @Override
+            public void setProperty(OpenWireMessage message, Object value) throws MessageFormatException {
+                String rc = (String) TypeConversionSupport.convert(value, String.class);
+                if (rc == null) {
+                    throw new MessageFormatException("Property JMSXGroupID cannot be set from a " + value.getClass().getName() + ".");
+                }
+                message.setGroupID(rc);
+            }
+        });
+        PROPERTY_SETTERS.put("JMSXGroupSeq", new PropertySetter() {
+            @Override
+            public void setProperty(OpenWireMessage message, Object value) throws MessageFormatException {
+                Integer rc = (Integer) TypeConversionSupport.convert(value, Integer.class);
+                if (rc == null) {
+                    throw new MessageFormatException("Property JMSXGroupSeq cannot be set from a " + value.getClass().getName() + ".");
+                }
+                message.setGroupSequence(rc.intValue());
+            }
+        });
+        PROPERTY_SETTERS.put("JMSCorrelationID", new PropertySetter() {
+            @Override
+            public void setProperty(OpenWireMessage message, Object value) throws MessageFormatException {
+                String rc = (String) TypeConversionSupport.convert(value, String.class);
+                if (rc == null) {
+                    throw new MessageFormatException("Property JMSCorrelationID cannot be set from a " + value.getClass().getName() + ".");
+                }
+                message.setCorrelationId(rc);
+            }
+        });
+        PROPERTY_SETTERS.put("JMSDeliveryMode", new PropertySetter() {
+            @Override
+            public void setProperty(OpenWireMessage message, Object value) throws MessageFormatException {
+                Integer rc = (Integer) TypeConversionSupport.convert(value, Integer.class);
+                if (rc == null) {
+                    Boolean bool = (Boolean) TypeConversionSupport.convert(value, Boolean.class);
+                    if (bool == null) {
+                        throw new MessageFormatException("Property JMSDeliveryMode cannot be set from a " + value.getClass().getName() + ".");
+                    } else {
+                        message.setPersistent(bool.booleanValue());
+                    }
+                } else {
+                    message.setPersistent(rc == DeliveryMode.PERSISTENT);
+                }
+            }
+        });
+        PROPERTY_SETTERS.put("JMSExpiration", new PropertySetter() {
+            @Override
+            public void setProperty(OpenWireMessage message, Object value) throws MessageFormatException {
+                Long rc = (Long) TypeConversionSupport.convert(value, Long.class);
+                if (rc == null) {
+                    throw new MessageFormatException("Property JMSExpiration cannot be set from a " + value.getClass().getName() + ".");
+                }
+                message.setExpiration(rc.longValue());
+            }
+        });
+        PROPERTY_SETTERS.put("JMSPriority", new PropertySetter() {
+            @Override
+            public void setProperty(OpenWireMessage message, Object value) throws MessageFormatException {
+                Integer rc = (Integer) TypeConversionSupport.convert(value, Integer.class);
+                if (rc == null) {
+                    throw new MessageFormatException("Property JMSPriority cannot be set from a " + value.getClass().getName() + ".");
+                }
+                message.setPriority(rc.byteValue());
+            }
+        });
+        PROPERTY_SETTERS.put("JMSRedelivered", new PropertySetter() {
+            @Override
+            public void setProperty(OpenWireMessage message, Object value) throws MessageFormatException {
+                Boolean rc = (Boolean) TypeConversionSupport.convert(value, Boolean.class);
+                if (rc == null) {
+                    throw new MessageFormatException("Property JMSRedelivered cannot be set from a " + value.getClass().getName() + ".");
+                }
+                message.setRedelivered(rc.booleanValue());
+            }
+        });
+        PROPERTY_SETTERS.put("JMSReplyTo", new PropertySetter() {
+            @Override
+            public void setProperty(OpenWireMessage message, Object value) throws MessageFormatException {
+                OpenWireDestination rc = (OpenWireDestination) TypeConversionSupport.convert(value, OpenWireDestination.class);
+                if (rc == null) {
+                    throw new MessageFormatException("Property JMSReplyTo cannot be set from a " + value.getClass().getName() + ".");
+                }
+                message.setReplyTo(rc);
+            }
+        });
+        PROPERTY_SETTERS.put("JMSTimestamp", new PropertySetter() {
+            @Override
+            public void setProperty(OpenWireMessage message, Object value) throws MessageFormatException {
+                Long rc = (Long) TypeConversionSupport.convert(value, Long.class);
+                if (rc == null) {
+                    throw new MessageFormatException("Property JMSTimestamp cannot be set from a " + value.getClass().getName() + ".");
+                }
+                message.setTimestamp(rc.longValue());
+            }
+        });
+        PROPERTY_SETTERS.put("JMSType", new PropertySetter() {
+            @Override
+            public void setProperty(OpenWireMessage message, Object value) throws MessageFormatException {
+                String rc = (String) TypeConversionSupport.convert(value, String.class);
+                if (rc == null) {
+                    throw new MessageFormatException("Property JMSType cannot be set from a " + value.getClass().getName() + ".");
+                }
+                message.setType(rc);
+            }
+        });
+    }
+
+    /**
+     * Static set method that takes a property name and sets the value either via
+     * a registered property set object or through the OpenWireMessage setProperty
+     * method.
+     *
+     * @param message
+     *        the OpenWireMessage instance to write to.
+     * @param name
+     *        the property name that is being written.
+     * @param value
+     *        the new value to assign for the named property.
+     *
+     * @throws JMSException if an error occurs while writting the defined property.
+     */
+    public static void setProperty(OpenWireMessage message, String name, Object value) throws JMSException {
+        PropertySetter jmsPropertyExpression = PROPERTY_SETTERS.get(name);
+        if (jmsPropertyExpression != null) {
+            jmsPropertyExpression.setProperty(message, value);
+        } else {
+            message.setProperty(name, value);
+        }
+    }
+
+    /**
+     * Allows for the additional PropertySetter instances to be added to the global set.
+     *
+     * @param propertyName
+     *        The name of the Message property that will be intercepted.
+     * @param getter
+     *        The PropertySetter instance that should be used for the named property.
+     */
+    public static void addPropertySetter(String propertyName, PropertySetter getter) {
+        PROPERTY_SETTERS.put(propertyName, getter);
+    }
+
+    /**
+     * Given a property name, remove the configured getter that has been assigned to
+     * intercept the queries for that property value.
+     *
+     * @param propertyName
+     *        The name of the Property Getter to remove.
+     *
+     * @return true if a getter was removed from the global set.
+     */
+    public boolean removePropertySetter(String propertyName) {
+        if (PROPERTY_SETTERS.remove(propertyName) != null) {
+            return true;
+        }
+
+        return false;
+    }
+
+    private final String name;
+    private final PropertySetter jmsPropertyExpression;
+
+    /**
+     * For each of the currently configured message property intercepter instance a
+     * string key value is inserted into an Set and returned.
+     *
+     * @return a Set<String> containing the names of all intercepted properties.
+     */
+    public static Set<String> getPropertyNames() {
+        return PROPERTY_SETTERS.keySet();
+    }
+
+    /**
+     * Creates an new property getter instance that is assigned to read the named value.
+     *
+     * @param name
+     *        the property value that this getter is assigned to lookup.
+     */
+    public OpenWireMessagePropertySetter(String name) {
+        this.name = name;
+        jmsPropertyExpression = PROPERTY_SETTERS.get(name);
+    }
+
+    /**
+     * Sets the correct property value from the OpenWireMessage instance based on
+     * the predefined property mappings.
+     *
+     * @param message
+     *        the OpenWireMessage whose property is being read.
+     * @param value
+     *        the value to be set on the intercepted OpenWireMessage property.
+     *
+     * @throws JMSException if an error occurs while reading the defined property.
+     */
+    public void set(OpenWireMessage message, Object value) throws JMSException {
+        if (jmsPropertyExpression != null) {
+            jmsPropertyExpression.setProperty(message, value);
+        } else {
+            message.setProperty(name, value);
+        }
+    }
+
+    /**
+     * @return the property name that is being intercepted for the OpenWireMessage.
+     */
+    public String getName() {
+        return name;
+    }
+
+    /**
+     * @see java.lang.Object#toString()
+     */
+    @Override
+    public String toString() {
+        return name;
+    }
+
+    /**
+     * @see java.lang.Object#hashCode()
+     */
+    @Override
+    public int hashCode() {
+        return name.hashCode();
+    }
+
+    /**
+     * @see java.lang.Object#equals(java.lang.Object)
+     */
+    @Override
+    public boolean equals(Object o) {
+        if (o == null || !this.getClass().equals(o.getClass())) {
+            return false;
+        }
+        return name.equals(((OpenWireMessagePropertySetter) o).name);
+    }
+}

http://git-wip-us.apache.org/repos/asf/activemq-openwire/blob/7ae454fa/openwire-jms/src/main/java/org/apache/activemq/openwire/jms/utils/TypeConversionSupport.java
----------------------------------------------------------------------
diff --git a/openwire-jms/src/main/java/org/apache/activemq/openwire/jms/utils/TypeConversionSupport.java b/openwire-jms/src/main/java/org/apache/activemq/openwire/jms/utils/TypeConversionSupport.java
new file mode 100644
index 0000000..a4121e4
--- /dev/null
+++ b/openwire-jms/src/main/java/org/apache/activemq/openwire/jms/utils/TypeConversionSupport.java
@@ -0,0 +1,255 @@
+/**
+ * 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.jms.utils;
+
+import java.math.BigInteger;
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.util.Date;
+import java.util.HashMap;
+import java.util.Map;
+
+import org.apache.activemq.openwire.commands.OpenWireDestination;
+import org.fusesource.hawtbuf.UTF8Buffer;
+
+/**
+ * Type conversion support for OpenWireMessage property types.
+ */
+public final class TypeConversionSupport {
+
+    private static final Converter IDENTITY_CONVERTER = new Converter() {
+        @Override
+        public Object convert(Object value) {
+            return value;
+        }
+    };
+
+    private static class ConversionKey {
+        final Class<?> from;
+        final Class<?> to;
+        final int hashCode;
+
+        public ConversionKey(Class<?> from, Class<?> to) {
+            this.from = from;
+            this.to = to;
+            this.hashCode = from.hashCode() ^ (to.hashCode() << 1);
+        }
+
+        @Override
+        public boolean equals(Object o) {
+            ConversionKey x = (ConversionKey) o;
+            return x.from == from && x.to == to;
+        }
+
+        @Override
+        public int hashCode() {
+            return hashCode;
+        }
+    }
+
+    public interface Converter {
+        Object convert(Object value);
+    }
+
+    private static final Map<ConversionKey, Converter> CONVERSION_MAP = new HashMap<ConversionKey, Converter>();
+    static {
+        Converter toStringConverter = new Converter() {
+            @Override
+            public Object convert(Object value) {
+                return value.toString();
+            }
+        };
+        CONVERSION_MAP.put(new ConversionKey(Boolean.class, String.class), toStringConverter);
+        CONVERSION_MAP.put(new ConversionKey(Byte.class, String.class), toStringConverter);
+        CONVERSION_MAP.put(new ConversionKey(Short.class, String.class), toStringConverter);
+        CONVERSION_MAP.put(new ConversionKey(Integer.class, String.class), toStringConverter);
+        CONVERSION_MAP.put(new ConversionKey(Long.class, String.class), toStringConverter);
+        CONVERSION_MAP.put(new ConversionKey(Float.class, String.class), toStringConverter);
+        CONVERSION_MAP.put(new ConversionKey(Double.class, String.class), toStringConverter);
+        CONVERSION_MAP.put(new ConversionKey(UTF8Buffer.class, String.class), toStringConverter);
+        CONVERSION_MAP.put(new ConversionKey(URI.class, String.class), toStringConverter);
+        CONVERSION_MAP.put(new ConversionKey(BigInteger.class, String.class), toStringConverter);
+
+        CONVERSION_MAP.put(new ConversionKey(String.class, Boolean.class), new Converter() {
+            @Override
+            public Object convert(Object value) {
+                return Boolean.valueOf((String) value);
+            }
+        });
+        CONVERSION_MAP.put(new ConversionKey(String.class, Byte.class), new Converter() {
+            @Override
+            public Object convert(Object value) {
+                return Byte.valueOf((String) value);
+            }
+        });
+        CONVERSION_MAP.put(new ConversionKey(String.class, Short.class), new Converter() {
+            @Override
+            public Object convert(Object value) {
+                return Short.valueOf((String) value);
+            }
+        });
+        CONVERSION_MAP.put(new ConversionKey(String.class, Integer.class), new Converter() {
+            @Override
+            public Object convert(Object value) {
+                return Integer.valueOf((String) value);
+            }
+        });
+        CONVERSION_MAP.put(new ConversionKey(String.class, Long.class), new Converter() {
+            @Override
+            public Object convert(Object value) {
+                return Long.valueOf((String) value);
+            }
+        });
+        CONVERSION_MAP.put(new ConversionKey(String.class, Float.class), new Converter() {
+            @Override
+            public Object convert(Object value) {
+                return Float.valueOf((String) value);
+            }
+        });
+        CONVERSION_MAP.put(new ConversionKey(String.class, Double.class), new Converter() {
+            @Override
+            public Object convert(Object value) {
+                return Double.valueOf((String) value);
+            }
+        });
+
+        Converter longConverter = new Converter() {
+            @Override
+            public Object convert(Object value) {
+                return Long.valueOf(((Number) value).longValue());
+            }
+        };
+        CONVERSION_MAP.put(new ConversionKey(Byte.class, Long.class), longConverter);
+        CONVERSION_MAP.put(new ConversionKey(Short.class, Long.class), longConverter);
+        CONVERSION_MAP.put(new ConversionKey(Integer.class, Long.class), longConverter);
+        CONVERSION_MAP.put(new ConversionKey(Date.class, Long.class), new Converter() {
+            @Override
+            public Object convert(Object value) {
+                return Long.valueOf(((Date) value).getTime());
+            }
+        });
+
+        Converter intConverter = new Converter() {
+            @Override
+            public Object convert(Object value) {
+                return Integer.valueOf(((Number) value).intValue());
+            }
+        };
+        CONVERSION_MAP.put(new ConversionKey(Byte.class, Integer.class), intConverter);
+        CONVERSION_MAP.put(new ConversionKey(Short.class, Integer.class), intConverter);
+
+        CONVERSION_MAP.put(new ConversionKey(Byte.class, Short.class), new Converter() {
+            @Override
+            public Object convert(Object value) {
+                return Short.valueOf(((Number) value).shortValue());
+            }
+        });
+
+        CONVERSION_MAP.put(new ConversionKey(Float.class, Double.class), new Converter() {
+            @Override
+            public Object convert(Object value) {
+                return new Double(((Number) value).doubleValue());
+            }
+        });
+        CONVERSION_MAP.put(new ConversionKey(String.class, OpenWireDestination.class), new Converter() {
+            @Override
+            public Object convert(Object value) {
+                return OpenWireDestination.createDestination((String) value, OpenWireDestination.QUEUE_TYPE);
+            }
+        });
+        CONVERSION_MAP.put(new ConversionKey(String.class, URI.class), new Converter() {
+            @Override
+            public Object convert(Object value) {
+                String text = value.toString();
+                try {
+                    return new URI(text);
+                } catch (URISyntaxException e) {
+                    throw new RuntimeException(e);
+                }
+            }
+        });
+    }
+
+    private TypeConversionSupport() {
+    }
+
+    public static Object convert(Object value, Class<?> to) {
+        if (value == null) {
+            // lets avoid NullPointerException when converting to boolean for null values
+            if (boolean.class.isAssignableFrom(to)) {
+                return Boolean.FALSE;
+            }
+            return null;
+        }
+
+        // eager same instance type test to avoid the overhead of invoking the
+        // type converter if already same type
+        if (to.isInstance(value)) {
+            return to.cast(value);
+        }
+
+        // lookup converter
+        Converter c = lookupConverter(value.getClass(), to);
+        if (c != null) {
+            return c.convert(value);
+        } else {
+            return null;
+        }
+    }
+
+    public static Converter lookupConverter(Class<?> from, Class<?> to) {
+        // use wrapped type for primitives
+        if (from.isPrimitive()) {
+            from = convertPrimitiveTypeToWrapperType(from);
+        }
+        if (to.isPrimitive()) {
+            to = convertPrimitiveTypeToWrapperType(to);
+        }
+
+        if (from.equals(to)) {
+            return IDENTITY_CONVERTER;
+        }
+
+        return CONVERSION_MAP.get(new ConversionKey(from, to));
+    }
+
+    /**
+     * Converts primitive types such as int to its wrapper type like
+     * {@link Integer}
+     */
+    private static Class<?> convertPrimitiveTypeToWrapperType(Class<?> type) {
+        Class<?> rc = type;
+        if (type.isPrimitive()) {
+            if (type == int.class) {
+                rc = Integer.class;
+            } else if (type == long.class) {
+                rc = Long.class;
+            } else if (type == double.class) {
+                rc = Double.class;
+            } else if (type == float.class) {
+                rc = Float.class;
+            } else if (type == short.class) {
+                rc = Short.class;
+            } else if (type == byte.class) {
+                rc = Byte.class;
+            } else if (type == boolean.class) {
+                rc = Boolean.class;
+            }
+        }
+        return rc;
+    }
+}

http://git-wip-us.apache.org/repos/asf/activemq-openwire/blob/7ae454fa/openwire-jms/src/test/java/org/apache/activemq/openwire/jms/OpenWireJMSBytesMessageTest.java
----------------------------------------------------------------------
diff --git a/openwire-jms/src/test/java/org/apache/activemq/openwire/jms/OpenWireJMSBytesMessageTest.java b/openwire-jms/src/test/java/org/apache/activemq/openwire/jms/OpenWireJMSBytesMessageTest.java
new file mode 100644
index 0000000..04f19b2
--- /dev/null
+++ b/openwire-jms/src/test/java/org/apache/activemq/openwire/jms/OpenWireJMSBytesMessageTest.java
@@ -0,0 +1,487 @@
+/**
+ * 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.jms;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+
+import javax.jms.JMSException;
+import javax.jms.MessageFormatException;
+import javax.jms.MessageNotReadableException;
+import javax.jms.MessageNotWriteableException;
+
+import org.apache.activemq.openwire.commands.CommandTypes;
+import org.apache.activemq.openwire.jms.OpenWireJMSBytesMessage;
+import org.junit.Test;
+
+/**
+ * Test that the OpenWireJMSBytesMessage object is JMS Compliant.
+ */
+public class OpenWireJMSBytesMessageTest {
+
+    @Test
+    public void testGetDataStructureType() {
+        OpenWireJMSBytesMessage msg = new OpenWireJMSBytesMessage();
+        assertEquals(CommandTypes.OPENWIRE_BYTES_MESSAGE, msg.getOpenWireMessage().getDataStructureType());
+    }
+
+    @Test
+    public void testGetBodyLength() {
+        OpenWireJMSBytesMessage msg = new OpenWireJMSBytesMessage();
+        int len = 10;
+        try {
+            for (int i = 0; i < len; i++) {
+                msg.writeLong(5L);
+            }
+        } catch (JMSException ex) {
+            ex.printStackTrace();
+        }
+        try {
+            msg.reset();
+            assertTrue(msg.getBodyLength() == (len * 8));
+        } catch (Throwable e) {
+            e.printStackTrace();
+            assertTrue(false);
+        }
+    }
+
+    @Test
+    public void testReadBoolean() {
+        OpenWireJMSBytesMessage msg = new OpenWireJMSBytesMessage();
+        try {
+            msg.writeBoolean(true);
+            msg.reset();
+            assertTrue(msg.readBoolean());
+        } catch (JMSException jmsEx) {
+            jmsEx.printStackTrace();
+            assertTrue(false);
+        }
+    }
+
+    @Test
+    public void testReadByte() {
+        OpenWireJMSBytesMessage msg = new OpenWireJMSBytesMessage();
+        try {
+            msg.writeByte((byte) 2);
+            msg.reset();
+            assertTrue(msg.readByte() == 2);
+        } catch (JMSException jmsEx) {
+            jmsEx.printStackTrace();
+            assertTrue(false);
+        }
+    }
+
+    @Test
+    public void testReadUnsignedByte() {
+        OpenWireJMSBytesMessage msg = new OpenWireJMSBytesMessage();
+        try {
+            msg.writeByte((byte) 2);
+            msg.reset();
+            assertTrue(msg.readUnsignedByte() == 2);
+        } catch (JMSException jmsEx) {
+            jmsEx.printStackTrace();
+            assertTrue(false);
+        }
+    }
+
+    @Test
+    public void testReadShort() {
+        OpenWireJMSBytesMessage msg = new OpenWireJMSBytesMessage();
+        try {
+            msg.writeShort((short) 3000);
+            msg.reset();
+            assertTrue(msg.readShort() == 3000);
+        } catch (JMSException jmsEx) {
+            jmsEx.printStackTrace();
+            assertTrue(false);
+        }
+    }
+
+    @Test
+    public void testReadUnsignedShort() {
+        OpenWireJMSBytesMessage msg = new OpenWireJMSBytesMessage();
+        try {
+            msg.writeShort((short) 3000);
+            msg.reset();
+            assertTrue(msg.readUnsignedShort() == 3000);
+        } catch (JMSException jmsEx) {
+            jmsEx.printStackTrace();
+            assertTrue(false);
+        }
+    }
+
+    @Test
+    public void testReadChar() {
+        OpenWireJMSBytesMessage msg = new OpenWireJMSBytesMessage();
+        try {
+            msg.writeChar('a');
+            msg.reset();
+            assertTrue(msg.readChar() == 'a');
+        } catch (JMSException jmsEx) {
+            jmsEx.printStackTrace();
+            assertTrue(false);
+        }
+    }
+
+    @Test
+    public void testReadInt() {
+        OpenWireJMSBytesMessage msg = new OpenWireJMSBytesMessage();
+        try {
+            msg.writeInt(3000);
+            msg.reset();
+            assertTrue(msg.readInt() == 3000);
+        } catch (JMSException jmsEx) {
+            jmsEx.printStackTrace();
+            assertTrue(false);
+        }
+    }
+
+    @Test
+    public void testReadLong() {
+        OpenWireJMSBytesMessage msg = new OpenWireJMSBytesMessage();
+        try {
+            msg.writeLong(3000);
+            msg.reset();
+            assertTrue(msg.readLong() == 3000);
+        } catch (JMSException jmsEx) {
+            jmsEx.printStackTrace();
+            assertTrue(false);
+        }
+    }
+
+    @Test
+    public void testReadFloat() {
+        OpenWireJMSBytesMessage msg = new OpenWireJMSBytesMessage();
+        try {
+            msg.writeFloat(3.3f);
+            msg.reset();
+            assertTrue(msg.readFloat() == 3.3f);
+        } catch (JMSException jmsEx) {
+            jmsEx.printStackTrace();
+            assertTrue(false);
+        }
+    }
+
+    @Test
+    public void testReadDouble() {
+        OpenWireJMSBytesMessage msg = new OpenWireJMSBytesMessage();
+        try {
+            msg.writeDouble(3.3d);
+            msg.reset();
+            assertTrue(msg.readDouble() == 3.3d);
+        } catch (JMSException jmsEx) {
+            jmsEx.printStackTrace();
+            assertTrue(false);
+        }
+    }
+
+    @Test
+    public void testReadUTF() {
+        OpenWireJMSBytesMessage msg = new OpenWireJMSBytesMessage();
+        try {
+            String str = "this is a test";
+            msg.writeUTF(str);
+            msg.reset();
+            assertTrue(msg.readUTF().equals(str));
+        } catch (JMSException jmsEx) {
+            jmsEx.printStackTrace();
+            assertTrue(false);
+        }
+    }
+
+    @Test
+    public void testReadBytesbyteArray() {
+        OpenWireJMSBytesMessage msg = new OpenWireJMSBytesMessage();
+        try {
+            byte[] data = new byte[50];
+            for (int i = 0; i < data.length; i++) {
+                data[i] = (byte) i;
+            }
+            msg.writeBytes(data);
+            msg.reset();
+            byte[] test = new byte[data.length];
+            msg.readBytes(test);
+            for (int i = 0; i < test.length; i++) {
+                assertTrue(test[i] == i);
+            }
+        } catch (JMSException jmsEx) {
+            jmsEx.printStackTrace();
+            assertTrue(false);
+        }
+    }
+
+    @Test
+    public void testWriteObject() throws JMSException {
+        OpenWireJMSBytesMessage msg = new OpenWireJMSBytesMessage();
+        try {
+            msg.writeObject("fred");
+            msg.writeObject(Boolean.TRUE);
+            msg.writeObject(Character.valueOf('q'));
+            msg.writeObject(Byte.valueOf((byte) 1));
+            msg.writeObject(Short.valueOf((short) 3));
+            msg.writeObject(Integer.valueOf(3));
+            msg.writeObject(Long.valueOf(300L));
+            msg.writeObject(new Float(3.3f));
+            msg.writeObject(new Double(3.3));
+            msg.writeObject(new byte[3]);
+        } catch (MessageFormatException mfe) {
+            fail("objectified primitives should be allowed");
+        }
+        try {
+            msg.writeObject(new Object());
+            fail("only objectified primitives are allowed");
+        } catch (MessageFormatException mfe) {
+        }
+    }
+
+    @Test
+    public void testClearBody() throws JMSException {
+        OpenWireJMSBytesMessage bytesMessage = new OpenWireJMSBytesMessage();
+        try {
+            bytesMessage.writeInt(1);
+            bytesMessage.clearBody();
+            assertFalse(bytesMessage.isReadOnlyBody());
+            bytesMessage.writeInt(1);
+            bytesMessage.readInt();
+        } catch (MessageNotReadableException mnwe) {
+        } catch (MessageNotWriteableException mnwe) {
+            assertTrue(false);
+        }
+    }
+
+    @Test
+    public void testReset() throws JMSException {
+        OpenWireJMSBytesMessage message = new OpenWireJMSBytesMessage();
+        try {
+            message.writeDouble(24.5);
+            message.writeLong(311);
+        } catch (MessageNotWriteableException mnwe) {
+            fail("should be writeable");
+        }
+        message.reset();
+        try {
+            assertTrue(message.isReadOnlyBody());
+            assertEquals(message.readDouble(), 24.5, 0);
+            assertEquals(message.readLong(), 311);
+        } catch (MessageNotReadableException mnre) {
+            fail("should be readable");
+        }
+        try {
+            message.writeInt(33);
+            fail("should throw exception");
+        } catch (MessageNotWriteableException mnwe) {
+        }
+    }
+
+    @Test
+    public void testReadOnlyBody() throws JMSException {
+        OpenWireJMSBytesMessage message = new OpenWireJMSBytesMessage();
+        try {
+            message.writeBoolean(true);
+            message.writeByte((byte) 1);
+            message.writeByte((byte) 1);
+            message.writeBytes(new byte[1]);
+            message.writeBytes(new byte[3], 0, 2);
+            message.writeChar('a');
+            message.writeDouble(1.5);
+            message.writeFloat((float) 1.5);
+            message.writeInt(1);
+            message.writeLong(1);
+            message.writeObject("stringobj");
+            message.writeShort((short) 1);
+            message.writeShort((short) 1);
+            message.writeUTF("utfstring");
+        } catch (MessageNotWriteableException mnwe) {
+            fail("Should be writeable");
+        }
+        message.reset();
+        try {
+            message.readBoolean();
+            message.readByte();
+            message.readUnsignedByte();
+            message.readBytes(new byte[1]);
+            message.readBytes(new byte[2], 2);
+            message.readChar();
+            message.readDouble();
+            message.readFloat();
+            message.readInt();
+            message.readLong();
+            message.readUTF();
+            message.readShort();
+            message.readUnsignedShort();
+            message.readUTF();
+        } catch (MessageNotReadableException mnwe) {
+            fail("Should be readable");
+        }
+        try {
+            message.writeBoolean(true);
+            fail("Should have thrown exception");
+        } catch (MessageNotWriteableException mnwe) {
+        }
+        try {
+            message.writeByte((byte) 1);
+            fail("Should have thrown exception");
+        } catch (MessageNotWriteableException mnwe) {
+        }
+        try {
+            message.writeBytes(new byte[1]);
+            fail("Should have thrown exception");
+        } catch (MessageNotWriteableException mnwe) {
+        }
+        try {
+            message.writeBytes(new byte[3], 0, 2);
+            fail("Should have thrown exception");
+        } catch (MessageNotWriteableException mnwe) {
+        }
+        try {
+            message.writeChar('a');
+            fail("Should have thrown exception");
+        } catch (MessageNotWriteableException mnwe) {
+        }
+        try {
+            message.writeDouble(1.5);
+            fail("Should have thrown exception");
+        } catch (MessageNotWriteableException mnwe) {
+        }
+        try {
+            message.writeFloat((float) 1.5);
+            fail("Should have thrown exception");
+        } catch (MessageNotWriteableException mnwe) {
+        }
+        try {
+            message.writeInt(1);
+            fail("Should have thrown exception");
+        } catch (MessageNotWriteableException mnwe) {
+        }
+        try {
+            message.writeLong(1);
+            fail("Should have thrown exception");
+        } catch (MessageNotWriteableException mnwe) {
+        }
+        try {
+            message.writeObject("stringobj");
+            fail("Should have thrown exception");
+        } catch (MessageNotWriteableException mnwe) {
+        }
+        try {
+            message.writeShort((short) 1);
+            fail("Should have thrown exception");
+        } catch (MessageNotWriteableException mnwe) {
+        }
+        try {
+            message.writeUTF("utfstring");
+            fail("Should have thrown exception");
+        } catch (MessageNotWriteableException mnwe) {
+        }
+    }
+
+    @Test
+    public void testWriteOnlyBody() throws JMSException {
+        OpenWireJMSBytesMessage message = new OpenWireJMSBytesMessage();
+        message.clearBody();
+        try {
+            message.writeBoolean(true);
+            message.writeByte((byte) 1);
+            message.writeByte((byte) 1);
+            message.writeBytes(new byte[1]);
+            message.writeBytes(new byte[3], 0, 2);
+            message.writeChar('a');
+            message.writeDouble(1.5);
+            message.writeFloat((float) 1.5);
+            message.writeInt(1);
+            message.writeLong(1);
+            message.writeObject("stringobj");
+            message.writeShort((short) 1);
+            message.writeShort((short) 1);
+            message.writeUTF("utfstring");
+        } catch (MessageNotWriteableException mnwe) {
+            fail("Should be writeable");
+        }
+        try {
+            message.readBoolean();
+            fail("Should have thrown exception");
+        } catch (MessageNotReadableException mnwe) {
+        }
+        try {
+            message.readByte();
+            fail("Should have thrown exception");
+        } catch (MessageNotReadableException e) {
+        }
+        try {
+            message.readUnsignedByte();
+            fail("Should have thrown exception");
+        } catch (MessageNotReadableException e) {
+        }
+        try {
+            message.readBytes(new byte[1]);
+            fail("Should have thrown exception");
+        } catch (MessageNotReadableException e) {
+        }
+        try {
+            message.readBytes(new byte[2], 2);
+            fail("Should have thrown exception");
+        } catch (MessageNotReadableException e) {
+        }
+        try {
+            message.readChar();
+            fail("Should have thrown exception");
+        } catch (MessageNotReadableException e) {
+        }
+        try {
+            message.readDouble();
+            fail("Should have thrown exception");
+        } catch (MessageNotReadableException e) {
+        }
+        try {
+            message.readFloat();
+            fail("Should have thrown exception");
+        } catch (MessageNotReadableException e) {
+        }
+        try {
+            message.readInt();
+            fail("Should have thrown exception");
+        } catch (MessageNotReadableException e) {
+        }
+        try {
+            message.readLong();
+            fail("Should have thrown exception");
+        } catch (MessageNotReadableException e) {
+        }
+        try {
+            message.readUTF();
+            fail("Should have thrown exception");
+        } catch (MessageNotReadableException e) {
+        }
+        try {
+            message.readShort();
+            fail("Should have thrown exception");
+        } catch (MessageNotReadableException e) {
+        }
+        try {
+            message.readUnsignedShort();
+            fail("Should have thrown exception");
+        } catch (MessageNotReadableException e) {
+        }
+        try {
+            message.readUTF();
+            fail("Should have thrown exception");
+        } catch (MessageNotReadableException e) {
+        }
+    }
+}


Mime
View raw message