You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@qpid.apache.org by Colin Crist <co...@messageforge.org> on 2006/09/05 18:36:03 UTC

Bug: BytesMessage.reset() throws MessageNotWriteableException

 
Hi,
 
BytesMessage.reset() can be called on a read only message, its purpose
is to "reset" the message so it can be read again from the start, it
does not affect the message content.
 
2006-09-05 17:25:34,436 [AWT-EventQueue-0] ERROR
hermes.renderers.HexMessageRenderer - exception converting message to
byte[]: 
javax.jms.MessageNotWriteableException: You need to call clearBody() to
make the message writable
 at
org.apache.qpid.client.message.JMSBytesMessage.checkWritable(JMSBytesMes
sage.java:148)
 at
org.apache.qpid.client.message.JMSBytesMessage.reset(JMSBytesMessage.jav
a:342)
 
Regards,
 
Colin
http://hermesjms.com



Re: Bug: BytesMessage.reset() throws MessageNotWriteableException

Posted by Gordon Sim <gs...@redhat.com>.
Colin,

Thanks for pointing that out. Someone will get around to fixing that soon.

--Gordon.

Colin Crist wrote:
>  
> Hi,
>  
> BytesMessage.reset() can be called on a read only message, its purpose
> is to "reset" the message so it can be read again from the start, it
> does not affect the message content.
>  
> 2006-09-05 17:25:34,436 [AWT-EventQueue-0] ERROR
> hermes.renderers.HexMessageRenderer - exception converting message to
> byte[]: 
> javax.jms.MessageNotWriteableException: You need to call clearBody() to
> make the message writable
>  at
> org.apache.qpid.client.message.JMSBytesMessage.checkWritable(JMSBytesMes
> sage.java:148)
>  at
> org.apache.qpid.client.message.JMSBytesMessage.reset(JMSBytesMessage.jav
> a:342)
>  
> Regards,
>  
> Colin
> http://hermesjms.com
> 
> 
> 


RE: [java] Re: Bug: BytesMessage.reset() throws MessageNotWriteableException

Posted by Colin Crist <co...@hermesjms.com>.
Hi,

The suggested fix works with at least some limited testing in HermesJMS. 

Regards,

Colin.
http://hermesjms.com


-----Original Message-----
From: Gordon Sim [mailto:gsim@redhat.com] 
Sent: 11 September 2006 08:43
To: qpid-dev@incubator.apache.org
Subject: [java] Re: Bug: BytesMessage.reset() throws
MessageNotWriteableException

Apologies for slow reply, was out of the office for a couple of days...

Martin Ritchie wrote:
> I'm sure flip() is correct and all that need be done is remove the
> checkWritable() call. It would be good if someone (I guess Robert or
> Gordon) more familiar with this bit of code could OK this change.

I believe the idea behind the current code is that reset() gets called to
make a writable message readable. Whether this is required or not I can't
say for sure, but as pointed out at the start of this thread it should allow
users to invoke it multiple times once the message is readable though.

>    public void reset() throws JMSException
>     {
>         //checkWritable();
>         _data.flip();
>         _readable = true;
>     }

I think we still want to check whether the message is writable, and if it is
call _data.flip(), if it isn't call _data.rewind(). i.e. along the lines of:

if(_readable){
     _data.rewind();
}else{
     _data.flip();
     _readable = true;	
}





[java] Re: Bug: BytesMessage.reset() throws MessageNotWriteableException

Posted by Gordon Sim <gs...@redhat.com>.
Apologies for slow reply, was out of the office for a couple of days...

Martin Ritchie wrote:
> I'm sure flip() is correct and all that need be done is remove the 
> checkWritable() call. It would be good if someone (I guess Robert or 
> Gordon) more familiar with this bit of code could OK this change.

I believe the idea behind the current code is that reset() gets called 
to make a writable message readable. Whether this is required or not I 
can't say for sure, but as pointed out at the start of this thread it 
should allow users to invoke it multiple times once the message is 
readable though.

>    public void reset() throws JMSException
>     {
>         //checkWritable();
>         _data.flip();
>         _readable = true;
>     }

I think we still want to check whether the message is writable, and if 
it is call _data.flip(), if it isn't call _data.rewind(). i.e. along the 
lines of:

if(_readable){
     _data.rewind();
}else{
     _data.flip();
     _readable = true;	
}

Re: Bug: BytesMessage.reset() throws MessageNotWriteableException

Posted by Martin Ritchie <ma...@jpmorgan.com>.
I've had a look at the rest code and I would suggest the checkWritable(); 
is not required. Removing this as below would prevent the exception from 
occurring.

The problem is I don't understand the difference in mina between flip() 
and rewind().

from the mina spec.

flip() makes a buffer ready for a new sequence of channel-write or 
relative get operations: It sets the limit to the current position and 
then sets the position to zero.
rewind() makes a buffer ready for re-reading the data that it already 
contains: It leaves the limit unchanged and sets the position to zero. 

I seems to me that rewind() would be what we want for a JMS reset() [Puts 
the message body in read-only mode and repositions the stream of bytes to 
the beginning. ]

However the BytesMessageTest fails when using rewind() as the size of the 
read bytes is not known. Which suggests that the code uses the limit value 
in the mina buffer to determine the size of the ByteMessage and as it 
isn't set with a rewind() it returns the size of the Mina buffer (1024).

I'm sure flip() is correct and all that need be done is remove the 
checkWritable() call. It would be good if someone (I guess Robert or 
Gordon) more familiar with this bit of code could OK this change.


   public void reset() throws JMSException
    {
        //checkWritable();
        _data.flip();
        _readable = true;
    }

Cheers
-- 

Martin





"Colin Crist" <co...@messageforge.org>
2006-09-05 17:36
Please respond to qpid-dev
 
        To:     <qp...@incubator.apache.org>
        cc: 
        Subject:        Bug: BytesMessage.reset() throws 
MessageNotWriteableException


 
Hi,
 
BytesMessage.reset() can be called on a read only message, its purpose
is to "reset" the message so it can be read again from the start, it
does not affect the message content.
 
2006-09-05 17:25:34,436 [AWT-EventQueue-0] ERROR
hermes.renderers.HexMessageRenderer - exception converting message to
byte[]: 
javax.jms.MessageNotWriteableException: You need to call clearBody() to
make the message writable
 at
org.apache.qpid.client.message.JMSBytesMessage.checkWritable(JMSBytesMes
sage.java:148)
 at
org.apache.qpid.client.message.JMSBytesMessage.reset(JMSBytesMessage.jav
a:342)
 
Regards,
 
Colin
http://hermesjms.com






This communication is for informational purposes only. It is not intended as an offer or solicitation for the purchase or sale of any financial instrument or as an official confirmation of any transaction. All market prices, data and other information are not warranted as to completeness or accuracy and are subject to change without notice. Any comments or statements made herein do not necessarily reflect those of JPMorgan Chase & Co., its subsidiaries and affiliates.

This transmission may contain information that is privileged, confidential, legally privileged, and/or exempt from disclosure under applicable law. If you are not the intended recipient, you are hereby notified that any disclosure, copying, distribution, or use of the information contained herein (including any reliance thereon) is STRICTLY PROHIBITED. Although this transmission and any attachments are believed to be free of any virus or other defect that might affect any computer system into which it is received and opened, it is the responsibility of the recipient to ensure that it is virus free and no responsibility is accepted by JPMorgan Chase & Co., its subsidiaries and affiliates, as applicable, for any loss or damage arising in any way from its use. If you received this transmission in error, please immediately contact the sender and destroy the material in its entirety, whether in electronic or hard copy format. Thank you.