private void sendInternal(Message<?> message) { String destination = SimpMessageHeaderAccessor.getDestination(message.getHeaders()); Assert.notNull(destination, "Destination header required"); long timeout = this.sendTimeout; boolean sent = (timeout >= 0 ? this.messageChannel.send(message, timeout) : this.messageChannel.send(message)); if (!sent) { throw new MessageDeliveryException(message, "Failed to send message to destination '" + destination + "' within timeout: " + timeout); } }
@Override public boolean send(Message<?> message, long timeout) { this.replyMessage = message; boolean alreadyReceivedReply = this.hasReceived; this.replyLatch.countDown(); String errorDescription = null; if (this.hasTimedOut) { errorDescription = "Reply message received but the receiving thread has exited due to a timeout"; } else if (alreadyReceivedReply) { errorDescription = "Reply message received but the receiving thread has already received a reply"; } else if (this.hasSendFailed) { errorDescription = "Reply message received but the receiving thread has exited due to " + "an exception while sending the request message"; } if (errorDescription != null) { if (logger.isWarnEnabled()) { logger.warn(errorDescription + ":" + message); } if (this.throwExceptionOnLateReply) { throw new MessageDeliveryException(message, errorDescription); } } return true; } }
private void execute(Message<byte[]> message) { if (logger.isTraceEnabled()) { StompHeaderAccessor accessor = MessageHeaderAccessor.getAccessor(message, StompHeaderAccessor.class); if (accessor != null) { logger.trace("Sending " + accessor.getDetailedLogMessage(message.getPayload())); } } TcpConnection<byte[]> conn = this.connection; Assert.state(conn != null, "Connection closed"); try { conn.send(message).get(); } catch (ExecutionException ex) { throw new MessageDeliveryException(message, ex.getCause()); } catch (Throwable ex) { throw new MessageDeliveryException(message, ex); } }
@Override public ListenableFuture<Void> forward(Message<?> message, StompHeaderAccessor accessor) { try { ListenableFuture<Void> future = super.forward(message, accessor); if (message.getHeaders().get(SimpMessageHeaderAccessor.IGNORE_ERROR) == null) { future.get(); } return future; } catch (Throwable ex) { throw new MessageDeliveryException(message, ex); } } }
@Override public void run() { Message<?> message = this.inputMessage; try { message = applyBeforeHandle(message); if (message == null) { return; } this.messageHandler.handleMessage(message); triggerAfterMessageHandled(message, null); } catch (Exception ex) { triggerAfterMessageHandled(message, ex); if (ex instanceof MessagingException) { throw (MessagingException) ex; } String description = "Failed to handle " + message + " to " + this + " in " + this.messageHandler; throw new MessageDeliveryException(message, description, ex); } catch (Throwable err) { String description = "Failed to handle " + message + " to " + this + " in " + this.messageHandler; MessageDeliveryException ex2 = new MessageDeliveryException(message, description, err); triggerAfterMessageHandled(message, ex2); throw ex2; } }
@Override public final boolean send(Message<?> message, long timeout) { Assert.notNull(message, "Message must not be null"); Message<?> messageToUse = message; ChannelInterceptorChain chain = new ChannelInterceptorChain(); boolean sent = false; try { messageToUse = chain.applyPreSend(messageToUse, this); if (messageToUse == null) { return false; } sent = sendInternal(messageToUse, timeout); chain.applyPostSend(messageToUse, this, sent); chain.triggerAfterSendCompletion(messageToUse, this, sent, null); return sent; } catch (Exception ex) { chain.triggerAfterSendCompletion(messageToUse, this, sent, ex); if (ex instanceof MessagingException) { throw (MessagingException) ex; } throw new MessageDeliveryException(messageToUse,"Failed to send message to " + this, ex); } catch (Throwable err) { MessageDeliveryException ex2 = new MessageDeliveryException(messageToUse, "Failed to send message to " + this, err); chain.triggerAfterSendCompletion(messageToUse, this, sent, ex2); throw ex2; } }
protected final void doSend(MessageChannel channel, Message<?> message, long timeout) { Assert.notNull(channel, "MessageChannel is required"); Message<?> messageToSend = message; MessageHeaderAccessor accessor = MessageHeaderAccessor.getAccessor(message, MessageHeaderAccessor.class); if (accessor != null && accessor.isMutable()) { accessor.removeHeader(this.sendTimeoutHeader); accessor.removeHeader(this.receiveTimeoutHeader); accessor.setImmutable(); } else if (message.getHeaders().containsKey(this.sendTimeoutHeader) || message.getHeaders().containsKey(this.receiveTimeoutHeader)) { messageToSend = MessageBuilder.fromMessage(message) .setHeader(this.sendTimeoutHeader, null) .setHeader(this.receiveTimeoutHeader, null) .build(); } boolean sent = (timeout >= 0 ? channel.send(messageToSend, timeout) : channel.send(messageToSend)); if (!sent) { throw new MessageDeliveryException(message, "Failed to send message to channel '" + channel + "' within timeout: " + timeout); } }
throw new MessageDeliveryException("Message broker not active. Consider subscribing to " + "receive BrokerAvailabilityEvent's from an ApplicationListener Spring bean.");
/** * If the exception is not a {@link MessagingException} or does not have * a {@link MessagingException#getFailedMessage() failedMessage}, wrap it * in a new {@link MessageDeliveryException} with the message. * @param message the message. * @param text a Supplier for the new exception's message text. * @param e the exception. * @return the wrapper, if necessary, or the original exception. * @since 5.0.4 */ public static RuntimeException wrapInDeliveryExceptionIfNecessary(Message<?> message, Supplier<String> text, Exception e) { RuntimeException runtimeException = (e instanceof RuntimeException) ? (RuntimeException) e : new MessageDeliveryException(message, text.get(), e); if (!(e instanceof MessagingException) || ((MessagingException) e).getFailedMessage() == null) { runtimeException = new MessageDeliveryException(message, text.get(), e); } return runtimeException; }
@Override public Message<?> preSend(Message<?> message, MessageChannel channel) { for (MessageSelector selector : this.selectors) { if (!selector.accept(message)) { throw new MessageDeliveryException(message, "selector '" + selector + "' did not accept message"); } } return message; }
private void sendInternal(Message<?> message) { String destination = SimpMessageHeaderAccessor.getDestination(message.getHeaders()); Assert.notNull(destination, "Destination header required"); long timeout = this.sendTimeout; boolean sent = (timeout >= 0 ? this.messageChannel.send(message, timeout) : this.messageChannel.send(message)); if (!sent) { throw new MessageDeliveryException(message, "Failed to send message to destination '" + destination + "' within timeout: " + timeout); } }
private List<? extends Exception> exceptionsList() { firstProblem = new MessageDeliveryException(message, "first problem"); return Arrays.asList(firstProblem, new MessageDeliveryException(message, "second problem"), new MessageDeliveryException(message, "third problem")); }
private Object determineDestination(Message<?> message) { if (this.destination != null) { return this.destination; } if (this.destinationName != null) { return this.destinationName; } if (this.destinationExpressionProcessor != null) { Object result = this.destinationExpressionProcessor.processMessage(message); if (!(result instanceof Destination || result instanceof String)) { throw new MessageDeliveryException(message, "Evaluation of destinationExpression failed to produce a Destination or destination name. Result was: " + result); } return result; } return null; }
private Destination determineRequestDestination(Message<?> message, Session session) throws JMSException { if (this.requestDestination != null) { return this.requestDestination; } if (this.requestDestinationName != null) { return this.resolveRequestDestination(this.requestDestinationName, session); } if (this.requestDestinationExpressionProcessor != null) { Object result = this.requestDestinationExpressionProcessor.processMessage(message); if (result instanceof Destination) { return (Destination) result; } if (result instanceof String) { return this.resolveRequestDestination((String) result, session); } throw new MessageDeliveryException(message, "Evaluation of requestDestinationExpression failed " + "to produce a Destination or destination name. Result was: " + result); } throw new MessageDeliveryException(message, "No requestDestination, requestDestinationName, or requestDestinationExpression has been configured."); }
private void execute(Message<byte[]> message) { if (logger.isTraceEnabled()) { StompHeaderAccessor accessor = MessageHeaderAccessor.getAccessor(message, StompHeaderAccessor.class); if (accessor != null) { logger.trace("Sending " + accessor.getDetailedLogMessage(message.getPayload())); } } TcpConnection<byte[]> conn = this.connection; Assert.state(conn != null, "Connection closed"); try { conn.send(message).get(); } catch (ExecutionException ex) { throw new MessageDeliveryException(message, ex.getCause()); } catch (Throwable ex) { throw new MessageDeliveryException(message, ex); } }
@Override public ListenableFuture<Void> forward(Message<?> message, StompHeaderAccessor accessor) { try { ListenableFuture<Void> future = super.forward(message, accessor); if (message.getHeaders().get(SimpMessageHeaderAccessor.IGNORE_ERROR) == null) { future.get(); } return future; } catch (Throwable ex) { throw new MessageDeliveryException(message, ex); } } }
@SuppressWarnings({ "unused" }) public void handleMessage(Object payload) { Message<?> siMessage = SubscribableRedisChannel.this.messageConverter.toMessage(payload, null); try { SubscribableRedisChannel.this.dispatcher.dispatch(siMessage); } catch (MessageDispatchingException e) { String exceptionMessage = e.getMessage(); throw new MessageDeliveryException(siMessage, (exceptionMessage == null ? e.getClass().getSimpleName() : exceptionMessage) + " for redis-channel '" + (StringUtils.hasText(SubscribableRedisChannel.this.topicName) ? SubscribableRedisChannel.this.topicName : "unknown") + "' (" + getFullChannelName() + ").", e); // NOSONAR false positive - never null } }
@Override protected boolean doSend(Message<?> message, long timeout) { try { return getRequiredDispatcher().dispatch(message); } catch (MessageDispatchingException e) { String description = e.getMessage() + " for channel '" + this.getFullChannelName() + "'."; throw new MessageDeliveryException(message, description, e); } }
@Override public void handleFrame(StompHeaders headers, Object payload) { Object thePayload = payload; if (thePayload == null) { thePayload = headers.getFirst(StompHeaderAccessor.STOMP_MESSAGE_HEADER); } if (thePayload != null) { Message<?> failedMessage = getMessageBuilderFactory().withPayload(thePayload) .copyHeaders(StompMessageHandler.this.headerMapper.toHeaders(headers)) .build(); MessagingException exception = new MessageDeliveryException(failedMessage, "STOMP frame handling error."); if (StompMessageHandler.this.applicationEventPublisher != null) { StompMessageHandler.this.applicationEventPublisher.publishEvent( new StompExceptionEvent(StompMessageHandler.this, exception)); } else { logger.error(exception); } } }
private Destination determineReplyDestination(Message<?> message, Session session) throws JMSException { if (this.replyDestination != null) { return this.replyDestination; } if (this.replyDestinationName != null) { return this.resolveReplyDestination(this.replyDestinationName, session); } if (this.replyDestinationExpressionProcessor != null) { Object result = this.replyDestinationExpressionProcessor.processMessage(message); if (result instanceof Destination) { return (Destination) result; } if (result instanceof String) { return this.resolveReplyDestination((String) result, session); } throw new MessageDeliveryException(message, "Evaluation of replyDestinationExpression failed to produce a Destination or destination name. " + "Result was: " + result); } return session.createTemporaryQueue(); }