/** * Build a descriptive exception message for the given JMSException, * incorporating a linked exception's message if appropriate. * @param ex the JMSException to build a message for * @return the descriptive message String * @see javax.jms.JMSException#getLinkedException() */ public static String buildExceptionMessage(JMSException ex) { String message = ex.getMessage(); Exception linkedEx = ex.getLinkedException(); if (linkedEx != null) { if (message == null) { message = linkedEx.toString(); } else { String linkedMessage = linkedEx.getMessage(); if (linkedMessage != null && !message.contains(linkedMessage)) { message = message + "; nested exception is " + linkedEx; } } } return message; }
/** * Return the detail message, including the message from the linked exception * if there is one. * @see javax.jms.JMSException#getLinkedException() */ @Override @Nullable public String getMessage() { String message = super.getMessage(); Throwable cause = getCause(); if (cause instanceof JMSException) { Exception linkedEx = ((JMSException) cause).getLinkedException(); if (linkedEx != null) { String linkedMessage = linkedEx.getMessage(); String causeMessage = cause.getMessage(); if (linkedMessage != null && (causeMessage == null || !causeMessage.contains(linkedMessage))) { message = message + "; nested exception is " + linkedEx; } } } return message; }
private static JMSException findRootJMSException(JMSException jmse) { if (jmse.getLinkedException() != null) { Throwable rootCause = getRootCause(jmse.getLinkedException()); if (rootCause instanceof JMSException) { return (JMSException) rootCause; } } return jmse; }
try { . . code that might throw a JMSException . } catch (JMSException je) { System.err.println("caught "+je); Exception e = je.getLinkedException(); if (e != null) { System.err.println("linked exception: "+e); } else { System.err.println("No linked exception found."); } }
public void onException(JMSException arg0) { log.error("JMS onException (" + arg0.getErrorCode() + ")", arg0); if(arg0.getLinkedException() != null) log.error("Linked exception ", arg0.getLinkedException()); } }
try { . . code that might throw a JMSException . } catch (JMSException je) { System.err.println("caught "+je); Exception e = je.getLinkedException(); if (e != null) { System.err.println("linked exception: "+e); } else { System.err.println("No linked exception found."); } }
public void onException(JMSException arg0) { log.error("JMS onException (" + arg0.getErrorCode() + ")", arg0); if(arg0.getLinkedException() != null) log.error("Linked exception ", arg0.getLinkedException()); }
/** * Default action on exception receiving. * * @param exception * JMS Exception received on connection. */ protected void onExceptionDefault(JMSException exception) { log.error("JMS onException (error code = " + exception.getErrorCode() + ")", exception); if (exception.getLinkedException() != null) log.error("Linked exception ", exception.getLinkedException()); } }
public static void logJMSException(Logger log, String additionalMessage, JMSException exception) { log.error(additionalMessage + "; (error code = " + exception.getErrorCode() + ")", exception); if (exception.getLinkedException() != null){ log.error("Linked exception ", exception.getLinkedException()); } } }
MQQueueConnectionFactory cf = new MQQueueConnectionFactory(); ExceptionListener exceptionListener = new ExceptionListener(){ @Override public void onException(JMSException e) { System.out.println(e); if(e.getLinkedException() != null) System.out.println(e.getLinkedException()); } }; MQQueueConnection connection = (MQQueueConnection) cf.createQueueConnection(); connection.setExceptionListener(exceptionListener);
public class MyConsumer implements ExceptionListener, MessageListener { private void init(){ Connection connection = ... //create connection connection.setExceptionListener(this); connection.start(); } public void onException(JMSException e){ String errorCode = e.getErrorCode(); Exception ex = e.getLinkedException(); //clean up resources, or, attempt to reconnect } public void onMessage(Message m){ ... }
@Override public void printStackTrace(final PrintStream ps) { super.printStackTrace(ps); if (JMSException.class.isInstance(getCause())) { final JMSException jmsException = JMSException.class.cast(getCause()); if (jmsException.getLinkedException() != null) { ps.print("Linked by: "); jmsException.getLinkedException().printStackTrace(ps); } } }
@Override public void printStackTrace(final PrintWriter pw) { super.printStackTrace(pw); if (JMSException.class.isInstance(getCause())) { final JMSException jmsException = JMSException.class.cast(getCause()); if (jmsException.getLinkedException() != null) { pw.print("Linked by: "); jmsException.getLinkedException().printStackTrace(pw); } } }
/** * Build a descriptive exception message for the given JMSException, * incorporating a linked exception's message if appropriate. * @param ex the JMSException to build a message for * @return the descriptive message String * @see javax.jms.JMSException#getLinkedException() */ public static String buildExceptionMessage(JMSException ex) { String message = ex.getMessage(); Exception linkedEx = ex.getLinkedException(); if (linkedEx != null) { if (message == null) { message = linkedEx.toString(); } else { String linkedMessage = linkedEx.getMessage(); if (linkedMessage != null && !message.contains(linkedMessage)) { message = message + "; nested exception is " + linkedEx; } } } return message; }
private void logError( JMSException e ) { if (e.getErrorCode() != null) err.println("error={"+e.getErrorCode()+"} "+e.getMessage()); else err.println(e.getMessage()); if (e.getLinkedException() != null) { err.println("Linked exception was : "); e.getLinkedException().printStackTrace(err); } }
/** * Generate a single line String consisted of the summary of a JMSException * @param e the exception * @return summary of the exception in one line */ static public String exceptionSummary(JMSException e){ Throwable cause = e.getCause(); Exception linked = e.getLinkedException(); return "JMSException: " + e.getMessage() + ", error code: " + e.getErrorCode() + ", linked exception: " + (linked == null ? null : (linked.getClass().getName() + " - " + linked.getMessage())) + ", cause: " + (cause == null ? null : (cause.getClass().getName() + " - " + cause.getMessage())); }
/** * Return the detail message, including the message from the linked exception * if there is one. * @see javax.jms.JMSException#getLinkedException() */ public String getMessage() { String message = super.getMessage(); Throwable cause = getCause(); if (cause instanceof JMSException) { Exception linkedEx = ((JMSException) cause).getLinkedException(); if (linkedEx != null) { String linkedMessage = linkedEx.getMessage(); String causeMessage = cause.getMessage(); if (linkedMessage != null && (causeMessage == null || !causeMessage.contains(linkedMessage))) { message = message + "; nested exception is " + linkedEx; } } } return message; }
try { ActiveMQConnectionFactory factory = new ActiveMQConnectionFactory(url); // set transport listener so that active MQ start is notified. factory.setTransportListener(transportListenerObject); Connection connection = factory.createConnection(); // This will throw error if activeMQ is not running. connection.setClientID("my_client_id"); } catch (JMSException ex) { if (ex.getLinkedException() instanceof IOException) { // ActiveMQ is not running. Do some logic here. // use the TransportListener to restart the activeMQ connection // when activeMQ comes back up. } else { // Something seriously went wrong with the factory or connection // creation. Abort the process here, as nothing can be done. // Log the error and troubleshoot. } }
/** * Return the detail message, including the message from the linked exception * if there is one. * @see javax.jms.JMSException#getLinkedException() */ @Override public String getMessage() { String message = super.getMessage(); Throwable cause = getCause(); if (cause instanceof JMSException) { Exception linkedEx = ((JMSException) cause).getLinkedException(); if (linkedEx != null) { String linkedMessage = linkedEx.getMessage(); String causeMessage = cause.getMessage(); if (linkedMessage != null && (causeMessage == null || !causeMessage.contains(linkedMessage))) { message = message + "; nested exception is " + linkedEx; } } } return message; }
/** * Fails a test with an exception which will be used for a message. * * If the exception is an instance of <code>javax.jms.JMSException</code>, the * message of the failure will contained both the JMSException and its linked exception * (provided there's one). */ public void fail(final Exception e) { if (e instanceof javax.jms.JMSException) { JMSException exception = (JMSException) e; String message = e.toString(); Exception linkedException = exception.getLinkedException(); if (linkedException != null) { message += " [linked exception: " + linkedException + "]"; } Assert.fail(message); } else { Assert.fail(e.getMessage()); } }