Search in sources :

Example 1 with Rejected

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

the class AnonymousTerminusTest method transferUnsettledInTransactionToUnknownDestinationWhenRejectedOutcomeSupportedBySource.

@Test
public void transferUnsettledInTransactionToUnknownDestinationWhenRejectedOutcomeSupportedBySource() throws Exception {
    try (FrameTransport transport = new FrameTransport(_brokerAddress).connect()) {
        final Interaction interaction = openInteractionWithAnonymousRelayCapability(transport);
        final UnsignedInteger linkHandle = UnsignedInteger.ONE;
        final InteractionTransactionalState txnState = interaction.createTransactionalState(UnsignedInteger.ZERO);
        interaction.begin().consumeResponse(Begin.class).txnAttachCoordinatorLink(txnState).txnDeclare(txnState).attachRole(Role.SENDER).attachSourceOutcomes(Accepted.ACCEPTED_SYMBOL, Rejected.REJECTED_SYMBOL).attachHandle(linkHandle).attach().consumeResponse(Attach.class).consumeResponse(Flow.class).transferHandle(linkHandle).transferPayload(generateMessagePayloadToDestination("Unknown")).transferDeliveryTag(_deliveryTag).transferTransactionalState(txnState.getCurrentTransactionId()).transferSettled(Boolean.FALSE).transfer();
        Disposition disposition = interaction.consumeResponse().getLatestResponse(Disposition.class);
        assertThat(disposition.getSettled(), is(true));
        DeliveryState dispositionState = disposition.getState();
        assertThat(dispositionState, is(instanceOf(TransactionalState.class)));
        final TransactionalState receivedTxnState = (TransactionalState) dispositionState;
        assertThat(receivedTxnState.getOutcome(), is(instanceOf(Rejected.class)));
        final Error rejectedError = ((Rejected) receivedTxnState.getOutcome()).getError();
        assertThat(rejectedError.getCondition(), is(equalTo(AmqpError.NOT_FOUND)));
        assertThat(rejectedError.getInfo(), is(notNullValue()));
        assertThat(rejectedError.getInfo().get(DELIVERY_TAG), is(equalTo(_deliveryTag)));
        interaction.txnDischarge(txnState, false);
    }
}
Also used : FrameTransport(org.apache.qpid.tests.protocol.v1_0.FrameTransport) InteractionTransactionalState(org.apache.qpid.tests.protocol.v1_0.InteractionTransactionalState) DeliveryState(org.apache.qpid.server.protocol.v1_0.type.DeliveryState) Interaction(org.apache.qpid.tests.protocol.v1_0.Interaction) Attach(org.apache.qpid.server.protocol.v1_0.type.transport.Attach) Disposition(org.apache.qpid.server.protocol.v1_0.type.transport.Disposition) Error(org.apache.qpid.server.protocol.v1_0.type.transport.Error) AmqpError(org.apache.qpid.server.protocol.v1_0.type.transport.AmqpError) TransactionError(org.apache.qpid.server.protocol.v1_0.type.transaction.TransactionError) Rejected(org.apache.qpid.server.protocol.v1_0.type.messaging.Rejected) UnsignedInteger(org.apache.qpid.server.protocol.v1_0.type.UnsignedInteger) InteractionTransactionalState(org.apache.qpid.tests.protocol.v1_0.InteractionTransactionalState) TransactionalState(org.apache.qpid.server.protocol.v1_0.type.transaction.TransactionalState) Test(org.junit.Test) SpecificationTest(org.apache.qpid.tests.protocol.SpecificationTest)

Example 2 with Rejected

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

the class AnonymousTerminusTest method transferUnsettledToUnknownDestinationWhenRejectedOutcomeNotSupportedBySource.

@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." + " [...]" + " If the source of the link does not support the rejected outcome," + " [...] then the routing node MUST detach the link with an error." + " [...] the info field of error MUST contain an entry with symbolic key delivery-tag" + " and binary value of the delivery-tag of the message which caused the failure.")
@Test
public void transferUnsettledToUnknownDestinationWhenRejectedOutcomeNotSupportedBySource() throws Exception {
    try (FrameTransport transport = new FrameTransport(_brokerAddress).connect()) {
        final Interaction interaction = openInteractionWithAnonymousRelayCapability(transport);
        interaction.begin().consumeResponse(Begin.class).attachRole(Role.SENDER).attachSourceOutcomes(Accepted.ACCEPTED_SYMBOL).attach().consumeResponse(Attach.class).consumeResponse(Flow.class).transferPayload(generateMessagePayloadToDestination("Unknown")).transferDeliveryTag(_deliveryTag).transfer();
        Detach detach = interaction.consumeResponse().getLatestResponse(Detach.class);
        Error error = detach.getError();
        assertThat(error, is(notNullValue()));
        assertThat(error.getCondition(), is(equalTo(AmqpError.NOT_FOUND)));
        assertThat(error.getInfo(), is(notNullValue()));
        assertThat(error.getInfo().get(DELIVERY_TAG), is(equalTo(_deliveryTag)));
    }
}
Also used : FrameTransport(org.apache.qpid.tests.protocol.v1_0.FrameTransport) Interaction(org.apache.qpid.tests.protocol.v1_0.Interaction) Error(org.apache.qpid.server.protocol.v1_0.type.transport.Error) AmqpError(org.apache.qpid.server.protocol.v1_0.type.transport.AmqpError) TransactionError(org.apache.qpid.server.protocol.v1_0.type.transaction.TransactionError) Detach(org.apache.qpid.server.protocol.v1_0.type.transport.Detach) Flow(org.apache.qpid.server.protocol.v1_0.type.transport.Flow) Test(org.junit.Test) SpecificationTest(org.apache.qpid.tests.protocol.SpecificationTest) SpecificationTest(org.apache.qpid.tests.protocol.SpecificationTest)

Example 3 with Rejected

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

the class TransferTest method durableTransferWithRejectedOutcome.

@Test
@SpecificationTest(section = "3.2.1", description = "Durable messages MUST NOT be lost even if an intermediary is unexpectedly terminated and " + "restarted. A target which is not capable of fulfilling this guarantee MUST NOT accept messages " + "where the durable header is set to true: if the source allows the rejected outcome then the " + "message SHOULD be rejected with the precondition-failed error, otherwise the link MUST be " + "detached by the receiver with the same error.")
public void durableTransferWithRejectedOutcome() throws Exception {
    try (FrameTransport transport = new FrameTransport(_brokerAddress).connect()) {
        MessageEncoder messageEncoder = new MessageEncoder();
        final Header header = new Header();
        header.setDurable(true);
        messageEncoder.setHeader(header);
        messageEncoder.addData("foo");
        final Disposition receivedDisposition = transport.newInteraction().negotiateProtocol().consumeResponse().open().consumeResponse(Open.class).begin().consumeResponse(Begin.class).attachRole(Role.SENDER).attachTargetAddress(BrokerAdmin.TEST_QUEUE_NAME).attachRcvSettleMode(ReceiverSettleMode.SECOND).attachSourceOutcomes(Accepted.ACCEPTED_SYMBOL, Rejected.REJECTED_SYMBOL).attach().consumeResponse(Attach.class).consumeResponse(Flow.class).transferPayload(messageEncoder.getPayload()).transferRcvSettleMode(ReceiverSettleMode.FIRST).transfer().consumeResponse().getLatestResponse(Disposition.class);
        assertThat(receivedDisposition.getSettled(), is(true));
        assertThat(receivedDisposition.getState(), is(instanceOf(Outcome.class)));
        if (getBrokerAdmin().supportsRestart()) {
            assertThat(((Outcome) receivedDisposition.getState()).getSymbol(), is(Accepted.ACCEPTED_SYMBOL));
        } else {
            assertThat(((Outcome) receivedDisposition.getState()).getSymbol(), is(Rejected.REJECTED_SYMBOL));
        }
    }
}
Also used : FrameTransport(org.apache.qpid.tests.protocol.v1_0.FrameTransport) Header(org.apache.qpid.server.protocol.v1_0.type.messaging.Header) Disposition(org.apache.qpid.server.protocol.v1_0.type.transport.Disposition) MessageEncoder(org.apache.qpid.tests.protocol.v1_0.MessageEncoder) Flow(org.apache.qpid.server.protocol.v1_0.type.transport.Flow) SpecificationTest(org.apache.qpid.tests.protocol.SpecificationTest) Test(org.junit.Test) SpecificationTest(org.apache.qpid.tests.protocol.SpecificationTest)

Example 4 with Rejected

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

the class TransferTest method durableTransferWithoutRejectedOutcome.

@Test
@SpecificationTest(section = "3.2.1", description = "Durable messages MUST NOT be lost even if an intermediary is unexpectedly terminated and " + "restarted. A target which is not capable of fulfilling this guarantee MUST NOT accept messages " + "where the durable header is set to true: if the source allows the rejected outcome then the " + "message SHOULD be rejected with the precondition-failed error, otherwise the link MUST be " + "detached by the receiver with the same error.")
public void durableTransferWithoutRejectedOutcome() throws Exception {
    try (FrameTransport transport = new FrameTransport(_brokerAddress).connect()) {
        MessageEncoder messageEncoder = new MessageEncoder();
        final Header header = new Header();
        header.setDurable(true);
        messageEncoder.setHeader(header);
        messageEncoder.addData("foo");
        final Response<?> response = transport.newInteraction().negotiateProtocol().consumeResponse().open().consumeResponse(Open.class).begin().consumeResponse(Begin.class).attachRole(Role.SENDER).attachTargetAddress(BrokerAdmin.TEST_QUEUE_NAME).attachRcvSettleMode(ReceiverSettleMode.SECOND).attachSourceOutcomes(Accepted.ACCEPTED_SYMBOL).attach().consumeResponse(Attach.class).consumeResponse(Flow.class).transferPayload(messageEncoder.getPayload()).transferRcvSettleMode(ReceiverSettleMode.FIRST).transfer().consumeResponse().getLatestResponse();
        if (getBrokerAdmin().supportsRestart()) {
            assertThat(response, is(notNullValue()));
            assertThat(response.getBody(), is(instanceOf(Disposition.class)));
            final Disposition receivedDisposition = (Disposition) response.getBody();
            assertThat(receivedDisposition.getSettled(), is(true));
            assertThat(receivedDisposition.getState(), is(instanceOf(Outcome.class)));
            assertThat(((Outcome) receivedDisposition.getState()).getSymbol(), is(Accepted.ACCEPTED_SYMBOL));
        } else {
            assertThat(response, is(notNullValue()));
            assertThat(response.getBody(), is(instanceOf(Detach.class)));
            final Detach receivedDetach = (Detach) response.getBody();
            assertThat(receivedDetach.getError(), is(notNullValue()));
            assertThat(receivedDetach.getError().getCondition(), is(AmqpError.PRECONDITION_FAILED));
        }
    }
}
Also used : FrameTransport(org.apache.qpid.tests.protocol.v1_0.FrameTransport) Header(org.apache.qpid.server.protocol.v1_0.type.messaging.Header) Disposition(org.apache.qpid.server.protocol.v1_0.type.transport.Disposition) MessageEncoder(org.apache.qpid.tests.protocol.v1_0.MessageEncoder) Detach(org.apache.qpid.server.protocol.v1_0.type.transport.Detach) Flow(org.apache.qpid.server.protocol.v1_0.type.transport.Flow) SpecificationTest(org.apache.qpid.tests.protocol.SpecificationTest) Test(org.junit.Test) SpecificationTest(org.apache.qpid.tests.protocol.SpecificationTest)

Example 5 with Rejected

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

the class StandardReceivingLinkEndpoint method receiveDelivery.

@Override
protected Error receiveDelivery(Delivery delivery) {
    ReceiverSettleMode transferReceiverSettleMode = delivery.getReceiverSettleMode();
    if (delivery.getResume()) {
        DeliveryState deliveryState = _unsettled.get(delivery.getDeliveryTag());
        if (deliveryState instanceof Outcome) {
            boolean settled = shouldReceiverSettleFirst(transferReceiverSettleMode);
            updateDisposition(delivery.getDeliveryTag(), deliveryState, settled);
            return null;
        } else {
        // TODO: QPID-7845: create message ?
        }
    } else {
        ServerMessage<?> serverMessage;
        UnsignedInteger messageFormat = delivery.getMessageFormat();
        DeliveryState xfrState = delivery.getState();
        MessageFormat format = MessageFormatRegistry.getFormat(messageFormat.intValue());
        if (format != null) {
            try (QpidByteBuffer payload = delivery.getPayload()) {
                serverMessage = format.createMessage(payload, getAddressSpace().getMessageStore(), getSession().getConnection().getReference());
            } catch (AmqpErrorRuntimeException e) {
                return e.getCause().getError();
            }
        } else {
            final Error err = new Error();
            err.setCondition(AmqpError.NOT_IMPLEMENTED);
            err.setDescription("Unknown message format: " + messageFormat);
            return err;
        }
        MessageReference<?> reference = serverMessage.newReference();
        try {
            Binary transactionId = null;
            if (xfrState != null) {
                if (xfrState instanceof TransactionalState) {
                    transactionId = ((TransactionalState) xfrState).getTxnId();
                }
            }
            final ServerTransaction transaction;
            boolean setRollbackOnly = true;
            if (transactionId != null) {
                try {
                    transaction = getSession().getTransaction(transactionId);
                } catch (UnknownTransactionException e) {
                    return new Error(TransactionError.UNKNOWN_ID, String.format("transaction-id '%s' is unknown.", transactionId));
                }
                if (!(transaction instanceof AutoCommitTransaction)) {
                    transaction.addPostTransactionAction(new ServerTransaction.Action() {

                        @Override
                        public void postCommit() {
                            updateDisposition(delivery.getDeliveryTag(), null, true);
                        }

                        @Override
                        public void onRollback() {
                            updateDisposition(delivery.getDeliveryTag(), null, true);
                        }
                    });
                }
            } else {
                transaction = new AsyncAutoCommitTransaction(getAddressSpace().getMessageStore(), this);
            }
            try {
                Session_1_0 session = getSession();
                session.getAMQPConnection().checkAuthorizedMessagePrincipal(serverMessage.getMessageHeader().getUserId());
                Outcome outcome;
                if (serverMessage.isPersistent() && !getAddressSpace().getMessageStore().isPersistent()) {
                    final Error preconditionFailedError = new Error(AmqpError.PRECONDITION_FAILED, "Non-durable message store cannot accept durable message.");
                    if (_rejectedOutcomeSupportedBySource) {
                        final Rejected rejected = new Rejected();
                        rejected.setError(preconditionFailedError);
                        outcome = rejected;
                    } else {
                        // TODO - disposition not updated for the non-transaction case
                        return preconditionFailedError;
                    }
                } else {
                    try {
                        getReceivingDestination().send(serverMessage, transaction, session.getSecurityToken());
                        outcome = ACCEPTED;
                    } catch (UnroutableMessageException e) {
                        final Error error = new Error();
                        error.setCondition(e.getErrorCondition());
                        error.setDescription(e.getMessage());
                        String targetAddress = getTarget().getAddress();
                        if (targetAddress == null || "".equals(targetAddress.trim())) {
                            error.setInfo(Collections.singletonMap(DELIVERY_TAG, delivery.getDeliveryTag()));
                        }
                        if (!_rejectedOutcomeSupportedBySource || (delivery.isSettled() && !(transaction instanceof LocalTransaction))) {
                            return error;
                        } else {
                            if (delivery.isSettled() && transaction instanceof LocalTransaction) {
                                ((LocalTransaction) transaction).setRollbackOnly();
                            }
                            Rejected rejected = new Rejected();
                            rejected.setError(error);
                            outcome = rejected;
                        }
                    }
                }
                Outcome sourceDefaultOutcome = getSource().getDefaultOutcome();
                boolean defaultOutcome = sourceDefaultOutcome != null && sourceDefaultOutcome.getSymbol().equals(outcome.getSymbol());
                DeliveryState resultantState;
                if (transactionId == null) {
                    resultantState = defaultOutcome ? null : outcome;
                } else {
                    TransactionalState transactionalState = new TransactionalState();
                    transactionalState.setOutcome(defaultOutcome ? null : outcome);
                    transactionalState.setTxnId(transactionId);
                    resultantState = transactionalState;
                }
                boolean settled = shouldReceiverSettleFirst(transferReceiverSettleMode);
                if (transaction instanceof AsyncAutoCommitTransaction) {
                    _pendingDispositions.add(new PendingDispositionHolder(delivery.getDeliveryTag(), resultantState, settled));
                } else {
                    getSession().receivedComplete();
                    updateDisposition(delivery.getDeliveryTag(), resultantState, settled);
                }
                getSession().getAMQPConnection().registerMessageReceived(serverMessage.getSize());
                if (transactionId != null) {
                    getSession().getAMQPConnection().registerTransactedMessageReceived();
                }
                setRollbackOnly = false;
            } catch (AccessControlException e) {
                final Error err = new Error();
                err.setCondition(AmqpError.NOT_ALLOWED);
                err.setDescription(e.getMessage());
                return err;
            } finally {
                if (setRollbackOnly && transaction instanceof LocalTransaction) {
                    ((LocalTransaction) transaction).setRollbackOnly();
                }
            }
        } finally {
            reference.release();
        }
    }
    return null;
}
Also used : AsyncAutoCommitTransaction(org.apache.qpid.server.txn.AsyncAutoCommitTransaction) AutoCommitTransaction(org.apache.qpid.server.txn.AutoCommitTransaction) AsyncAutoCommitTransaction(org.apache.qpid.server.txn.AsyncAutoCommitTransaction) LocalTransaction(org.apache.qpid.server.txn.LocalTransaction) Rejected(org.apache.qpid.server.protocol.v1_0.type.messaging.Rejected) ReceiverSettleMode(org.apache.qpid.server.protocol.v1_0.type.transport.ReceiverSettleMode) ServerTransaction(org.apache.qpid.server.txn.ServerTransaction) AmqpErrorRuntimeException(org.apache.qpid.server.protocol.v1_0.type.AmqpErrorRuntimeException) MessageFormat(org.apache.qpid.server.plugin.MessageFormat) TransactionError(org.apache.qpid.server.protocol.v1_0.type.transaction.TransactionError) Error(org.apache.qpid.server.protocol.v1_0.type.transport.Error) AmqpError(org.apache.qpid.server.protocol.v1_0.type.transport.AmqpError) AccessControlException(java.security.AccessControlException) TransactionalState(org.apache.qpid.server.protocol.v1_0.type.transaction.TransactionalState) DeliveryState(org.apache.qpid.server.protocol.v1_0.type.DeliveryState) Outcome(org.apache.qpid.server.protocol.v1_0.type.Outcome) QpidByteBuffer(org.apache.qpid.server.bytebuffer.QpidByteBuffer) Binary(org.apache.qpid.server.protocol.v1_0.type.Binary) UnsignedInteger(org.apache.qpid.server.protocol.v1_0.type.UnsignedInteger)

Aggregations

SpecificationTest (org.apache.qpid.tests.protocol.SpecificationTest)12 FrameTransport (org.apache.qpid.tests.protocol.v1_0.FrameTransport)12 Test (org.junit.Test)12 Rejected (org.apache.qpid.server.protocol.v1_0.type.messaging.Rejected)10 TransactionError (org.apache.qpid.server.protocol.v1_0.type.transaction.TransactionError)10 Disposition (org.apache.qpid.server.protocol.v1_0.type.transport.Disposition)10 Error (org.apache.qpid.server.protocol.v1_0.type.transport.Error)10 Interaction (org.apache.qpid.tests.protocol.v1_0.Interaction)10 Binary (org.apache.qpid.server.protocol.v1_0.type.Binary)8 AmqpError (org.apache.qpid.server.protocol.v1_0.type.transport.AmqpError)8 Flow (org.apache.qpid.server.protocol.v1_0.type.transport.Flow)8 UnsignedInteger (org.apache.qpid.server.protocol.v1_0.type.UnsignedInteger)6 Discharge (org.apache.qpid.server.protocol.v1_0.type.transaction.Discharge)6 Attach (org.apache.qpid.server.protocol.v1_0.type.transport.Attach)6 Detach (org.apache.qpid.server.protocol.v1_0.type.transport.Detach)6 DeliveryState (org.apache.qpid.server.protocol.v1_0.type.DeliveryState)5 Begin (org.apache.qpid.server.protocol.v1_0.type.transport.Begin)4 InteractionTransactionalState (org.apache.qpid.tests.protocol.v1_0.InteractionTransactionalState)4 Accepted (org.apache.qpid.server.protocol.v1_0.type.messaging.Accepted)3 Target (org.apache.qpid.server.protocol.v1_0.type.messaging.Target)3