Search in sources :

Example 11 with QueueConnectionFactory

use of javax.jms.QueueConnectionFactory in project spring-framework by spring-projects.

the class SingleConnectionFactoryTests method testCachingConnectionFactoryWithQueueConnectionFactoryAndJms102Usage.

@Test
public void testCachingConnectionFactoryWithQueueConnectionFactoryAndJms102Usage() throws JMSException {
    QueueConnectionFactory cf = mock(QueueConnectionFactory.class);
    QueueConnection con = mock(QueueConnection.class);
    QueueSession txSession = mock(QueueSession.class);
    QueueSession nonTxSession = mock(QueueSession.class);
    given(cf.createQueueConnection()).willReturn(con);
    given(con.createQueueSession(true, Session.AUTO_ACKNOWLEDGE)).willReturn(txSession);
    given(txSession.getTransacted()).willReturn(true);
    given(con.createQueueSession(false, Session.CLIENT_ACKNOWLEDGE)).willReturn(nonTxSession);
    CachingConnectionFactory scf = new CachingConnectionFactory(cf);
    scf.setReconnectOnException(false);
    Connection con1 = scf.createQueueConnection();
    Session session1 = con1.createSession(true, Session.AUTO_ACKNOWLEDGE);
    session1.rollback();
    session1.close();
    session1 = con1.createSession(false, Session.CLIENT_ACKNOWLEDGE);
    session1.close();
    con1.start();
    QueueConnection con2 = scf.createQueueConnection();
    Session session2 = con2.createQueueSession(false, Session.CLIENT_ACKNOWLEDGE);
    session2.close();
    session2 = con2.createSession(true, Session.AUTO_ACKNOWLEDGE);
    session2.getTransacted();
    // should lead to rollback
    session2.close();
    con2.start();
    con1.close();
    con2.close();
    // should trigger actual close
    scf.destroy();
    verify(txSession).rollback();
    verify(txSession).close();
    verify(nonTxSession).close();
    verify(con).start();
    verify(con).stop();
    verify(con).close();
}
Also used : QueueConnection(javax.jms.QueueConnection) QueueConnectionFactory(javax.jms.QueueConnectionFactory) Connection(javax.jms.Connection) TopicConnection(javax.jms.TopicConnection) QueueConnection(javax.jms.QueueConnection) QueueSession(javax.jms.QueueSession) QueueSession(javax.jms.QueueSession) Session(javax.jms.Session) TopicSession(javax.jms.TopicSession) Test(org.junit.Test)

Example 12 with QueueConnectionFactory

use of javax.jms.QueueConnectionFactory in project spring-framework by spring-projects.

the class SingleConnectionFactoryTests method testWithQueueConnectionFactoryAndJms102Usage.

@Test
public void testWithQueueConnectionFactoryAndJms102Usage() throws JMSException {
    QueueConnectionFactory cf = mock(QueueConnectionFactory.class);
    QueueConnection con = mock(QueueConnection.class);
    given(cf.createQueueConnection()).willReturn(con);
    SingleConnectionFactory scf = new SingleConnectionFactory(cf);
    Connection con1 = scf.createQueueConnection();
    Connection con2 = scf.createQueueConnection();
    con1.start();
    con2.start();
    con1.close();
    con2.close();
    // should trigger actual close
    scf.destroy();
    verify(con).start();
    verify(con).stop();
    verify(con).close();
    verifyNoMoreInteractions(con);
}
Also used : QueueConnection(javax.jms.QueueConnection) QueueConnectionFactory(javax.jms.QueueConnectionFactory) Connection(javax.jms.Connection) TopicConnection(javax.jms.TopicConnection) QueueConnection(javax.jms.QueueConnection) Test(org.junit.Test)

Example 13 with QueueConnectionFactory

use of javax.jms.QueueConnectionFactory in project spring-framework by spring-projects.

the class TransactionAwareConnectionFactoryProxy method createQueueConnection.

@Override
public QueueConnection createQueueConnection(String username, String password) throws JMSException {
    ConnectionFactory target = obtainTargetConnectionFactory();
    if (!(target instanceof QueueConnectionFactory)) {
        throw new javax.jms.IllegalStateException("'targetConnectionFactory' is no QueueConnectionFactory");
    }
    QueueConnection targetConnection = ((QueueConnectionFactory) target).createQueueConnection(username, password);
    return (QueueConnection) getTransactionAwareConnectionProxy(targetConnection);
}
Also used : QueueConnectionFactory(javax.jms.QueueConnectionFactory) TopicConnectionFactory(javax.jms.TopicConnectionFactory) ConnectionFactory(javax.jms.ConnectionFactory) QueueConnection(javax.jms.QueueConnection) QueueConnectionFactory(javax.jms.QueueConnectionFactory)

Example 14 with QueueConnectionFactory

use of javax.jms.QueueConnectionFactory in project spring-framework by spring-projects.

the class UserCredentialsConnectionFactoryAdapter method doCreateQueueConnection.

/**
	 * This implementation delegates to the {@code createQueueConnection(username, password)}
	 * method of the target QueueConnectionFactory, passing in the specified user credentials.
	 * If the specified username is empty, it will simply delegate to the standard
	 * {@code createQueueConnection()} method of the target ConnectionFactory.
	 * @param username the username to use
	 * @param password the password to use
	 * @return the Connection
	 * @see javax.jms.QueueConnectionFactory#createQueueConnection(String, String)
	 * @see javax.jms.QueueConnectionFactory#createQueueConnection()
	 */
protected QueueConnection doCreateQueueConnection(String username, String password) throws JMSException {
    ConnectionFactory target = obtainTargetConnectionFactory();
    if (!(target instanceof QueueConnectionFactory)) {
        throw new javax.jms.IllegalStateException("'targetConnectionFactory' is not a QueueConnectionFactory");
    }
    QueueConnectionFactory queueFactory = (QueueConnectionFactory) target;
    if (StringUtils.hasLength(username)) {
        return queueFactory.createQueueConnection(username, password);
    } else {
        return queueFactory.createQueueConnection();
    }
}
Also used : TopicConnectionFactory(javax.jms.TopicConnectionFactory) ConnectionFactory(javax.jms.ConnectionFactory) QueueConnectionFactory(javax.jms.QueueConnectionFactory) QueueConnectionFactory(javax.jms.QueueConnectionFactory)

Example 15 with QueueConnectionFactory

use of javax.jms.QueueConnectionFactory in project wildfly by wildfly.

the class MDBRoleTestCase method testIsMDBinRole.

@Test
public void testIsMDBinRole() throws NamingException, JMSException {
    final InitialContext ctx = new InitialContext();
    final QueueConnectionFactory factory = (QueueConnectionFactory) ctx.lookup("java:/JmsXA");
    final QueueConnection connection = factory.createQueueConnection();
    connection.start();
    final QueueSession session = connection.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
    final Queue replyDestination = session.createTemporaryQueue();
    final QueueReceiver receiver = session.createReceiver(replyDestination);
    final Message message = session.createTextMessage("Let's test it!");
    message.setJMSReplyTo(replyDestination);
    final Destination destination = (Destination) ctx.lookup("queue/myAwesomeQueue");
    final MessageProducer producer = session.createProducer(destination);
    producer.send(message);
    producer.close();
    final Message reply = receiver.receive(TimeoutUtil.adjust(5000));
    assertNotNull(reply);
    final String result = ((TextMessage) reply).getText();
    assertEquals(SimpleSLSB.SUCCESS, result);
    connection.close();
}
Also used : Destination(javax.jms.Destination) QueueConnection(javax.jms.QueueConnection) Message(javax.jms.Message) TextMessage(javax.jms.TextMessage) QueueConnectionFactory(javax.jms.QueueConnectionFactory) QueueReceiver(javax.jms.QueueReceiver) MessageProducer(javax.jms.MessageProducer) Queue(javax.jms.Queue) InitialContext(javax.naming.InitialContext) QueueSession(javax.jms.QueueSession) TextMessage(javax.jms.TextMessage) Test(org.junit.Test)

Aggregations

QueueConnectionFactory (javax.jms.QueueConnectionFactory)27 ConnectionFactory (javax.jms.ConnectionFactory)18 TopicConnectionFactory (javax.jms.TopicConnectionFactory)18 JMSException (javax.jms.JMSException)16 AssertionFailedError (junit.framework.AssertionFailedError)15 TestFailureException (org.apache.openejb.test.TestFailureException)15 EJBException (javax.ejb.EJBException)13 InitialContext (javax.naming.InitialContext)11 BasicStatefulObject (org.apache.openejb.test.stateful.BasicStatefulObject)11 BasicStatelessObject (org.apache.openejb.test.stateless.BasicStatelessObject)11 RemoteException (java.rmi.RemoteException)10 QueueConnection (javax.jms.QueueConnection)10 BasicBmpObject (org.apache.openejb.test.entity.bmp.BasicBmpObject)10 Test (org.junit.Test)7 Queue (javax.jms.Queue)6 QueueSession (javax.jms.QueueSession)6 Message (javax.jms.Message)5 MessageProducer (javax.jms.MessageProducer)5 TextMessage (javax.jms.TextMessage)5 RemoveException (javax.ejb.RemoveException)4