Search in sources :

Example 6 with ActiveMQRAConnectionFactoryImpl

use of org.apache.activemq.artemis.ra.ActiveMQRAConnectionFactoryImpl in project activemq-artemis by apache.

the class OutgoingConnectionTest method testJMSContext.

@Test
public void testJMSContext() throws Exception {
    resourceAdapter = newResourceAdapter();
    MyBootstrapContext ctx = new MyBootstrapContext();
    resourceAdapter.start(ctx);
    ActiveMQRAManagedConnectionFactory mcf = new ActiveMQRAManagedConnectionFactory();
    mcf.setResourceAdapter(resourceAdapter);
    ActiveMQRAConnectionFactory qraConnectionFactory = new ActiveMQRAConnectionFactoryImpl(mcf, qraConnectionManager);
    JMSContext jmsctx = qraConnectionFactory.createContext(JMSContext.DUPS_OK_ACKNOWLEDGE);
    assertEquals(JMSContext.DUPS_OK_ACKNOWLEDGE, jmsctx.getSessionMode());
}
Also used : ActiveMQRAManagedConnectionFactory(org.apache.activemq.artemis.ra.ActiveMQRAManagedConnectionFactory) ActiveMQRAConnectionFactory(org.apache.activemq.artemis.ra.ActiveMQRAConnectionFactory) JMSContext(javax.jms.JMSContext) ActiveMQRAConnectionFactoryImpl(org.apache.activemq.artemis.ra.ActiveMQRAConnectionFactoryImpl) Test(org.junit.Test)

Example 7 with ActiveMQRAConnectionFactoryImpl

use of org.apache.activemq.artemis.ra.ActiveMQRAConnectionFactoryImpl in project activemq-artemis by apache.

the class OutgoingConnectionTest method testInexistentUserOnCreateConnection.

@Test
public void testInexistentUserOnCreateConnection() throws Exception {
    resourceAdapter = newResourceAdapter();
    MyBootstrapContext ctx = new MyBootstrapContext();
    resourceAdapter.start(ctx);
    ActiveMQRAManagedConnectionFactory mcf = new ActiveMQRAManagedConnectionFactory();
    mcf.setResourceAdapter(resourceAdapter);
    ActiveMQRAConnectionFactory qraConnectionFactory = new ActiveMQRAConnectionFactoryImpl(mcf, qraConnectionManager);
    Connection conn = null;
    try {
        conn = qraConnectionFactory.createConnection("IDont", "Exist");
        fail("Exception was expected");
    } catch (JMSSecurityException expected) {
    }
    conn = qraConnectionFactory.createConnection("testuser", "testpassword");
    conn.close();
    try {
        XAConnection xaconn = qraConnectionFactory.createXAConnection("IDont", "Exist");
        fail("Exception was expected");
    } catch (JMSSecurityException expected) {
    }
    XAConnection xaconn = qraConnectionFactory.createXAConnection("testuser", "testpassword");
    xaconn.close();
    try {
        TopicConnection topicconn = qraConnectionFactory.createTopicConnection("IDont", "Exist");
        fail("Exception was expected");
    } catch (JMSSecurityException expected) {
    }
    TopicConnection topicconn = qraConnectionFactory.createTopicConnection("testuser", "testpassword");
    topicconn.close();
    try {
        QueueConnection queueconn = qraConnectionFactory.createQueueConnection("IDont", "Exist");
        fail("Exception was expected");
    } catch (JMSSecurityException expected) {
    }
    QueueConnection queueconn = qraConnectionFactory.createQueueConnection("testuser", "testpassword");
    queueconn.close();
    mcf.stop();
}
Also used : ActiveMQRAManagedConnectionFactory(org.apache.activemq.artemis.ra.ActiveMQRAManagedConnectionFactory) XAQueueConnection(javax.jms.XAQueueConnection) QueueConnection(javax.jms.QueueConnection) JMSSecurityException(javax.jms.JMSSecurityException) XAQueueConnection(javax.jms.XAQueueConnection) XAConnection(javax.jms.XAConnection) ManagedConnection(javax.resource.spi.ManagedConnection) Connection(javax.jms.Connection) TopicConnection(javax.jms.TopicConnection) ActiveMQRAManagedConnection(org.apache.activemq.artemis.ra.ActiveMQRAManagedConnection) QueueConnection(javax.jms.QueueConnection) ActiveMQRAConnectionFactory(org.apache.activemq.artemis.ra.ActiveMQRAConnectionFactory) TopicConnection(javax.jms.TopicConnection) ActiveMQRAConnectionFactoryImpl(org.apache.activemq.artemis.ra.ActiveMQRAConnectionFactoryImpl) XAConnection(javax.jms.XAConnection) Test(org.junit.Test)

Example 8 with ActiveMQRAConnectionFactoryImpl

use of org.apache.activemq.artemis.ra.ActiveMQRAConnectionFactoryImpl in project activemq-artemis by apache.

the class IgnoreJTATest method testSendAndReceive.

private void testSendAndReceive(Boolean ignoreJTA) throws Exception {
    setDummyTX();
    setupDLQ(10);
    resourceAdapter = newResourceAdapter();
    if (ignoreJTA != null) {
        resourceAdapter.setIgnoreJTA(ignoreJTA);
    }
    MyBootstrapContext ctx = new MyBootstrapContext();
    resourceAdapter.start(ctx);
    ActiveMQRAManagedConnectionFactory mcf = new ActiveMQRAManagedConnectionFactory();
    mcf.setResourceAdapter(resourceAdapter);
    ActiveMQRAConnectionFactory qraConnectionFactory = new ActiveMQRAConnectionFactoryImpl(mcf, qraConnectionManager);
    QueueConnection queueConnection = qraConnectionFactory.createQueueConnection();
    Session s = queueConnection.createSession(true, Session.AUTO_ACKNOWLEDGE);
    Queue q = ActiveMQJMSClient.createQueue(MDBQUEUE);
    MessageProducer mp = s.createProducer(q);
    MessageConsumer consumer = s.createConsumer(q);
    Message message = s.createTextMessage("test");
    mp.send(message);
    s.commit();
    queueConnection.start();
    TextMessage textMessage = (TextMessage) consumer.receive(1000);
    assertNotNull(textMessage);
    assertEquals(textMessage.getText(), "test");
    s.rollback();
    textMessage = (TextMessage) consumer.receive(1000);
    assertNotNull(textMessage);
    assertEquals(textMessage.getText(), "test");
    s.commit();
}
Also used : ActiveMQRAManagedConnectionFactory(org.apache.activemq.artemis.ra.ActiveMQRAManagedConnectionFactory) MessageConsumer(javax.jms.MessageConsumer) QueueConnection(javax.jms.QueueConnection) TextMessage(javax.jms.TextMessage) Message(javax.jms.Message) ActiveMQRAConnectionFactory(org.apache.activemq.artemis.ra.ActiveMQRAConnectionFactory) MessageProducer(javax.jms.MessageProducer) Queue(javax.jms.Queue) TextMessage(javax.jms.TextMessage) ActiveMQRAConnectionFactoryImpl(org.apache.activemq.artemis.ra.ActiveMQRAConnectionFactoryImpl) Session(javax.jms.Session)

Example 9 with ActiveMQRAConnectionFactoryImpl

use of org.apache.activemq.artemis.ra.ActiveMQRAConnectionFactoryImpl in project activemq-artemis by apache.

the class JMSContextTest method setUp.

@Override
@Before
public void setUp() throws Exception {
    useDummyTransactionManager();
    super.setUp();
    ActiveMQJAASSecurityManager securityManager = (ActiveMQJAASSecurityManager) server.getSecurityManager();
    securityManager.getConfiguration().addUser("testuser", "testpassword");
    securityManager.getConfiguration().addUser("guest", "guest");
    securityManager.getConfiguration().setDefaultUser("guest");
    securityManager.getConfiguration().addRole("testuser", "arole");
    securityManager.getConfiguration().addRole("guest", "arole");
    Role role = new Role("arole", true, true, true, true, true, true, true, true, true, true);
    Set<Role> roles = new HashSet<>();
    roles.add(role);
    server.getSecurityRepository().addMatch(MDBQUEUEPREFIXED, roles);
    resourceAdapter = new ActiveMQResourceAdapter();
    resourceAdapter.setConnectorClassName(InVMConnectorFactory.class.getName());
    MyBootstrapContext ctx = new MyBootstrapContext();
    resourceAdapter.start(ctx);
    ActiveMQRAManagedConnectionFactory mcf = new ActiveMQRAManagedConnectionFactory();
    mcf.setResourceAdapter(resourceAdapter);
    qraConnectionFactory = new ActiveMQRAConnectionFactoryImpl(mcf, qraConnectionManager);
}
Also used : Role(org.apache.activemq.artemis.core.security.Role) ActiveMQRAManagedConnectionFactory(org.apache.activemq.artemis.ra.ActiveMQRAManagedConnectionFactory) ActiveMQJAASSecurityManager(org.apache.activemq.artemis.spi.core.security.ActiveMQJAASSecurityManager) ActiveMQResourceAdapter(org.apache.activemq.artemis.ra.ActiveMQResourceAdapter) InVMConnectorFactory(org.apache.activemq.artemis.core.remoting.impl.invm.InVMConnectorFactory) HashSet(java.util.HashSet) ActiveMQRAConnectionFactoryImpl(org.apache.activemq.artemis.ra.ActiveMQRAConnectionFactoryImpl) Before(org.junit.Before)

Example 10 with ActiveMQRAConnectionFactoryImpl

use of org.apache.activemq.artemis.ra.ActiveMQRAConnectionFactoryImpl in project activemq-artemis by apache.

the class OutgoingConnectionJTATest method testSimpleMessageSendAndReceiveTransacted.

@Test
public void testSimpleMessageSendAndReceiveTransacted() throws Exception {
    setDummyTX();
    setupDLQ(10);
    resourceAdapter = newResourceAdapter();
    MyBootstrapContext ctx = new MyBootstrapContext();
    resourceAdapter.start(ctx);
    ActiveMQRAManagedConnectionFactory mcf = new ActiveMQRAManagedConnectionFactory();
    mcf.setResourceAdapter(resourceAdapter);
    ActiveMQRAConnectionFactory qraConnectionFactory = new ActiveMQRAConnectionFactoryImpl(mcf, qraConnectionManager);
    QueueConnection queueConnection = qraConnectionFactory.createQueueConnection();
    Session s = queueConnection.createSession(true, Session.AUTO_ACKNOWLEDGE);
    Queue q = ActiveMQJMSClient.createQueue(MDBQUEUE);
    MessageProducer mp = s.createProducer(q);
    MessageConsumer consumer = s.createConsumer(q);
    Message message = s.createTextMessage("test");
    mp.send(message);
    s.commit();
    queueConnection.start();
    TextMessage textMessage = (TextMessage) consumer.receive(1000);
    assertNotNull(textMessage);
    assertEquals(textMessage.getText(), "test");
    s.rollback();
    textMessage = (TextMessage) consumer.receive(1000);
    assertNotNull(textMessage);
    assertEquals(textMessage.getText(), "test");
    s.commit();
}
Also used : ActiveMQRAManagedConnectionFactory(org.apache.activemq.artemis.ra.ActiveMQRAManagedConnectionFactory) MessageConsumer(javax.jms.MessageConsumer) QueueConnection(javax.jms.QueueConnection) ClientMessage(org.apache.activemq.artemis.api.core.client.ClientMessage) Message(javax.jms.Message) TextMessage(javax.jms.TextMessage) ActiveMQRAConnectionFactory(org.apache.activemq.artemis.ra.ActiveMQRAConnectionFactory) MessageProducer(javax.jms.MessageProducer) Queue(javax.jms.Queue) TextMessage(javax.jms.TextMessage) ActiveMQRAConnectionFactoryImpl(org.apache.activemq.artemis.ra.ActiveMQRAConnectionFactoryImpl) Session(javax.jms.Session) ClientSession(org.apache.activemq.artemis.api.core.client.ClientSession) Test(org.junit.Test)

Aggregations

ActiveMQRAConnectionFactoryImpl (org.apache.activemq.artemis.ra.ActiveMQRAConnectionFactoryImpl)20 ActiveMQRAManagedConnectionFactory (org.apache.activemq.artemis.ra.ActiveMQRAManagedConnectionFactory)20 ActiveMQRAConnectionFactory (org.apache.activemq.artemis.ra.ActiveMQRAConnectionFactory)15 QueueConnection (javax.jms.QueueConnection)14 Test (org.junit.Test)14 Session (javax.jms.Session)9 XAQueueConnection (javax.jms.XAQueueConnection)8 ActiveMQResourceAdapter (org.apache.activemq.artemis.ra.ActiveMQResourceAdapter)8 InVMConnectorFactory (org.apache.activemq.artemis.core.remoting.impl.invm.InVMConnectorFactory)7 MessageProducer (javax.jms.MessageProducer)6 QueueSession (javax.jms.QueueSession)6 Message (javax.jms.Message)5 MessageConsumer (javax.jms.MessageConsumer)5 Queue (javax.jms.Queue)5 TextMessage (javax.jms.TextMessage)5 ClientSession (org.apache.activemq.artemis.api.core.client.ClientSession)5 ActiveMQRAManagedConnection (org.apache.activemq.artemis.ra.ActiveMQRAManagedConnection)5 ActiveMQRASession (org.apache.activemq.artemis.ra.ActiveMQRASession)5 Before (org.junit.Before)5 HashSet (java.util.HashSet)4