Search in sources :

Example 56 with Data

use of org.apache.qpid.server.protocol.v1_0.type.messaging.Data in project qpid-broker-j by apache.

the class MessageConverter_1_0_to_v0_8Test method testDataWithContentTypeJmsMapMessage.

public void testDataWithContentTypeJmsMapMessage() throws Exception {
    Map<String, Object> originalMap = Collections.singletonMap("testKey", "testValue");
    byte[] bytes = new MapToJmsMapMessage().toMimeContent(originalMap);
    final Data value = new Data(new Binary(bytes));
    Properties properties = new Properties();
    properties.setContentType(Symbol.valueOf("jms/map-message"));
    Message_1_0 sourceMessage = createTestMessage(properties, value.createEncodingRetainingSection());
    final AMQMessage convertedMessage = _converter.convert(sourceMessage, mock(NamedAddressSpace.class));
    assertEquals("Unexpected mime type", "jms/map-message", convertedMessage.getMessageHeader().getMimeType());
    final QpidByteBuffer content = convertedMessage.getContent(0, (int) convertedMessage.getSize());
    assertArrayEquals("Unexpected content", bytes, getBytes(content));
}
Also used : MapToJmsMapMessage(org.apache.qpid.server.typedmessage.mimecontentconverter.MapToJmsMapMessage) NamedAddressSpace(org.apache.qpid.server.model.NamedAddressSpace) Message_1_0(org.apache.qpid.server.protocol.v1_0.Message_1_0) Data(org.apache.qpid.server.protocol.v1_0.type.messaging.Data) QpidByteBuffer(org.apache.qpid.server.bytebuffer.QpidByteBuffer) Binary(org.apache.qpid.server.protocol.v1_0.type.Binary) ApplicationProperties(org.apache.qpid.server.protocol.v1_0.type.messaging.ApplicationProperties) Properties(org.apache.qpid.server.protocol.v1_0.type.messaging.Properties) AMQMessage(org.apache.qpid.server.protocol.v0_8.AMQMessage)

Example 57 with Data

use of org.apache.qpid.server.protocol.v1_0.type.messaging.Data in project qpid-broker-j by apache.

the class MessageConverter_1_0_to_v0_8Test method testData.

public void testData() throws Exception {
    final byte[] expected = getObjectBytes("helloworld".getBytes(UTF_8));
    final Data value = new Data(new Binary(expected));
    final Message_1_0 sourceMessage = createTestMessage(value.createEncodingRetainingSection());
    final AMQMessage convertedMessage = _converter.convert(sourceMessage, mock(NamedAddressSpace.class));
    assertEquals("Unexpected mime type", "application/octet-stream", convertedMessage.getMessageHeader().getMimeType());
    final QpidByteBuffer content = convertedMessage.getContent(0, (int) convertedMessage.getSize());
    assertArrayEquals("Unexpected content", expected, getBytes(content));
}
Also used : NamedAddressSpace(org.apache.qpid.server.model.NamedAddressSpace) Message_1_0(org.apache.qpid.server.protocol.v1_0.Message_1_0) Data(org.apache.qpid.server.protocol.v1_0.type.messaging.Data) QpidByteBuffer(org.apache.qpid.server.bytebuffer.QpidByteBuffer) Binary(org.apache.qpid.server.protocol.v1_0.type.Binary) AMQMessage(org.apache.qpid.server.protocol.v0_8.AMQMessage)

Example 58 with Data

use of org.apache.qpid.server.protocol.v1_0.type.messaging.Data in project qpid-broker-j by apache.

the class SymbolTypeConstructor method construct.

@Override
public Symbol construct(final QpidByteBuffer in, final ValueHandler handler) throws AmqpErrorException {
    int size;
    if (!in.hasRemaining(getSize())) {
        throw new AmqpErrorException(AmqpError.DECODE_ERROR, "Cannot construct symbol: insufficient input data");
    }
    if (getSize() == 1) {
        size = in.getUnsignedByte();
    } else {
        size = in.getInt();
    }
    if (!in.hasRemaining(size)) {
        throw new AmqpErrorException(AmqpError.DECODE_ERROR, "Cannot construct symbol: insufficient input data");
    }
    byte[] data = new byte[size];
    in.get(data);
    final BinaryString binaryStr = new BinaryString(data);
    Symbol symbolVal = SYMBOL_MAP.get(binaryStr);
    if (symbolVal == null) {
        symbolVal = Symbol.valueOf(new String(data, ASCII));
        SYMBOL_MAP.putIfAbsent(binaryStr, symbolVal);
    }
    return symbolVal;
}
Also used : Symbol(org.apache.qpid.server.protocol.v1_0.type.Symbol) AmqpErrorException(org.apache.qpid.server.protocol.v1_0.type.AmqpErrorException)

Example 59 with Data

use of org.apache.qpid.server.protocol.v1_0.type.messaging.Data in project qpid-broker-j by apache.

the class FilterTest method selectorFilter.

@Test
@BrokerSpecific(kind = KIND_BROKER_J)
@SpecificationTest(section = "3.5.1", description = "A source can restrict the messages transferred from a source by specifying a filter.")
public void selectorFilter() throws Exception {
    try (FrameTransport transport = new FrameTransport(_brokerAddress).connect()) {
        final Interaction interaction = transport.newInteraction();
        interaction.negotiateProtocol().consumeResponse().open().consumeResponse(Open.class).begin().consumeResponse(Begin.class).attachRole(Role.SENDER).attachTargetAddress(BrokerAdmin.TEST_QUEUE_NAME).attach().consumeResponse(Attach.class).consumeResponse(Flow.class);
        Flow flow = interaction.getLatestResponse(Flow.class);
        assumeThat("insufficient credit for the test", flow.getLinkCredit().intValue(), is(greaterThan(1)));
        for (int i = 0; i < 2; i++) {
            QpidByteBuffer payload = generateMessagePayloadWithApplicationProperties(Collections.singletonMap("index", i), TEST_MESSAGE_CONTENT);
            interaction.transferPayload(payload).transferSettled(true).transfer();
        }
        interaction.detachClose(true).detach().close().sync();
    }
    try (FrameTransport transport = new FrameTransport(_brokerAddress).connect()) {
        final Interaction interaction = transport.newInteraction();
        interaction.negotiateProtocol().consumeResponse().open().consumeResponse(Open.class).begin().consumeResponse(Begin.class).attachRole(Role.RECEIVER).attachSourceAddress(BrokerAdmin.TEST_QUEUE_NAME).attachRcvSettleMode(ReceiverSettleMode.FIRST).attachSourceFilter(Collections.singletonMap(Symbol.valueOf("selector-filter"), new JMSSelectorFilter("index=1"))).attach().consumeResponse().flowIncomingWindow(UnsignedInteger.ONE).flowNextIncomingId(UnsignedInteger.ZERO).flowOutgoingWindow(UnsignedInteger.ZERO).flowNextOutgoingId(UnsignedInteger.ZERO).flowLinkCredit(UnsignedInteger.ONE).flowHandleFromLinkHandle().flow();
        Object data = interaction.receiveDelivery().decodeLatestDelivery().getDecodedLatestDelivery();
        assertThat(data, is(equalTo(TEST_MESSAGE_CONTENT)));
        Map<String, Object> applicationProperties = interaction.getLatestDeliveryApplicationProperties();
        assertThat(applicationProperties, is(notNullValue()));
        assertThat(applicationProperties.get("index"), is(equalTo(1)));
        interaction.dispositionSettled(true).dispositionRole(Role.RECEIVER).dispositionState(new Accepted()).disposition();
        interaction.close().sync();
    }
}
Also used : FrameTransport(org.apache.qpid.tests.protocol.v1_0.FrameTransport) JMSSelectorFilter(org.apache.qpid.server.protocol.v1_0.type.messaging.JMSSelectorFilter) Interaction(org.apache.qpid.tests.protocol.v1_0.Interaction) Attach(org.apache.qpid.server.protocol.v1_0.type.transport.Attach) Accepted(org.apache.qpid.server.protocol.v1_0.type.messaging.Accepted) Open(org.apache.qpid.server.protocol.v1_0.type.transport.Open) Flow(org.apache.qpid.server.protocol.v1_0.type.transport.Flow) Begin(org.apache.qpid.server.protocol.v1_0.type.transport.Begin) QpidByteBuffer(org.apache.qpid.server.bytebuffer.QpidByteBuffer) Test(org.junit.Test) SpecificationTest(org.apache.qpid.tests.protocol.SpecificationTest) BrokerSpecific(org.apache.qpid.tests.utils.BrokerSpecific) SpecificationTest(org.apache.qpid.tests.protocol.SpecificationTest)

Example 60 with Data

use of org.apache.qpid.server.protocol.v1_0.type.messaging.Data in project qpid-broker-j by apache.

the class TransactionTimeoutTest method transactionalRetirementTimeout.

@Test
public void transactionalRetirementTimeout() throws Exception {
    getBrokerAdmin().putMessageOnQueue(BrokerAdmin.TEST_QUEUE_NAME, TEST_MESSAGE_CONTENT);
    try (FrameTransport transport = new FrameTransport(_brokerAddress).connect()) {
        final Interaction interaction = transport.newInteraction();
        final InteractionTransactionalState txnState = interaction.createTransactionalState(UnsignedInteger.ZERO);
        interaction.negotiateProtocol().consumeResponse().open().consumeResponse(Open.class).begin().consumeResponse(Begin.class).txnAttachCoordinatorLink(txnState).txnDeclare(txnState).attachRole(Role.RECEIVER).attachHandle(UnsignedInteger.ONE).attachSourceAddress(BrokerAdmin.TEST_QUEUE_NAME).attachRcvSettleMode(ReceiverSettleMode.FIRST).attach().consumeResponse(Attach.class).flowIncomingWindow(UnsignedInteger.MAX_VALUE).flowNextIncomingId(UnsignedInteger.ZERO).flowOutgoingWindow(UnsignedInteger.ZERO).flowNextOutgoingId(UnsignedInteger.ZERO).flowLinkCredit(UnsignedInteger.MAX_VALUE).flowHandleFromLinkHandle().flow().receiveDelivery().decodeLatestDelivery();
        Object data = interaction.getDecodedLatestDelivery();
        assertThat(data, is(equalTo(TEST_MESSAGE_CONTENT)));
        interaction.dispositionSettled(true).dispositionRole(Role.RECEIVER).dispositionTransactionalState(txnState.getCurrentTransactionId(), new Accepted()).disposition().sync();
        Response<?> response = interaction.consumeResponse(Close.class, Flow.class).getLatestResponse();
        Close responseClose;
        if (response.getBody() instanceof Close) {
            responseClose = (Close) response.getBody();
        } else {
            responseClose = interaction.consumeResponse().getLatestResponse(Close.class);
        }
        assertThat(responseClose.getError(), is(Matchers.notNullValue()));
        assertThat(responseClose.getError().getCondition(), equalTo(TransactionError.TRANSACTION_TIMEOUT));
    }
}
Also used : FrameTransport(org.apache.qpid.tests.protocol.v1_0.FrameTransport) InteractionTransactionalState(org.apache.qpid.tests.protocol.v1_0.InteractionTransactionalState) Interaction(org.apache.qpid.tests.protocol.v1_0.Interaction) Attach(org.apache.qpid.server.protocol.v1_0.type.transport.Attach) Begin(org.apache.qpid.server.protocol.v1_0.type.transport.Begin) Close(org.apache.qpid.server.protocol.v1_0.type.transport.Close) Accepted(org.apache.qpid.server.protocol.v1_0.type.messaging.Accepted) Open(org.apache.qpid.server.protocol.v1_0.type.transport.Open) Flow(org.apache.qpid.server.protocol.v1_0.type.transport.Flow) Test(org.junit.Test)

Aggregations

Binary (org.apache.qpid.server.protocol.v1_0.type.Binary)42 QpidByteBuffer (org.apache.qpid.server.bytebuffer.QpidByteBuffer)39 Data (org.apache.qpid.server.protocol.v1_0.type.messaging.Data)32 NamedAddressSpace (org.apache.qpid.server.model.NamedAddressSpace)30 Message_1_0 (org.apache.qpid.server.protocol.v1_0.Message_1_0)29 ApplicationProperties (org.apache.qpid.server.protocol.v1_0.type.messaging.ApplicationProperties)29 Properties (org.apache.qpid.server.protocol.v1_0.type.messaging.Properties)28 FrameTransport (org.apache.qpid.tests.protocol.v1_0.FrameTransport)19 Interaction (org.apache.qpid.tests.protocol.v1_0.Interaction)19 Test (org.junit.Test)19 SpecificationTest (org.apache.qpid.tests.protocol.SpecificationTest)18 MessageTransferMessage (org.apache.qpid.server.protocol.v0_10.MessageTransferMessage)14 AMQMessage (org.apache.qpid.server.protocol.v0_8.AMQMessage)14 Accepted (org.apache.qpid.server.protocol.v1_0.type.messaging.Accepted)13 Attach (org.apache.qpid.server.protocol.v1_0.type.transport.Attach)12 ArrayList (java.util.ArrayList)9 Begin (org.apache.qpid.server.protocol.v1_0.type.transport.Begin)9 Open (org.apache.qpid.server.protocol.v1_0.type.transport.Open)9 Transfer (org.apache.qpid.server.protocol.v1_0.type.transport.Transfer)8 InteractionTransactionalState (org.apache.qpid.tests.protocol.v1_0.InteractionTransactionalState)8