use of org.apache.qpid.server.protocol.v1_0.type.messaging.Source in project qpid-broker-j by apache.
the class Session_1_0 method createExchangeDestination.
private ExchangeSendingDestination createExchangeDestination(final String exchangeName, final String bindingKey, final String linkName, final Source source) throws AmqpErrorException {
ExchangeSendingDestination exchangeDestination = null;
Exchange<?> exchange = getExchange(exchangeName);
if (exchange != null) {
if (!Boolean.TRUE.equals(source.getDynamic())) {
String remoteContainerId = getConnection().getRemoteContainerId();
exchangeDestination = new ExchangeSendingDestination(exchange, linkName, bindingKey, remoteContainerId, source);
source.setFilter(exchangeDestination.getFilters());
source.setDistributionMode(StdDistMode.COPY);
} else {
// TODO
throw new AmqpErrorException(new Error(AmqpError.NOT_IMPLEMENTED, "Temporary subscription is not implemented"));
}
}
return exchangeDestination;
}
use of org.apache.qpid.server.protocol.v1_0.type.messaging.Source in project qpid-broker-j by apache.
the class Session_1_0 method getSendingDestination.
public SendingDestination getSendingDestination(final Link_1_0<?, ?> link, final Source source) throws AmqpErrorException {
SendingDestination destination = null;
if (Boolean.TRUE.equals(source.getDynamic())) {
MessageSource tempSource = createDynamicSource(link, source.getDynamicNodeProperties());
if (tempSource != null) {
source.setAddress(_primaryDomain + tempSource.getName());
} else {
throw new AmqpErrorException(AmqpError.INTERNAL_ERROR, "Cannot create dynamic source");
}
}
String address = source.getAddress();
if (address != null) {
if (!address.startsWith("/") && address.contains("/")) {
destination = createExchangeDestination(address, link.getName(), source);
} else {
MessageSource queue = getAddressSpace().getAttainedMessageSource(address);
if (queue != null) {
destination = new StandardSendingDestination(queue);
} else {
destination = createExchangeDestination(address, null, link.getName(), source);
}
}
}
if (destination == null) {
throw new AmqpErrorException(AmqpError.NOT_FOUND, String.format("Could not find destination for source '%s'", source));
}
return destination;
}
use of org.apache.qpid.server.protocol.v1_0.type.messaging.Source 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.server.protocol.v1_0.type.messaging.Source in project qpid-broker-j by apache.
the class TxnCoordinatorReceivingLinkEndpoint method establishLink.
@Override
protected void establishLink(final Attach attach) throws AmqpErrorException {
if (getSource() != null || getTarget() != null) {
throw new IllegalStateException("LinkEndpoint and Termini should be null when establishing a Link.");
}
Coordinator target = new Coordinator();
Source source = (Source) attach.getSource();
getLink().setTermini(source, target);
attachReceived(attach);
}
use of org.apache.qpid.server.protocol.v1_0.type.messaging.Source 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)));
}
}
Aggregations