Java Code Examples for javax.jms.JMSException#getCause()
The following examples show how to use
javax.jms.JMSException#getCause() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: JMS11WorkerThread.java From perf-harness with MIT License | 6 votes |
/** * Overloaded method to cross-link JDK 1.4 initCause and JMS 1.1 * linkedException if it has not already been done by the JMS vendor * implementation. * * @param je */ protected void handleException(JMSException je) { // Cross-link JDK 1.4 initCause and JMS 1.1 linkedexception if it has // not already been done by the JMS vendor implementation. if ( endTime==0 ) { endTime = System.currentTimeMillis(); } Exception le = je.getLinkedException(); Throwable t = je.getCause(); if (null==t && null!=le && t != le) { je.initCause(le); } handleException((Exception) je); }
Example 2
Source File: JMSSenderWorker.java From maestro-java with Apache License 2.0 | 5 votes |
private void handleProtocolSpecificConditions(JMSException e, JmsOptions options) { AbstractConfiguration config = ConfigurationWrapper.getConfig(); /* * This handles a special condition when using AMQP 1.0 with QPid JMS. As explained by Keith on * issue #141, "... this corresponds to the condition where the sending link is blocked awaiting credit. * When the peer is the Artemis Broker, this can correspond to a queue/disk full situation ..." as well * as serving as a work-around for some SUT issues like https://issues.apache.org/jira/browse/ARTEMIS-1898 * * In the future, this behavior should be driven by the front end, so we still have the ability to mark as fail * situations when the clients or the SUTs failed to cleanup/terminate/shutdown correctly. * * The previous behavior can be changed by the option worker.protocol.amqp10.block.is.failure */ boolean amqpBlockIsFailure = config.getBoolean("worker.protocol.amqp10.block.is.failure", false); if (amqpBlockIsFailure) { logger.error("JMS error while running the sender worker: {}", e.getMessage(), e); workerStateInfo.setState(false, WorkerStateInfo.WorkerExitStatus.WORKER_EXIT_FAILURE, e); } else { if (options.getProtocol() == JMSProtocol.AMQP && e.getCause() instanceof InterruptedException) { logger.warn("Ignoring JMS error while running the sender worker: {}", e.getMessage(), e); workerStateInfo.setState(false, WorkerStateInfo.WorkerExitStatus.WORKER_EXIT_SUCCESS, e); } else { logger.error("JMS error while running the sender worker: {}", e.getMessage(), e); workerStateInfo.setState(false, WorkerStateInfo.WorkerExitStatus.WORKER_EXIT_FAILURE, e); } } }
Example 3
Source File: AmqpPublisherActor.java From ditto with Eclipse Public License 2.0 | 5 votes |
private static String jmsExceptionToString(final JMSException jmsException) { if (jmsException.getCause() != null) { return String.format("[%s] %s (cause: %s - %s)", jmsException.getErrorCode(), jmsException.getMessage(), jmsException.getCause().getClass().getSimpleName(), jmsException.getCause().getMessage()); } return String.format("[%s] %s", jmsException.getErrorCode(), jmsException.getMessage()); }
Example 4
Source File: JmsExceptionThrowingFunction.java From ditto with Eclipse Public License 2.0 | 5 votes |
/** * Wraps a {@link org.eclipse.ditto.services.connectivity.messaging.amqp.JmsExceptionThrowingFunction} returning * a function by converting thrown {@link javax.jms.JMSException} to {@link javax.jms.JMSRuntimeException}. * * @param throwingFunction the JmsExceptionThrowingBiConsumer that throws {@link javax.jms.JMSException} * @param <T> type of results. * @return a function that throws {@link javax.jms.JMSRuntimeException} */ static <T> Function<Message, T> wrap(final JmsExceptionThrowingFunction<T> throwingFunction) { return (m) -> { try { return throwingFunction.apply(m); } catch (final JMSException jmsException) { throw new JMSRuntimeException(jmsException.getMessage(), jmsException.getErrorCode(), jmsException.getCause()); } }; }
Example 5
Source File: JmsExceptionThrowingBiConsumer.java From ditto with Eclipse Public License 2.0 | 5 votes |
/** * Wraps a {@link JmsExceptionThrowingBiConsumer} returning a BiConsumer by converting thrown {@link JMSException}s * to {@link JMSRuntimeException}s. * * @param throwingConsumer the JmsExceptionThrowingBiConsumer that throws {@link JMSException} * @return a BiConsumer that throws {@link JMSRuntimeException} */ static <T> BiConsumer<Message, T> wrap(final JmsExceptionThrowingBiConsumer<T> throwingConsumer) { return (m, v) -> { try { throwingConsumer.accept(m, v); } catch (final JMSException jmsException) { throw new JMSRuntimeException(jmsException.getMessage(), jmsException.getErrorCode(), jmsException.getCause()); } }; }
Example 6
Source File: JMS20WorkerThread.java From perf-harness with MIT License | 5 votes |
/** * Overloaded method to cross-link JDK 1.4 initCause and JMS 1.1 * linkedException if it has not already been done by the JMS vendor * implementation. * * @param je */ protected void handleException(JMSException je) { //If thread not already stopped, set endTime if (endTime == 0) { endTime = System.currentTimeMillis(); } Exception le = je.getLinkedException(); Throwable t = je.getCause(); if ((null == t) && (null != le) && (t != le)) { je.initCause(le); } handleException((Exception) je); }
Example 7
Source File: SecurityTestSupport.java From activemq-artemis with Apache License 2.0 | 5 votes |
/** * @throws JMSException */ public Message doSend(boolean fail) throws JMSException { Connection adminConnection = factory.createConnection("system", "manager"); connections.add(adminConnection); adminConnection.start(); Session adminSession = adminConnection.createSession(false, Session.AUTO_ACKNOWLEDGE); MessageConsumer consumer = adminSession.createConsumer(destination); Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); try { sendMessages(session, destination, 1); } catch (JMSException e) { // If test is expected to fail, the cause must only be a // SecurityException // otherwise rethrow the exception if (!fail || !(e.getCause() instanceof SecurityException)) { throw e; } } Message m = consumer.receive(1000); if (fail) { assertNull(m); } else { assertNotNull(m); assertEquals("0", ((TextMessage) m).getText()); assertNull(consumer.receiveNoWait()); } return m; }
Example 8
Source File: SecurityTestSupport.java From activemq-artemis with Apache License 2.0 | 5 votes |
/** * @throws JMSException */ public Message doReceive(boolean fail) throws JMSException { connection.start(); Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); MessageConsumer consumer = null; try { consumer = session.createConsumer(destination); if (fail) { fail("Expected failure due to security constraint."); } } catch (JMSException e) { if (fail && e.getCause() instanceof SecurityException) { return null; } throw e; } Connection adminConnection = factory.createConnection("system", "manager"); connections.add(adminConnection); Session adminSession = adminConnection.createSession(false, Session.AUTO_ACKNOWLEDGE); sendMessages(adminSession, destination, 1); Message m = consumer.receive(1000); assertNotNull(m); assertEquals("0", ((TextMessage) m).getText()); assertNull(consumer.receiveNoWait()); return m; }
Example 9
Source File: DurableSubProcessMultiRestartTest.java From activemq-artemis with Apache License 2.0 | 5 votes |
@Override public void run() { long end = System.currentTimeMillis() + RUNTIME; try { // while (true) { while (end > System.currentTimeMillis()) { processLock.readLock().lock(); try { process(5000); } finally { processLock.readLock().unlock(); } } unsubscribe(); } catch (JMSException maybe) { if (maybe.getCause() instanceof IOException) { // ok on broker shutdown; } else { exit(toString() + " failed with JMSException", maybe); } } catch (Throwable e) { exit(toString() + " failed.", e); } LOG.info(toString() + " DONE. MsgCout=" + msgCount); }
Example 10
Source File: FailedConnectionsIntegrationTest.java From qpid-jms with Apache License 2.0 | 5 votes |
@Test(timeout = 20000) public void testConnectWithRedirect() throws Exception { Map<Symbol, Object> redirectInfo = new HashMap<Symbol, Object>(); redirectInfo.put(OPEN_HOSTNAME, "vhost"); redirectInfo.put(NETWORK_HOST, "127.0.0.1"); redirectInfo.put(PORT, 5672); try (TestAmqpPeer testPeer = new TestAmqpPeer();) { testPeer.rejectConnect(ConnectionError.REDIRECT, "Server is full, go away", redirectInfo); try { establishAnonymousConnecton(testPeer, true); fail("Should have thrown JMSException"); } catch (JMSException jmsex) { assertTrue(jmsex.getCause() instanceof ProviderConnectionRedirectedException); ProviderConnectionRedirectedException redirectEx = (ProviderConnectionRedirectedException) jmsex.getCause(); URI redirectionURI = redirectEx.getRedirectionURI(); assertNotNull(redirectionURI); assertTrue("vhost", redirectionURI.getQuery().contains("amqp.vhost=vhost")); assertEquals("127.0.0.1", redirectionURI.getHost()); assertEquals(5672, redirectionURI.getPort()); } catch (Exception ex) { fail("Should have thrown JMSException: " + ex); } testPeer.waitForAllHandlersToComplete(1000); } }
Example 11
Source File: KillSlowConsumerExample.java From activemq-artemis with Apache License 2.0 | 4 votes |
public static void main(final String[] args) throws Exception { // Step 1. Create an initial context to perform the JNDI lookup. InitialContext initialContext = new InitialContext(); // Step 2. Perform a lookup on the queue Queue slowConsumerKillQueue = (Queue) initialContext.lookup("queue/slow.consumer.kill"); // Step 3. Perform a lookup on the Connection Factory ConnectionFactory connectionFactory = (ConnectionFactory) initialContext.lookup("ConnectionFactory"); // Step 4.Create a JMS Connection try (Connection connection = connectionFactory.createConnection()) { // Step 5. Create a JMS Session Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); // Step 6. Create a JMS Message Producer MessageProducer producer = session.createProducer(slowConsumerKillQueue); // Step 7. Create a Text Message TextMessage message = session.createTextMessage("This is a text message"); System.out.println("Sending messages to queue ... "); // Step 8. Send messages to the queue for (int i = 0; i < 50; i++) { producer.send(message); } // Step 9. Create a JMS Message Consumer MessageConsumer messageConsumer = session.createConsumer(slowConsumerKillQueue); // Step 10. Start the Connection connection.start(); System.out.println("About to wait for " + WAIT_TIME + " seconds"); // Step 11. Wait for slow consumer to be detected Thread.sleep(TimeUnit.SECONDS.toMillis(WAIT_TIME)); try { //step 12. Try to us the connection - expect it to be closed already messageConsumer.receive(TimeUnit.SECONDS.toMillis(1)); //messageConsumer.receive() should throw exception - we should not get to here. throw new RuntimeException("SlowConsumerExample.slowConsumerKill() FAILED - expected " + "connection to be shutdown by Slow Consumer policy"); } catch (JMSException ex) { if (ex.getCause() instanceof ActiveMQObjectClosedException) { //received exception - as expected System.out.println("SUCCESS! Received EXPECTED exception: " + ex); } else { throw new RuntimeException("SlowConsumerExample.slowConsumerKill() FAILED - expected " + "ActiveMQObjectClosedException BUT got " + ex.getCause()); } } } }