Search in sources :

Example 1 with QueueConnectionFactory

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

the class TransactionAwareConnectionFactoryProxy method createQueueConnection.

@Override
public QueueConnection createQueueConnection() throws JMSException {
    ConnectionFactory target = obtainTargetConnectionFactory();
    if (!(target instanceof QueueConnectionFactory)) {
        throw new javax.jms.IllegalStateException("'targetConnectionFactory' is no QueueConnectionFactory");
    }
    QueueConnection targetConnection = ((QueueConnectionFactory) target).createQueueConnection();
    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 2 with QueueConnectionFactory

use of javax.jms.QueueConnectionFactory in project jmeter by apache.

the class JMSSampler method threadStarted.

@Override
public void threadStarted() {
    logThreadStart();
    thrown = null;
    try {
        context = getInitialContext();
        Object obj = context.lookup(getQueueConnectionFactory());
        if (!(obj instanceof QueueConnectionFactory)) {
            String msg = "QueueConnectionFactory expected, but got " + (obj != null ? obj.getClass().getName() : "null");
            LOGGER.error(msg);
            throw new IllegalStateException(msg);
        }
        QueueConnectionFactory factory = (QueueConnectionFactory) obj;
        Queue sendQueue = (Queue) context.lookup(getSendQueue());
        if (!useTemporyQueue()) {
            receiveQueue = (Queue) context.lookup(getReceiveQueue());
            receiverThread = Receiver.createReceiver(factory, receiveQueue, Utils.getFromEnvironment(context, Context.SECURITY_PRINCIPAL), Utils.getFromEnvironment(context, Context.SECURITY_CREDENTIALS), isUseResMsgIdAsCorrelId(), getJMSSelector());
        }
        String principal = null;
        String credentials = null;
        if (USE_SECURITY_PROPERTIES) {
            principal = Utils.getFromEnvironment(context, Context.SECURITY_PRINCIPAL);
            credentials = Utils.getFromEnvironment(context, Context.SECURITY_CREDENTIALS);
        }
        if (principal != null && credentials != null) {
            connection = factory.createQueueConnection(principal, credentials);
        } else {
            connection = factory.createQueueConnection();
        }
        session = connection.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
        LOGGER.debug("Session created");
        if (isOneway()) {
            producer = session.createSender(sendQueue);
            if (isNonPersistent()) {
                producer.setDeliveryMode(DeliveryMode.NON_PERSISTENT);
            }
            producer.setPriority(Integer.parseInt(getPriority()));
            producer.setTimeToLive(Long.parseLong(getExpiration()));
        } else {
            if (useTemporyQueue()) {
                executor = new TemporaryQueueExecutor(session, sendQueue);
            } else {
                producer = session.createSender(sendQueue);
                executor = new FixedQueueExecutor(producer, getTimeoutAsInt(), isUseReqMsgIdAsCorrelId());
            }
        }
        LOGGER.debug("Starting connection");
        connection.start();
        LOGGER.debug("Connection started");
    } catch (Exception | NoClassDefFoundError e) {
        thrown = e;
        LOGGER.error(e.getLocalizedMessage(), e);
    }
}
Also used : QueueConnectionFactory(javax.jms.QueueConnectionFactory) Queue(javax.jms.Queue) NamingException(javax.naming.NamingException) JMSException(javax.jms.JMSException)

Example 3 with QueueConnectionFactory

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

the class GetCallerPrincipalTestCase method testMDBLifecycle.

/**
     * Run this one in the container so it can lookup the queue
     * @throws Exception
     */
@OperateOnDeployment("test")
@Test
public void testMDBLifecycle() throws Exception {
    deployer.deploy("mdb");
    SecurityClient client = this.login();
    ITestResultsSingleton results = this.getResultsSingleton();
    MessageProducer producer = null;
    MessageConsumer consumer = null;
    QueueConnection conn = null;
    Session session = null;
    try {
        QueueConnectionFactory qcf = (QueueConnectionFactory) new InitialContext().lookup("java:/ConnectionFactory");
        Queue queue = (Queue) new InitialContext().lookup("java:jboss/" + QUEUE_NAME);
        conn = qcf.createQueueConnection("guest", "guest");
        conn.start();
        session = conn.createQueueSession(false, QueueSession.AUTO_ACKNOWLEDGE);
        TemporaryQueue replyQueue = session.createTemporaryQueue();
        TextMessage msg = session.createTextMessage("Hello world");
        msg.setJMSDeliveryMode(DeliveryMode.NON_PERSISTENT);
        msg.setJMSReplyTo(replyQueue);
        producer = session.createProducer(queue);
        producer.send(msg);
        consumer = session.createConsumer(replyQueue);
        Message replyMsg = consumer.receive(5000);
        Object obj = ((ObjectMessage) replyMsg).getObject();
        log.trace("MDB message get: " + obj);
        Assert.assertEquals(OK + "start", results.getMdb("postconstruct"));
        deployer.undeploy("mdb");
        Assert.assertEquals(OK + "stop", results.getMdb("predestroy"));
    } finally {
        if (consumer != null) {
            consumer.close();
        }
        if (producer != null) {
            producer.close();
        }
        if (session != null) {
            session.close();
        }
        if (conn != null) {
            conn.close();
        }
        client.logout();
    }
}
Also used : SecurityClient(org.jboss.security.client.SecurityClient) MessageConsumer(javax.jms.MessageConsumer) ObjectMessage(javax.jms.ObjectMessage) Message(javax.jms.Message) TextMessage(javax.jms.TextMessage) QueueConnectionFactory(javax.jms.QueueConnectionFactory) InitialContext(javax.naming.InitialContext) QueueConnection(javax.jms.QueueConnection) ObjectMessage(javax.jms.ObjectMessage) TemporaryQueue(javax.jms.TemporaryQueue) MessageProducer(javax.jms.MessageProducer) Queue(javax.jms.Queue) TemporaryQueue(javax.jms.TemporaryQueue) TextMessage(javax.jms.TextMessage) Session(javax.jms.Session) QueueSession(javax.jms.QueueSession) OperateOnDeployment(org.jboss.arquillian.container.test.api.OperateOnDeployment) Test(org.junit.Test)

Example 4 with QueueConnectionFactory

use of javax.jms.QueueConnectionFactory in project tomee by apache.

the class ContextLookupStatefulPojoBean method lookupJMSConnectionFactory.

public void lookupJMSConnectionFactory() throws TestFailureException {
    try {
        try {
            Object obj = ejbContext.lookup("jms");
            Assert.assertNotNull("The JMS ConnectionFactory is null", obj);
            Assert.assertTrue("Not an instance of ConnectionFactory", obj instanceof ConnectionFactory);
            final ConnectionFactory connectionFactory = (ConnectionFactory) obj;
            testJmsConnection(connectionFactory.createConnection());
            obj = ejbContext.lookup("TopicCF");
            Assert.assertNotNull("The JMS TopicConnectionFactory is null", obj);
            Assert.assertTrue("Not an instance of TopicConnectionFactory", obj instanceof TopicConnectionFactory);
            final TopicConnectionFactory topicConnectionFactory = (TopicConnectionFactory) obj;
            testJmsConnection(topicConnectionFactory.createConnection());
            obj = ejbContext.lookup("QueueCF");
            Assert.assertNotNull("The JMS QueueConnectionFactory is null", obj);
            Assert.assertTrue("Not an instance of QueueConnectionFactory", obj instanceof QueueConnectionFactory);
            final QueueConnectionFactory queueConnectionFactory = (QueueConnectionFactory) obj;
            testJmsConnection(queueConnectionFactory.createConnection());
        } catch (final Exception e) {
            e.printStackTrace();
            Assert.fail("Received Exception " + e.getClass() + " : " + e.getMessage());
        }
    } catch (final AssertionFailedError afe) {
        throw new TestFailureException(afe);
    }
}
Also used : TopicConnectionFactory(javax.jms.TopicConnectionFactory) QueueConnectionFactory(javax.jms.QueueConnectionFactory) TopicConnectionFactory(javax.jms.TopicConnectionFactory) ConnectionFactory(javax.jms.ConnectionFactory) QueueConnectionFactory(javax.jms.QueueConnectionFactory) BasicStatelessObject(org.apache.openejb.test.stateless.BasicStatelessObject) BasicBmpObject(org.apache.openejb.test.entity.bmp.BasicBmpObject) TestFailureException(org.apache.openejb.test.TestFailureException) AssertionFailedError(junit.framework.AssertionFailedError) JMSException(javax.jms.JMSException) TestFailureException(org.apache.openejb.test.TestFailureException)

Example 5 with QueueConnectionFactory

use of javax.jms.QueueConnectionFactory in project tomee by apache.

the class ContextLookupStatelessBean method lookupJMSConnectionFactory.

public void lookupJMSConnectionFactory() throws TestFailureException {
    try {
        try {
            Object obj = ejbContext.lookup("jms");
            Assert.assertNotNull("The JMS ConnectionFactory is null", obj);
            Assert.assertTrue("Not an instance of ConnectionFactory", obj instanceof ConnectionFactory);
            final ConnectionFactory connectionFactory = (ConnectionFactory) obj;
            testJmsConnection(connectionFactory.createConnection());
            obj = ejbContext.lookup("TopicCF");
            Assert.assertNotNull("The JMS TopicConnectionFactory is null", obj);
            Assert.assertTrue("Not an instance of TopicConnectionFactory", obj instanceof TopicConnectionFactory);
            final TopicConnectionFactory topicConnectionFactory = (TopicConnectionFactory) obj;
            testJmsConnection(topicConnectionFactory.createConnection());
            obj = ejbContext.lookup("QueueCF");
            Assert.assertNotNull("The JMS QueueConnectionFactory is null", obj);
            Assert.assertTrue("Not an instance of QueueConnectionFactory", obj instanceof QueueConnectionFactory);
            final QueueConnectionFactory queueConnectionFactory = (QueueConnectionFactory) obj;
            testJmsConnection(queueConnectionFactory.createConnection());
        } catch (final Exception e) {
            e.printStackTrace();
            Assert.fail("Received Exception " + e.getClass() + " : " + e.getMessage());
        }
    } catch (final AssertionFailedError afe) {
        throw new TestFailureException(afe);
    }
}
Also used : TopicConnectionFactory(javax.jms.TopicConnectionFactory) QueueConnectionFactory(javax.jms.QueueConnectionFactory) TopicConnectionFactory(javax.jms.TopicConnectionFactory) ConnectionFactory(javax.jms.ConnectionFactory) QueueConnectionFactory(javax.jms.QueueConnectionFactory) BasicStatefulObject(org.apache.openejb.test.stateful.BasicStatefulObject) BasicBmpObject(org.apache.openejb.test.entity.bmp.BasicBmpObject) TestFailureException(org.apache.openejb.test.TestFailureException) AssertionFailedError(junit.framework.AssertionFailedError) JMSException(javax.jms.JMSException) RemoteException(java.rmi.RemoteException) EJBException(javax.ejb.EJBException) TestFailureException(org.apache.openejb.test.TestFailureException)

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