Skip to content

Commit

Permalink
Consistent not-null assertions for configured interceptors
Browse files Browse the repository at this point in the history
Closes gh-25221
  • Loading branch information
jhoeller committed Jun 10, 2020
1 parent 31cda09 commit 700fede
Showing 1 changed file with 17 additions and 13 deletions.
@@ -1,5 +1,5 @@
/*
* Copyright 2002-2019 the original author or authors.
* Copyright 2002-2020 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -75,11 +75,13 @@ public void setInterceptors(List<ChannelInterceptor> interceptors) {

@Override
public void addInterceptor(ChannelInterceptor interceptor) {
Assert.notNull(interceptor, "ChannelInterceptor must not be null");
this.interceptors.add(interceptor);
}

@Override
public void addInterceptor(int index, ChannelInterceptor interceptor) {
Assert.notNull(interceptor, "ChannelInterceptor must not be null");
this.interceptors.add(index, interceptor);
}

Expand Down Expand Up @@ -107,29 +109,30 @@ public final boolean send(Message<?> message) {
@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 {
message = chain.applyPreSend(message, this);
if (message == null) {
messageToUse = chain.applyPreSend(messageToUse, this);
if (messageToUse == null) {
return false;
}
sent = sendInternal(message, timeout);
chain.applyPostSend(message, this, sent);
chain.triggerAfterSendCompletion(message, this, sent, null);
sent = sendInternal(messageToUse, timeout);
chain.applyPostSend(messageToUse, this, sent);
chain.triggerAfterSendCompletion(messageToUse, this, sent, null);
return sent;
}
catch (Exception ex) {
chain.triggerAfterSendCompletion(message, this, sent, ex);
chain.triggerAfterSendCompletion(messageToUse, this, sent, ex);
if (ex instanceof MessagingException) {
throw (MessagingException) ex;
}
throw new MessageDeliveryException(message,"Failed to send message to " + this, ex);
throw new MessageDeliveryException(messageToUse,"Failed to send message to " + this, ex);
}
catch (Throwable err) {
MessageDeliveryException ex2 =
new MessageDeliveryException(message, "Failed to send message to " + this, err);
chain.triggerAfterSendCompletion(message, this, sent, ex2);
new MessageDeliveryException(messageToUse, "Failed to send message to " + this, err);
chain.triggerAfterSendCompletion(messageToUse, this, sent, ex2);
throw ex2;
}
}
Expand Down Expand Up @@ -200,13 +203,14 @@ public boolean applyPreReceive(MessageChannel channel) {
}

public Message<?> applyPostReceive(Message<?> message, MessageChannel channel) {
Message<?> messageToUse = message;
for (ChannelInterceptor interceptor : interceptors) {
message = interceptor.postReceive(message, channel);
if (message == null) {
messageToUse = interceptor.postReceive(messageToUse, channel);
if (messageToUse == null) {
return null;
}
}
return message;
return messageToUse;
}

public void triggerAfterReceiveCompletion(Message<?> message, MessageChannel channel, Exception ex) {
Expand Down

0 comments on commit 700fede

Please sign in to comment.