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();
}
}
}
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();
}
}
}
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();
}
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();
}
}
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();
}
}
}
Aggregations