Java 类javax.jms.QueueConnection 实例源码

项目:pooled-jms    文件:XAConnectionPoolTest.java   
@Test(timeout = 60000)
public void testSenderAndPublisherDest() throws Exception {
    JmsPoolXAConnectionFactory pcf = new JmsPoolXAConnectionFactory();
    pcf.setConnectionFactory(new ActiveMQXAConnectionFactory(
        "vm://test?broker.persistent=false&broker.useJmx=false"));

    QueueConnection connection = pcf.createQueueConnection();
    QueueSession session = connection.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
    QueueSender sender = session.createSender(session.createQueue("AA"));
    assertNotNull(sender.getQueue().getQueueName());

    connection.close();

    TopicConnection topicConnection = pcf.createTopicConnection();
    TopicSession topicSession = topicConnection.createTopicSession(false, Session.AUTO_ACKNOWLEDGE);
    TopicPublisher topicPublisher = topicSession.createPublisher(topicSession.createTopic("AA"));
    assertNotNull(topicPublisher.getTopic().getTopicName());

    topicConnection.close();
    pcf.stop();
}
项目:ats-framework    文件:ManagedConnection.java   
public static ManagedConnection create(
                                        final Connection connection ) {

    if ( (connection instanceof XAQueueConnection) && (connection instanceof XATopicConnection)) {
        return new ManagedXAQueueTopicConnection(connection);
    } else if (connection instanceof XAQueueConnection) {
        return new ManagedXAQueueConnection((XAQueueConnection) connection);
    } else if (connection instanceof XATopicConnection) {
        return new ManagedXATopicConnection((XATopicConnection) connection);
    } else if ( (connection instanceof QueueConnection) && (connection instanceof TopicConnection)) {
        return new ManagedQueueTopicConnection(connection);
    } else if (connection instanceof QueueConnection) {
        return new ManagedQueueConnection((QueueConnection) connection);
    } else if (connection instanceof TopicConnection) {
        return new ManagedTopicConnection((TopicConnection) connection);
    } else {
        return new ManagedConnection(connection);
    }
}
项目:loyalty-level    文件:LoyaltyLevel.java   
/** Send a JSON message to our notification queue.
 */
public void invokeJMS(JsonObject json) throws JMSException, NamingException {
    if (!initialized) initialize(); //gets our JMS managed resources (Q and QCF)

    QueueConnection connection = queueCF.createQueueConnection();
    QueueSession session = connection.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);

    TextMessage message = session.createTextMessage(json.toString());
    System.out.println("Sending "+json.toString()+" to "+queue.getQueueName());
    QueueSender sender = session.createSender(queue);
    sender.send(message);

    sender.close();
    session.close();
    connection.close();

    System.out.println("Message sent successfully!");
}
项目:spring4-understanding    文件:SingleConnectionFactory.java   
/**
 * Create a default Session for this ConnectionFactory,
 * adapting to JMS 1.0.2 style queue/topic mode if necessary.
 * @param con the JMS Connection to operate on
 * @param mode the Session acknowledgement mode
 * ({@code Session.TRANSACTED} or one of the common modes)
 * @return the newly created Session
 * @throws JMSException if thrown by the JMS API
 */
protected Session createSession(Connection con, Integer mode) throws JMSException {
    // Determine JMS API arguments...
    boolean transacted = (mode == Session.SESSION_TRANSACTED);
    int ackMode = (transacted ? Session.AUTO_ACKNOWLEDGE : mode);
    // Now actually call the appropriate JMS factory method...
    if (Boolean.FALSE.equals(this.pubSubMode) && con instanceof QueueConnection) {
        return ((QueueConnection) con).createQueueSession(transacted, ackMode);
    }
    else if (Boolean.TRUE.equals(this.pubSubMode) && con instanceof TopicConnection) {
        return ((TopicConnection) con).createTopicSession(transacted, ackMode);
    }
    else {
        return con.createSession(transacted, ackMode);
    }
}
项目:spring4-understanding    文件:SingleConnectionFactoryTests.java   
@Test
public void testWithQueueConnection() throws JMSException {
    Connection con = mock(QueueConnection.class);

    SingleConnectionFactory scf = new SingleConnectionFactory(con);
    QueueConnection con1 = scf.createQueueConnection();
    con1.start();
    con1.stop();
    con1.close();
    QueueConnection con2 = scf.createQueueConnection();
    con2.start();
    con2.stop();
    con2.close();
    scf.destroy();  // should trigger actual close

    verify(con, times(2)).start();
    verify(con, times(2)).stop();
    verify(con).close();
    verifyNoMoreInteractions(con);
}
项目:spring4-understanding    文件:SingleConnectionFactoryTests.java   
@Test
public void testWithQueueConnectionFactoryAndJms11Usage() throws JMSException {
    QueueConnectionFactory cf = mock(QueueConnectionFactory.class);
    QueueConnection con = mock(QueueConnection.class);

    given(cf.createConnection()).willReturn(con);

    SingleConnectionFactory scf = new SingleConnectionFactory(cf);
    Connection con1 = scf.createConnection();
    Connection con2 = scf.createConnection();
    con1.start();
    con2.start();
    con1.close();
    con2.close();
    scf.destroy();  // should trigger actual close

    verify(con).start();
    verify(con).stop();
    verify(con).close();
    verifyNoMoreInteractions(con);
}
项目:spring4-understanding    文件:SingleConnectionFactoryTests.java   
@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();
    scf.destroy();  // should trigger actual close

    verify(con).start();
    verify(con).stop();
    verify(con).close();
    verifyNoMoreInteractions(con);
}
项目:perf-harness    文件:AbstractJMSProvider.java   
public QueueConnection getQueueConnection(QueueConnectionFactory qcf)
        throws JMSException {

    final QueueConnection qc;
    final String username = Config.parms.getString("us");
    if (username != null && username.length() != 0) {
        Log.logger.log(Level.INFO, "getQueueConnection(): authenticating as \"" + username + "\"");
        final String password = Config.parms.getString("pw");
        qc = qcf.createQueueConnection(username, password);
    } else {
        qc = qcf.createQueueConnection();
    }

    return qc;

}
项目:mdw    文件:InternalEventListener.java   
private void acknowledge(Message jmsMessage, String msgid) throws JMSException, ServiceLocatorException {
        QueueConnection connection = null;
        QueueSession session = null;
        QueueSender sender = null;
        try {
            Queue respQueue = (Queue) jmsMessage.getJMSReplyTo();
            QueueConnectionFactory qcf = JMSServices.getInstance().getQueueConnectionFactory(null);
            connection = qcf.createQueueConnection();
            session = connection.createQueueSession(false, QueueSession.DUPS_OK_ACKNOWLEDGE);
            sender = session.createSender(respQueue);
            Message respMsg = session.createTextMessage(msgid);
//        respMsg.setJMSCorrelationID(correlationId); not used
            sender.send(respMsg);
        } finally {
            if (sender != null) sender.close();
            if (session != null) session.close();
            if (connection != null) connection.close();
        }
    }
项目:mdw    文件:ExternalEventListener.java   
private void acknowledge(Message jmsMessage, String msgid) throws JMSException, ServiceLocatorException {
        QueueConnection connection = null;
        QueueSession session = null;
        QueueSender sender = null;
        try {
            Queue respQueue = (Queue) jmsMessage.getJMSReplyTo();
            QueueConnectionFactory qcf = JMSServices.getInstance().getQueueConnectionFactory(null);
            connection = qcf.createQueueConnection();
            session = connection.createQueueSession(false, QueueSession.DUPS_OK_ACKNOWLEDGE);
            sender = session.createSender(respQueue);
            Message respMsg = session.createTextMessage(msgid);
//        respMsg.setJMSCorrelationID(correlationId); not used
            sender.send(respMsg);
        } finally {
            if (sender != null) sender.close();
            if (session != null) session.close();
            if (connection != null) connection.close();
        }
    }
项目:product-ei    文件:JmsTypeHeaderInboundEndpointTestCase.java   
/**
 * Send a message to testInboundQueue queue
 *
 * @throws Exception
 */
private void sendMessage() throws Exception {
    InitialContext initialContext = JmsClientHelper.getActiveMqInitialContext();
    QueueConnectionFactory connectionFactory
            = (QueueConnectionFactory) initialContext.lookup(JmsClientHelper.QUEUE_CONNECTION_FACTORY);
    QueueConnection queueConnection = connectionFactory.createQueueConnection();
    QueueSession queueSession = queueConnection.createQueueSession(false, QueueSession.AUTO_ACKNOWLEDGE);
    QueueSender sender = queueSession.createSender(queueSession.createQueue(QUEUE_NAME));

    String message = "<?xml version='1.0' encoding='UTF-8'?>" +
            "    <ser:getQuote xmlns:ser=\"http://services.samples\" xmlns:xsd=\"http://services.samples/xsd\"> " +
            "      <ser:request>" +
            "        <xsd:symbol>IBM</xsd:symbol>" +
            "      </ser:request>" +
            "    </ser:getQuote>";
    try {
        TextMessage jmsMessage = queueSession.createTextMessage(message);
        jmsMessage.setJMSType("incorrecttype");
        sender.send(jmsMessage);
    } finally {
        queueConnection.close();
    }
}
项目:msf4j-queueing    文件:ReorderRequestMessageListener.java   
public ReorderRequestMessageListener() {
    try {
        Properties properties = new Properties();
        properties.put(Context.INITIAL_CONTEXT_FACTORY, QPID_ICF);
        properties.put(CF_NAME_PREFIX + CF_NAME, getTCPConnectionURL(USERNAME, PASSWORD));
        properties.put(QUEUE_NAME_PREFIX + REORDER_REQUEST_QUEUE, REORDER_REQUEST_QUEUE);
        InitialContext ctx = new InitialContext(properties);
        // Lookup connection factory
        QueueConnectionFactory connFactory = (QueueConnectionFactory) ctx.lookup(CF_NAME);
        QueueConnection queueConnection = connFactory.createQueueConnection();
        queueConnection.start();
        QueueSession queueSession = queueConnection.createQueueSession(false, QueueSession.AUTO_ACKNOWLEDGE);
        //Receive message
        Queue queue = (Queue) ctx.lookup(REORDER_REQUEST_QUEUE);
        MessageConsumer consumer = queueSession.createConsumer(queue);
        consumer.setMessageListener(this);
    } catch (NamingException | JMSException e) {
        e.printStackTrace();
    }
}
项目:daq-eclipse    文件:SimpleJmsQueueConnector.java   
protected void initializeInboundDestinationBridgesOutboundSide(QueueConnection connection) throws JMSException {
    if (inboundQueueBridges != null) {
        QueueSession outboundSession = connection.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);

        for (InboundQueueBridge bridge : inboundQueueBridges) {
            String queueName = bridge.getInboundQueueName();
            Queue foreignQueue = createForeignQueue(outboundSession, queueName);
            bridge.setConsumer(null);
            bridge.setConsumerQueue(foreignQueue);
            bridge.setConsumerConnection(connection);
            bridge.setJmsConnector(this);
            addInboundBridge(bridge);
        }
        outboundSession.close();
    }
}
项目:daq-eclipse    文件:SimpleJmsQueueConnector.java   
protected void initializeInboundDestinationBridgesLocalSide(QueueConnection connection) throws JMSException {
    if (inboundQueueBridges != null) {
        QueueSession localSession = connection.createQueueSession(false,Session.AUTO_ACKNOWLEDGE);

        for (InboundQueueBridge bridge : inboundQueueBridges) {
            String localQueueName = bridge.getLocalQueueName();
            Queue activemqQueue = createActiveMQQueue(localSession, localQueueName);
            bridge.setProducerQueue(activemqQueue);
            bridge.setProducerConnection(connection);
            if (bridge.getJmsMessageConvertor() == null) {
                bridge.setJmsMessageConvertor(getInboundMessageConvertor());
            }
            bridge.setJmsConnector(this);
            addInboundBridge(bridge);
        }
        localSession.close();
    }
}
项目:daq-eclipse    文件:SimpleJmsQueueConnector.java   
protected void initializeOutboundDestinationBridgesOutboundSide(QueueConnection connection) throws JMSException {
    if (outboundQueueBridges != null) {
        QueueSession outboundSession = connection.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);

        for (OutboundQueueBridge bridge : outboundQueueBridges) {
            String queueName = bridge.getOutboundQueueName();
            Queue foreignQueue = createForeignQueue(outboundSession, queueName);
            bridge.setProducerQueue(foreignQueue);
            bridge.setProducerConnection(connection);
            if (bridge.getJmsMessageConvertor() == null) {
                bridge.setJmsMessageConvertor(getOutboundMessageConvertor());
            }
            bridge.setJmsConnector(this);
            addOutboundBridge(bridge);
        }
        outboundSession.close();
    }
}
项目:daq-eclipse    文件:SimpleJmsQueueConnector.java   
protected void initializeOutboundDestinationBridgesLocalSide(QueueConnection connection) throws JMSException {
    if (outboundQueueBridges != null) {
        QueueSession localSession =
                connection.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);

        for (OutboundQueueBridge bridge : outboundQueueBridges) {
            String localQueueName = bridge.getLocalQueueName();
            Queue activemqQueue = createActiveMQQueue(localSession, localQueueName);
            bridge.setConsumer(null);
            bridge.setConsumerQueue(activemqQueue);
            bridge.setConsumerConnection(connection);
            bridge.setJmsConnector(this);
            addOutboundBridge(bridge);
        }
        localSession.close();
    }
}
项目:carbon-transports    文件:JMSConnectionResourceFactory.java   
/**
 * Create JMS {@link Session} instance on top of the provided {@link Connection} instance.
 *
 * @param connection JMS Connection.
 * @return Session instance.
 * @throws JMSConnectorException Error when creating the JMS Session.
 */
public Session createSession(Connection connection) throws JMSConnectorException {
    try {
        if (logger.isDebugEnabled()) {
            logger.debug("Creating a new JMS Session on: " + this.connectionFactoryString);
        }
        if (JMSConstants.JMS_SPEC_VERSION_1_1.equals(jmsSpec) || JMSConstants.JMS_SPEC_VERSION_2_0
                .equals(jmsSpec)) {
            return connection.createSession(transactedSession, sessionAckMode);
        } else if (JMSConstants.JMSDestinationType.QUEUE.equals(this.destinationType)) {
            return ((QueueConnection) (connection)).createQueueSession(transactedSession, sessionAckMode);
        } else {
            return ((TopicConnection) (connection)).createTopicSession(transactedSession, sessionAckMode);

        }
    } catch (JMSException e) {
        throw new JMSConnectorException(
                "JMS Exception while obtaining session for factory " + connectionFactoryString, e);
    }
}
项目:carbon-transports    文件:JMSConnectionResourceFactory.java   
/**
 * Close a JMS {@link Connection}.
 * @param connection Connection that need to be closed.
 * @throws JMSException if an error occurs while closing the connection.
 */
public void closeConnection(Connection connection) throws JMSException {
    if (connection != null) {
        if (logger.isDebugEnabled()) {
            logger.debug("Closing a JMS Connection of: " + this.connectionFactoryString);
        }
        if ((JMSConstants.JMS_SPEC_VERSION_1_1.equals(jmsSpec)) || (JMSConstants.JMS_SPEC_VERSION_2_0
                .equals(jmsSpec))) {
            connection.close();
        } else {
            if (JMSConstants.JMSDestinationType.QUEUE.equals(this.destinationType)) {
                ((QueueConnection) connection).close();
            } else {
                ((TopicConnection) connection).close();
            }
        }
    }
}
项目:carbon-transports    文件:JMSServer.java   
/**
 * To publish the messages to a queue.
 *
 * @throws JMSException         JMS Exception.
 * @throws InterruptedException Interrupted exception while waiting in between messages.
 */
public void publishMessagesToQueue(String queueName) throws JMSException, InterruptedException {
    QueueConnection queueConn = (QueueConnection) connectionFactory.createConnection();
    queueConn.start();
    QueueSession queueSession = queueConn.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
    Destination destination = queueSession.createQueue(queueName);
    MessageProducer queueSender = queueSession.createProducer(destination);
    queueSender.setDeliveryMode(DeliveryMode.NON_PERSISTENT);
    for (int index = 0; index < 10; index++) {
        String queueText = "Queue Message : " + (index + 1);
        TextMessage queueMessage = queueSession.createTextMessage(queueText);
        queueSender.send(queueMessage);
        Thread.sleep(1000);
        logger.info("Publishing " + queueText + " to queue " + queueName);
    }
    queueConn.close();
    queueSession.close();
    queueSender.close();
}
项目:carbon-transports    文件:JMSServer.java   
/**
 * To receive a message from a queue.
 *
 * @throws JMSException         JMS Exception.
 * @throws InterruptedException Interrupted exception while waiting in between messages.
 */
public void receiveMessagesFromQueue() throws JMSException, InterruptedException {
    QueueConnection queueConn = (QueueConnection) connectionFactory.createConnection();
    QueueSession queueSession = queueConn.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
    Destination destination = queueSession.createQueue(JMSTestConstants.QUEUE_NAME_1);
    MessageConsumer queueReceiver = queueSession.createConsumer(destination);
    MessageListener listener = message -> {
        try {
            if (message instanceof TextMessage) {
                TextMessage textMessage = (TextMessage) message;
                logger.info("Message text received : " + (textMessage.getText()));
            }
        } catch (JMSException e) {
            logger.info("JMS exception occurred.");
        }
    };
    queueReceiver.setMessageListener(listener);
    queueConn.start();
}
项目:activemq-artemis    文件:OutgoingConnectionTest.java   
@Test
public void testMultipleSessionsThrowsException() throws Exception {
   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(false, Session.AUTO_ACKNOWLEDGE);
   try {
      Session s2 = queueConnection.createSession(false, Session.AUTO_ACKNOWLEDGE);
      fail("should throw javax,jms.IllegalStateException: Only allowed one session per connection. See the J2EE spec, e.g. J2EE1.4 Section 6.6");
   } catch (JMSException e) {
   }
}
项目:activemq-artemis    文件:OutgoingConnectionTest.java   
@Test
public void testConnectionCredentialsFail() throws Exception {
   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();
   QueueSession session = queueConnection.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);

   ManagedConnection mc = ((ActiveMQRASession) session).getManagedConnection();
   queueConnection.close();
   mc.destroy();

   try {
      queueConnection = qraConnectionFactory.createQueueConnection("testuser", "testwrongpassword");
      queueConnection.createQueueSession(false, Session.AUTO_ACKNOWLEDGE).close();
      fail("should throw esxception");
   } catch (JMSException e) {
      //pass
   }
}
项目:activemq-artemis    文件:OutgoingConnectionTest.java   
@Test
public void testConnectionCredentialsFailRecovery() throws Exception {
   resourceAdapter = newResourceAdapter();
   MyBootstrapContext ctx = new MyBootstrapContext();
   resourceAdapter.start(ctx);
   ActiveMQRAManagedConnectionFactory mcf = new ActiveMQRAManagedConnectionFactory();
   mcf.setResourceAdapter(resourceAdapter);
   ActiveMQRAConnectionFactory qraConnectionFactory = new ActiveMQRAConnectionFactoryImpl(mcf, qraConnectionManager);
   try {
      QueueConnection queueConnection = qraConnectionFactory.createQueueConnection("testuser", "testwrongpassword");
      queueConnection.createQueueSession(false, Session.AUTO_ACKNOWLEDGE).close();
      fail("should throw esxception");
   } catch (JMSException e) {
      //make sure the recovery is null
      assertNull(mcf.getResourceRecovery());
   }
}
项目:activemq-artemis    文件:QueueReceiverTest.java   
/**
 * com.sun.ts.tests.jms.ee.all.queueconn.QueueConnTest line 171
 */
@Test
public void testCreateReceiverWithMessageSelector() throws Exception {
   QueueConnection qc = null;

   try {
      qc = createQueueConnection();
      QueueSession qs = qc.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);

      QueueReceiver qreceiver = qs.createReceiver(queue1, "targetMessage = TRUE");

      qc.start();

      TextMessage m = qs.createTextMessage();
      m.setText("one");
      m.setBooleanProperty("targetMessage", false);

      QueueSender qsender = qs.createSender(queue1);

      qsender.send(m);

      m.setText("two");
      m.setBooleanProperty("targetMessage", true);

      qsender.send(m);

      TextMessage rm = (TextMessage) qreceiver.receive(1000);

      ProxyAssertSupport.assertEquals("two", rm.getText());
   } finally {
      if (qc != null) {
         qc.close();
      }
      Thread.sleep(2000);
      removeAllMessages(queue1.getQueueName(), true);
      checkEmpty(queue1);
   }
}
项目:activemq-artemis    文件:ConnectionFactoryTest.java   
private void assertConnectionType(Connection conn, String type) {
   if ("generic".equals(type) || "queue".equals(type) || "topic".equals(type)) {
      //generic
      Assert.assertFalse(conn instanceof XAConnection);
      Assert.assertTrue(conn instanceof QueueConnection);
      Assert.assertFalse(conn instanceof XAQueueConnection);
      Assert.assertTrue(conn instanceof TopicConnection);
      Assert.assertFalse(conn instanceof XATopicConnection);
   } else if ("xa".equals(type) || "xa-queue".equals(type) || "xa-topic".equals(type)) {
      Assert.assertTrue(conn instanceof XAConnection);
      Assert.assertTrue(conn instanceof QueueConnection);
      Assert.assertTrue(conn instanceof XAQueueConnection);
      Assert.assertTrue(conn instanceof TopicConnection);
      Assert.assertTrue(conn instanceof XATopicConnection);
   } else {
      Assert.fail("Unknown connection type: " + type);
   }
}
项目:activemq-artemis    文件:ActiveMQRAConnectionFactoryImpl.java   
/**
 * Create a queue connection
 *
 * @param userName The user name
 * @param password The password
 * @return The connection
 * @throws JMSException Thrown if the operation fails
 */
@Override
public QueueConnection createQueueConnection(final String userName, final String password) throws JMSException {
   if (ActiveMQRAConnectionFactoryImpl.trace) {
      ActiveMQRALogger.LOGGER.trace("createQueueConnection(" + userName + ", ****)");
   }

   ActiveMQRASessionFactoryImpl s = new ActiveMQRASessionFactoryImpl(mcf, cm, getResourceAdapter().getTM(), ActiveMQRAConnectionFactory.QUEUE_CONNECTION);
   s.setUserName(userName);
   s.setPassword(password);

   validateUser(s);

   if (ActiveMQRAConnectionFactoryImpl.trace) {
      ActiveMQRALogger.LOGGER.trace("Created queue connection: " + s);
   }

   return s;
}
项目:javamail    文件:SmtpJmsTransportTest.java   
@Before
public void setUp() throws Exception {
    System.setProperty(Context.INITIAL_CONTEXT_FACTORY, TestContextFactory.class.getName());
    QueueConnectionFactory queueConnectionFactory = Mockito.mock(QueueConnectionFactory.class);
    Queue queue = Mockito.mock(Queue.class);
    Context context = Mockito.mock(Context.class);
    TestContextFactory.context = context;
    when(context.lookup(eq("jms/queueConnectionFactory"))).thenReturn(queueConnectionFactory);
    when(context.lookup(eq("jms/mailQueue"))).thenReturn(queue);
    queueSender = Mockito.mock(QueueSender.class);
    QueueConnection queueConnection = Mockito.mock(QueueConnection.class);
    when(queueConnectionFactory.createQueueConnection()).thenReturn(queueConnection);
    when(queueConnectionFactory.createQueueConnection(anyString(), anyString())).thenReturn(queueConnection);
    QueueSession queueSession = Mockito.mock(QueueSession.class);
    bytesMessage = Mockito.mock(BytesMessage.class);
    when(queueSession.createBytesMessage()).thenReturn(bytesMessage);
    when(queueConnection.createQueueSession(anyBoolean(), anyInt())).thenReturn(queueSession);
    when(queueSession.createSender(eq(queue))).thenReturn(queueSender);
    transport = new SmtpJmsTransport(Session.getDefaultInstance(new Properties()), new URLName("jms"));
    transportListener = Mockito.mock(TransportListener.class);
    transport.addTransportListener(transportListener);
}
项目:class-guard    文件:SingleConnectionFactory.java   
/**
 * Create a default Session for this ConnectionFactory,
 * adaptign to JMS 1.0.2 style queue/topic mode if necessary.
 * @param con the JMS Connection to operate on
 * @param mode the Session acknowledgement mode
 * ({@code Session.TRANSACTED} or one of the common modes)
 * @return the newly created Session
 * @throws JMSException if thrown by the JMS API
 */
protected Session createSession(Connection con, Integer mode) throws JMSException {
    // Determine JMS API arguments...
    boolean transacted = (mode == Session.SESSION_TRANSACTED);
    int ackMode = (transacted ? Session.AUTO_ACKNOWLEDGE : mode);
    // Now actually call the appropriate JMS factory method...
    if (Boolean.FALSE.equals(this.pubSubMode) && con instanceof QueueConnection) {
        return ((QueueConnection) con).createQueueSession(transacted, ackMode);
    }
    else if (Boolean.TRUE.equals(this.pubSubMode) && con instanceof TopicConnection) {
        return ((TopicConnection) con).createTopicSession(transacted, ackMode);
    }
    else {
        return con.createSession(transacted, ackMode);
    }
}
项目:class-guard    文件:JmsTransactionManagerTests.java   
@Test
@Deprecated
public void testTransactionCommit102WithQueue() throws JMSException {
    QueueConnectionFactory cf = mock(QueueConnectionFactory.class);
    QueueConnection con = mock(QueueConnection.class);
    final QueueSession session = mock(QueueSession.class);

    given(cf.createQueueConnection()).willReturn(con);
    given(con.createQueueSession(true, Session.AUTO_ACKNOWLEDGE)).willReturn(session);

    JmsTransactionManager tm = new JmsTransactionManager102(cf, false);
    TransactionStatus ts = tm.getTransaction(new DefaultTransactionDefinition());
    JmsTemplate jt = new JmsTemplate102(cf, false);
    jt.execute(new SessionCallback() {
        @Override
        public Object doInJms(Session sess) {
            assertTrue(sess == session);
            return null;
        }
    });
    tm.commit(ts);

    verify(session).commit();
    verify(session).close();
    verify(con).close();
}
项目:class-guard    文件:SingleConnectionFactoryTests.java   
@Test
public void testWithQueueConnection() throws JMSException {
    Connection con = mock(QueueConnection.class);

    SingleConnectionFactory scf = new SingleConnectionFactory(con);
    QueueConnection con1 = scf.createQueueConnection();
    con1.start();
    con1.stop();  // should be ignored
    con1.close();  // should be ignored
    QueueConnection con2 = scf.createQueueConnection();
    con2.start();
    con2.stop();  // should be ignored
    con2.close();  // should be ignored
    scf.destroy();  // should trigger actual close

    verify(con).start();
    verify(con).stop();
    verify(con).close();
    verifyNoMoreInteractions(con);
}
项目:class-guard    文件:SingleConnectionFactoryTests.java   
@Test
public void testWithQueueConnectionFactoryAndJms11Usage() throws JMSException {
    QueueConnectionFactory cf = mock(QueueConnectionFactory.class);
    QueueConnection con = mock(QueueConnection.class);

    given(cf.createConnection()).willReturn(con);

    SingleConnectionFactory scf = new SingleConnectionFactory(cf);
    Connection con1 = scf.createConnection();
    con1.start();
    con1.close();  // should be ignored
    Connection con2 = scf.createConnection();
    con2.start();
    con2.close();  // should be ignored
    scf.destroy();  // should trigger actual close

    verify(con).start();
    verify(con).stop();
    verify(con).close();
    verifyNoMoreInteractions(con);
}
项目:class-guard    文件:SingleConnectionFactoryTests.java   
@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();
    con1.start();
    con1.close();  // should be ignored
    Connection con2 = scf.createQueueConnection();
    con2.start();
    con2.close();  // should be ignored
    scf.destroy();  // should trigger actual close

    verify(con).start();
    verify(con).stop();
    verify(con).close();
    verifyNoMoreInteractions(con);
}
项目:class-guard    文件:SingleConnectionFactoryTests.java   
@Test
public void testConnectionFactory102WithQueue() throws JMSException {
    QueueConnectionFactory cf = mock(QueueConnectionFactory.class);
    QueueConnection con = mock(QueueConnection.class);

    given(cf.createQueueConnection()).willReturn(con);

    SingleConnectionFactory scf = new SingleConnectionFactory102(cf, false);
    QueueConnection con1 = scf.createQueueConnection();
    con1.start();
    con1.close();  // should be ignored
    QueueConnection con2 = scf.createQueueConnection();
    con2.start();
    con2.close();  // should be ignored
    scf.destroy();  // should trigger actual close

    verify(con).start();
    verify(con).stop();
    verify(con).close();
    verifyNoMoreInteractions(con);
}
项目:wso2-axis2-transports    文件:JMSUtils.java   
/**
 * This is a JMS spec independent method to create a Session. Please be cautious when
 * making any changes
 *
 * @param connection the JMS Connection
 * @param transacted should the session be transacted?
 * @param ackMode the ACK mode for the session
 * @param jmsSpec should we use the JMS 1.1, 1.0.2b or 2.0
 * @param isQueue is this Session to deal with a Queue?
 * @return a Session created for the given information
 * @throws JMSException on errors, to be handled and logged by the caller
 */
public static Session createSession(Connection connection, boolean transacted, int ackMode,
    String jmsSpec, Boolean isQueue) throws JMSException {

    if (JMSConstants.JMS_SPEC_VERSION_1_1.equals(jmsSpec) || JMSConstants.JMS_SPEC_VERSION_2_0.equals(jmsSpec)
            || isQueue == null) {
        return connection.createSession(transacted, ackMode);

    } else {
        if (isQueue) {
            return ((QueueConnection) connection).createQueueSession(transacted, ackMode);
        } else {
            return ((TopicConnection) connection).createTopicSession(transacted, ackMode);
        }
    }
}
项目:ffmq    文件:LocalQueueSessionTest.java   
public void testCreateReceiverQueue() throws Exception
{        
    QueueSession session;       
    session = ((QueueConnection)connection).createQueueSession(false, Session.AUTO_ACKNOWLEDGE);

    try
    {
        session.createReceiver(null);
        fail("Should have failed");
    }
    catch (JMSException e)
    {
        assertTrue(e.getMessage().indexOf("destination") != -1);
    }

    session.createReceiver(queue1);
    session.close();
}
项目:ffmq    文件:LocalQueueSessionTest.java   
public void testCreateReceiverQueueString() throws Exception
{
    QueueSession session;       
    session = ((QueueConnection)connection).createQueueSession(false, Session.AUTO_ACKNOWLEDGE);

    try
    {
        session.createReceiver(null,null);
        fail("Should have failed");
    }
    catch (JMSException e)
    {
        assertTrue(e.getMessage().indexOf("destination") != -1);
    }

    session.createReceiver(queue1,null);
    session.createReceiver(queue1,"JMSMessageID='toto'");
    session.close();
}
项目:ffmq    文件:QueueSenderThread.java   
/**
 * Constructor
 */
public QueueSenderThread(String name,
                         DummyMessageFactory msgFactory,
                         SynchronizationPoint startSynchro,
                         QueueConnection connection,
                         boolean transacted, 
                         int messageCount,
                         int messageSize,
                         int minDelay,
                         int maxDelay,
                         Queue queue,
                         int deliveryMode,
                         int priority,
                         long timeToLive)
{
    super(name, startSynchro, connection, transacted, Session.AUTO_ACKNOWLEDGE, queue);
    this.msgFactory = msgFactory;
    this.messageCount = messageCount;
    this.messageSize = messageSize;
    this.minDelay = minDelay;
    this.maxDelay = maxDelay;
    this.deliveryMode = deliveryMode;
    this.priority = priority;
    this.timeToLive = timeToLive;
}
项目:ffmq    文件:FFMQQueueConnectionFactory.java   
@Override
public QueueConnection createQueueConnection(String userName, String password) throws JMSException
   {
       URI providerURL = getProviderURI();

       String scheme = providerURL.getScheme();
       if (scheme.equals(PacketTransportType.VM))
       {
           String engineName = providerURL.getHost();
           return FFMQEngine.getDeployedInstance(engineName).openQueueConnection(userName, password, clientID);
       }
       else 
       if (scheme.equals(PacketTransportType.TCP) ||
           scheme.equals(PacketTransportType.TCPS) ||
           scheme.equals(PacketTransportType.TCPNIO))
       {
           return new RemoteQueueConnection(providerURL, userName, password, clientID);
       }
       else
           throw new FFMQException("Unknown transport protocol : " + scheme,"INVALID_TRANSPORT_PROTOCOL");
   }
项目:qpid-jms    文件:JmsConnectionFactory.java   
@Override
public QueueConnection createQueueConnection(String username, String password) throws JMSException {
    JmsQueueConnection connection = null;

    try {
        JmsConnectionInfo connectionInfo = configureConnectionInfo(username, password);
        Provider provider = createProvider(remoteURI);

        connection = new JmsQueueConnection(connectionInfo, provider);
        connection.setExceptionListener(exceptionListener);
        connection.connect();
    } catch (Exception e) {
        if (connection != null) {
            try {
                connection.close();
            } catch (Throwable ignored) {}
        }
        throw JmsExceptionSupport.create(e);
    }

    return connection;
}
项目:qpid-jms    文件:ConnectionFactoryIntegrationTest.java   
@Test(timeout=20000)
public void testCreateQueueConnectionGoodProviderString() throws Exception {
    try (TestAmqpPeer testPeer = new TestAmqpPeer();) {
        // Ignore errors from peer close due to not sending any Open / Close frames
        testPeer.setSuppressReadExceptionOnClose(true);

        // DONT create a test fixture, we will drive everything directly.
        testPeer.expectSaslAnonymous();

        JmsConnectionFactory factory = new JmsConnectionFactory("amqp://127.0.0.1:" + testPeer.getServerPort());
        QueueConnection connection = factory.createQueueConnection();
        assertNotNull(connection);

        testPeer.waitForAllHandlersToComplete(1000);

        testPeer.expectOpen();
        testPeer.expectClose();

        connection.close();

        testPeer.waitForAllHandlersToCompleteNoAssert(1000);
    }
}