/** * Invoke the handler, wrapping any exception to a {@link ListenerExecutionFailedException} * with a dedicated error message. */ @Nullable private Object invokeHandler(javax.jms.Message jmsMessage, @Nullable Session session, Message<?> message) { InvocableHandlerMethod handlerMethod = getHandlerMethod(); try { return handlerMethod.invoke(message, jmsMessage, session); } catch (MessagingException ex) { throw new ListenerExecutionFailedException( createMessagingErrorMessage("Listener method could not be invoked with incoming message"), ex); } catch (Exception ex) { throw new ListenerExecutionFailedException("Listener method '" + handlerMethod.getMethod().toGenericString() + "' threw exception", ex); } }
@Test public void exceptionInListener() { javax.jms.Message message = new StubTextMessage("foo"); Session session = mock(Session.class); MessagingMessageListenerAdapter listener = getSimpleInstance("fail", String.class); try { listener.onMessage(message, session); fail("Should have thrown an exception"); } catch (JMSException ex) { fail("Should not have thrown a JMS exception"); } catch (ListenerExecutionFailedException ex) { assertEquals(IllegalArgumentException.class, ex.getCause().getClass()); assertEquals("Expected test exception", ex.getCause().getMessage()); } }
throw new ListenerExecutionFailedException( "Listener method '" + methodName + "' threw exception", targetEx); throw new ListenerExecutionFailedException("Failed to invoke target method '" + methodName + "' with arguments " + ObjectUtils.nullSafeToString(arguments), ex);
@Override protected void handleListenerException(Throwable ex) { assertNotNull("The Throwable passed to the handleListenerException(..) method must never be null.", ex); assertTrue("The Throwable passed to the handleListenerException(..) method must be of type [ListenerExecutionFailedException].", ex instanceof ListenerExecutionFailedException); ListenerExecutionFailedException lefx = (ListenerExecutionFailedException) ex; Throwable cause = lefx.getCause(); assertNotNull("The cause of a ListenerExecutionFailedException must be preserved.", cause); assertSame(exception, cause); } };
public Object doInJms(Session session) throws JMSException { try { processExchange(exchange, session, context); } catch (Exception e) { throw new ListenerExecutionFailedException("Exchange processing failed", e); } return null; } });
@Test public void exceptionInInvocation() { javax.jms.Message message = new StubTextMessage("foo"); Session session = mock(Session.class); MessagingMessageListenerAdapter listener = getSimpleInstance("wrongParam", Integer.class); try { listener.onMessage(message, session); fail("Should have thrown an exception"); } catch (JMSException ex) { fail("Should not have thrown a JMS exception"); } catch (ListenerExecutionFailedException ex) { assertEquals(MessageConversionException.class, ex.getCause().getClass()); } }
public Object doInJms(Session session) throws JMSException { try { sendError(exchange, error, session, context); } catch (Exception e) { throw new ListenerExecutionFailedException("Exchange processing failed", e); } return null; } });
public void onMessage(Message message) { try { JmsJcaConsumerEndpoint.this.onMessage(message, null); } catch (JMSException e) { throw new ListenerExecutionFailedException("Unable to handle message", e); } } }, tm);
/** * Invoke the handler, wrapping any exception to a {@link ListenerExecutionFailedException} * with a dedicated error message. */ @Nullable private Object invokeHandler(javax.jms.Message jmsMessage, @Nullable Session session, Message<?> message) { InvocableHandlerMethod handlerMethod = getHandlerMethod(); try { return handlerMethod.invoke(message, jmsMessage, session); } catch (MessagingException ex) { throw new ListenerExecutionFailedException( createMessagingErrorMessage("Listener method could not be invoked with incoming message"), ex); } catch (Exception ex) { throw new ListenerExecutionFailedException("Listener method '" + handlerMethod.getMethod().toGenericString() + "' threw exception", ex); } }
/** * Invoke the handler, wrapping any exception to a {@link ListenerExecutionFailedException} * with a dedicated error message. */ private Object invokeHandler(javax.jms.Message jmsMessage, Session session, Message<?> message) { try { return this.handlerMethod.invoke(message, jmsMessage, session); } catch (MessagingException ex) { throw new ListenerExecutionFailedException( createMessagingErrorMessage("Listener method could not be invoked with incoming message"), ex); } catch (Exception ex) { throw new ListenerExecutionFailedException("Listener method '" + this.handlerMethod.getMethod().toGenericString() + "' threw exception", ex); } }
throw new ListenerExecutionFailedException( "Listener method '" + methodName + "' threw exception", targetEx); throw new ListenerExecutionFailedException("Failed to invoke target method '" + methodName + "' with arguments " + ObjectUtils.nullSafeToString(arguments), ex);
throw new ListenerExecutionFailedException( "Listener method '" + methodName + "' threw exception", targetEx); throw new ListenerExecutionFailedException("Failed to invoke target method '" + methodName + "' with arguments " + ObjectUtils.nullSafeToString(arguments), ex);