Changed ClientHttpRequestInterceptor array to List
This commit is contained in:
@@ -18,8 +18,8 @@ package org.springframework.http.client;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.URI;
|
||||
import java.util.Arrays;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
import org.springframework.http.HttpHeaders;
|
||||
import org.springframework.http.HttpMethod;
|
||||
@@ -36,14 +36,14 @@ class InterceptingClientHttpRequest extends AbstractBufferingClientHttpRequest {
|
||||
|
||||
private final ClientHttpRequestFactory requestFactory;
|
||||
|
||||
private final ClientHttpRequestInterceptor[] interceptors;
|
||||
private final List<ClientHttpRequestInterceptor> interceptors;
|
||||
|
||||
private HttpMethod method;
|
||||
|
||||
private URI uri;
|
||||
|
||||
protected InterceptingClientHttpRequest(ClientHttpRequestFactory requestFactory,
|
||||
ClientHttpRequestInterceptor[] interceptors,
|
||||
List<ClientHttpRequestInterceptor> interceptors,
|
||||
URI uri,
|
||||
HttpMethod method) {
|
||||
this.requestFactory = requestFactory;
|
||||
@@ -72,7 +72,7 @@ class InterceptingClientHttpRequest extends AbstractBufferingClientHttpRequest {
|
||||
private final Iterator<ClientHttpRequestInterceptor> iterator;
|
||||
|
||||
private RequestExecution() {
|
||||
this.iterator = Arrays.asList(interceptors).iterator();
|
||||
this.iterator = interceptors.iterator();
|
||||
}
|
||||
|
||||
public ClientHttpResponse execute(HttpRequest request, byte[] body) throws IOException {
|
||||
|
||||
@@ -17,9 +17,10 @@
|
||||
package org.springframework.http.client;
|
||||
|
||||
import java.net.URI;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import org.springframework.http.HttpMethod;
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
/**
|
||||
* Wrapper for a {@link ClientHttpRequestFactory} that has support for {@link ClientHttpRequestInterceptor}s.
|
||||
@@ -29,7 +30,7 @@ import org.springframework.util.Assert;
|
||||
*/
|
||||
public class InterceptingClientHttpRequestFactory extends AbstractClientHttpRequestFactoryWrapper {
|
||||
|
||||
private final ClientHttpRequestInterceptor[] interceptors;
|
||||
private final List<ClientHttpRequestInterceptor> interceptors;
|
||||
|
||||
/**
|
||||
* Creates a new instance of the {@code InterceptingClientHttpRequestFactory} with the given parameters.
|
||||
@@ -38,10 +39,9 @@ public class InterceptingClientHttpRequestFactory extends AbstractClientHttpRequ
|
||||
* @param interceptors the interceptors that are to be applied. Can be {@code null}.
|
||||
*/
|
||||
public InterceptingClientHttpRequestFactory(ClientHttpRequestFactory requestFactory,
|
||||
ClientHttpRequestInterceptor[] interceptors) {
|
||||
List<ClientHttpRequestInterceptor> interceptors) {
|
||||
super(requestFactory);
|
||||
Assert.notNull(requestFactory, "'requestFactory' must not be null");
|
||||
this.interceptors = interceptors != null ? interceptors : new ClientHttpRequestInterceptor[0];
|
||||
this.interceptors = interceptors != null ? interceptors : Collections.<ClientHttpRequestInterceptor>emptyList();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -16,10 +16,12 @@
|
||||
|
||||
package org.springframework.http.client.support;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.springframework.http.client.ClientHttpRequestFactory;
|
||||
import org.springframework.http.client.ClientHttpRequestInterceptor;
|
||||
import org.springframework.http.client.InterceptingClientHttpRequestFactory;
|
||||
import org.springframework.util.ObjectUtils;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
|
||||
/**
|
||||
* Base class for {@link org.springframework.web.client.RestTemplate} and other HTTP accessing gateway helpers, adding
|
||||
@@ -31,26 +33,26 @@ import org.springframework.util.ObjectUtils;
|
||||
*/
|
||||
public abstract class InterceptingHttpAccessor extends HttpAccessor {
|
||||
|
||||
private ClientHttpRequestInterceptor[] interceptors;
|
||||
private List<ClientHttpRequestInterceptor> interceptors;
|
||||
|
||||
/**
|
||||
* Sets the request interceptors that this accessor should use.
|
||||
*/
|
||||
public void setInterceptors(ClientHttpRequestInterceptor[] interceptors) {
|
||||
public void setInterceptors(List<ClientHttpRequestInterceptor> interceptors) {
|
||||
this.interceptors = interceptors;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the request interceptor that this accessor uses.
|
||||
*/
|
||||
public ClientHttpRequestInterceptor[] getInterceptors() {
|
||||
public List<ClientHttpRequestInterceptor> getInterceptors() {
|
||||
return interceptors;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ClientHttpRequestFactory getRequestFactory() {
|
||||
ClientHttpRequestFactory delegate = super.getRequestFactory();
|
||||
if (!ObjectUtils.isEmpty(getInterceptors())) {
|
||||
if (!CollectionUtils.isEmpty(getInterceptors())) {
|
||||
return new InterceptingClientHttpRequestFactory(delegate, getInterceptors());
|
||||
}
|
||||
else {
|
||||
|
||||
Reference in New Issue
Block a user