setAttributesIfNecessary(message, null); getMessagingTemplate().send(getErrorChannel(), buildErrorMessage(null, new ListenerExecutionFailedException("Message conversion failed", e, message)));
setAttributesIfNecessary(message, null); AmqpInboundGateway.this.messagingTemplate.send(errorChannel, buildErrorMessage(null, new ListenerExecutionFailedException("Message conversion failed", e, message)));
/** * @param e The Exception. * @param message The failed message. * @return If 'e' is of type {@link ListenerExecutionFailedException} - return 'e' as it is, otherwise wrap it to * {@link ListenerExecutionFailedException} and return. */ protected ListenerExecutionFailedException wrapToListenerExecutionFailedExceptionIfNeeded(Exception e, Message message) { if (!(e instanceof ListenerExecutionFailedException)) { // Wrap exception to ListenerExecutionFailedException. return new ListenerExecutionFailedException("Listener threw exception", e, message); } return (ListenerExecutionFailedException) e; }
/** * @param e The Exception. * @param message The failed message. * @return If 'e' is of type {@link ListenerExecutionFailedException} - return 'e' as it is, otherwise wrap it to * {@link ListenerExecutionFailedException} and return. */ protected ListenerExecutionFailedException wrapToListenerExecutionFailedExceptionIfNeeded(Exception e, Message message) { if (!(e instanceof ListenerExecutionFailedException)) { // Wrap exception to ListenerExecutionFailedException. return new ListenerExecutionFailedException("Listener threw exception", e, message); } return (ListenerExecutionFailedException) e; }
@Override public void recover(Message message, Throwable cause) { if (this.logger.isWarnEnabled()) { this.logger.warn("Retries exhausted for message " + message, cause); } throw new ListenerExecutionFailedException("Retry Policy Exhausted", new AmqpRejectAndDontRequeueException(cause), message); }
@Override public void recover(Message message, Throwable cause) { if (this.logger.isWarnEnabled()) { this.logger.warn("Retries exhausted for message " + message, cause); } throw new ListenerExecutionFailedException("Retry Policy Exhausted", new AmqpRejectAndDontRequeueException(cause), message); }
/** * Invoke the handler, wrapping any exception to a {@link ListenerExecutionFailedException} * with a dedicated error message. * @param amqpMessage the raw message. * @param channel the channel. * @param message the messaging message. * @return the result of invoking the handler. */ private InvocationResult invokeHandler(org.springframework.amqp.core.Message amqpMessage, Channel channel, Message<?> message) { try { return this.handlerAdapter.invoke(message, amqpMessage, channel); } catch (MessagingException ex) { throw new ListenerExecutionFailedException(createMessagingErrorMessage("Listener method could not " + "be invoked with the incoming message", message.getPayload()), ex, amqpMessage); } catch (Exception ex) { throw new ListenerExecutionFailedException("Listener method '" + this.handlerAdapter.getMethodAsString(message.getPayload()) + "' threw exception", ex, amqpMessage); } }
/** * Invoke the handler, wrapping any exception to a {@link ListenerExecutionFailedException} * with a dedicated error message. * @param amqpMessage the raw message. * @param channel the channel. * @param message the messaging message. * @return the result of invoking the handler. */ private InvocationResult invokeHandler(org.springframework.amqp.core.Message amqpMessage, Channel channel, Message<?> message) { try { return this.handlerAdapter.invoke(message, amqpMessage, channel); } catch (MessagingException ex) { throw new ListenerExecutionFailedException(createMessagingErrorMessage("Listener method could not " + "be invoked with the incoming message", message.getPayload()), ex, amqpMessage); } catch (Exception ex) { throw new ListenerExecutionFailedException("Listener method '" + this.handlerAdapter.getMethodAsString(message.getPayload()) + "' threw exception", ex, amqpMessage); } }
@Override public void handleMessage(org.springframework.messaging.Message<?> message) throws MessagingException { Message amqpMessage = (Message) message.getHeaders() .get(AmqpMessageHeaderErrorMessageStrategy.AMQP_RAW_MESSAGE); /* * NOTE: The following IF and subsequent ELSE IF should never happen under normal interaction and * it should always go to the last ELSE * However, given that this is a handler subscribing to the public channel and that we can't control what * type of Message may be sent to that channel (user decides to send a Message manually) the 'IF/ELSE IF' provides * a safety net to handle any message properly. */ if (!(message instanceof ErrorMessage)) { logger.error("Expected an ErrorMessage, not a " + message.getClass().toString() + " for: " + message); throw new ListenerExecutionFailedException("Unexpected error message " + message, new AmqpRejectAndDontRequeueException(""), null); } else if (amqpMessage == null) { logger.error("No raw message header in " + message); throw new ListenerExecutionFailedException("Unexpected error message " + message, new AmqpRejectAndDontRequeueException(""), amqpMessage); } else { this.recoverer.recover(amqpMessage, (Throwable) message.getPayload()); } }
@Override public void handleMessage(org.springframework.messaging.Message<?> message) throws MessagingException { Message amqpMessage = (Message) message.getHeaders() .get(AmqpMessageHeaderErrorMessageStrategy.AMQP_RAW_MESSAGE); /* * NOTE: The following IF and subsequent ELSE IF should never happen under normal interaction and * it should always go to the last ELSE * However, given that this is a handler subscribing to the public channel and that we can't control what * type of Message may be sent to that channel (user decides to send a Message manually) the 'IF/ELSE IF' provides * a safety net to handle any message properly. */ if (!(message instanceof ErrorMessage)) { logger.error("Expected an ErrorMessage, not a " + message.getClass().toString() + " for: " + message); throw new ListenerExecutionFailedException("Unexpected error message " + message, new AmqpRejectAndDontRequeueException(""), null); } else if (amqpMessage == null) { logger.error("No raw message header in " + message); throw new ListenerExecutionFailedException("Unexpected error message " + message, new AmqpRejectAndDontRequeueException(""), amqpMessage); } else { this.recoverer.recover(amqpMessage, (Throwable) message.getPayload()); } }
@Test public void testErrorHandlerListenerExecutionFailedExceptionFromListener() throws Exception { int messageCount = 3; CountDownLatch latch = new CountDownLatch(messageCount); doTest(messageCount, errorHandler, latch, new ThrowingExceptionListener(latch, new ListenerExecutionFailedException("Listener throws specific runtime exception", null, mock(Message.class)))); }
throw new ListenerExecutionFailedException("Listener method '" // NOSONAR lost stack trace + methodName + "' threw exception", targetEx, originalMessage); throw new ListenerExecutionFailedException("Failed to invoke target method '" + methodName + "' with argument type = [" + StringUtils.collectionToCommaDelimitedString(arrayClass) + "], value = [" + ObjectUtils.nullSafeToString(arguments) + "]", ex, originalMessage);
int length = byteBuffer.getInt(); if (length < 0 || length > byteBuffer.remaining()) { throw new ListenerExecutionFailedException("Bad batched message received", new MessageConversionException("Insufficient batch data at offset " + byteBuffer.position()), message);
int length = byteBuffer.getInt(); if (length < 0 || length > byteBuffer.remaining()) { throw new ListenerExecutionFailedException("Bad batched message received", new MessageConversionException("Insufficient batch data at offset " + byteBuffer.position()), message);
setAttributesIfNecessary(message, null); getMessagingTemplate().send(getErrorChannel(), buildErrorMessage(null, new ListenerExecutionFailedException("Message conversion failed", e, message)));
setAttributesIfNecessary(message, null); AmqpInboundGateway.this.messagingTemplate.send(errorChannel, buildErrorMessage(null, new ListenerExecutionFailedException("Message conversion failed", e, message)));
throw new ListenerExecutionFailedException("Cannot retry message more than once without an ID", new AmqpRejectAndDontRequeueException("Not retryable; rejecting and not requeuing", ex), messageIn);
throw new ListenerExecutionFailedException("Cannot retry message more than once without an ID", new AmqpRejectAndDontRequeueException("Not retryable; rejecting and not requeuing", ex), messageIn);
private void doTest(Throwable cause) { ConditionalRejectingErrorHandler handler = new ConditionalRejectingErrorHandler(); handler.handleError( new ListenerExecutionFailedException("test", cause, new org.springframework.amqp.core.Message(new byte[0], new MessageProperties()))); }
willDoNothing().given(logger).warn(anyString(), any(Throwable.class)); new DirectFieldAccessor(handler).setPropertyValue("logger", logger); handler.handleError(new ListenerExecutionFailedException("intended", new RuntimeException(), new org.springframework.amqp.core.Message("".getBytes(), new MessageProperties()))); handler.handleError(new ListenerExecutionFailedException("intended", new MessageConversionException(""), new org.springframework.amqp.core.Message("".getBytes(), new MessageProperties()))); fail("Expected exception"); handler.handleError(new ListenerExecutionFailedException("intended", new org.springframework.messaging.converter.MessageConversionException(""), new org.springframework.amqp.core.Message("".getBytes(), new MessageProperties()))); MethodParameter mp = new MethodParameter(Foo.class.getMethod("foo", String.class), 0); try { handler.handleError(new ListenerExecutionFailedException("intended", new MethodArgumentNotValidException(message, mp), new org.springframework.amqp.core.Message("".getBytes(), new MessageProperties()))); handler.handleError(new ListenerExecutionFailedException("intended", new MethodArgumentTypeMismatchException(message, mp, ""), new org.springframework.amqp.core.Message("".getBytes(), new MessageProperties())));