Return-Path: X-Original-To: apmail-activemq-dev-archive@www.apache.org Delivered-To: apmail-activemq-dev-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 04FE210715 for ; Thu, 5 Dec 2013 16:20:41 +0000 (UTC) Received: (qmail 15521 invoked by uid 500); 5 Dec 2013 16:20:37 -0000 Delivered-To: apmail-activemq-dev-archive@activemq.apache.org Received: (qmail 15344 invoked by uid 500); 5 Dec 2013 16:20:36 -0000 Mailing-List: contact dev-help@activemq.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@activemq.apache.org Delivered-To: mailing list dev@activemq.apache.org Received: (qmail 15305 invoked by uid 99); 5 Dec 2013 16:20:36 -0000 Received: from arcas.apache.org (HELO arcas.apache.org) (140.211.11.28) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 05 Dec 2013 16:20:36 +0000 Date: Thu, 5 Dec 2013 16:20:36 +0000 (UTC) From: "Timothy Bish (JIRA)" To: dev@activemq.apache.org Message-ID: In-Reply-To: References: Subject: [jira] [Commented] (AMQ-4887) ActiveMQBytesMessage will lost content if message's property was set before copy MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit X-JIRA-FingerPrint: 30527f35849b9dde25b450d4833f0394 [ https://issues.apache.org/jira/browse/AMQ-4887?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13840219#comment-13840219 ] Timothy Bish commented on AMQ-4887: ----------------------------------- I'm also going to guess that the StreamMessage implementation suffers from the same problem and the test should be expanded to check that message too, as well as the compressed case. > ActiveMQBytesMessage will lost content if message's property was set before copy > --------------------------------------------------------------------------------- > > Key: AMQ-4887 > URL: https://issues.apache.org/jira/browse/AMQ-4887 > Project: ActiveMQ > Issue Type: Bug > Components: Broker > Affects Versions: 5.9.0 > Reporter: caoyunfei > Assignee: Timothy Bish > Attachments: AMQ-4887.patch, ActiveMQBytesMessage.java.patch, ActiveMQBytesMessageTest.java, Consumer.java, Producer.java > > Original Estimate: 24h > Remaining Estimate: 24h > > ActiveMQBytesMessage will lost content if message's property was set before copy. Here is the test code: > Producer: > MessageProducer producer; > //initialize Connection, Session, MessageProducer > byte[] bs = "bytes message".getBytes(); > BytesMessage message = session.createBytesMessage(); > message.writeBytes(bs); //write bytes to message 1 > > for(int i=0; i< 0; i++){ > // then set message's propery 2 > message.setLongProperty("sendTime", System.currentTimeMillis()); > try{ > producer.send(message); > }catch(){ > e.printStackTrace(); > } > } > Consumer: > MessageConsumer consumer > //initailize Connection, Session, MessageConsumer > for(int i=0; i<10; i++){ > ActiveMQBytesMessage msg = (ActiveMQBytesMessage)consumer.receive(60*1000); > long sendTime = message.getLongProperty("sendTime"); > System.out.println("sendtime:" + sendTime); > ByteSequence bs = message.getMessage().getContent(); > System.out.println("bytes data:" + new String(bs.getData())); > } > Expected result: > consumer gets bytes data in all received messages > Actual result: > only the fisrt message has bytes data, all other messages lost bytes data, while long property value is not lost; > Analysization: > message gets copied when send, it will call storeContent() before copy, DataOutputStream dataOut will be closed and the data in dataOut will be set to conent. This works correctly if there are no property was set. > when setLongProperty was called, it will call setObjectProperty() then will call initializeWriting(), here DataOutputStream dataOut will be create AGAIN. > So when message was copied in second time, DataOutputStream dataOut is NOT null, but EMPTY, it will clear the value in content. > suggestion: > restore the content data to DataOutputStream dataOut when nitializeWriting() > my fix: > ActiveMQBytesMessage : > private void initializeWriting() throws JMSException { > 669 The original code > ...... > 701 > //fix code > if(this.content !=null && this.content.length >0){ > try{ > this.dataOut.write(this.content.getData()); > }catch(IOException ioe){ > throw JMSExceptionSupport.create(ioe); > } > } > 702 } -- This message was sent by Atlassian JIRA (v6.1#6144)