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));
}
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));
}
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;
}
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();
}
}
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));
}
}
Aggregations