org.apache.qpid.proton.codec.ReadableBuffer Java Examples

The following examples show how to use org.apache.qpid.proton.codec.ReadableBuffer. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: AmqpReadableBuffer.java    From qpid-jms with Apache License 2.0 6 votes vote down vote up
@Override
public ReadableBuffer get(WritableBuffer target) {
    int start = target.position();

    if (buffer.hasArray()) {
        target.put(buffer.array(), buffer.arrayOffset() + buffer.readerIndex(), buffer.readableBytes());
    } else {
        target.put(buffer.nioBuffer());
    }

    int written = target.position() - start;

    buffer.readerIndex(buffer.readerIndex() + written);

    return this;
}
 
Example #2
Source File: AMQPMessageTest.java    From activemq-artemis with Apache License 2.0 6 votes vote down vote up
@Test
public void testGetSendBufferAddsDeliveryCountOnlyToSendMessage() {
   AMQPStandardMessage message = new AMQPStandardMessage(0, encodedProtonMessage, null, null);

   ReadableBuffer buffer = message.getSendBuffer(7);
   assertNotNull(buffer);
   message.reencode(); // Ensures Header is current if accidentally updated

   AMQPStandardMessage copy = new AMQPStandardMessage(0, buffer, null, null);

   MessageImpl originalsProtonMessage = message.getProtonMessage();
   MessageImpl copyProtonMessage = copy.getProtonMessage();
   assertProtonMessageNotEquals(originalsProtonMessage, copyProtonMessage);

   assertNull(originalsProtonMessage.getHeader().getDeliveryCount());
   assertEquals(6, copyProtonMessage.getHeader().getDeliveryCount().intValue());
}
 
Example #3
Source File: NettyReadable.java    From activemq-artemis with Apache License 2.0 6 votes vote down vote up
@Override
public ReadableBuffer get(WritableBuffer target) {
   int start = target.position();

   if (buffer.hasArray()) {
      target.put(buffer.array(), buffer.arrayOffset() + buffer.readerIndex(), buffer.readableBytes());
   } else {
      target.put(buffer.nioBuffer());
   }

   int written = target.position() - start;

   buffer.readerIndex(buffer.readerIndex() + written);

   return this;
}
 
Example #4
Source File: FrameWriterBenchmark.java    From qpid-proton-j with Apache License 2.0 6 votes vote down vote up
public void initProton() {
    byteBuf = ByteBuffer.allocate(DEFAULT_BUFFER_SIZE);
    this.decoder = new DecoderImpl();
    this.encoder = new EncoderImpl(decoder);
    AMQPDefinedTypes.registerAllTypes(decoder, encoder);

    transport = (TransportImpl) Proton.transport();
    frameWriter = new FrameWriter(encoder, 16 * 1024, (byte) 0, transport);

    transfer = new Transfer();
    transfer.setDeliveryId(UnsignedInteger.ONE);
    transfer.setHandle(UnsignedInteger.valueOf(16));
    transfer.setDeliveryTag(new Binary(new byte[] { 0, 1}));
    transfer.setMessageFormat(UnsignedInteger.ZERO);

    payload = ReadableBuffer.ByteBufferReader.wrap(PAYLOAD_BYTES);
}
 
Example #5
Source File: FastPathDeliveryAnnotationsType.java    From qpid-proton-j with Apache License 2.0 6 votes vote down vote up
private static TypeConstructor<?> findNextDecoder(DecoderImpl decoder, ReadableBuffer buffer, TypeConstructor<?> previousConstructor) {
    if (previousConstructor == null) {
        return decoder.readConstructor();
    } else {
        byte encodingCode = buffer.get(buffer.position());
        if (encodingCode == EncodingCodes.DESCRIBED_TYPE_INDICATOR || !(previousConstructor instanceof PrimitiveTypeEncoding<?>)) {
            previousConstructor = decoder.readConstructor();
        } else {
            PrimitiveTypeEncoding<?> primitiveConstructor = (PrimitiveTypeEncoding<?>) previousConstructor;
            if (encodingCode != primitiveConstructor.getEncodingCode()) {
                previousConstructor = decoder.readConstructor();
            } else {
                // consume the encoding code byte for real
                encodingCode = buffer.get();
            }
        }
    }

    if (previousConstructor == null) {
        throw new DecodeException("Unknown constructor found in Map encoding: ");
    }

    return previousConstructor;
}
 
Example #6
Source File: ProtonWritableBufferImplTest.java    From vertx-proton with Apache License 2.0 6 votes vote down vote up
private void doPutReadableBufferTestImpl(boolean readOnly) {
  ByteBuffer buf = ByteBuffer.allocate(1024);
  buf.put((byte) 1);
  buf.flip();
  if (readOnly) {
    buf = buf.asReadOnlyBuffer();
  }

  ReadableBuffer input = new ReadableBuffer.ByteBufferReader(buf);

  if (readOnly) {
    assertFalse("Expected buffer not to hasArray()", input.hasArray());
  } else {
    assertTrue("Expected buffer to hasArray()", input.hasArray());
  }

  ByteBuf buffer = Unpooled.buffer(1024);
  ProtonWritableBufferImpl writable = new ProtonWritableBufferImpl(buffer);

  assertEquals(0, writable.position());
  writable.put(input);
  assertEquals(1, writable.position());
}
 
Example #7
Source File: FastPathApplicationPropertiesType.java    From qpid-proton-j with Apache License 2.0 6 votes vote down vote up
private static TypeConstructor<?> findNextDecoder(DecoderImpl decoder, ReadableBuffer buffer, TypeConstructor<?> previousConstructor) {
    if (previousConstructor == null) {
        return decoder.readConstructor();
    } else {
        byte encodingCode = buffer.get(buffer.position());
        if (encodingCode == EncodingCodes.DESCRIBED_TYPE_INDICATOR || !(previousConstructor instanceof PrimitiveTypeEncoding<?>)) {
            previousConstructor = decoder.readConstructor();
        } else {
            PrimitiveTypeEncoding<?> primitiveConstructor = (PrimitiveTypeEncoding<?>) previousConstructor;
            if (encodingCode != primitiveConstructor.getEncodingCode()) {
                previousConstructor = decoder.readConstructor();
            } else {
                // consume the encoding code byte for real
                encodingCode = buffer.get();
            }
        }
    }

    if (previousConstructor == null) {
        throw new DecodeException("Unknown constructor found in Map encoding: ");
    }

    return previousConstructor;
}
 
Example #8
Source File: FrameWriter.java    From qpid-proton-j with Apache License 2.0 6 votes vote down vote up
void writeFrame(int channel, Object frameBody, ReadableBuffer payload, Runnable onPayloadTooLarge) {
    frameStart = frameBuffer.position();

    final int performativeSize = writePerformative(frameBody, payload, onPayloadTooLarge);
    final int capacity = maxFrameSize > 0 ? maxFrameSize - performativeSize : Integer.MAX_VALUE;
    final int payloadSize = Math.min(payload == null ? 0 : payload.remaining(), capacity);

    if (transport.isFrameTracingEnabled()) {
        logFrame(channel, frameBody, payload, payloadSize);
    }

    if (payloadSize > 0) {
        int oldLimit = payload.limit();
        payload.limit(payload.position() + payloadSize);
        frameBuffer.put(payload);
        payload.limit(oldLimit);
    }

    endFrame(channel);

    framesOutput++;
}
 
Example #9
Source File: ProtonReadableBufferImpl.java    From vertx-proton with Apache License 2.0 6 votes vote down vote up
@Override
public ReadableBuffer get(WritableBuffer target) {
  int start = target.position();

  if (buffer.hasArray()) {
    target.put(buffer.array(), buffer.arrayOffset() + buffer.readerIndex(), buffer.readableBytes());
  } else {
    target.put(buffer.nioBuffer());
  }

  int written = target.position() - start;

  buffer.readerIndex(buffer.readerIndex() + written);

  return this;
}
 
Example #10
Source File: DeliveryImplTest.java    From qpid-proton-j with Apache License 2.0 6 votes vote down vote up
@Test
public void testAfterSendPreservesInteralBufferWhenEmpty() throws Exception
{
    DeliveryImpl delivery = createSenderDelivery();

    byte[] data = new byte[] { 0, 1, 2, 3, 4, 5 };
    ReadableBuffer buffer = ReadableBuffer.ByteBufferReader.wrap(data);

    delivery.send(buffer);

    assertEquals(data.length, delivery.pending());
    assertEquals(data.length, delivery.getData().remaining());

    CompositeReadableBuffer composite = (CompositeReadableBuffer) delivery.getData();

    assertNotSame(data, composite.array());
    assertArrayEquals(data, composite.array());

    delivery.getData().position(delivery.getData().limit());
    delivery.afterSend();

    assertSame(composite, delivery.getData());
}
 
Example #11
Source File: DeliveryImpl.java    From qpid-proton-j with Apache License 2.0 6 votes vote down vote up
private byte[] copyContents(ReadableBuffer buffer)
{
    byte[] copy = new byte[buffer.remaining()];

    if (buffer.hasArray())
    {
        System.arraycopy(buffer.array(), buffer.arrayOffset() + buffer.position(), copy, 0, buffer.remaining());
        buffer.position(buffer.limit());
    }
    else
    {
        buffer.get(copy, 0, buffer.remaining());
    }

    return copy;
}
 
Example #12
Source File: DeliveryImplTest.java    From qpid-proton-j with Apache License 2.0 6 votes vote down vote up
@Test
public void testRecvAllAsReadableBuffer() throws Exception
{
    DeliveryImpl delivery = new DeliveryImpl(null, Mockito.mock(LinkImpl.class), null);

    byte[] data1 = new byte[] { 0, 1, 2, 3, 4, 5 };
    byte[] data2 = new byte[] { 6, 7, 8, 9, 10, 11 };

    int legnth = data1.length + data2.length;

    Binary binary1 = new Binary(data1);
    Binary binary2 = new Binary(data2);

    delivery.append(binary1);
    delivery.append(binary2);

    ReadableBuffer payload = delivery.recv();
    assertTrue(payload instanceof CompositeReadableBuffer);
    CompositeReadableBuffer composite = (CompositeReadableBuffer) payload;
    assertEquals(2, composite.getArrays().size());

    assertNotNull(payload);
    assertEquals(legnth, payload.remaining());
    assertEquals(0, payload.get(0));
    assertEquals(11, payload.get(11));
}
 
Example #13
Source File: AmqpMessageSupport.java    From qpid-jms with Apache License 2.0 6 votes vote down vote up
/**
 * Given a Message instance, encode the Message to the wire level representation
 * of that Message.
 *
 * @param message
 *      the Message that is to be encoded into the wire level representation.
 *
 * @return a buffer containing the wire level representation of the input Message.
 */
public static ReadableBuffer encodeMessage(Message message) {
    final int BUFFER_SIZE = 4096;
    byte[] encodedMessage = new byte[BUFFER_SIZE];
    int encodedSize = 0;
    while (true) {
        try {
            encodedSize = message.encode(encodedMessage, 0, encodedMessage.length);
            break;
        } catch (java.nio.BufferOverflowException e) {
            encodedMessage = new byte[encodedMessage.length * 2];
        }
    }

    return ReadableBuffer.ByteBufferReader.wrap(ByteBuffer.wrap(encodedMessage, 0, encodedSize));
}
 
Example #14
Source File: DeliveryImplTest.java    From qpid-proton-j with Apache License 2.0 6 votes vote down vote up
@Test
public void testSendSingleReadableBuffer() throws Exception
{
    DeliveryImpl delivery = createSenderDelivery();

    byte[] data = new byte[] { 0, 1, 2, 3, 4, 5 };
    ReadableBuffer buffer = ReadableBuffer.ByteBufferReader.wrap(data);

    delivery.send(buffer);

    assertEquals(data.length, delivery.pending());
    assertEquals(data.length, delivery.getData().remaining());

    CompositeReadableBuffer composite = (CompositeReadableBuffer) delivery.getData();

    assertNotSame(data, composite.array());
    assertArrayEquals(data, composite.array());
}
 
Example #15
Source File: ReceiverImpl.java    From qpid-proton-j with Apache License 2.0 6 votes vote down vote up
@Override
public ReadableBuffer recv()
{
    if (_current == null) {
        throw new IllegalStateException("no current delivery");
    }

    ReadableBuffer consumed = _current.recv();
    if (consumed.remaining() > 0) {
        getSession().incrementIncomingBytes(-consumed.remaining());
        if (getSession().getTransportSession().getIncomingWindowSize().equals(UnsignedInteger.ZERO)) {
            modified();
        }
    }
    return consumed;
}
 
Example #16
Source File: AMQPMessageTest.java    From activemq-artemis with Apache License 2.0 6 votes vote down vote up
@Test
public void testGetSendBufferRemoveDeliveryAnnotations() {
   MessageImpl protonMessage = createProtonMessage();
   DeliveryAnnotations deliveryAnnotations = new DeliveryAnnotations(new HashMap<>());
   deliveryAnnotations.getValue().put(Symbol.valueOf("testGetSendBufferRemoveDeliveryAnnotations"), "X");
   protonMessage.setDeliveryAnnotations(deliveryAnnotations);
   AMQPStandardMessage message = new AMQPStandardMessage(0, encodeMessage(protonMessage), null, null);

   ReadableBuffer buffer = message.getSendBuffer(1);
   assertNotNull(buffer);

   AMQPStandardMessage copy = new AMQPStandardMessage(0, buffer, null, null);

   MessageImpl copyProtonMessage = copy.getProtonMessage();
   assertProtonMessageNotEquals(message.getProtonMessage(), copyProtonMessage);
   assertNull(copyProtonMessage.getDeliveryAnnotations());
}
 
Example #17
Source File: SenderImpl.java    From qpid-proton-j with Apache License 2.0 6 votes vote down vote up
@Override
public int sendNoCopy(final ReadableBuffer buffer)
{
    if (getLocalState() == EndpointState.CLOSED)
    {
        throw new IllegalStateException("send not allowed after the sender is closed.");
    }
    DeliveryImpl current = current();
    if (current == null || current.getLink() != this)
    {
        throw new IllegalArgumentException();
    }
    int sent = current.sendNoCopy(buffer);
    if (sent > 0) {
        getSession().incrementOutgoingBytes(sent);
    }
    return sent;
}
 
Example #18
Source File: AmqpWritableBufferTest.java    From qpid-jms with Apache License 2.0 6 votes vote down vote up
private void doPutReadableBufferTestImpl(boolean readOnly) {
    ByteBuffer buf = ByteBuffer.allocate(1024);
    buf.put((byte) 1);
    buf.flip();
    if(readOnly) {
        buf = buf.asReadOnlyBuffer();
    }

    ReadableBuffer input = new ReadableBuffer.ByteBufferReader(buf);

    if(readOnly) {
        assertFalse("Expected buffer not to hasArray()", input.hasArray());
    } else {
        assertTrue("Expected buffer to hasArray()", input.hasArray());
    }

    ByteBuf buffer = Unpooled.buffer(1024);
    AmqpWritableBuffer writable = new AmqpWritableBuffer(buffer);

    assertEquals(0, writable.position());
    writable.put(input);
    assertEquals(1, writable.position());
}
 
Example #19
Source File: DeliveryImpl.java    From qpid-proton-j with Apache License 2.0 6 votes vote down vote up
int sendNoCopy(ReadableBuffer buffer)
{
    int length = buffer.remaining();

    if (_dataView == null || !_dataView.hasRemaining())
    {
        _dataView = buffer;
    }
    else
    {
        consolidateSendBuffers(buffer);
    }

    addToTransportWorkList();
    return length;
}
 
Example #20
Source File: FrameWriterBufferTest.java    From qpid-proton-j with Apache License 2.0 5 votes vote down vote up
@Test
public void testPutReadableBuffer() {
    FrameWriterBuffer buffer = new FrameWriterBuffer(10);

    byte[] data = new byte[] { 127, (byte) 128 };
    ReadableBuffer readable = ReadableBuffer.ByteBufferReader.wrap(data);

    assertEquals(0, buffer.position());
    buffer.put(readable.duplicate());
    assertEquals(2, buffer.position());
    buffer.put(readable.duplicate());
    assertEquals(4, buffer.position());

    assertEquals(Integer.MAX_VALUE - 4, buffer.remaining());
}
 
Example #21
Source File: NettyReadableTest.java    From activemq-artemis with Apache License 2.0 5 votes vote down vote up
@Test
public void testDuplicate() {
   byte[] data = new byte[] {0, 1, 2, 3, 4};
   ByteBuf byteBuffer = Unpooled.wrappedBuffer(data);
   NettyReadable buffer = new NettyReadable(byteBuffer);

   ReadableBuffer duplicate = buffer.duplicate();

   for (int i = 0; i < data.length; i++) {
      assertEquals(data[i], duplicate.get());
   }

   assertFalse(duplicate.hasRemaining());
}
 
Example #22
Source File: DeliveryImplTest.java    From qpid-proton-j with Apache License 2.0 5 votes vote down vote up
@Test
public void testAfterSendOnEmptyDelivery() throws Exception
{
    DeliveryImpl delivery = createSenderDelivery();

    ReadableBuffer sendBuffer = delivery.getData();

    delivery.afterSend();

    assertSame(sendBuffer, delivery.getData());
}
 
Example #23
Source File: AMQPStandardMessage.java    From activemq-artemis with Apache License 2.0 5 votes vote down vote up
@Override
public org.apache.activemq.artemis.api.core.Message copy() {
   ensureDataIsValid();

   ReadableBuffer view = data.duplicate().rewind();
   byte[] newData = new byte[view.remaining()];

   // Copy the full message contents with delivery annotations as they will
   // be trimmed on send and may become useful on the broker at a later time.
   view.get(newData);

   AMQPStandardMessage newEncode = new AMQPStandardMessage(this.messageFormat, newData, extraProperties, coreMessageObjectPools);
   newEncode.setMessageID(this.getMessageID());
   return newEncode;
}
 
Example #24
Source File: ProtonReceiverImpl.java    From vertx-proton with Apache License 2.0 5 votes vote down vote up
private void handlePartial(final Receiver receiver, final Delivery delivery) {
  if (sessionIncomingCapacity <= 0 || maxFrameSize <= 0 || session.getIncomingBytes() < windowFullThreshhold) {
    // No window, or there is still capacity, so do nothing.
  } else {
    // The session window could be effectively full, we need to
    // read part of the delivery content to ensure there is
    // room made for receiving more of the delivery.
    if(delivery.available() > 0) {
      ReadableBuffer buff = receiver.recv();

      if(splitContent == null && buff instanceof CompositeReadableBuffer) {
        // Its a composite and there is no prior partial content, use it.
        splitContent = (CompositeReadableBuffer) buff;
      } else {
        int remaining = buff.remaining();
        if(remaining > 0) {
          if (splitContent == null) {
            splitContent = new CompositeReadableBuffer();
          }

          byte[] chunk = new byte[remaining];
          buff.get(chunk);

          splitContent.append(chunk);
        }
      }
    }
  }
}
 
Example #25
Source File: AMQPLargeMessage.java    From activemq-artemis with Apache License 2.0 5 votes vote down vote up
@Override
public ReadableBuffer getData() {
   if (parsingData == null) {
      throw new RuntimeException("AMQP Large Message is not open");
   }

   return parsingData;
}
 
Example #26
Source File: AMQPMessageSymbolSearch.java    From activemq-artemis with Apache License 2.0 5 votes vote down vote up
private static boolean lookupOnSection(IdentityHashMap<Class<?>, Boolean> stopSet, final Class section, final ReadableBuffer data, final KMPNeedle[] needles, final int startAt) {
   DecoderImpl decoder = TLSEncode.getDecoder();
   final int position = data.position();
   decoder.setBuffer(data.position(startAt));
   try {
      while (data.hasRemaining()) {
         TypeConstructor<?> constructor = decoder.readConstructor();
         final Class<?> typeClass = constructor.getTypeClass();
         if (MSG_ANNOTATIONS_STOPSET.containsKey(typeClass)) {
            if (section.equals(typeClass)) {
               final int start = data.position();
               constructor.skipValue();
               final int end = data.position();
               for (int i = 0, count = needles.length; i < count; i++) {
                  final int foundIndex = needles[i].searchInto(data, start, end);
                  if (foundIndex != -1) {
                     return true;
                  }
               }
            }
            return false;
         }
         constructor.skipValue();
      }
      return false;
   } finally {
      decoder.setBuffer(null);
      data.position(position);
   }
}
 
Example #27
Source File: AMQPMessage.java    From activemq-artemis with Apache License 2.0 5 votes vote down vote up
protected ReadableBuffer createCopyWithNewDeliveryCount(int deliveryCount) {
   assert deliveryCount > 1;

   final int amqpDeliveryCount = deliveryCount - 1;

   final ByteBuf result = PooledByteBufAllocator.DEFAULT.heapBuffer(getEncodeSize());

   // If this is re-delivering the message then the header must be re-encoded
   // otherwise we want to write the original header if present.  When a
   // Header is present we need to copy it as we are updating the re-delivered
   // message and not the stored version which we don't want to invalidate here.
   Header header = this.header;
   if (header == null) {
      header = new Header();
   } else {
      header = new Header(header);
   }

   header.setDeliveryCount(UnsignedInteger.valueOf(amqpDeliveryCount));
   TLSEncode.getEncoder().setByteBuffer(new NettyWritable(result));
   TLSEncode.getEncoder().writeObject(header);
   TLSEncode.getEncoder().setByteBuffer((WritableBuffer) null);

   writeDeliveryAnnotationsForSendBuffer(result);
   // skip existing delivery annotations of the original message
   getData().position(encodedHeaderSize + encodedDeliveryAnnotationsSize);
   result.writeBytes(getData().byteBuffer());
   getData().position(0);

   return new NettyReadable(result);
}
 
Example #28
Source File: AMQPMessageTest.java    From activemq-artemis with Apache License 2.0 5 votes vote down vote up
@Test
public void testPartialDecodeIgnoresDeliveryAnnotationsByDefault() {
   Header header = new Header();
   header.setDurable(true);
   header.setPriority(UnsignedByte.valueOf((byte) 6));

   ByteBuf encodedBytes = Unpooled.buffer(1024);
   NettyWritable writable = new NettyWritable(encodedBytes);

   EncoderImpl encoder = TLSEncode.getEncoder();
   encoder.setByteBuffer(writable);
   encoder.writeObject(header);

   // Signal body of AmqpValue but write corrupt underlying type info
   encodedBytes.writeByte(EncodingCodes.DESCRIBED_TYPE_INDICATOR);
   encodedBytes.writeByte(EncodingCodes.SMALLULONG);
   encodedBytes.writeByte(DELIVERY_ANNOTATIONS_DESCRIPTOR.byteValue());
   encodedBytes.writeByte(EncodingCodes.MAP8);
   encodedBytes.writeByte(2);  // Size
   encodedBytes.writeByte(2);  // Elements
   // Use bad encoding code on underlying type of map key which will fail the decode if run
   encodedBytes.writeByte(255);

   ReadableBuffer readable = new NettyReadable(encodedBytes);

   AMQPStandardMessage message = null;
   try {
      message = new AMQPStandardMessage(0, readable, null, null);
   } catch (Exception decodeError) {
      fail("Should not have encountered an exception on partial decode: " + decodeError.getMessage());
   }

   try {
      // This should perform the lazy decode of the DeliveryAnnotations portion of the message
      message.getDeliveryAnnotations();
      fail("Should have thrown an error when attempting to decode the ApplicationProperties which are malformed.");
   } catch (Exception ex) {
      // Expected decode to fail when building full message.
   }
}
 
Example #29
Source File: AMQPMessageTest.java    From activemq-artemis with Apache License 2.0 5 votes vote down vote up
@Test
public void testPartialDecodeIgnoresBodyByDefault() {
   Header header = new Header();
   header.setDurable(true);
   header.setPriority(UnsignedByte.valueOf((byte) 6));

   ByteBuf encodedBytes = Unpooled.buffer(1024);
   NettyWritable writable = new NettyWritable(encodedBytes);

   EncoderImpl encoder = TLSEncode.getEncoder();
   encoder.setByteBuffer(writable);
   encoder.writeObject(header);

   // Signal body of AmqpValue but write corrupt underlying type info
   encodedBytes.writeByte(EncodingCodes.DESCRIBED_TYPE_INDICATOR);
   encodedBytes.writeByte(EncodingCodes.SMALLULONG);
   encodedBytes.writeByte(AMQPVALUE_DESCRIPTOR.byteValue());
   // Use bad encoding code on underlying type
   encodedBytes.writeByte(255);

   ReadableBuffer readable = new NettyReadable(encodedBytes);

   AMQPStandardMessage message = null;
   try {
      message = new AMQPStandardMessage(0, readable, null, null);
   } catch (Exception decodeError) {
      fail("Should not have encountered an exception on partial decode: " + decodeError.getMessage());
   }

   assertTrue(message.isDurable());

   try {
      // This will decode the body section if present in order to present it as a Proton Message object
      message.getBody();
      fail("Should have thrown an error when attempting to decode the body which is malformed.");
   } catch (Exception ex) {
      // Expected decode to fail when building full message.
   }
}
 
Example #30
Source File: AmqpCodec.java    From qpid-jms with Apache License 2.0 5 votes vote down vote up
private static ReadableBuffer getCachedMessageAnnotationsBuffer(AmqpJmsMessageFacade message, EncoderDecoderContext context) {
    byte msgType = message.getJmsMsgType();
    byte toType = AmqpDestinationHelper.toTypeAnnotation(message.getDestination());
    byte replyToType = AmqpDestinationHelper.toTypeAnnotation(message.getReplyTo());

    Integer entryKey = Integer.valueOf((replyToType << 16) | (toType << 8) | msgType);

    ReadableBuffer result = context.messageAnnotationsCache.get(entryKey);
    if (result == null) {
        result = populateMessageAnnotationsCacheEntry(message, entryKey, context);
    }

    return result.rewind();
}