@@ -82,7 +82,7 @@ protected NativeMessageHeaderAccessor(@Nullable Message<?> message) {
82
82
83
83
84
84
/**
85
- * Sub-classes can use this method to access the "native" headers sub-map.
85
+ * Subclasses can use this method to access the "native" headers sub-map.
86
86
*/
87
87
@ SuppressWarnings ("unchecked" )
88
88
@ Nullable
@@ -139,14 +139,17 @@ public void copyHeaders(@Nullable Map<String, ?> headersToCopy) {
139
139
140
140
/**
141
141
* Whether the native header map contains the give header name.
142
+ * @param headerName the name of the header
142
143
*/
143
144
public boolean containsNativeHeader (String headerName ) {
144
145
Map <String , List <String >> map = getNativeHeaders ();
145
146
return (map != null && map .containsKey (headerName ));
146
147
}
147
148
148
149
/**
149
- * Return the values for the specified native header, if present.
150
+ * Return all values for the specified native header, if present.
151
+ * @param headerName the name of the header
152
+ * @return the associated values, or {@code null} if none
150
153
*/
151
154
@ Nullable
152
155
public List <String > getNativeHeader (String headerName ) {
@@ -156,13 +159,15 @@ public List<String> getNativeHeader(String headerName) {
156
159
157
160
/**
158
161
* Return the first value for the specified native header, if present.
162
+ * @param headerName the name of the header
163
+ * @return the associated value, or {@code null} if none
159
164
*/
160
165
@ Nullable
161
166
public String getFirstNativeHeader (String headerName ) {
162
167
Map <String , List <String >> map = getNativeHeaders ();
163
168
if (map != null ) {
164
169
List <String > values = map .get (headerName );
165
- if (values != null ) {
170
+ if (! CollectionUtils . isEmpty ( values ) ) {
166
171
return values .get (0 );
167
172
}
168
173
}
@@ -200,6 +205,8 @@ public void setNativeHeader(String name, @Nullable String value) {
200
205
* Add the specified native header value to existing values.
201
206
* <p>In order for this to work, the accessor must be {@link #isMutable()
202
207
* mutable}. See {@link MessageHeaderAccessor} for details.
208
+ * @param name the name of the header
209
+ * @param value the header value to set
203
210
*/
204
211
public void addNativeHeader (String name , @ Nullable String value ) {
205
212
Assert .state (isMutable (), "Already immutable" );
@@ -216,6 +223,10 @@ public void addNativeHeader(String name, @Nullable String value) {
216
223
setModified (true );
217
224
}
218
225
226
+ /**
227
+ * Add the specified native headers to existing values.
228
+ * @param headers the headers to set
229
+ */
219
230
public void addNativeHeaders (@ Nullable MultiValueMap <String , String > headers ) {
220
231
if (headers == null ) {
221
232
return ;
@@ -227,24 +238,34 @@ public void addNativeHeaders(@Nullable MultiValueMap<String, String> headers) {
227
238
* Remove the specified native header value replacing existing values.
228
239
* <p>In order for this to work, the accessor must be {@link #isMutable()
229
240
* mutable}. See {@link MessageHeaderAccessor} for details.
241
+ * @param headerName the name of the header
242
+ * @return the associated values, or {@code null} if the header was not present
230
243
*/
231
244
@ Nullable
232
- public List <String > removeNativeHeader (String name ) {
245
+ public List <String > removeNativeHeader (String headerName ) {
233
246
Assert .state (isMutable (), "Already immutable" );
234
247
Map <String , List <String >> nativeHeaders = getNativeHeaders ();
235
- if (nativeHeaders == null ) {
248
+ if (CollectionUtils . isEmpty ( nativeHeaders ) ) {
236
249
return null ;
237
250
}
238
- return nativeHeaders .remove (name );
251
+ return nativeHeaders .remove (headerName );
239
252
}
240
253
254
+
255
+ /**
256
+ * Return the first value for the specified native header,
257
+ * or {@code null} if none.
258
+ * @param headerName the name of the header
259
+ * @param headers the headers map to introspect
260
+ * @return the associated value, or {@code null} if none
261
+ */
241
262
@ SuppressWarnings ("unchecked" )
242
263
@ Nullable
243
264
public static String getFirstNativeHeader (String headerName , Map <String , Object > headers ) {
244
265
Map <String , List <String >> map = (Map <String , List <String >>) headers .get (NATIVE_HEADERS );
245
266
if (map != null ) {
246
267
List <String > values = map .get (headerName );
247
- if (values != null ) {
268
+ if (! CollectionUtils . isEmpty ( values ) ) {
248
269
return values .get (0 );
249
270
}
250
271
}
0 commit comments