|
|
|
|
@ -20,7 +20,6 @@ import java.io.IOException;
@@ -20,7 +20,6 @@ import java.io.IOException;
|
|
|
|
|
import java.io.OutputStream; |
|
|
|
|
import java.net.URI; |
|
|
|
|
import java.util.List; |
|
|
|
|
import java.util.ListIterator; |
|
|
|
|
|
|
|
|
|
import org.springframework.http.HttpHeaders; |
|
|
|
|
import org.springframework.http.HttpMethod; |
|
|
|
|
@ -69,39 +68,23 @@ class InterceptingClientHttpRequest extends AbstractBufferingClientHttpRequest {
@@ -69,39 +68,23 @@ class InterceptingClientHttpRequest extends AbstractBufferingClientHttpRequest {
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
protected final ClientHttpResponse executeInternal(HttpHeaders headers, byte[] bufferedOutput) throws IOException { |
|
|
|
|
ClientHttpRequestExecution requestExecution = new DelegatingRequestExecution(this.requestFactory); |
|
|
|
|
ListIterator<ClientHttpRequestInterceptor> iterator = this.interceptors.listIterator(this.interceptors.size()); |
|
|
|
|
while (iterator.hasPrevious()) { |
|
|
|
|
ClientHttpRequestInterceptor interceptor = iterator.previous(); |
|
|
|
|
requestExecution = new InterceptingRequestExecution(interceptor, requestExecution); |
|
|
|
|
} |
|
|
|
|
return requestExecution.execute(this, bufferedOutput); |
|
|
|
|
return getExecution().execute(this, bufferedOutput); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private static class InterceptingRequestExecution implements ClientHttpRequestExecution { |
|
|
|
|
|
|
|
|
|
private final ClientHttpRequestInterceptor interceptor; |
|
|
|
|
|
|
|
|
|
private final ClientHttpRequestExecution nextExecution; |
|
|
|
|
|
|
|
|
|
public InterceptingRequestExecution(ClientHttpRequestInterceptor interceptor, ClientHttpRequestExecution nextExecution) { |
|
|
|
|
this.interceptor = interceptor; |
|
|
|
|
this.nextExecution = nextExecution; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
public ClientHttpResponse execute(HttpRequest request, byte[] body) throws IOException { |
|
|
|
|
return this.interceptor.intercept(request, body, this.nextExecution); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private ClientHttpRequestExecution getExecution() { |
|
|
|
|
ClientHttpRequestExecution execution = new EndOfChainRequestExecution(this.requestFactory); |
|
|
|
|
return this.interceptors.stream() |
|
|
|
|
.reduce(ClientHttpRequestInterceptor::andThen) |
|
|
|
|
.map(interceptor -> interceptor.apply(execution)) |
|
|
|
|
.orElse(execution); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private static class DelegatingRequestExecution implements ClientHttpRequestExecution { |
|
|
|
|
|
|
|
|
|
private static class EndOfChainRequestExecution implements ClientHttpRequestExecution { |
|
|
|
|
|
|
|
|
|
private final ClientHttpRequestFactory requestFactory; |
|
|
|
|
|
|
|
|
|
public DelegatingRequestExecution(ClientHttpRequestFactory requestFactory) { |
|
|
|
|
public EndOfChainRequestExecution(ClientHttpRequestFactory requestFactory) { |
|
|
|
|
this.requestFactory = requestFactory; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|