Search in sources :

Example 11 with ExceptionListener

use of javax.jms.ExceptionListener in project eap-additional-testsuite by jboss-set.

the class HornetQServerManagementTestCase method testCloseConnectionForUser.

@Test
public void testCloseConnectionForUser() throws Exception {
    Connection connection = connectionFactory.createConnection("guest", "guest");
    connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
    final CountDownLatch connectionClosed = new CountDownLatch(1);
    connection.setExceptionListener(new ExceptionListener() {

        @Override
        public void onException(JMSException e) {
            System.out.println("HornetQServerManagementTestCase.onException");
            connectionClosed.countDown();
        }
    });
    ModelNode operation = getHornetQServerOperation("close-connections-for-user");
    operation.get("user").set("guest");
    ModelNode result = execute(operation, true);
    assertTrue(result.isDefined());
    assertEquals(true, result.asBoolean());
    assertTrue(connectionClosed.await(500, MILLISECONDS));
    // connection is no longer valid
    try {
        connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
        Assert.fail("connection can no longer be used after it has been closed");
    } catch (JMSException e) {
    }
}
Also used : Connection(javax.jms.Connection) ExceptionListener(javax.jms.ExceptionListener) JMSException(javax.jms.JMSException) CountDownLatch(java.util.concurrent.CountDownLatch) ModelNode(org.jboss.dmr.ModelNode) Test(org.junit.Test)

Example 12 with ExceptionListener

use of javax.jms.ExceptionListener in project camel by apache.

the class SjmsEndpoint method createConnectionResource.

protected ConnectionResource createConnectionResource(Object source) {
    if (getConnectionFactory() == null) {
        throw new IllegalArgumentException(String.format("ConnectionResource or ConnectionFactory must be configured for %s", this));
    }
    try {
        logger.debug("Creating ConnectionResource with connectionCount: {} using ConnectionFactory", getConnectionCount(), getConnectionFactory());
        // We always use a connection pool, even for a pool of 1
        ConnectionFactoryResource connections = new ConnectionFactoryResource(getConnectionCount(), getConnectionFactory(), getComponent().getConnectionUsername(), getComponent().getConnectionPassword(), getComponent().getConnectionClientId(), getComponent().getConnectionMaxWait(), getComponent().isConnectionTestOnBorrow());
        if (exceptionListener != null) {
            connections.setExceptionListener(exceptionListener);
        } else {
            // add a exception listener that logs so we can see any errors that happens
            ExceptionListener listener = new SjmsLoggingExceptionListener(new LoggingExceptionHandler(getCamelContext(), source.getClass()), isErrorHandlerLogStackTrace());
            connections.setExceptionListener(listener);
        }
        connections.fillPool();
        return connections;
    } catch (Exception e) {
        throw ObjectHelper.wrapRuntimeCamelException(e);
    }
}
Also used : LoggingExceptionHandler(org.apache.camel.support.LoggingExceptionHandler) ConnectionFactoryResource(org.apache.camel.component.sjms.jms.ConnectionFactoryResource) ExceptionListener(javax.jms.ExceptionListener)

Example 13 with ExceptionListener

use of javax.jms.ExceptionListener in project camel by apache.

the class JmsEndpointConfigurationTest method testSettingEndpointOptions.

@SuppressWarnings("deprecation")
@Test
public void testSettingEndpointOptions() throws Exception {
    JmsEndpoint endpoint = resolveMandatoryEndpoint("jms:queue:Foo", JmsEndpoint.class);
    endpoint.setAcceptMessagesWhileStopping(true);
    assertTrue(endpoint.isAcceptMessagesWhileStopping());
    endpoint.setAllowReplyManagerQuickStop(true);
    assertTrue(endpoint.isAllowReplyManagerQuickStop());
    endpoint.setAcknowledgementMode(2);
    assertEquals(2, endpoint.getAcknowledgementMode());
    endpoint.setAcknowledgementModeName("CLIENT_ACKNOWLEDGE");
    assertEquals("CLIENT_ACKNOWLEDGE", endpoint.getAcknowledgementModeName());
    endpoint.setAlwaysCopyMessage(true);
    assertTrue(endpoint.isAlwaysCopyMessage());
    endpoint.setCacheLevel(2);
    assertEquals(2, endpoint.getCacheLevel());
    endpoint.setCacheLevelName("foo");
    assertEquals("foo", endpoint.getCacheLevelName());
    endpoint.setClientId("bar");
    assertEquals("bar", endpoint.getClientId());
    endpoint.setConcurrentConsumers(5);
    assertEquals(5, endpoint.getConcurrentConsumers());
    endpoint.setDeliveryPersistent(true);
    assertTrue(endpoint.isDeliveryPersistent());
    endpoint.setDestinationName("cool");
    assertEquals("cool", endpoint.getDestinationName());
    endpoint.setDisableReplyTo(true);
    assertTrue(endpoint.isDisableReplyTo());
    endpoint.setEagerLoadingOfProperties(true);
    assertTrue(endpoint.isEagerLoadingOfProperties());
    endpoint.setExceptionListener(new ExceptionListener() {

        public void onException(JMSException exception) {
        }
    });
    assertNotNull(endpoint.getExceptionListener());
    endpoint.setErrorHandler(new ErrorHandler() {

        public void handleError(Throwable t) {
        }
    });
    assertNotNull(endpoint.getErrorHandler());
    endpoint.setExplicitQosEnabled(true);
    assertTrue(endpoint.isExplicitQosEnabled());
    endpoint.setExposeListenerSession(true);
    assertTrue(endpoint.isExposeListenerSession());
    endpoint.setIdleTaskExecutionLimit(5);
    assertEquals(5, endpoint.getIdleTaskExecutionLimit());
    endpoint.setIdleConsumerLimit(5);
    assertEquals(5, endpoint.getIdleConsumerLimit());
    endpoint.setMaxConcurrentConsumers(4);
    assertEquals(4, endpoint.getMaxConcurrentConsumers());
    endpoint.setMaxMessagesPerTask(9);
    assertEquals(9, endpoint.getMaxMessagesPerTask());
    endpoint.setMessageConverter(new SimpleMessageConverter());
    assertNotNull(endpoint.getMessageConverter());
    endpoint.setMessageIdEnabled(true);
    assertTrue(endpoint.isMessageIdEnabled());
    endpoint.setMessageTimestampEnabled(true);
    assertTrue(endpoint.isMessageTimestampEnabled());
    endpoint.setPreserveMessageQos(true);
    assertTrue(endpoint.isPreserveMessageQos());
    endpoint.setPriority(6);
    assertEquals(6, endpoint.getPriority());
    endpoint.setPubSubNoLocal(true);
    assertTrue(endpoint.isPubSubNoLocal());
    endpoint.setPubSubNoLocal(true);
    assertTrue(endpoint.isPubSubNoLocal());
    assertFalse(endpoint.isPubSubDomain());
    endpoint.setReceiveTimeout(5000);
    assertEquals(5000, endpoint.getReceiveTimeout());
    endpoint.setRecoveryInterval(6000);
    assertEquals(6000, endpoint.getRecoveryInterval());
    endpoint.setReplyTo("bar");
    assertEquals("bar", endpoint.getReplyTo());
    endpoint.setReplyToDeliveryPersistent(true);
    assertTrue(endpoint.isReplyToDeliveryPersistent());
    endpoint.setReplyToDestinationSelectorName("me");
    assertEquals("me", endpoint.getReplyToDestinationSelectorName());
    endpoint.setRequestTimeout(3000);
    assertEquals(3000, endpoint.getRequestTimeout());
    endpoint.setSelector("you");
    assertEquals("you", endpoint.getSelector());
    endpoint.setTimeToLive(4000);
    assertEquals(4000, endpoint.getTimeToLive());
    endpoint.setTransacted(true);
    assertTrue(endpoint.isTransacted());
    endpoint.setTransactedInOut(true);
    assertTrue(endpoint.isTransactedInOut());
    endpoint.setTransferExchange(true);
    assertTrue(endpoint.isTransferExchange());
    endpoint.setTransferException(true);
    assertTrue(endpoint.isTransferException());
    endpoint.setJmsMessageType(JmsMessageType.Text);
    assertEquals(JmsMessageType.Text, endpoint.getJmsMessageType());
}
Also used : ErrorHandler(org.springframework.util.ErrorHandler) ExceptionListener(javax.jms.ExceptionListener) JMSException(javax.jms.JMSException) SimpleMessageConverter(org.springframework.jms.support.converter.SimpleMessageConverter) Test(org.junit.Test)

Example 14 with ExceptionListener

use of javax.jms.ExceptionListener in project activemq-artemis by apache.

the class JMSClientTestSupport method createConnection.

private Connection createConnection(URI remoteURI, String username, String password, String clientId, boolean start) throws JMSException {
    JmsConnectionFactory factory = new JmsConnectionFactory(remoteURI);
    Connection connection = trackJMSConnection(factory.createConnection(username, password));
    connection.setExceptionListener(new ExceptionListener() {

        @Override
        public void onException(JMSException exception) {
            exception.printStackTrace();
        }
    });
    if (clientId != null && !clientId.isEmpty()) {
        connection.setClientID(clientId);
    }
    if (start) {
        connection.start();
    }
    return connection;
}
Also used : JmsConnectionFactory(org.apache.qpid.jms.JmsConnectionFactory) Connection(javax.jms.Connection) ExceptionListener(javax.jms.ExceptionListener) JMSException(javax.jms.JMSException)

Example 15 with ExceptionListener

use of javax.jms.ExceptionListener in project activemq-artemis by apache.

the class JMSClientTestSupport method createCoreConnection.

private Connection createCoreConnection(String connectionString, String username, String password, String clientId, boolean start) throws JMSException {
    ActiveMQJMSConnectionFactory factory = new ActiveMQJMSConnectionFactory(connectionString);
    Connection connection = trackJMSConnection(factory.createConnection(username, password));
    connection.setExceptionListener(new ExceptionListener() {

        @Override
        public void onException(JMSException exception) {
            exception.printStackTrace();
        }
    });
    if (clientId != null && !clientId.isEmpty()) {
        connection.setClientID(clientId);
    }
    if (start) {
        connection.start();
    }
    return connection;
}
Also used : ActiveMQJMSConnectionFactory(org.apache.activemq.artemis.jms.client.ActiveMQJMSConnectionFactory) Connection(javax.jms.Connection) ExceptionListener(javax.jms.ExceptionListener) JMSException(javax.jms.JMSException)

Aggregations

ExceptionListener (javax.jms.ExceptionListener)28 JMSException (javax.jms.JMSException)25 Connection (javax.jms.Connection)17 Test (org.junit.Test)13 CountDownLatch (java.util.concurrent.CountDownLatch)7 Session (javax.jms.Session)7 MessageConsumer (javax.jms.MessageConsumer)5 ConnectionFactory (javax.jms.ConnectionFactory)4 MessageProducer (javax.jms.MessageProducer)4 TextMessage (javax.jms.TextMessage)4 AtomicReference (java.util.concurrent.atomic.AtomicReference)3 Queue (javax.jms.Queue)3 InitialContext (javax.naming.InitialContext)3 NamingException (javax.naming.NamingException)3 TimeUnit (java.util.concurrent.TimeUnit)2 Destination (javax.jms.Destination)2 IllegalStateException (javax.jms.IllegalStateException)2 Message (javax.jms.Message)2 QueueConnection (javax.jms.QueueConnection)2 Topic (javax.jms.Topic)2