|
|
|
@ -1,5 +1,5 @@ |
|
|
|
/* |
|
|
|
/* |
|
|
|
* Copyright 2002-2018 the original author or authors. |
|
|
|
* Copyright 2002-2020 the original author or authors. |
|
|
|
* |
|
|
|
* |
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License"); |
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License"); |
|
|
|
* you may not use this file except in compliance with the License. |
|
|
|
* you may not use this file except in compliance with the License. |
|
|
|
@ -53,14 +53,14 @@ public class NativeMessageHeaderAccessor extends MessageHeaderAccessor { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* A protected constructor to create new headers. |
|
|
|
* Protected constructor to create a new instance. |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
protected NativeMessageHeaderAccessor() { |
|
|
|
protected NativeMessageHeaderAccessor() { |
|
|
|
this((Map<String, List<String>>) null); |
|
|
|
this((Map<String, List<String>>) null); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* A protected constructor to create new headers. |
|
|
|
* Protected constructor to create an instance with the given native headers. |
|
|
|
* @param nativeHeaders native headers to create the message with (may be {@code null}) |
|
|
|
* @param nativeHeaders native headers to create the message with (may be {@code null}) |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
protected NativeMessageHeaderAccessor(@Nullable Map<String, List<String>> nativeHeaders) { |
|
|
|
protected NativeMessageHeaderAccessor(@Nullable Map<String, List<String>> nativeHeaders) { |
|
|
|
@ -70,7 +70,7 @@ public class NativeMessageHeaderAccessor extends MessageHeaderAccessor { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* A protected constructor accepting the headers of an existing message to copy. |
|
|
|
* Protected constructor that copies headers from another message. |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
protected NativeMessageHeaderAccessor(@Nullable Message<?> message) { |
|
|
|
protected NativeMessageHeaderAccessor(@Nullable Message<?> message) { |
|
|
|
super(message); |
|
|
|
super(message); |
|
|
|
@ -85,6 +85,10 @@ public class NativeMessageHeaderAccessor extends MessageHeaderAccessor { |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
|
|
* Subclasses can use this method to access the "native" headers sub-map. |
|
|
|
|
|
|
|
*/ |
|
|
|
@SuppressWarnings("unchecked") |
|
|
|
@SuppressWarnings("unchecked") |
|
|
|
@Nullable |
|
|
|
@Nullable |
|
|
|
protected Map<String, List<String>> getNativeHeaders() { |
|
|
|
protected Map<String, List<String>> getNativeHeaders() { |
|
|
|
@ -92,7 +96,7 @@ public class NativeMessageHeaderAccessor extends MessageHeaderAccessor { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* Return a copy of the native header values or an empty map. |
|
|
|
* Return a copy of the native headers sub-map, or an empty map. |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public Map<String, List<String>> toNativeHeaderMap() { |
|
|
|
public Map<String, List<String>> toNativeHeaderMap() { |
|
|
|
Map<String, List<String>> map = getNativeHeaders(); |
|
|
|
Map<String, List<String>> map = getNativeHeaders(); |
|
|
|
@ -114,6 +118,7 @@ public class NativeMessageHeaderAccessor extends MessageHeaderAccessor { |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* Whether the native header map contains the give header name. |
|
|
|
* Whether the native header map contains the give header name. |
|
|
|
|
|
|
|
* @param headerName the name of the header |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public boolean containsNativeHeader(String headerName) { |
|
|
|
public boolean containsNativeHeader(String headerName) { |
|
|
|
Map<String, List<String>> map = getNativeHeaders(); |
|
|
|
Map<String, List<String>> map = getNativeHeaders(); |
|
|
|
@ -121,8 +126,9 @@ public class NativeMessageHeaderAccessor extends MessageHeaderAccessor { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* Return all values for the specified native header. |
|
|
|
* Return all values for the specified native header, if present. |
|
|
|
* or {@code null} if none. |
|
|
|
* @param headerName the name of the header |
|
|
|
|
|
|
|
* @return the associated values, or {@code null} if none |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
@Nullable |
|
|
|
@Nullable |
|
|
|
public List<String> getNativeHeader(String headerName) { |
|
|
|
public List<String> getNativeHeader(String headerName) { |
|
|
|
@ -131,15 +137,16 @@ public class NativeMessageHeaderAccessor extends MessageHeaderAccessor { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* Return the first value for the specified native header, |
|
|
|
* Return the first value for the specified native header, if present. |
|
|
|
* or {@code null} if none. |
|
|
|
* @param headerName the name of the header |
|
|
|
|
|
|
|
* @return the associated value, or {@code null} if none |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
@Nullable |
|
|
|
@Nullable |
|
|
|
public String getFirstNativeHeader(String headerName) { |
|
|
|
public String getFirstNativeHeader(String headerName) { |
|
|
|
Map<String, List<String>> map = getNativeHeaders(); |
|
|
|
Map<String, List<String>> map = getNativeHeaders(); |
|
|
|
if (map != null) { |
|
|
|
if (map != null) { |
|
|
|
List<String> values = map.get(headerName); |
|
|
|
List<String> values = map.get(headerName); |
|
|
|
if (values != null) { |
|
|
|
if (!CollectionUtils.isEmpty(values)) { |
|
|
|
return values.get(0); |
|
|
|
return values.get(0); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
@ -148,6 +155,8 @@ public class NativeMessageHeaderAccessor extends MessageHeaderAccessor { |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* Set the specified native header value replacing existing values. |
|
|
|
* Set the specified native header value replacing existing values. |
|
|
|
|
|
|
|
* <p>In order for this to work, the accessor must be {@link #isMutable() |
|
|
|
|
|
|
|
* mutable}. See {@link MessageHeaderAccessor} for details. |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public void setNativeHeader(String name, @Nullable String value) { |
|
|
|
public void setNativeHeader(String name, @Nullable String value) { |
|
|
|
Assert.state(isMutable(), "Already immutable"); |
|
|
|
Assert.state(isMutable(), "Already immutable"); |
|
|
|
@ -173,6 +182,10 @@ public class NativeMessageHeaderAccessor extends MessageHeaderAccessor { |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* Add the specified native header value to existing values. |
|
|
|
* Add the specified native header value to existing values. |
|
|
|
|
|
|
|
* <p>In order for this to work, the accessor must be {@link #isMutable() |
|
|
|
|
|
|
|
* mutable}. See {@link MessageHeaderAccessor} for details. |
|
|
|
|
|
|
|
* @param name the name of the header |
|
|
|
|
|
|
|
* @param value the header value to set |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public void addNativeHeader(String name, @Nullable String value) { |
|
|
|
public void addNativeHeader(String name, @Nullable String value) { |
|
|
|
Assert.state(isMutable(), "Already immutable"); |
|
|
|
Assert.state(isMutable(), "Already immutable"); |
|
|
|
@ -189,6 +202,10 @@ public class NativeMessageHeaderAccessor extends MessageHeaderAccessor { |
|
|
|
setModified(true); |
|
|
|
setModified(true); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
|
|
* Add the specified native headers to existing values. |
|
|
|
|
|
|
|
* @param headers the headers to set |
|
|
|
|
|
|
|
*/ |
|
|
|
public void addNativeHeaders(@Nullable MultiValueMap<String, String> headers) { |
|
|
|
public void addNativeHeaders(@Nullable MultiValueMap<String, String> headers) { |
|
|
|
if (headers == null) { |
|
|
|
if (headers == null) { |
|
|
|
return; |
|
|
|
return; |
|
|
|
@ -196,23 +213,38 @@ public class NativeMessageHeaderAccessor extends MessageHeaderAccessor { |
|
|
|
headers.forEach((key, values) -> values.forEach(value -> addNativeHeader(key, value))); |
|
|
|
headers.forEach((key, values) -> values.forEach(value -> addNativeHeader(key, value))); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
|
|
* Remove the specified native header value replacing existing values. |
|
|
|
|
|
|
|
* <p>In order for this to work, the accessor must be {@link #isMutable() |
|
|
|
|
|
|
|
* mutable}. See {@link MessageHeaderAccessor} for details. |
|
|
|
|
|
|
|
* @param headerName the name of the header |
|
|
|
|
|
|
|
* @return the associated values, or {@code null} if the header was not present |
|
|
|
|
|
|
|
*/ |
|
|
|
@Nullable |
|
|
|
@Nullable |
|
|
|
public List<String> removeNativeHeader(String name) { |
|
|
|
public List<String> removeNativeHeader(String headerName) { |
|
|
|
Assert.state(isMutable(), "Already immutable"); |
|
|
|
Assert.state(isMutable(), "Already immutable"); |
|
|
|
Map<String, List<String>> nativeHeaders = getNativeHeaders(); |
|
|
|
Map<String, List<String>> nativeHeaders = getNativeHeaders(); |
|
|
|
if (nativeHeaders == null) { |
|
|
|
if (CollectionUtils.isEmpty(nativeHeaders)) { |
|
|
|
return null; |
|
|
|
return null; |
|
|
|
} |
|
|
|
} |
|
|
|
return nativeHeaders.remove(name); |
|
|
|
return nativeHeaders.remove(headerName); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
|
|
* Return the first value for the specified native header, |
|
|
|
|
|
|
|
* or {@code null} if none. |
|
|
|
|
|
|
|
* @param headerName the name of the header |
|
|
|
|
|
|
|
* @param headers the headers map to introspect |
|
|
|
|
|
|
|
* @return the associated value, or {@code null} if none |
|
|
|
|
|
|
|
*/ |
|
|
|
@SuppressWarnings("unchecked") |
|
|
|
@SuppressWarnings("unchecked") |
|
|
|
@Nullable |
|
|
|
@Nullable |
|
|
|
public static String getFirstNativeHeader(String headerName, Map<String, Object> headers) { |
|
|
|
public static String getFirstNativeHeader(String headerName, Map<String, Object> headers) { |
|
|
|
Map<String, List<String>> map = (Map<String, List<String>>) headers.get(NATIVE_HEADERS); |
|
|
|
Map<String, List<String>> map = (Map<String, List<String>>) headers.get(NATIVE_HEADERS); |
|
|
|
if (map != null) { |
|
|
|
if (map != null) { |
|
|
|
List<String> values = map.get(headerName); |
|
|
|
List<String> values = map.get(headerName); |
|
|
|
if (values != null) { |
|
|
|
if (!CollectionUtils.isEmpty(values)) { |
|
|
|
return values.get(0); |
|
|
|
return values.get(0); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|