|
|
@ -91,7 +91,7 @@ public class RestTemplateBuilder {
|
|
|
|
|
|
|
|
|
|
|
|
private final BasicAuthentication basicAuthentication;
|
|
|
|
private final BasicAuthentication basicAuthentication;
|
|
|
|
|
|
|
|
|
|
|
|
private final Map<String, String> defaultHeaders;
|
|
|
|
private final Map<String, List<String>> defaultHeaders;
|
|
|
|
|
|
|
|
|
|
|
|
private final Set<RestTemplateCustomizer> customizers;
|
|
|
|
private final Set<RestTemplateCustomizer> customizers;
|
|
|
|
|
|
|
|
|
|
|
@ -122,7 +122,7 @@ public class RestTemplateBuilder {
|
|
|
|
String rootUri, Set<HttpMessageConverter<?>> messageConverters,
|
|
|
|
String rootUri, Set<HttpMessageConverter<?>> messageConverters,
|
|
|
|
Set<ClientHttpRequestInterceptor> interceptors, Supplier<ClientHttpRequestFactory> requestFactorySupplier,
|
|
|
|
Set<ClientHttpRequestInterceptor> interceptors, Supplier<ClientHttpRequestFactory> requestFactorySupplier,
|
|
|
|
UriTemplateHandler uriTemplateHandler, ResponseErrorHandler errorHandler,
|
|
|
|
UriTemplateHandler uriTemplateHandler, ResponseErrorHandler errorHandler,
|
|
|
|
BasicAuthentication basicAuthentication, Map<String, String> defaultHeaders,
|
|
|
|
BasicAuthentication basicAuthentication, Map<String, List<String>> defaultHeaders,
|
|
|
|
Set<RestTemplateCustomizer> customizers, Set<RestTemplateRequestCustomizer<?>> requestCustomizers) {
|
|
|
|
Set<RestTemplateCustomizer> customizers, Set<RestTemplateRequestCustomizer<?>> requestCustomizers) {
|
|
|
|
this.requestFactoryCustomizer = requestFactoryCustomizer;
|
|
|
|
this.requestFactoryCustomizer = requestFactoryCustomizer;
|
|
|
|
this.detectRequestFactory = detectRequestFactory;
|
|
|
|
this.detectRequestFactory = detectRequestFactory;
|
|
|
@ -395,15 +395,17 @@ public class RestTemplateBuilder {
|
|
|
|
* Add a default header that will be set if not already present on the outgoing
|
|
|
|
* Add a default header that will be set if not already present on the outgoing
|
|
|
|
* {@link HttpClientRequest}.
|
|
|
|
* {@link HttpClientRequest}.
|
|
|
|
* @param name the name of the header
|
|
|
|
* @param name the name of the header
|
|
|
|
* @param value the header value
|
|
|
|
* @param values the header values
|
|
|
|
* @return a new builder instance
|
|
|
|
* @return a new builder instance
|
|
|
|
* @since 2.2.0
|
|
|
|
* @since 2.2.0
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
public RestTemplateBuilder defaultHeader(String name, String value) {
|
|
|
|
public RestTemplateBuilder defaultHeader(String name, String... values) {
|
|
|
|
|
|
|
|
Assert.notNull(name, "Name must not be null");
|
|
|
|
|
|
|
|
Assert.notNull(values, "Values must not be null");
|
|
|
|
return new RestTemplateBuilder(this.requestFactoryCustomizer, this.detectRequestFactory, this.rootUri,
|
|
|
|
return new RestTemplateBuilder(this.requestFactoryCustomizer, this.detectRequestFactory, this.rootUri,
|
|
|
|
this.messageConverters, this.interceptors, this.requestFactory, this.uriTemplateHandler,
|
|
|
|
this.messageConverters, this.interceptors, this.requestFactory, this.uriTemplateHandler,
|
|
|
|
this.errorHandler, this.basicAuthentication, append(this.defaultHeaders, name, value), this.customizers,
|
|
|
|
this.errorHandler, this.basicAuthentication, append(this.defaultHeaders, name, values),
|
|
|
|
this.requestCustomizers);
|
|
|
|
this.customizers, this.requestCustomizers);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
@ -683,6 +685,10 @@ public class RestTemplateBuilder {
|
|
|
|
return Collections.unmodifiableSet(new LinkedHashSet<>(collection));
|
|
|
|
return Collections.unmodifiableSet(new LinkedHashSet<>(collection));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private static <T> List<T> listOf(T[] items) {
|
|
|
|
|
|
|
|
return Collections.unmodifiableList(new ArrayList<>(Arrays.asList(items)));
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private static <T> Set<T> append(Collection<? extends T> collection, Collection<? extends T> additions) {
|
|
|
|
private static <T> Set<T> append(Collection<? extends T> collection, Collection<? extends T> additions) {
|
|
|
|
Set<T> result = new LinkedHashSet<>((collection != null) ? collection : Collections.emptySet());
|
|
|
|
Set<T> result = new LinkedHashSet<>((collection != null) ? collection : Collections.emptySet());
|
|
|
|
if (additions != null) {
|
|
|
|
if (additions != null) {
|
|
|
@ -691,9 +697,11 @@ public class RestTemplateBuilder {
|
|
|
|
return Collections.unmodifiableSet(result);
|
|
|
|
return Collections.unmodifiableSet(result);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private static <K, V> Map<K, V> append(Map<K, V> map, K key, V value) {
|
|
|
|
private static <K, V> Map<K, List<V>> append(Map<K, List<V>> map, K key, V[] values) {
|
|
|
|
Map<K, V> result = new LinkedHashMap<>((map != null) ? map : Collections.emptyMap());
|
|
|
|
Map<K, List<V>> result = new LinkedHashMap<>((map != null) ? map : Collections.emptyMap());
|
|
|
|
result.put(key, value);
|
|
|
|
if (values != null) {
|
|
|
|
|
|
|
|
result.put(key, listOf(values));
|
|
|
|
|
|
|
|
}
|
|
|
|
return Collections.unmodifiableMap(result);
|
|
|
|
return Collections.unmodifiableMap(result);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|