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) {
}
}
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);
}
}
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());
}
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;
}
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;
}
Aggregations