Search in sources :

Example 1 with ClientSession

use of org.apache.activemq.artemis.api.core.client.ClientSession in project wildfly by wildfly.

the class SecurityTestCase method testUnsuccessfulAuthorization.

@Test
public void testUnsuccessfulAuthorization() throws Exception {
    final String queueName = "queue.testUnsuccessfulAuthorization";
    final ClientSessionFactory sf = createClientSessionFactory(managementClient.getMgmtAddress(), managementClient.getWebUri().getPort());
    ClientSession session = null;
    try {
        session = sf.createSession("guest", "guest", false, true, true, false, 1);
        session.createQueue(queueName, queueName, true);
        fail("Must not create a durable queue without the CREATE_DURABLE_QUEUE permission");
    } catch (ActiveMQException e) {
        assertEquals(ActiveMQExceptionType.SECURITY_EXCEPTION, e.getType());
        assertTrue(e.getMessage().startsWith("AMQ119032"));
        assertTrue(e.getMessage().contains(CheckType.CREATE_DURABLE_QUEUE.toString()));
    } finally {
        if (session != null) {
            session.close();
        }
    }
}
Also used : ActiveMQException(org.apache.activemq.artemis.api.core.ActiveMQException) ClientSession(org.apache.activemq.artemis.api.core.client.ClientSession) ClientSessionFactory(org.apache.activemq.artemis.api.core.client.ClientSessionFactory) Test(org.junit.Test)

Example 2 with ClientSession

use of org.apache.activemq.artemis.api.core.client.ClientSession in project wildfly by wildfly.

the class SecurityTestCase method testSuccessfulAuthorization.

@Test
public void testSuccessfulAuthorization() throws Exception {
    final String queueName = "queue.testSuccessfulAuthorization";
    final ClientSessionFactory sf = createClientSessionFactory(managementClient.getMgmtAddress(), managementClient.getWebUri().getPort());
    ClientSession session = null;
    try {
        session = sf.createSession("guest", "guest", false, true, true, false, 1);
        session.createQueue(queueName, queueName, false);
        ClientConsumer messageConsumer = session.createConsumer(queueName);
        session.start();
        session.stop();
        messageConsumer.close();
        session.deleteQueue(queueName);
    } finally {
        if (session != null) {
            session.close();
        }
    }
}
Also used : ClientSession(org.apache.activemq.artemis.api.core.client.ClientSession) ClientSessionFactory(org.apache.activemq.artemis.api.core.client.ClientSessionFactory) ClientConsumer(org.apache.activemq.artemis.api.core.client.ClientConsumer) Test(org.junit.Test)

Example 3 with ClientSession

use of org.apache.activemq.artemis.api.core.client.ClientSession in project wildfly by wildfly.

the class ArtemisMessagingTestCase method start.

@Before
public void start() throws Exception {
    //Not using JNDI so we use the core services directly
    sf = ActiveMQClient.createServerLocatorWithoutHA(new TransportConfiguration(InVMConnectorFactory.class.getName())).createSessionFactory();
    session = sf.createSession();
    //Create a queue
    ClientSession coreSession = sf.createSession();
    coreSession.createQueue(QUEUE_EXAMPLE_QUEUE, QUEUE_EXAMPLE_QUEUE, false);
    coreSession.close();
    session = sf.createSession();
    session.start();
}
Also used : ClientSession(org.apache.activemq.artemis.api.core.client.ClientSession) TransportConfiguration(org.apache.activemq.artemis.api.core.TransportConfiguration) Before(org.junit.Before)

Example 4 with ClientSession

use of org.apache.activemq.artemis.api.core.client.ClientSession in project wildfly by wildfly.

the class MessagingClientTestCase method doMessagingClient.

private void doMessagingClient(ClientSessionFactory sf) throws Exception {
    final String queueName = "queue.standalone";
    final ModelControllerClient client = managementClient.getControllerClient();
    // Check that the queue does not exists
    if (queueExists(queueName, sf)) {
        throw new IllegalStateException();
    }
    // Create a new core queue using the standalone client
    ModelNode op = new ModelNode();
    op.get("operation").set("add");
    op.get("address").add("subsystem", "messaging-activemq");
    op.get("address").add("server", "default");
    op.get("address").add("queue", queueName);
    op.get("queue-address").set(queueName);
    applyUpdate(op, client);
    // Check if the queue exists
    if (!queueExists(queueName, sf)) {
        throw new IllegalStateException();
    }
    ClientSession session = null;
    try {
        session = sf.createSession("guest", "guest", false, true, true, false, 1);
        ClientProducer producer = session.createProducer(queueName);
        ClientMessage message = session.createMessage(false);
        final String propName = "myprop";
        message.putStringProperty(propName, "Hello sent at " + new Date());
        producer.send(message);
        ClientConsumer messageConsumer = session.createConsumer(queueName);
        session.start();
        ClientMessage messageReceived = messageConsumer.receive(1000);
        assertNotNull("a message MUST have been received", messageReceived);
    } finally {
        if (session != null) {
            session.close();
        }
    }
    op = new ModelNode();
    op.get("operation").set("remove");
    op.get("address").add("subsystem", "messaging-activemq");
    op.get("address").add("server", "default");
    op.get("address").add("queue", queueName);
    applyUpdate(op, client);
    // Check that the queue does not exists
    if (queueExists(queueName, sf)) {
        throw new IllegalStateException();
    }
}
Also used : IllegalStateException(javax.resource.spi.IllegalStateException) ModelControllerClient(org.jboss.as.controller.client.ModelControllerClient) ClientSession(org.apache.activemq.artemis.api.core.client.ClientSession) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) ClientMessage(org.apache.activemq.artemis.api.core.client.ClientMessage) ModelNode(org.jboss.dmr.ModelNode) ClientConsumer(org.apache.activemq.artemis.api.core.client.ClientConsumer) ClientProducer(org.apache.activemq.artemis.api.core.client.ClientProducer) Date(java.util.Date)

Example 5 with ClientSession

use of org.apache.activemq.artemis.api.core.client.ClientSession in project wildfly by wildfly.

the class SecurityTestCase method testSuccessfulAuthentication.

@Test
public void testSuccessfulAuthentication() throws Exception {
    final ClientSessionFactory sf = createClientSessionFactory(managementClient.getMgmtAddress(), managementClient.getWebUri().getPort());
    ClientSession session = null;
    try {
        session = sf.createSession("guest", "guest", false, true, true, false, 1);
        assertNotNull(session);
    } finally {
        if (session != null) {
            session.close();
        }
    }
}
Also used : ClientSession(org.apache.activemq.artemis.api.core.client.ClientSession) ClientSessionFactory(org.apache.activemq.artemis.api.core.client.ClientSessionFactory) Test(org.junit.Test)

Aggregations

ClientSession (org.apache.activemq.artemis.api.core.client.ClientSession)7 ClientSessionFactory (org.apache.activemq.artemis.api.core.client.ClientSessionFactory)4 Test (org.junit.Test)3 TransportConfiguration (org.apache.activemq.artemis.api.core.TransportConfiguration)2 ClientConsumer (org.apache.activemq.artemis.api.core.client.ClientConsumer)2 File (java.io.File)1 FileInputStream (java.io.FileInputStream)1 InputStream (java.io.InputStream)1 Date (java.util.Date)1 IllegalStateException (javax.resource.spi.IllegalStateException)1 ActiveMQException (org.apache.activemq.artemis.api.core.ActiveMQException)1 SimpleString (org.apache.activemq.artemis.api.core.SimpleString)1 ClientMessage (org.apache.activemq.artemis.api.core.client.ClientMessage)1 ClientProducer (org.apache.activemq.artemis.api.core.client.ClientProducer)1 ServerLocator (org.apache.activemq.artemis.api.core.client.ServerLocator)1 XmlDataImporter (org.apache.activemq.artemis.cli.commands.tools.XmlDataImporter)1 OperationFailedException (org.jboss.as.controller.OperationFailedException)1 ModelControllerClient (org.jboss.as.controller.client.ModelControllerClient)1 ModelNode (org.jboss.dmr.ModelNode)1 After (org.junit.After)1