org.apache.qpid.proton.amqp.messaging.AmqpSequence Java Examples

The following examples show how to use org.apache.qpid.proton.amqp.messaging.AmqpSequence. 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: AmqpSourceTest.java    From smallrye-reactive-messaging with Apache License 2.0 6 votes vote down vote up
@Test
public void testSourceWithSeqContent() {
    String topic = UUID.randomUUID().toString();
    Map<String, Object> config = getConfig(topic);
    List<Message<List<String>>> messages = new ArrayList<>();
    provider = new AmqpConnector();
    provider.setup(executionHolder);

    PublisherBuilder<? extends Message<?>> builder = provider.getPublisherBuilder(new MapBasedConfig(config));
    AtomicBoolean opened = new AtomicBoolean();

    builder.to(createSubscriber(messages, opened)).run();
    await().until(opened::get);

    await().until(() -> provider.isReady(config.get(CHANNEL_NAME_ATTRIBUTE).toString()));

    List<String> list = new ArrayList<>();
    list.add("tag");
    list.add("bonjour");
    usage.produce(topic, 1, () -> new AmqpSequence(list));

    await().atMost(2, TimeUnit.MINUTES).until(() -> !messages.isEmpty());
    List<String> result = messages.get(0).getPayload();
    assertThat(result)
            .containsOnly("tag", "bonjour");
}
 
Example #2
Source File: AmqpJmsStreamMessageFacadeTest.java    From qpid-jms with Apache License 2.0 6 votes vote down vote up
@Test
public void testPopFullyReadListThrowsMEOFE() throws Exception {
    Message message = Message.Factory.create();
    List<Object> list = new ArrayList<Object>();
    list.add(Boolean.FALSE);
    message.setBody(new AmqpSequence(list));

    AmqpJmsStreamMessageFacade amqpStreamMessageFacade = createReceivedStreamMessageFacade(createMockAmqpConsumer(), message);

    assertEquals("Unexpected value retrieved", Boolean.FALSE, amqpStreamMessageFacade.peek());
    amqpStreamMessageFacade.pop();

    try {
        amqpStreamMessageFacade.pop();
        fail("expected exception to be thrown");
    } catch (MessageEOFException meofe) {
        // expected
    }
}
 
Example #3
Source File: AmqpJmsStreamMessageFacadeTest.java    From qpid-jms with Apache License 2.0 6 votes vote down vote up
@Test
public void testResetPositionAfterPop() throws Exception {
    Message message = Message.Factory.create();
    List<Object> list = new ArrayList<Object>();
    list.add(Boolean.FALSE);
    list.add(Boolean.TRUE);
    message.setBody(new AmqpSequence(list));

    AmqpJmsStreamMessageFacade amqpStreamMessageFacade = createReceivedStreamMessageFacade(createMockAmqpConsumer(), message);

    assertEquals("Unexpected value retrieved", Boolean.FALSE, amqpStreamMessageFacade.peek());
    amqpStreamMessageFacade.pop();

    amqpStreamMessageFacade.reset();

    assertEquals("Unexpected value retrieved", Boolean.FALSE, amqpStreamMessageFacade.peek());
    amqpStreamMessageFacade.pop();

    assertEquals("Unexpected value retrieved", Boolean.TRUE, amqpStreamMessageFacade.peek());
    amqpStreamMessageFacade.pop();
}
 
Example #4
Source File: AmqpCodecTest.java    From qpid-jms with Apache License 2.0 6 votes vote down vote up
/**
 * Test that an amqp-sequence body containing a binary value results in an ObjectMessage
 * when not otherwise annotated to indicate the type of JMS message it is.
 *
 * @throws Exception if an error occurs during the test.
 */
@Test
public void testCreateObjectMessageMessageFromAmqpSequence() throws Exception {
    Message message = Proton.message();
    List<String> list = new ArrayList<String>();
    message.setBody(new AmqpSequence(list));

    JmsMessage jmsMessage = AmqpCodec.decodeMessage(mockConsumer, encodeMessage(message)).asJmsMessage();
    assertNotNull("Message should not be null", jmsMessage);
    assertEquals("Unexpected message class type", JmsObjectMessage.class, jmsMessage.getClass());

    JmsMessageFacade facade = jmsMessage.getFacade();
    assertNotNull("Facade should not be null", facade);
    assertEquals("Unexpected facade class type", AmqpJmsObjectMessageFacade.class, facade.getClass());

    AmqpObjectTypeDelegate delegate = ((AmqpJmsObjectMessageFacade) facade).getDelegate();
    assertTrue("Unexpected delegate type: " + delegate, delegate instanceof AmqpTypedObjectDelegate);
}
 
Example #5
Source File: JMSMappingOutboundTransformerTest.java    From activemq-artemis with Apache License 2.0 6 votes vote down vote up
@Test
public void testConvertStreamMessageToAmqpMessageWithAmqpSequencey() throws Exception {
   ServerJMSStreamMessage outbound = createStreamMessage();
   outbound.setShortProperty(JMS_AMQP_ORIGINAL_ENCODING, AMQP_SEQUENCE);
   outbound.writeBoolean(false);
   outbound.writeString("test");
   outbound.encode();

   AMQPMessage amqp = AMQPConverter.getInstance().fromCore(outbound.getInnerMessage(), null);

   assertNotNull(amqp.getBody());
   assertTrue(amqp.getBody() instanceof AmqpSequence);
   assertTrue(((AmqpSequence) amqp.getBody()).getValue() instanceof List);

   @SuppressWarnings("unchecked")
   List<Object> amqpList = ((AmqpSequence) amqp.getBody()).getValue();

   assertEquals(2, amqpList.size());
}
 
Example #6
Source File: TestConversions.java    From activemq-artemis with Apache License 2.0 6 votes vote down vote up
@Test
public void testSimpleConversionStream() throws Exception {
   Map<String, Object> mapprop = createPropertiesMap();
   ApplicationProperties properties = new ApplicationProperties(mapprop);
   MessageImpl message = (MessageImpl) Message.Factory.create();
   message.setApplicationProperties(properties);

   List<Object> objects = new LinkedList<>();
   objects.add(new Integer(10));
   objects.add("10");

   message.setBody(new AmqpSequence(objects));

   AMQPMessage encodedMessage = encodeAndCreateAMQPMessage(message);

   ICoreMessage serverMessage = encodedMessage.toCore();

   ServerJMSStreamMessage streamMessage = (ServerJMSStreamMessage) ServerJMSMessage.wrapCoreMessage(serverMessage);

   verifyProperties(streamMessage);

   streamMessage.reset();

   assertEquals(10, streamMessage.readInt());
   assertEquals("10", streamMessage.readString());
}
 
Example #7
Source File: AmqpJmsStreamMessageFacadeTest.java    From qpid-jms with Apache License 2.0 5 votes vote down vote up
@Test
public void testCreateWithEmptyAmqpSequenceBodySection() throws Exception
{
    Message message = Message.Factory.create();
    message.setBody(new AmqpSequence(null));

    AmqpJmsStreamMessageFacade amqpStreamMessageFacade = createReceivedStreamMessageFacade(createMockAmqpConsumer(), message);

    //Should be able to use the message, e.g clearing it and adding to it.
    amqpStreamMessageFacade.clearBody();
    amqpStreamMessageFacade.put("myString");
}
 
Example #8
Source File: AmqpJmsStreamMessageFacadeTest.java    From qpid-jms with Apache License 2.0 5 votes vote down vote up
@Test
public void testResetPositionAfterPeekThrowsMEOFE() throws Exception {
    Message message = Message.Factory.create();
    List<Object> list = new ArrayList<Object>();
    list.add(Boolean.FALSE);
    list.add(Boolean.TRUE);
    message.setBody(new AmqpSequence(list));

    AmqpJmsStreamMessageFacade amqpStreamMessageFacade = createReceivedStreamMessageFacade(createMockAmqpConsumer(), message);

    assertEquals("Unexpected value retrieved", Boolean.FALSE, amqpStreamMessageFacade.peek());
    amqpStreamMessageFacade.pop();
    assertEquals("Unexpected value retrieved", Boolean.TRUE, amqpStreamMessageFacade.peek());
    amqpStreamMessageFacade.pop();

    try {
        amqpStreamMessageFacade.peek();
        fail("expected exception to be thrown");
    } catch (MessageEOFException meofe) {
        // expected
    }

    amqpStreamMessageFacade.reset();

    assertEquals("Unexpected value retrieved", Boolean.FALSE, amqpStreamMessageFacade.peek());
    amqpStreamMessageFacade.pop();
    assertEquals("Unexpected value retrieved", Boolean.TRUE, amqpStreamMessageFacade.peek());
}
 
Example #9
Source File: AmqpJmsStreamMessageFacadeTest.java    From qpid-jms with Apache License 2.0 5 votes vote down vote up
@Test
public void testRepeatedPeekAfterPopReturnsExpectedValue() throws Exception {
    Message message = Message.Factory.create();
    List<Object> list = new ArrayList<Object>();
    list.add(Boolean.FALSE);
    list.add(Boolean.TRUE);
    message.setBody(new AmqpSequence(list));

    AmqpJmsStreamMessageFacade amqpStreamMessageFacade = createReceivedStreamMessageFacade(createMockAmqpConsumer(), message);

    assertEquals("Unexpected value retrieved", Boolean.FALSE, amqpStreamMessageFacade.peek());
    amqpStreamMessageFacade.pop();
    assertEquals("Unexpected value retrieved", Boolean.TRUE, amqpStreamMessageFacade.peek());
}
 
Example #10
Source File: AmqpJmsStreamMessageFacadeTest.java    From qpid-jms with Apache License 2.0 5 votes vote down vote up
@Test
public void testRepeatedPeekReturnsExpectedValue() throws Exception {
    Message message = Message.Factory.create();
    List<Object> list = new ArrayList<Object>();
    list.add(Boolean.FALSE);
    list.add(Boolean.TRUE);
    message.setBody(new AmqpSequence(list));

    AmqpJmsStreamMessageFacade amqpStreamMessageFacade = createReceivedStreamMessageFacade(createMockAmqpConsumer(), message);

    assertTrue("Message should report that it contains a body", amqpStreamMessageFacade.hasBody());
    assertEquals("Unexpected value retrieved", Boolean.FALSE, amqpStreamMessageFacade.peek());
    assertEquals("Unexpected value retrieved", Boolean.FALSE, amqpStreamMessageFacade.peek());
}
 
Example #11
Source File: AmqpJmsStreamMessageFacadeTest.java    From qpid-jms with Apache License 2.0 5 votes vote down vote up
@Test
public void testPeekUsingReceivedMessageWithAmqpSequenceBodyReturnsExpectedValue() throws Exception {
    Message message = Message.Factory.create();
    List<Object> list = new ArrayList<Object>();
    list.add(Boolean.FALSE);
    message.setBody(new AmqpSequence(list));

    AmqpJmsStreamMessageFacade amqpStreamMessageFacade = createReceivedStreamMessageFacade(createMockAmqpConsumer(), message);

    assertEquals("Unexpected value retrieved", Boolean.FALSE, amqpStreamMessageFacade.peek());
}
 
Example #12
Source File: AmqpJmsStreamMessageFacadeTest.java    From qpid-jms with Apache License 2.0 5 votes vote down vote up
@Test
public void testNewMessageToSendContainsAmqpSequenceBody() throws Exception {
    AmqpJmsStreamMessageFacade amqpStreamMessageFacade = createNewStreamMessageFacade();

    Section body = amqpStreamMessageFacade.getBody();

    assertNotNull("Body section was not present", body);
    assertTrue("Body section was not of expected type: " + body.getClass(), body instanceof AmqpSequence);
}
 
Example #13
Source File: AmqpJmsMapMessageFacadeTest.java    From qpid-jms with Apache License 2.0 5 votes vote down vote up
@Test
public void testCreateWithAmqpSequenceBodySectionThrowsISE() throws Exception {
    Message message = Message.Factory.create();
    message.setBody(new AmqpSequence(null)   );

    try {
        createReceivedMapMessageFacade(createMockAmqpConsumer(), message);
        fail("expected exception to be thrown");
    } catch (IllegalStateException ise) {
        // expected
    }
}
 
Example #14
Source File: AmqpJmsTextMessageFacadeTest.java    From qpid-jms with Apache License 2.0 5 votes vote down vote up
@Test
public void testGetTextWithNonAmqpValueOrDataSectionThrowsISE() throws Exception {
    Message message = Message.Factory.create();
    message.setBody(new AmqpSequence(new ArrayList<Object>()));
    AmqpJmsTextMessageFacade amqpTextMessageFacade = createReceivedTextMessageFacade(createMockAmqpConsumer(), message);

    try {
        amqpTextMessageFacade.getText();
        fail("expected exception not thrown");
    } catch (IllegalStateException ise) {
        // expected
    }
}
 
Example #15
Source File: AmqpJmsTextMessageFacadeTest.java    From qpid-jms with Apache License 2.0 5 votes vote down vote up
@Test
public void testGetTextWithNonAmqpValueOrDataSectionReportsNoBody() throws Exception {
    Message message = Message.Factory.create();
    message.setBody(new AmqpSequence(new ArrayList<Object>()));
    AmqpJmsTextMessageFacade amqpTextMessageFacade = createReceivedTextMessageFacade(createMockAmqpConsumer(), message);
    assertFalse(amqpTextMessageFacade.hasBody());
}
 
Example #16
Source File: AmqpJmsStreamMessageFacade.java    From qpid-jms with Apache License 2.0 5 votes vote down vote up
private List<Object> initializeEmptyBodyList(boolean useSequenceBody) {
    List<Object> emptyList = new ArrayList<Object>();

    if (useSequenceBody) {
        setBody(new AmqpSequence(emptyList));
    } else {
        setBody(new AmqpValue(emptyList));
    }

    return emptyList;
}
 
Example #17
Source File: AmqpTypedObjectDelegate.java    From qpid-jms with Apache License 2.0 5 votes vote down vote up
@Override
public Serializable getObject() throws IOException, ClassNotFoundException {
    Section body = null;

    if (encodedBody != null) {
        body = AmqpCodec.decode(encodedBody);
    }

    if (body == null) {
        return null;
    } else if (body instanceof AmqpValue) {
        // TODO: This is assuming the object can be immediately returned, and is
        //       deeply Serializable. We will actually have to ensure elements are
        //       Serializable and e.g convert the Uint/Ubyte etc wrappers.
        return (Serializable) ((AmqpValue) body).getValue();
    } else if (body instanceof Data) {
        // TODO: return as byte[]? ByteBuffer?
        throw new UnsupportedOperationException("Data support still to be added");
    } else if (body instanceof AmqpSequence) {
        // TODO: This is assuming the object can be immediately returned, and is
        //       deeply Serializable. We will actually have to ensure elements are
        //       Serializable and e.g convert the Uint/Ubyte etc wrappers.
        return (Serializable) ((AmqpSequence) body).getValue();
    } else {
        throw new IllegalStateException("Unexpected body type: " + body.getClass().getSimpleName());
    }
}
 
Example #18
Source File: JMSMappingInboundTransformerTest.java    From activemq-artemis with Apache License 2.0 5 votes vote down vote up
/**
 * Test that an amqp-sequence body containing a list results in an StreamMessage when not
 * otherwise annotated to indicate the type of JMS message it is.
 *
 * @throws Exception
 *         if an error occurs during the test.
 */
@Test
public void testCreateAmqpStreamMessageFromAmqpSequence() throws Exception {
   MessageImpl message = (MessageImpl) Message.Factory.create();
   List<String> list = new ArrayList<>();
   message.setBody(new AmqpSequence(list));

   javax.jms.Message jmsMessage = ServerJMSMessage.wrapCoreMessage(encodeAndCreateAMQPMessage(message).toCore());

   assertNotNull("Message should not be null", jmsMessage);
   assertEquals("Unexpected message class type", ServerJMSStreamMessage.class, jmsMessage.getClass());
}
 
Example #19
Source File: AMQPMessage.java    From activemq-artemis with Apache License 2.0 5 votes vote down vote up
/**
 * Retrieves the AMQP Section that composes the body of this message by decoding a
 * fresh copy from the encoded message data.  Changes to the returned value are not
 * reflected in the value encoded in the original message.
 *
 * @return the Section that makes up the body of this message.
 */
public final Section getBody() {
   ensureScanning();

   // We only handle Sections of AmqpSequence, AmqpValue and Data types so we filter on those.
   // There could also be a Footer and no body so this will prevent a faulty return type in case
   // of no body or message type we don't handle.
   return scanForMessageSection(Math.max(0, remainingBodyPosition), AmqpSequence.class, AmqpValue.class, Data.class);
}
 
Example #20
Source File: FastPathAmqpSequenceType.java    From qpid-proton-j with Apache License 2.0 5 votes vote down vote up
@Override
public void write(AmqpSequence sequence) {
    WritableBuffer buffer = getEncoder().getBuffer();
    buffer.put(EncodingCodes.DESCRIBED_TYPE_INDICATOR);
    buffer.put(EncodingCodes.SMALLULONG);
    buffer.put(DESCRIPTOR_CODE);
    getEncoder().writeObject(sequence.getValue());
}
 
Example #21
Source File: AmqpLargeMessageTest.java    From activemq-artemis with Apache License 2.0 4 votes vote down vote up
@SuppressWarnings({ "unchecked", "rawtypes" })
@Test(timeout = 60000)
public void testMessageWithAmqpSequencePreservesBodyType() throws Exception {
   server.getAddressSettingsRepository().addMatch("#", new AddressSettings().setDefaultAddressRoutingType(RoutingType.ANYCAST));

   AmqpClient client = createAmqpClient();
   AmqpConnection connection = addConnection(client.connect());
   try {
      AmqpSession session = connection.createSession();
      AmqpSender sender = session.createSender(getTestName());

      AmqpMessage message = createAmqpLargeMessageWithNoBody();

      List<String> values = new ArrayList<>();
      values.add("1");
      values.add("2");
      values.add("3");

      message.getWrappedMessage().setBody(new AmqpSequence(values));

      sender.send(message);
      sender.close();

      AmqpReceiver receiver = session.createReceiver(getTestName());
      receiver.flow(1);

      AmqpMessage received = receiver.receive(10, TimeUnit.SECONDS);
      assertNotNull("failed to read large AMQP message", received);
      MessageImpl wrapped = (MessageImpl) received.getWrappedMessage();

      assertTrue(wrapped.getBody() instanceof AmqpSequence);
      AmqpSequence body = (AmqpSequence) wrapped.getBody();
      assertTrue(body.getValue() instanceof List);
      List<String> payload = (List) body.getValue();
      assertEquals(3, payload.size());

      received.accept();
      session.close();
   } finally {
      connection.close();
   }
}
 
Example #22
Source File: FastPathAmqpSequenceType.java    From qpid-proton-j with Apache License 2.0 4 votes vote down vote up
@Override
public AmqpSequence readValue() {
    return new AmqpSequence(getDecoder().readList());
}
 
Example #23
Source File: FastPathAmqpSequenceType.java    From qpid-proton-j with Apache License 2.0 4 votes vote down vote up
@Override
public Collection<? extends TypeEncoding<AmqpSequence>> getAllEncodings() {
    return sequenceType.getAllEncodings();
}
 
Example #24
Source File: FastPathAmqpSequenceType.java    From qpid-proton-j with Apache License 2.0 4 votes vote down vote up
@Override
public TypeEncoding<AmqpSequence> getCanonicalEncoding() {
    return sequenceType.getCanonicalEncoding();
}
 
Example #25
Source File: FastPathAmqpSequenceType.java    From qpid-proton-j with Apache License 2.0 4 votes vote down vote up
@Override
public TypeEncoding<AmqpSequence> getEncoding(AmqpSequence val) {
    return sequenceType.getEncoding(val);
}
 
Example #26
Source File: FastPathAmqpSequenceType.java    From qpid-proton-j with Apache License 2.0 4 votes vote down vote up
@Override
public Class<AmqpSequence> getTypeClass() {
    return AmqpSequence.class;
}
 
Example #27
Source File: AmqpSequenceType.java    From qpid-proton-j with Apache License 2.0 4 votes vote down vote up
public Class<AmqpSequence> getTypeClass()
{
    return AmqpSequence.class;
}
 
Example #28
Source File: AmqpSequenceType.java    From qpid-proton-j with Apache License 2.0 4 votes vote down vote up
public AmqpSequence newInstance(Object described)
{
    return new AmqpSequence( (List) described );
}
 
Example #29
Source File: AmqpSequenceType.java    From qpid-proton-j with Apache License 2.0 4 votes vote down vote up
@Override
protected List wrap(AmqpSequence val)
{
    return val.getValue();
}