Search in sources :

Example 6 with AmqpClient

use of org.apache.activemq.transport.amqp.client.AmqpClient in project activemq-artemis by apache.

the class AmqpSecurityTest method testSaslAuthWithInvalidCredentials.

@Test(timeout = 60000)
public void testSaslAuthWithInvalidCredentials() throws Exception {
    AmqpConnection connection = null;
    AmqpClient client = createAmqpClient(fullUser, guestUser);
    try {
        connection = client.connect();
        fail("Should not authenticate when invalid credentials provided");
    } catch (Exception ex) {
    // Expected
    } finally {
        if (connection != null) {
            connection.close();
        }
    }
}
Also used : AmqpConnection(org.apache.activemq.transport.amqp.client.AmqpConnection) AmqpClient(org.apache.activemq.transport.amqp.client.AmqpClient) Test(org.junit.Test)

Example 7 with AmqpClient

use of org.apache.activemq.transport.amqp.client.AmqpClient in project activemq-artemis by apache.

the class AmqpSecurityTest method testSaslAuthWithoutAuthzid.

@Test(timeout = 60000)
public void testSaslAuthWithoutAuthzid() throws Exception {
    AmqpConnection connection = null;
    AmqpClient client = createAmqpClient(guestUser, guestPass);
    try {
        connection = client.connect();
    } catch (Exception ex) {
        fail("Should authenticate even with authzid set");
    } finally {
        if (connection != null) {
            connection.close();
        }
    }
}
Also used : AmqpConnection(org.apache.activemq.transport.amqp.client.AmqpConnection) AmqpClient(org.apache.activemq.transport.amqp.client.AmqpClient) Test(org.junit.Test)

Example 8 with AmqpClient

use of org.apache.activemq.transport.amqp.client.AmqpClient in project activemq-artemis by apache.

the class AmqpSecurityTest method testSendMessageFailsOnAnonymousRelayWhenNotAuthorizedToSendToAddress.

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

        @Override
        public void inspectDeliveryUpdate(Sender sender, Delivery delivery) {
            DeliveryState state = delivery.getRemoteState();
            if (!delivery.remotelySettled()) {
                markAsInvalid("delivery is not remotely settled");
            }
            if (state instanceof Rejected) {
                Rejected rejected = (Rejected) state;
                if (rejected.getError() == null || rejected.getError().getCondition() == null) {
                    markAsInvalid("Delivery should have been Rejected with an error condition");
                } else {
                    ErrorCondition error = rejected.getError();
                    if (!error.getCondition().equals(AmqpError.UNAUTHORIZED_ACCESS)) {
                        markAsInvalid("Should have been tagged with unauthorized access error");
                    }
                }
            } else {
                markAsInvalid("Delivery should have been Rejected");
            }
            latch.countDown();
        }
    });
    AmqpConnection connection = client.connect();
    try {
        AmqpSession session = connection.createSession();
        AmqpSender sender = session.createAnonymousSender();
        AmqpMessage message = new AmqpMessage();
        message.setAddress(getQueueName());
        message.setMessageId("msg" + 1);
        message.setText("Test-Message");
        try {
            sender.send(message);
            fail("Should not be able to send, message should be rejected");
        } catch (Exception ex) {
            ex.printStackTrace();
        } finally {
            sender.close();
        }
        assertTrue(latch.await(5000, TimeUnit.MILLISECONDS));
        connection.getStateInspector().assertValid();
    } finally {
        connection.close();
    }
}
Also used : AmqpConnection(org.apache.activemq.transport.amqp.client.AmqpConnection) ErrorCondition(org.apache.qpid.proton.amqp.transport.ErrorCondition) AmqpClient(org.apache.activemq.transport.amqp.client.AmqpClient) Rejected(org.apache.qpid.proton.amqp.messaging.Rejected) CountDownLatch(java.util.concurrent.CountDownLatch) AmqpSender(org.apache.activemq.transport.amqp.client.AmqpSender) AmqpMessage(org.apache.activemq.transport.amqp.client.AmqpMessage) AmqpValidator(org.apache.activemq.transport.amqp.client.AmqpValidator) AmqpSender(org.apache.activemq.transport.amqp.client.AmqpSender) Sender(org.apache.qpid.proton.engine.Sender) AmqpSession(org.apache.activemq.transport.amqp.client.AmqpSession) DeliveryState(org.apache.qpid.proton.amqp.transport.DeliveryState) Delivery(org.apache.qpid.proton.engine.Delivery) Test(org.junit.Test)

Example 9 with AmqpClient

use of org.apache.activemq.transport.amqp.client.AmqpClient in project activemq-artemis by apache.

the class AmqpSendReceiveTest method testCloseBusyReceiver.

@Test(timeout = 60000)
public void testCloseBusyReceiver() throws Exception {
    final int MSG_COUNT = 20;
    AmqpClient client = createAmqpClient();
    AmqpConnection connection = addConnection(client.connect());
    AmqpSession session = connection.createSession();
    AmqpSender sender = session.createSender(getQueueName());
    for (int i = 0; i < MSG_COUNT; i++) {
        AmqpMessage message = new AmqpMessage();
        message.setMessageId("msg" + i);
        message.setMessageAnnotation("serialNo", i);
        message.setText("Test-Message");
        System.out.println("Sending message: " + message.getMessageId());
        sender.send(message);
    }
    sender.close();
    Queue queue = getProxyToQueue(getQueueName());
    Wait.assertEquals(MSG_COUNT, queue::getMessageCount);
    AmqpReceiver receiver1 = session.createReceiver(getQueueName());
    receiver1.flow(MSG_COUNT);
    AmqpMessage received = receiver1.receive(5, TimeUnit.SECONDS);
    assertNotNull("Should have got a message", received);
    assertEquals("msg0", received.getMessageId());
    receiver1.close();
    AmqpReceiver receiver2 = session.createReceiver(getQueueName());
    receiver2.flow(200);
    for (int i = 0; i < MSG_COUNT; ++i) {
        received = receiver2.receive(5, TimeUnit.SECONDS);
        assertNotNull("Should have got a message", received);
        System.out.println("Read message: " + received.getMessageId());
        assertEquals("msg" + i, received.getMessageId());
    }
    receiver2.close();
    connection.close();
}
Also used : AmqpConnection(org.apache.activemq.transport.amqp.client.AmqpConnection) AmqpSession(org.apache.activemq.transport.amqp.client.AmqpSession) AmqpReceiver(org.apache.activemq.transport.amqp.client.AmqpReceiver) AmqpClient(org.apache.activemq.transport.amqp.client.AmqpClient) AmqpSender(org.apache.activemq.transport.amqp.client.AmqpSender) Queue(org.apache.activemq.artemis.core.server.Queue) AmqpMessage(org.apache.activemq.transport.amqp.client.AmqpMessage) Test(org.junit.Test)

Example 10 with AmqpClient

use of org.apache.activemq.transport.amqp.client.AmqpClient in project activemq-artemis by apache.

the class AmqpSendReceiveTest method testReceiveMessageAndRefillCreditBeforeAccept.

@Test(timeout = 60000)
public void testReceiveMessageAndRefillCreditBeforeAccept() throws Exception {
    AmqpClient client = createAmqpClient();
    AmqpConnection connection = addConnection(client.connect());
    AmqpSession session = connection.createSession();
    final String address = getQueueName();
    AmqpReceiver receiver = session.createReceiver(address);
    AmqpSender sender = session.createSender(address);
    for (int i = 0; i < 2; i++) {
        AmqpMessage message = new AmqpMessage();
        message.setMessageId("msg" + i);
        sender.send(message);
    }
    sender.close();
    receiver.flow(1);
    AmqpMessage received = receiver.receive(5, TimeUnit.SECONDS);
    assertNotNull(received);
    receiver.flow(1);
    received.accept();
    received = receiver.receive(10, TimeUnit.SECONDS);
    assertNotNull(received);
    received.accept();
    receiver.close();
    connection.close();
}
Also used : AmqpConnection(org.apache.activemq.transport.amqp.client.AmqpConnection) AmqpSession(org.apache.activemq.transport.amqp.client.AmqpSession) AmqpReceiver(org.apache.activemq.transport.amqp.client.AmqpReceiver) AmqpClient(org.apache.activemq.transport.amqp.client.AmqpClient) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) AmqpSender(org.apache.activemq.transport.amqp.client.AmqpSender) AmqpMessage(org.apache.activemq.transport.amqp.client.AmqpMessage) Test(org.junit.Test)

Aggregations

AmqpClient (org.apache.activemq.transport.amqp.client.AmqpClient)183 AmqpConnection (org.apache.activemq.transport.amqp.client.AmqpConnection)183 AmqpSession (org.apache.activemq.transport.amqp.client.AmqpSession)168 Test (org.junit.Test)158 AmqpReceiver (org.apache.activemq.transport.amqp.client.AmqpReceiver)123 AmqpMessage (org.apache.activemq.transport.amqp.client.AmqpMessage)114 AmqpSender (org.apache.activemq.transport.amqp.client.AmqpSender)91 Queue (org.apache.activemq.artemis.core.server.Queue)70 Source (org.apache.qpid.proton.amqp.messaging.Source)25 AddressInfo (org.apache.activemq.artemis.core.server.impl.AddressInfo)22 AmqpValidator (org.apache.activemq.transport.amqp.client.AmqpValidator)21 SimpleString (org.apache.activemq.artemis.api.core.SimpleString)14 Receiver (org.apache.qpid.proton.engine.Receiver)12 CountDownLatch (java.util.concurrent.CountDownLatch)8 Map (java.util.Map)7 AddressSettings (org.apache.activemq.artemis.core.settings.impl.AddressSettings)7 RemotingConnection (org.apache.activemq.artemis.spi.core.protocol.RemotingConnection)7 Sender (org.apache.qpid.proton.engine.Sender)7 URI (java.net.URI)6 HashMap (java.util.HashMap)6