use of org.apache.qpid.amqp_1_0.type.Binary in project qpid-broker-j by apache.
the class SendingLinkEndpoint method attachReceived.
@Override
public void attachReceived(final Attach attach) throws AmqpErrorException {
super.attachReceived(attach);
Target target = (Target) attach.getTarget();
Source source = getSource();
if (source == null) {
source = new Source();
Source attachSource = (Source) attach.getSource();
final Modified defaultOutcome = new Modified();
defaultOutcome.setDeliveryFailed(true);
source.setDefaultOutcome(defaultOutcome);
source.setOutcomes(Accepted.ACCEPTED_SYMBOL, Released.RELEASED_SYMBOL, Rejected.REJECTED_SYMBOL);
source.setAddress(attachSource.getAddress());
source.setDynamic(attachSource.getDynamic());
if (Boolean.TRUE.equals(attachSource.getDynamic()) && attachSource.getDynamicNodeProperties() != null) {
Map<Symbol, Object> dynamicNodeProperties = new HashMap<>();
if (attachSource.getDynamicNodeProperties().containsKey(Session_1_0.LIFETIME_POLICY)) {
dynamicNodeProperties.put(Session_1_0.LIFETIME_POLICY, attachSource.getDynamicNodeProperties().get(Session_1_0.LIFETIME_POLICY));
}
source.setDynamicNodeProperties(dynamicNodeProperties);
}
source.setDurable(TerminusDurability.min(attachSource.getDurable(), getLink().getHighestSupportedTerminusDurability()));
source.setExpiryPolicy(attachSource.getExpiryPolicy());
source.setDistributionMode(attachSource.getDistributionMode());
source.setFilter(attachSource.getFilter());
source.setCapabilities(attachSource.getCapabilities());
final SendingDestination destination = getSession().getSendingDestination(getLink(), source);
source.setCapabilities(destination.getCapabilities());
getLink().setSource(source);
prepareConsumerOptionsAndFilters(destination);
}
getLink().setTarget(target);
final MessageInstanceConsumer oldConsumer = getConsumer();
createConsumerTarget();
_resumeAcceptedTransfers.clear();
_resumeFullTransfers.clear();
final NamedAddressSpace addressSpace = getSession().getConnection().getAddressSpace();
// TODO: QPID-7845 : Resuming links is unsupported at the moment. Thus, cleaning up unsettled deliveries unconditionally.
cleanUpUnsettledDeliveries();
getSession().addDeleteTask(_cleanUpUnsettledDeliveryTask);
Map<Binary, OutgoingDelivery> unsettledCopy = new HashMap<>(_unsettled);
Map<Binary, DeliveryState> remoteUnsettled = attach.getUnsettled() == null ? Collections.emptyMap() : new HashMap<>(attach.getUnsettled());
final boolean isUnsettledComplete = !Boolean.TRUE.equals(attach.getIncompleteUnsettled());
for (Map.Entry<Binary, OutgoingDelivery> entry : unsettledCopy.entrySet()) {
Binary deliveryTag = entry.getKey();
final MessageInstance queueEntry = entry.getValue().getMessageInstance();
if (!remoteUnsettled.containsKey(deliveryTag) && isUnsettledComplete) {
queueEntry.setRedelivered();
queueEntry.release(oldConsumer);
_unsettled.remove(deliveryTag);
} else if (remoteUnsettled.get(deliveryTag) instanceof Outcome) {
Outcome outcome = (Outcome) remoteUnsettled.get(deliveryTag);
if (outcome instanceof Accepted) {
if (oldConsumer.acquires()) {
AutoCommitTransaction txn = new AutoCommitTransaction(addressSpace.getMessageStore());
if (queueEntry.acquire() || queueEntry.isAcquired()) {
txn.dequeue(Collections.singleton(queueEntry), new ServerTransaction.Action() {
@Override
public void postCommit() {
queueEntry.delete();
}
@Override
public void onRollback() {
}
});
}
}
} else if (outcome instanceof Released) {
if (oldConsumer.acquires()) {
AutoCommitTransaction txn = new AutoCommitTransaction(addressSpace.getMessageStore());
txn.dequeue(Collections.singleton(queueEntry), new ServerTransaction.Action() {
@Override
public void postCommit() {
queueEntry.release(oldConsumer);
}
@Override
public void onRollback() {
}
});
}
}
// TODO: QPID-7845: Handle rejected and modified outcome
remoteUnsettled.remove(deliveryTag);
_resumeAcceptedTransfers.add(deliveryTag);
} else {
_resumeFullTransfers.add(queueEntry);
// TODO:QPID-7845: exists in receivers map, but not yet got an outcome ... should resend with resume = true
}
}
getConsumerTarget().updateNotifyWorkDesired();
}
use of org.apache.qpid.amqp_1_0.type.Binary in project qpid-broker-j by apache.
the class StandardReceivingLinkEndpoint method attachReceived.
@Override
public void attachReceived(final Attach attach) throws AmqpErrorException {
super.attachReceived(attach);
Source source = (Source) attach.getSource();
Target target = new Target();
Target attachTarget = (Target) attach.getTarget();
setDeliveryCount(new SequenceNumber(attach.getInitialDeliveryCount().intValue()));
target.setAddress(attachTarget.getAddress());
target.setDynamic(attachTarget.getDynamic());
if (Boolean.TRUE.equals(attachTarget.getDynamic()) && attachTarget.getDynamicNodeProperties() != null) {
Map<Symbol, Object> dynamicNodeProperties = new HashMap<>();
if (attachTarget.getDynamicNodeProperties().containsKey(Session_1_0.LIFETIME_POLICY)) {
dynamicNodeProperties.put(Session_1_0.LIFETIME_POLICY, attachTarget.getDynamicNodeProperties().get(Session_1_0.LIFETIME_POLICY));
}
target.setDynamicNodeProperties(dynamicNodeProperties);
}
target.setDurable(TerminusDurability.min(attachTarget.getDurable(), getLink().getHighestSupportedTerminusDurability()));
final List<Symbol> targetCapabilities = new ArrayList<>();
if (attachTarget.getCapabilities() != null) {
final List<Symbol> desiredCapabilities = Arrays.asList(attachTarget.getCapabilities());
if (desiredCapabilities.contains(Symbol.valueOf("temporary-topic"))) {
targetCapabilities.add(Symbol.valueOf("temporary-topic"));
}
if (desiredCapabilities.contains(Symbol.valueOf("topic"))) {
targetCapabilities.add(Symbol.valueOf("topic"));
}
target.setCapabilities(targetCapabilities.toArray(new Symbol[targetCapabilities.size()]));
}
target.setExpiryPolicy(attachTarget.getExpiryPolicy());
final ReceivingDestination destination = getSession().getReceivingDestination(getLink(), target);
targetCapabilities.addAll(Arrays.asList(destination.getCapabilities()));
target.setCapabilities(targetCapabilities.toArray(new Symbol[targetCapabilities.size()]));
setCapabilities(targetCapabilities);
setDestination(destination);
if (!Boolean.TRUE.equals(attach.getIncompleteUnsettled())) {
Map remoteUnsettled = attach.getUnsettled();
Map<Binary, DeliveryState> unsettledCopy = new HashMap<>(_unsettled);
for (Map.Entry<Binary, DeliveryState> entry : unsettledCopy.entrySet()) {
Binary deliveryTag = entry.getKey();
if (remoteUnsettled == null || !remoteUnsettled.containsKey(deliveryTag)) {
_unsettled.remove(deliveryTag);
}
}
}
getLink().setTermini(source, target);
_rejectedOutcomeSupportedBySource = source.getOutcomes() != null && Arrays.asList(source.getOutcomes()).contains(Rejected.REJECTED_SYMBOL);
}
use of org.apache.qpid.amqp_1_0.type.Binary in project qpid-broker-j by apache.
the class MessageConverter_v1_0_to_InternalTest method testAmqpValueWithList.
public void testAmqpValueWithList() throws Exception {
final List<Object> originalList = new ArrayList<>();
originalList.add(new Binary(new byte[] { 0x00, (byte) 0xFF }));
originalList.add(42);
originalList.add(null);
originalList.add(Collections.singletonMap("foo", "bar"));
final AmqpValue amqpValue = new AmqpValue(originalList);
Message_1_0 sourceMessage = createTestMessage(amqpValue.createEncodingRetainingSection());
final InternalMessage convertedMessage = _converter.convert(sourceMessage, mock(NamedAddressSpace.class));
assertEquals("Unexpected mime type", null, convertedMessage.getMessageHeader().getMimeType());
List<Object> convertedList = ((List<Object>) convertedMessage.getMessageBody());
assertEquals("Unexpected size", originalList.size(), convertedList.size());
assertArrayEquals("Unexpected binary item", ((Binary) originalList.get(0)).getArray(), (byte[]) convertedList.get(0));
assertEquals("Unexpected int item", originalList.get(1), convertedList.get(1));
assertEquals("Unexpected null item", originalList.get(2), convertedList.get(2));
assertEquals("Unexpected map item", new HashMap((Map) originalList.get(3)), new HashMap((Map) convertedList.get(3)));
}
use of org.apache.qpid.amqp_1_0.type.Binary in project qpid-broker-j by apache.
the class AnonymousTerminusTest method transferPreSettledInTransactionToUnknownDestinationWhenRejectOutcomeSupportedByTxController.
@SpecificationTest(section = "Using the Anonymous Terminus for Message Routing. 2.2.2 Routing Errors", description = "It is possible that a message sent to a routing node has an address in the to field" + " of properties which, if used in the address field of target of an attach," + " would result in an unsuccessful link establishment (for example," + " if the address cannot be resolved to a node). In this case the routing node" + " MUST communicate the error back to the sender of the message." + " [...]" + " <Not in spec yet>" + " AMQP-140" + " If a message cannot be routed to the destination implied in the \"to:\" field," + " and the source does not allow for the rejected outcome" + " [...] when messages are being sent within a transaction and have been sent pre-settled." + " In this case the behaviour defined for transactions (of essentially marking" + " the transaction as rollback only) should take precedence. " + "" + " AMQP spec 4.3 Discharging a Transaction" + " If the coordinator is unable to complete the discharge, the coordinator MUST convey" + " the error to the controller as a transaction-error. If the source for the link to" + " the coordinator supports the rejected outcome, then the message MUST be rejected" + " with this outcome carrying the transaction-error.")
@Test
public void transferPreSettledInTransactionToUnknownDestinationWhenRejectOutcomeSupportedByTxController() throws Exception {
try (FrameTransport transport = new FrameTransport(_brokerAddress).connect()) {
final UnsignedInteger linkHandle = UnsignedInteger.ONE;
final Interaction interaction = openInteractionWithAnonymousRelayCapability(transport);
final InteractionTransactionalState txnState = interaction.createTransactionalState(UnsignedInteger.ZERO);
interaction.begin().consumeResponse(Begin.class).txnAttachCoordinatorLink(txnState).txnDeclare(txnState).attachRole(Role.SENDER).attachHandle(linkHandle).attachSourceOutcomes(Accepted.ACCEPTED_SYMBOL, Rejected.REJECTED_SYMBOL).attach().consumeResponse(Attach.class).consumeResponse(Flow.class).transferHandle(linkHandle).transferPayload(generateMessagePayloadToDestination("Unknown")).transferDeliveryTag(_deliveryTag).transferTransactionalState(txnState.getCurrentTransactionId()).transferSettled(Boolean.TRUE).transferDeliveryId(UnsignedInteger.valueOf(1)).transfer();
final Discharge discharge = new Discharge();
discharge.setTxnId(txnState.getCurrentTransactionId());
discharge.setFail(false);
interaction.transferHandle(txnState.getHandle()).transferDeliveryId(UnsignedInteger.valueOf(2)).transferSettled(Boolean.FALSE).transferDeliveryTag(new Binary(("transaction-" + 2).getBytes(StandardCharsets.UTF_8))).transferPayloadData(discharge).transfer();
Disposition dischargeTransactionDisposition = getDispositionForDeliveryId(interaction, UnsignedInteger.valueOf(2));
assertThat(dischargeTransactionDisposition.getSettled(), is(equalTo(true)));
assertThat(dischargeTransactionDisposition.getState(), is(instanceOf(Rejected.class)));
Rejected rejected = (Rejected) dischargeTransactionDisposition.getState();
Error error = rejected.getError();
assertThat(error, is(notNullValue()));
assertThat(error.getCondition(), is(equalTo(TransactionError.TRANSACTION_ROLLBACK)));
}
}
use of org.apache.qpid.amqp_1_0.type.Binary in project qpid-broker-j by apache.
the class AnonymousTerminusTest method transferPreSettledInTransactionToUnknownDestinationWhenRejectOutcomeNotSupportedByTxController.
@SpecificationTest(section = "Using the Anonymous Terminus for Message Routing. 2.2.2 Routing Errors", description = "It is possible that a message sent to a routing node has an address in the to field" + " of properties which, if used in the address field of target of an attach," + " would result in an unsuccessful link establishment (for example," + " if the address cannot be resolved to a node). In this case the routing node" + " MUST communicate the error back to the sender of the message." + " [...]" + " <Not in spec yet>" + " AMQP-140" + " If a message cannot be routed to the destination implied in the \"to:\" field," + " and the source does not allow for the rejected outcome" + " [...] when messages are being sent within a transaction and have been sent pre-settled." + " In this case the behaviour defined for transactions (of essentially marking" + " the transaction as rollback only) should take precedence. " + "" + " AMQP spec 4.3 Discharging a Transaction" + " If the coordinator is unable to complete the discharge, the coordinator MUST convey" + " the error to the controller as a transaction-error." + " [...]" + " If the source does not support the rejected outcome, the transactional resource MUST" + " detach the link to the coordinator, with the detach performative carrying" + " the transaction-error")
@Test
public void transferPreSettledInTransactionToUnknownDestinationWhenRejectOutcomeNotSupportedByTxController() throws Exception {
try (FrameTransport transport = new FrameTransport(_brokerAddress).connect()) {
final UnsignedInteger linkHandle = UnsignedInteger.ONE;
final Interaction interaction = openInteractionWithAnonymousRelayCapability(transport);
final InteractionTransactionalState txnState = interaction.createTransactionalState(UnsignedInteger.ZERO);
interaction.begin().consumeResponse(Begin.class).attachRole(Role.SENDER).attachName("testTransactionCoordinator-" + txnState.getHandle()).attachHandle(txnState.getHandle()).attachInitialDeliveryCount(UnsignedInteger.ZERO).attachTarget(new Coordinator()).attachSourceOutcomes(Accepted.ACCEPTED_SYMBOL).attach().consumeResponse(Attach.class).consumeResponse(Flow.class).txnDeclare(txnState).attachRole(Role.SENDER).attachHandle(linkHandle).attachTarget(new Target()).attachName("link-" + linkHandle).attachSourceOutcomes(Accepted.ACCEPTED_SYMBOL, Rejected.REJECTED_SYMBOL).attach().consumeResponse(Attach.class).consumeResponse(Flow.class).transferHandle(linkHandle).transferPayload(generateMessagePayloadToDestination("Unknown")).transferDeliveryTag(_deliveryTag).transferTransactionalState(txnState.getCurrentTransactionId()).transferSettled(Boolean.TRUE).transfer();
final Discharge discharge = new Discharge();
discharge.setTxnId(txnState.getCurrentTransactionId());
discharge.setFail(false);
interaction.transferHandle(txnState.getHandle()).transferSettled(Boolean.FALSE).transferDeliveryId(UnsignedInteger.valueOf(4)).transferDeliveryTag(new Binary(("transaction-" + 4).getBytes(StandardCharsets.UTF_8))).transferPayloadData(discharge).transfer();
Detach transactionCoordinatorDetach = interaction.consumeResponse().getLatestResponse(Detach.class);
Error transactionCoordinatorDetachError = transactionCoordinatorDetach.getError();
assertThat(transactionCoordinatorDetachError, is(notNullValue()));
assertThat(transactionCoordinatorDetachError.getCondition(), is(equalTo(TransactionError.TRANSACTION_ROLLBACK)));
}
}
Aggregations