/** * Convenience method to get the vendor specific error code if * the root cause was an instance of JMSException. * @return a string specifying the vendor-specific error code if the * root cause is an instance of JMSException, or {@code null} */ @Nullable public String getErrorCode() { Throwable cause = getCause(); if (cause instanceof JMSException) { return ((JMSException) cause).getErrorCode(); } return null; }
protected MessagingException convertJmsException(JmsException ex) { if (ex instanceof org.springframework.jms.support.destination.DestinationResolutionException || ex instanceof InvalidDestinationException) { return new DestinationResolutionException(ex.getMessage(), ex); } if (ex instanceof org.springframework.jms.support.converter.MessageConversionException) { return new MessageConversionException(ex.getMessage(), ex); } // Fallback return new MessagingException(ex.getMessage(), ex); }
@Test public void testExceptionStackTrace() { JMSException jmsEx = new JMSException("could not connect"); Exception innerEx = new Exception("host not found"); jmsEx.setLinkedException(innerEx); JmsException springJmsEx = JmsUtils.convertJmsAccessException(jmsEx); StringWriter sw = new StringWriter(); PrintWriter out = new PrintWriter(sw); springJmsEx.printStackTrace(out); String trace = sw.toString(); assertTrue("inner jms exception not found", trace.indexOf("host not found") > 0); }
@Override public void forwardAlarms(List<NorthboundAlarm> alarms) throws NorthbounderException { for (final NorthboundAlarm alarm : alarms) { final Integer count = alarm.getCount(); LOG.debug("Does destination {} take only first occurances? {} Is new alarm? Has count of {}.", m_jmsDestination.getName(), m_jmsDestination.isFirstOccurrenceOnly(), count); if(count > 1 && m_jmsDestination.isFirstOccurrenceOnly()) { LOG.debug("Skipping because not new alarm."); continue; } LOG.debug("Attempting to send a message to {} of type {}", m_jmsDestination.getJmsDestination(), m_jmsDestination.getDestinationType()); try { m_template.send(m_jmsDestination.getJmsDestination(), new MessageCreator() { @Override public Message createMessage(Session session) throws JMSException { if (m_jmsDestination.isSendAsObjectMessageEnabled()) { return session.createObjectMessage(alarm); } else { return session.createTextMessage(convertAlarmToText(alarm)); } } }); LOG.debug("Sent message"); } catch (JmsException e) { LOG.error("Unable to send alarm to northbound JMS because {}", e.getLocalizedMessage(), e); } } }
/** * 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; }
protected MessagingException convertJmsException(JmsException ex) { if (ex instanceof org.springframework.jms.support.destination.DestinationResolutionException || ex instanceof InvalidDestinationException) { return new DestinationResolutionException(ex.getMessage(), ex); } if (ex instanceof org.springframework.jms.support.converter.MessageConversionException) { return new MessageConversionException(ex.getMessage(), ex); } // Fallback return new MessagingException(ex.getMessage(), ex); }
protected void doTestJmsException(JMSException original, Class<? extends JmsException> thrownExceptionClass) throws Exception { JmsTemplate template = createTemplate(); template.setConnectionFactory(this.connectionFactory); template.setMessageConverter(new SimpleMessageConverter()); String s = "Hello world"; MessageProducer messageProducer = mock(MessageProducer.class); TextMessage textMessage = mock(TextMessage.class); reset(this.session); given(this.session.createProducer(this.queue)).willReturn(messageProducer); given(this.session.createTextMessage("Hello world")).willReturn(textMessage); willThrow(original).given(messageProducer).send(textMessage); try { template.convertAndSend(this.queue, s); fail("Should have thrown JmsException"); } catch (JmsException wrappedEx) { // expected assertEquals(thrownExceptionClass, wrappedEx.getClass()); assertEquals(original, wrappedEx.getCause()); } verify(messageProducer).close(); verify(this.session).close(); verify(this.connection).close(); }
@Override protected void doStart() { if (!listenerContainer.isRunning()) { try { listenerContainer.start(); } catch (JmsException ex) { LOG.error("Error starting message listener container: " + ex.getMessage(), ex); throw ex; } LOG.info("Started"); } }
/** * Convenience method to get the vendor specific error code if * the root cause was an instance of JMSException. * @return a string specifying the vendor-specific error code if the * root cause is an instance of JMSException, or {@code null} */ public String getErrorCode() { Throwable cause = getCause(); if (cause instanceof JMSException) { return ((JMSException) cause).getErrorCode(); } return null; }
@Override protected void doStop() { if (listenerContainer.isRunning()) { try { listenerContainer.stop(); } catch (JmsException ex) { LOG.error("Error stopping message listener container: " + ex.getMessage(), ex); throw ex; } LOG.info("Stopped"); } }
/** * Convenience method to get the vendor specific error code if * the root cause was an instance of JMSException. * @return a string specifying the vendor-specific error code if the * root cause is an instance of JMSException, or {@code null} */ public String getErrorCode() { Throwable cause = getCause(); if (cause instanceof JMSException) { return ((JMSException) cause).getErrorCode(); } return null; }
protected void doStop() { // stop all listener containers for (Entry<BridgedDestination, AbstractMessageListenerContainer> entry : listenerMap.entrySet()) { final BridgedDestination destination = entry.getKey(); final AbstractMessageListenerContainer listener = entry.getValue(); if (listener.isRunning()) { try { if (LOG.isDebugEnabled()) { LOG.debug("Stopping listener for " + destination); } listener.stop(); if (LOG.isDebugEnabled()) { LOG.debug("Listener stopped for " + destination); } } catch (JmsException e) { LOG.error("Error stopping connector for listener " + listener + ": " + e.getMessage(), e); } } } LOG.info("Stopped"); }
/** * Convenience method to get the vendor specific error code if * the root cause was an instance of JMSException. * @return a string specifying the vendor-specific error code if the * root cause is an instance of JMSException, or {@code null} */ @Nullable public String getErrorCode() { Throwable cause = getCause(); if (cause instanceof JMSException) { return ((JMSException) cause).getErrorCode(); } return null; }
protected void doStart() { JmsException failedException = null; // start all the listener containers for (Entry<BridgedDestination, AbstractMessageListenerContainer> entry : listenerMap.entrySet()) { final BridgedDestination destination = entry.getKey(); final AbstractMessageListenerContainer listener = entry.getValue(); if (!listener.isRunning()) { try { if (LOG.isDebugEnabled()) { LOG.debug("Starting listener for " + destination); } listener.start(); if (LOG.isDebugEnabled()) { LOG.debug("Listener started for " + destination); } } catch (JmsException e) { failedException = e; LOG.error("Error stopping connector for listener " + listener + ": " + e.getMessage(), e); break; } } } if (failedException != null) { // stop all listeners stop(); throw failedException; } LOG.info("Started"); }
/** * 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; }
+ destination.getName() + " : " + e.getMessage(), e);
/** * 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; }
@Override protected void doDestroy() { if (listenerContainer.isActive()) { try { listenerContainer.destroy(); } catch (JmsException ex) { LOG.error("Error destroying message listener container: " + ex.getMessage(), ex); throw ex; } } // check if we created pooled connection factories if (localBrokerConfig.getConnectionFactory() == null && localConnectionFactory != null) { ((PooledConnectionFactory)localConnectionFactory).stop(); } if (remoteBrokerConfig != null && remoteBrokerConfig.getConnectionFactory() == null && remoteConnectionFactory != null) { ((PooledConnectionFactory)remoteConnectionFactory).stop(); } LOG.info("Destroyed"); }
/** * 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; }