@Override public final boolean send(Message<?> message) { return send(message, INDEFINITE_TIMEOUT); }
private boolean detectImmutableMessageInterceptor(MessageChannel channel) { if (this.immutableMessageInterceptorPresent != null) { return this.immutableMessageInterceptorPresent; } if (channel instanceof AbstractMessageChannel) { for (ChannelInterceptor interceptor : ((AbstractMessageChannel) channel).getInterceptors()) { if (interceptor instanceof ImmutableMessageChannelInterceptor) { this.immutableMessageInterceptorPresent = true; return true; } } } this.immutableMessageInterceptorPresent = false; return false; }
final AtomicBoolean preSendInvoked = new AtomicBoolean(false); final AtomicBoolean completionInvoked = new AtomicBoolean(false); testChannel.addInterceptor(new ChannelInterceptor() { @Override public void postSend(Message<?> message, MessageChannel channel, boolean sent) { testChannel.send(MessageBuilder.withPayload("test").build()); assertTrue(preSendInvoked.get()); assertTrue(completionInvoked.get());
@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; } }
@Test public void afterCompletionWithSendException() { final AbstractMessageChannel testChannel = new AbstractMessageChannel() { @Override protected boolean sendInternal(Message<?> message, long timeout) { throw new RuntimeException("Simulated exception"); } }; PreSendInterceptor interceptor1 = new PreSendInterceptor(); PreSendInterceptor interceptor2 = new PreSendInterceptor(); testChannel.addInterceptor(interceptor1); testChannel.addInterceptor(interceptor2); try { testChannel.send(MessageBuilder.withPayload("test").build()); } catch (Exception ex) { assertEquals("Simulated exception", ex.getCause().getMessage()); } assertTrue(interceptor1.wasAfterCompletionInvoked()); assertTrue(interceptor2.wasAfterCompletionInvoked()); }
@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; } }
@Override public final boolean send(Message<?> message) { return send(message, INDEFINITE_TIMEOUT); }
@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; } }
private boolean detectImmutableMessageInterceptor(MessageChannel channel) { if (this.immutableMessageInterceptorPresent != null) { return this.immutableMessageInterceptorPresent; } if (channel instanceof AbstractMessageChannel) { for (ChannelInterceptor interceptor : ((AbstractMessageChannel) channel).getInterceptors()) { if (interceptor instanceof ImmutableMessageChannelInterceptor) { this.immutableMessageInterceptorPresent = true; return true; } } } this.immutableMessageInterceptorPresent = false; return false; }
@Override public final boolean send(Message<?> message) { return send(message, INDEFINITE_TIMEOUT); }
@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; } }
private boolean detectImmutableMessageInterceptor(MessageChannel channel) { if (this.immutableMessageInterceptorPresent != null) { return this.immutableMessageInterceptorPresent; } if (channel instanceof AbstractMessageChannel) { for (ChannelInterceptor interceptor : ((AbstractMessageChannel) channel).getInterceptors()) { if (interceptor instanceof ImmutableMessageChannelInterceptor) { this.immutableMessageInterceptorPresent = true; return true; } } } this.immutableMessageInterceptorPresent = false; return false; }
@Override public final boolean send(Message<?> message) { return send(message, INDEFINITE_TIMEOUT); }