Skip to content

Commit

Permalink
ARTEMIS-2025 Ensure correct calculation of message body size
Browse files Browse the repository at this point in the history
  • Loading branch information
mtaylor authored and clebertsuconic committed Aug 12, 2018
1 parent 3ac7b9a commit d6d73c7
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 2 deletions.
Expand Up @@ -189,7 +189,8 @@ public boolean isCompressed() {

@Override
public int getBodySize() {
return getBodyBuffer().writerIndex() - getBodyBuffer().readerIndex();
checkEncode();
return endOfBodyPosition - BUFFER_HEADER_SPACE;
}

@Override
Expand Down
Expand Up @@ -308,7 +308,7 @@ public void sendBuffer_1X(ByteBuf sendBuffer) {
sendBuffer.readerIndex(0);
}

private synchronized void checkEncode() {
protected synchronized void checkEncode() {
if (!validBuffer) {
encode();
}
Expand Down
Expand Up @@ -16,8 +16,13 @@
*/
package org.apache.activemq.artemis.tests.integration.ra;

import javax.jms.JMSConsumer;
import javax.jms.JMSContext;
import javax.jms.JMSProducer;
import javax.jms.JMSRuntimeException;
import javax.jms.MessageFormatRuntimeException;
import javax.jms.Queue;
import javax.jms.TextMessage;
import javax.transaction.TransactionManager;
import java.util.HashSet;
import java.util.Set;
Expand Down Expand Up @@ -143,4 +148,25 @@ public void clientAckTestNoActiveJTATx() throws Exception {
assertEquals(context.getSessionMode(), JMSContext.AUTO_ACKNOWLEDGE);
}

@Test
public void testJMSContextConsumerThrowsMessageFormatExceptionOnMalformedBody() throws Exception {
Queue queue = createQueue(true, "ContextMalformedBodyTestQueue");

JMSContext context = qraConnectionFactory.createContext();
JMSProducer producer = context.createProducer();

TextMessage message = context.createTextMessage("TestMessage");
producer.send(queue, message);

JMSConsumer consumer = context.createConsumer(queue);

try {
consumer.receiveBody(Boolean.class);
fail("Should thrown MessageFormatException");
} catch (MessageFormatRuntimeException mfre) {
// Do nothing test passed
} catch (Exception e) {
fail("Threw wrong exception, should be MessageFormatRuntimeException, instead got: " + e.getClass().getCanonicalName());
}
}
}

0 comments on commit d6d73c7

Please sign in to comment.