Search in sources :

Example 26 with ErrorCondition

use of org.apache.qpid.proton.amqp.transport.ErrorCondition in project activemq-artemis by apache.

the class AmqpSecurityTest method testSendAndRejected.

@Test(timeout = 60000)
public void testSendAndRejected() throws Exception {
    AmqpClient client = createAmqpClient(guestUser, guestPass);
    client.setValidator(new AmqpValidator() {

        @Override
        public void inspectOpenedResource(Sender sender) {
            ErrorCondition condition = sender.getRemoteCondition();
            if (condition != null && condition.getCondition() != null) {
                if (!condition.getCondition().equals(AmqpError.UNAUTHORIZED_ACCESS)) {
                    markAsInvalid("Should have been tagged with unauthorized access error");
                }
            } else {
                markAsInvalid("Sender should have been opened with an error");
            }
        }
    });
    AmqpConnection connection = addConnection(client.connect());
    AmqpSession session = connection.createSession();
    try {
        try {
            session.createSender(getQueueName());
            fail("Should not be able to consume here.");
        } catch (Exception ex) {
            IntegrationTestLogger.LOGGER.info("Caught expected exception");
        }
        connection.getStateInspector().assertValid();
    } finally {
        connection.close();
    }
}
Also used : AmqpSender(org.apache.activemq.transport.amqp.client.AmqpSender) Sender(org.apache.qpid.proton.engine.Sender) AmqpConnection(org.apache.activemq.transport.amqp.client.AmqpConnection) AmqpSession(org.apache.activemq.transport.amqp.client.AmqpSession) ErrorCondition(org.apache.qpid.proton.amqp.transport.ErrorCondition) AmqpClient(org.apache.activemq.transport.amqp.client.AmqpClient) AmqpValidator(org.apache.activemq.transport.amqp.client.AmqpValidator) Test(org.junit.Test)

Example 27 with ErrorCondition

use of org.apache.qpid.proton.amqp.transport.ErrorCondition in project activemq-artemis by apache.

the class AmqpSecurityTest method testConsumerNotAuthorizedToCreateQueues.

@Test(timeout = 30000)
public void testConsumerNotAuthorizedToCreateQueues() throws Exception {
    AmqpClient client = createAmqpClient(noprivUser, noprivPass);
    client.setValidator(new AmqpValidator() {

        @Override
        public void inspectOpenedResource(Sender sender) {
            ErrorCondition condition = sender.getRemoteCondition();
            if (condition != null && condition.getCondition() != null) {
                if (!condition.getCondition().equals(AmqpError.UNAUTHORIZED_ACCESS)) {
                    markAsInvalid("Should have been tagged with unauthorized access error");
                }
            } else {
                markAsInvalid("Sender should have been opened with an error");
            }
        }
    });
    AmqpConnection connection = client.connect();
    try {
        AmqpSession session = connection.createSession();
        try {
            session.createReceiver(getQueueName(getPrecreatedQueueSize() + 1));
            fail("Should not be able to consume here.");
        } catch (Exception ex) {
            IntegrationTestLogger.LOGGER.info("Caught expected exception");
        }
        connection.getStateInspector().assertValid();
    } finally {
        connection.close();
    }
}
Also used : AmqpSender(org.apache.activemq.transport.amqp.client.AmqpSender) Sender(org.apache.qpid.proton.engine.Sender) AmqpConnection(org.apache.activemq.transport.amqp.client.AmqpConnection) AmqpSession(org.apache.activemq.transport.amqp.client.AmqpSession) ErrorCondition(org.apache.qpid.proton.amqp.transport.ErrorCondition) AmqpClient(org.apache.activemq.transport.amqp.client.AmqpClient) AmqpValidator(org.apache.activemq.transport.amqp.client.AmqpValidator) Test(org.junit.Test)

Example 28 with ErrorCondition

use of org.apache.qpid.proton.amqp.transport.ErrorCondition in project activemq-artemis by apache.

the class AmqpSecurityTest method testReceiverNotAuthorized.

@Test(timeout = 30000)
public void testReceiverNotAuthorized() throws Exception {
    AmqpClient client = createAmqpClient(noprivUser, noprivPass);
    client.setValidator(new AmqpValidator() {

        @Override
        public void inspectOpenedResource(Receiver receiver) {
            ErrorCondition condition = receiver.getRemoteCondition();
            if (condition != null && condition.getCondition() != null) {
                if (!condition.getCondition().equals(AmqpError.UNAUTHORIZED_ACCESS)) {
                    markAsInvalid("Should have been tagged with unauthorized access error");
                }
            } else {
                markAsInvalid("Receiver should have been opened with an error");
            }
        }
    });
    AmqpConnection connection = client.connect();
    try {
        AmqpSession session = connection.createSession();
        try {
            session.createReceiver(getQueueName());
            fail("Should not be able to consume here.");
        } catch (Exception ex) {
            IntegrationTestLogger.LOGGER.info("Caught expected exception");
        }
        connection.getStateInspector().assertValid();
    } finally {
        connection.close();
    }
}
Also used : AmqpConnection(org.apache.activemq.transport.amqp.client.AmqpConnection) AmqpSession(org.apache.activemq.transport.amqp.client.AmqpSession) ErrorCondition(org.apache.qpid.proton.amqp.transport.ErrorCondition) AmqpClient(org.apache.activemq.transport.amqp.client.AmqpClient) Receiver(org.apache.qpid.proton.engine.Receiver) AmqpValidator(org.apache.activemq.transport.amqp.client.AmqpValidator) Test(org.junit.Test)

Example 29 with ErrorCondition

use of org.apache.qpid.proton.amqp.transport.ErrorCondition in project activemq-artemis by apache.

the class AmqpInboundConnectionTest method testCannotConnectWithSameContainerId.

@Test(timeout = 60000)
public void testCannotConnectWithSameContainerId() throws Exception {
    AmqpClient client = createAmqpClient();
    List<Symbol> desiredCapabilities = new ArrayList<>(1);
    desiredCapabilities.add(AmqpSupport.SOLE_CONNECTION_CAPABILITY);
    assertNotNull(client);
    AmqpConnection connection1 = addConnection(client.createConnection());
    AmqpConnection connection2 = addConnection(client.createConnection());
    connection1.setDesiredCapabilities(desiredCapabilities);
    connection2.setDesiredCapabilities(desiredCapabilities);
    connection1.setContainerId(getTestName());
    connection2.setContainerId(getTestName());
    connection1.connect();
    assertEquals(1, server.getConnectionCount());
    connection2.setStateInspector(new AmqpValidator() {

        @Override
        public void inspectOpenedResource(Connection connection) {
            if (!connection.getRemoteProperties().containsKey(CONNECTION_OPEN_FAILED)) {
                markAsInvalid("Broker did not set connection establishment failed property");
            }
        }

        @Override
        public void inspectClosedResource(Connection connection) {
            ErrorCondition remoteError = connection.getRemoteCondition();
            if (remoteError == null || remoteError.getCondition() == null) {
                markAsInvalid("Broker did not add error condition for duplicate client ID");
            } else {
                if (!remoteError.getCondition().equals(AmqpError.INVALID_FIELD)) {
                    markAsInvalid("Broker did not set condition to " + AmqpError.INVALID_FIELD);
                }
                if (!remoteError.getCondition().equals(AmqpError.INVALID_FIELD)) {
                    markAsInvalid("Broker did not set condition to " + AmqpError.INVALID_FIELD);
                }
            }
            // Validate the info map contains a hint that the container/client id was the
            // problem
            Map<?, ?> infoMap = remoteError.getInfo();
            if (infoMap == null) {
                markAsInvalid("Broker did not set an info map on condition");
            } else if (!infoMap.containsKey(INVALID_FIELD)) {
                markAsInvalid("Info map does not contain expected key");
            } else {
                Object value = infoMap.get(INVALID_FIELD);
                if (!CONTAINER_ID.equals(value)) {
                    markAsInvalid("Info map does not contain expected value: " + value);
                }
            }
        }
    });
    try {
        connection2.connect();
        fail("Should not be able to connect with same container Id.");
    } catch (Exception ex) {
        LOG.info("Second connection with same container Id failed as expected.");
    }
    connection2.getStateInspector().assertValid();
    connection2.close();
    Wait.assertEquals(1, server::getConnectionCount);
    connection1.close();
    Wait.assertEquals(0, server::getConnectionCount);
}
Also used : AmqpConnection(org.apache.activemq.transport.amqp.client.AmqpConnection) Symbol(org.apache.qpid.proton.amqp.Symbol) ErrorCondition(org.apache.qpid.proton.amqp.transport.ErrorCondition) ArrayList(java.util.ArrayList) RemotingConnection(org.apache.activemq.artemis.spi.core.protocol.RemotingConnection) AmqpConnection(org.apache.activemq.transport.amqp.client.AmqpConnection) Connection(org.apache.qpid.proton.engine.Connection) AmqpClient(org.apache.activemq.transport.amqp.client.AmqpClient) AmqpValidator(org.apache.activemq.transport.amqp.client.AmqpValidator) Map(java.util.Map) Test(org.junit.Test)

Example 30 with ErrorCondition

use of org.apache.qpid.proton.amqp.transport.ErrorCondition in project activemq-artemis by apache.

the class AmqpSender method processDeliveryUpdates.

@Override
public void processDeliveryUpdates(AmqpConnection connection, Delivery updated) throws IOException {
    List<Delivery> toRemove = new ArrayList<>();
    for (Delivery delivery : pending) {
        DeliveryState state = delivery.getRemoteState();
        if (state == null) {
            continue;
        }
        doDeliveryUpdateInspection(delivery);
        Outcome outcome = null;
        if (state instanceof TransactionalState) {
            LOG.trace("State of delivery is Transactional, retrieving outcome: {}", state);
            outcome = ((TransactionalState) state).getOutcome();
        } else if (state instanceof Outcome) {
            outcome = (Outcome) state;
        } else {
            LOG.warn("Message send updated with unsupported state: {}", state);
            outcome = null;
        }
        AsyncResult request = (AsyncResult) delivery.getContext();
        Exception deliveryError = null;
        if (outcome instanceof Accepted) {
            LOG.trace("Outcome of delivery was accepted: {}", delivery);
            if (request != null && !request.isComplete()) {
                request.onSuccess();
            }
        } else if (outcome instanceof Rejected) {
            LOG.trace("Outcome of delivery was rejected: {}", delivery);
            ErrorCondition remoteError = ((Rejected) outcome).getError();
            if (remoteError == null) {
                remoteError = getEndpoint().getRemoteCondition();
            }
            deliveryError = AmqpSupport.convertToException(remoteError);
        } else if (outcome instanceof Released) {
            LOG.trace("Outcome of delivery was released: {}", delivery);
            deliveryError = new IOException("Delivery failed: released by receiver");
        } else if (outcome instanceof Modified) {
            LOG.trace("Outcome of delivery was modified: {}", delivery);
            deliveryError = new IOException("Delivery failed: failure at remote");
        }
        if (deliveryError != null) {
            if (request != null && !request.isComplete()) {
                request.onFailure(deliveryError);
            } else {
                connection.fireClientException(deliveryError);
            }
        }
        tagGenerator.returnTag(delivery.getTag());
        delivery.settle();
        toRemove.add(delivery);
    }
    pending.removeAll(toRemove);
}
Also used : Released(org.apache.qpid.proton.amqp.messaging.Released) Modified(org.apache.qpid.proton.amqp.messaging.Modified) ErrorCondition(org.apache.qpid.proton.amqp.transport.ErrorCondition) ArrayList(java.util.ArrayList) Rejected(org.apache.qpid.proton.amqp.messaging.Rejected) IOException(java.io.IOException) InvalidDestinationException(javax.jms.InvalidDestinationException) IOException(java.io.IOException) Accepted(org.apache.qpid.proton.amqp.messaging.Accepted) TransactionalState(org.apache.qpid.proton.amqp.transaction.TransactionalState) DeliveryState(org.apache.qpid.proton.amqp.transport.DeliveryState) Outcome(org.apache.qpid.proton.amqp.messaging.Outcome) Delivery(org.apache.qpid.proton.engine.Delivery) AsyncResult(org.apache.activemq.transport.amqp.client.util.AsyncResult)

Aggregations

ErrorCondition (org.apache.qpid.proton.amqp.transport.ErrorCondition)45 Symbol (org.apache.qpid.proton.amqp.Symbol)13 Test (org.junit.Test)11 Handler (io.vertx.core.Handler)10 ProtonConnection (io.vertx.proton.ProtonConnection)10 DeliveryState (org.apache.qpid.proton.amqp.transport.DeliveryState)10 Message (org.apache.qpid.proton.message.Message)10 Vertx (io.vertx.core.Vertx)8 Logger (io.vertx.core.impl.logging.Logger)8 LoggerFactory (io.vertx.core.impl.logging.LoggerFactory)8 ExecutionException (java.util.concurrent.ExecutionException)8 TimeUnit (java.util.concurrent.TimeUnit)8 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)8 Rejected (org.apache.qpid.proton.amqp.messaging.Rejected)8 ProtonClient (io.vertx.proton.ProtonClient)7 Map (java.util.Map)7 CountDownLatch (java.util.concurrent.CountDownLatch)7 MockServer (io.vertx.proton.MockServer)6 AtomicReference (java.util.concurrent.atomic.AtomicReference)6 Proton (org.apache.qpid.proton.Proton)6