Search in sources :

Example 6 with JmsConnectionFactory

use of org.apache.qpid.jms.JmsConnectionFactory in project activemq-artemis by apache.

the class JMSSaslExternalTest method testConnection.

@Test(timeout = 600000)
public void testConnection() throws Exception {
    final String keystore = this.getClass().getClassLoader().getResource("client_not_revoked.jks").getFile();
    final String truststore = this.getClass().getClassLoader().getResource("truststore.jks").getFile();
    String connOptions = "?amqp.saslMechanisms=EXTERNAL" + "&" + "transport.trustStoreLocation=" + truststore + "&" + "transport.trustStorePassword=changeit" + "&" + "transport.keyStoreLocation=" + keystore + "&" + "transport.keyStorePassword=changeit" + "&" + "transport.verifyHost=false";
    JmsConnectionFactory factory = new JmsConnectionFactory(new URI("amqps://localhost:" + 61616 + connOptions));
    Connection connection = factory.createConnection("client", null);
    connection.start();
    try {
        Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
        javax.jms.Queue queue = session.createQueue("TEST");
        MessageConsumer consumer = session.createConsumer(queue);
        MessageProducer producer = session.createProducer(queue);
        final String text = RandomUtil.randomString();
        producer.send(session.createTextMessage(text));
        TextMessage m = (TextMessage) consumer.receive(1000);
        assertNotNull(m);
        assertEquals(text, m.getText());
    } finally {
        connection.close();
    }
}
Also used : MessageConsumer(javax.jms.MessageConsumer) JmsConnectionFactory(org.apache.qpid.jms.JmsConnectionFactory) Connection(javax.jms.Connection) MessageProducer(javax.jms.MessageProducer) URI(java.net.URI) TextMessage(javax.jms.TextMessage) Session(javax.jms.Session) Test(org.junit.Test)

Example 7 with JmsConnectionFactory

use of org.apache.qpid.jms.JmsConnectionFactory in project activemq-artemis by apache.

the class JMSSaslGssapiTest method testSaslPlainConnectionDenied.

@Test(timeout = 600000)
public void testSaslPlainConnectionDenied() throws Exception {
    JmsConnectionFactory factory = new JmsConnectionFactory(new URI("amqp://localhost:" + AMQP_PORT + "?amqp.saslMechanisms=PLAIN"));
    try {
        factory.createConnection("plain", "secret");
        fail("Expect sasl failure");
    } catch (JMSSecurityException expected) {
        assertTrue(expected.getMessage().contains("SASL"));
    }
}
Also used : JmsConnectionFactory(org.apache.qpid.jms.JmsConnectionFactory) JMSSecurityException(javax.jms.JMSSecurityException) URI(java.net.URI) Test(org.junit.Test)

Example 8 with JmsConnectionFactory

use of org.apache.qpid.jms.JmsConnectionFactory in project activemq-artemis by apache.

the class JMSTopicConsumerTest method testSendAndReceiveOnAutoCreatedTopicJMS2.

@Test(timeout = 60000)
public void testSendAndReceiveOnAutoCreatedTopicJMS2() throws Exception {
    ConnectionFactory cf = new JmsConnectionFactory(getBrokerQpidJMSConnectionURI());
    JMSContext context = cf.createContext();
    String topicName = UUID.randomUUID().toString();
    SimpleString simpleTopicName = SimpleString.toSimpleString(topicName);
    try {
        Topic topic = context.createTopic(topicName);
        JMSProducer producer = context.createProducer();
        TextMessage message = context.createTextMessage("test-message");
        // this will auto-create the address, but not the subscription queue
        producer.send(topic, message);
        assertNotNull(server.getAddressInfo(simpleTopicName));
        assertEquals(RoutingType.MULTICAST, server.getAddressInfo(simpleTopicName).getRoutingType());
        assertTrue(server.getAddressInfo(simpleTopicName).isAutoCreated());
        assertTrue(server.getPostOffice().getBindingsForAddress(simpleTopicName).getBindings().isEmpty());
        // this will auto-create the subscription queue
        JMSConsumer consumer = context.createConsumer(topic);
        assertFalse(server.getPostOffice().getBindingsForAddress(simpleTopicName).getBindings().isEmpty());
        producer.send(topic, message);
        context.start();
        message = (TextMessage) consumer.receive(1000);
        assertNotNull(message);
        assertNotNull(message.getText());
        assertEquals("test-message", message.getText());
        consumer.close();
        assertTrue(server.getPostOffice().getBindingsForAddress(simpleTopicName).getBindings().isEmpty());
    } finally {
        context.close();
    }
}
Also used : JmsConnectionFactory(org.apache.qpid.jms.JmsConnectionFactory) ConnectionFactory(javax.jms.ConnectionFactory) JMSConsumer(javax.jms.JMSConsumer) JmsConnectionFactory(org.apache.qpid.jms.JmsConnectionFactory) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) JMSProducer(javax.jms.JMSProducer) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) Topic(javax.jms.Topic) JMSContext(javax.jms.JMSContext) TextMessage(javax.jms.TextMessage) Test(org.junit.Test)

Example 9 with JmsConnectionFactory

use of org.apache.qpid.jms.JmsConnectionFactory in project activemq-artemis by apache.

the class JMSWebSocketConnectionTest method testSendLargeMessageToClientFromOpenWire.

@Test(timeout = 30000)
public void testSendLargeMessageToClientFromOpenWire() throws Exception {
    JmsConnectionFactory factory = new JmsConnectionFactory(getBrokerQpidJMSConnectionURI());
    JmsConnection connection = (JmsConnection) factory.createConnection();
    sendLargeMessageViaOpenWire();
    try {
        Session session = connection.createSession();
        Queue queue = session.createQueue(getQueueName());
        connection.start();
        MessageConsumer consumer = session.createConsumer(queue);
        Message message = consumer.receive(1000);
        assertNotNull(message);
        assertTrue(message instanceof BytesMessage);
    } finally {
        connection.close();
    }
}
Also used : MessageConsumer(javax.jms.MessageConsumer) BytesMessage(javax.jms.BytesMessage) Message(javax.jms.Message) JmsConnectionFactory(org.apache.qpid.jms.JmsConnectionFactory) BytesMessage(javax.jms.BytesMessage) JmsConnection(org.apache.qpid.jms.JmsConnection) Queue(javax.jms.Queue) Session(javax.jms.Session) Test(org.junit.Test)

Example 10 with JmsConnectionFactory

use of org.apache.qpid.jms.JmsConnectionFactory in project activemq-artemis by apache.

the class JMSWebSocketConnectionTest method testCreateConnectionAndStart.

@Test(timeout = 30000)
public void testCreateConnectionAndStart() throws Exception {
    JmsConnectionFactory factory = new JmsConnectionFactory(getBrokerQpidJMSConnectionURI());
    JmsConnection connection = (JmsConnection) factory.createConnection();
    assertNotNull(connection);
    connection.start();
    connection.close();
}
Also used : JmsConnectionFactory(org.apache.qpid.jms.JmsConnectionFactory) JmsConnection(org.apache.qpid.jms.JmsConnection) Test(org.junit.Test)

Aggregations

JmsConnectionFactory (org.apache.qpid.jms.JmsConnectionFactory)40 Connection (javax.jms.Connection)19 Session (javax.jms.Session)19 MessageConsumer (javax.jms.MessageConsumer)17 MessageProducer (javax.jms.MessageProducer)17 Test (org.junit.Test)17 TextMessage (javax.jms.TextMessage)14 ConnectionFactory (javax.jms.ConnectionFactory)10 Queue (javax.jms.Queue)10 Message (javax.jms.Message)8 BytesMessage (javax.jms.BytesMessage)4 JmsConnection (org.apache.qpid.jms.JmsConnection)4 JMSException (javax.jms.JMSException)3 Topic (javax.jms.Topic)3 SimpleString (org.apache.activemq.artemis.api.core.SimpleString)3 AMQPComponent (org.apache.camel.component.amqp.AMQPComponent)3 URI (java.net.URI)2 JMSSecurityException (javax.jms.JMSSecurityException)2 InitialContext (javax.naming.InitialContext)2 Configuration (org.apache.activemq.artemis.core.config.Configuration)2