|
1 | 1 | /*
|
2 |
| - * Copyright 2002-2019 the original author or authors. |
| 2 | + * Copyright 2002-2020 the original author or authors. |
3 | 3 | *
|
4 | 4 | * Licensed under the Apache License, Version 2.0 (the "License");
|
5 | 5 | * you may not use this file except in compliance with the License.
|
@@ -75,11 +75,13 @@ public void setInterceptors(List<ChannelInterceptor> interceptors) {
|
75 | 75 |
|
76 | 76 | @Override
|
77 | 77 | public void addInterceptor(ChannelInterceptor interceptor) {
|
| 78 | + Assert.notNull(interceptor, "ChannelInterceptor must not be null"); |
78 | 79 | this.interceptors.add(interceptor);
|
79 | 80 | }
|
80 | 81 |
|
81 | 82 | @Override
|
82 | 83 | public void addInterceptor(int index, ChannelInterceptor interceptor) {
|
| 84 | + Assert.notNull(interceptor, "ChannelInterceptor must not be null"); |
83 | 85 | this.interceptors.add(index, interceptor);
|
84 | 86 | }
|
85 | 87 |
|
@@ -107,29 +109,30 @@ public final boolean send(Message<?> message) {
|
107 | 109 | @Override
|
108 | 110 | public final boolean send(Message<?> message, long timeout) {
|
109 | 111 | Assert.notNull(message, "Message must not be null");
|
| 112 | + Message<?> messageToUse = message; |
110 | 113 | ChannelInterceptorChain chain = new ChannelInterceptorChain();
|
111 | 114 | boolean sent = false;
|
112 | 115 | try {
|
113 |
| - message = chain.applyPreSend(message, this); |
114 |
| - if (message == null) { |
| 116 | + messageToUse = chain.applyPreSend(messageToUse, this); |
| 117 | + if (messageToUse == null) { |
115 | 118 | return false;
|
116 | 119 | }
|
117 |
| - sent = sendInternal(message, timeout); |
118 |
| - chain.applyPostSend(message, this, sent); |
119 |
| - chain.triggerAfterSendCompletion(message, this, sent, null); |
| 120 | + sent = sendInternal(messageToUse, timeout); |
| 121 | + chain.applyPostSend(messageToUse, this, sent); |
| 122 | + chain.triggerAfterSendCompletion(messageToUse, this, sent, null); |
120 | 123 | return sent;
|
121 | 124 | }
|
122 | 125 | catch (Exception ex) {
|
123 |
| - chain.triggerAfterSendCompletion(message, this, sent, ex); |
| 126 | + chain.triggerAfterSendCompletion(messageToUse, this, sent, ex); |
124 | 127 | if (ex instanceof MessagingException) {
|
125 | 128 | throw (MessagingException) ex;
|
126 | 129 | }
|
127 |
| - throw new MessageDeliveryException(message,"Failed to send message to " + this, ex); |
| 130 | + throw new MessageDeliveryException(messageToUse,"Failed to send message to " + this, ex); |
128 | 131 | }
|
129 | 132 | catch (Throwable err) {
|
130 | 133 | MessageDeliveryException ex2 =
|
131 |
| - new MessageDeliveryException(message, "Failed to send message to " + this, err); |
132 |
| - chain.triggerAfterSendCompletion(message, this, sent, ex2); |
| 134 | + new MessageDeliveryException(messageToUse, "Failed to send message to " + this, err); |
| 135 | + chain.triggerAfterSendCompletion(messageToUse, this, sent, ex2); |
133 | 136 | throw ex2;
|
134 | 137 | }
|
135 | 138 | }
|
@@ -200,13 +203,14 @@ public boolean applyPreReceive(MessageChannel channel) {
|
200 | 203 | }
|
201 | 204 |
|
202 | 205 | public Message<?> applyPostReceive(Message<?> message, MessageChannel channel) {
|
| 206 | + Message<?> messageToUse = message; |
203 | 207 | for (ChannelInterceptor interceptor : interceptors) {
|
204 |
| - message = interceptor.postReceive(message, channel); |
205 |
| - if (message == null) { |
| 208 | + messageToUse = interceptor.postReceive(messageToUse, channel); |
| 209 | + if (messageToUse == null) { |
206 | 210 | return null;
|
207 | 211 | }
|
208 | 212 | }
|
209 |
| - return message; |
| 213 | + return messageToUse; |
210 | 214 | }
|
211 | 215 |
|
212 | 216 | public void triggerAfterReceiveCompletion(Message<?> message, MessageChannel channel, Exception ex) {
|
|
0 commit comments