InterceptingHttpAccessor uses internal ArrayList for sorting

Also caches InterceptingClientHttpRequestFactory (if applicable)

Issue: SPR-16137
This commit is contained in:
Juergen Hoeller
2017-10-31 16:33:38 +01:00
parent 48c2cc18b9
commit d06129debd
4 changed files with 75 additions and 29 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2016 the original author or authors.
* Copyright 2002-2017 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -16,9 +16,6 @@
package org.springframework.http.client.support;
import static org.junit.Assert.*;
import java.io.IOException;
import java.util.Arrays;
import java.util.List;
@@ -32,6 +29,8 @@ import org.springframework.http.client.ClientHttpRequestExecution;
import org.springframework.http.client.ClientHttpRequestInterceptor;
import org.springframework.http.client.ClientHttpResponse;
import static org.junit.Assert.*;
/**
* Tests for {@link InterceptingHttpAccessor}.
*
@@ -40,7 +39,7 @@ import org.springframework.http.client.ClientHttpResponse;
public class InterceptingHttpAccessorTests {
@Test
public void getInterceptors() throws Exception {
public void getInterceptors() {
TestInterceptingHttpAccessor accessor = new TestInterceptingHttpAccessor();
List<ClientHttpRequestInterceptor> interceptors = Arrays.asList(
new SecondClientHttpRequestInterceptor(),
@@ -55,22 +54,25 @@ public class InterceptingHttpAccessorTests {
assertThat(accessor.getInterceptors().get(2), Matchers.instanceOf(ThirdClientHttpRequestInterceptor.class));
}
private class TestInterceptingHttpAccessor extends InterceptingHttpAccessor {
}
@Order(1)
private class FirstClientHttpRequestInterceptor implements ClientHttpRequestInterceptor {
@Override
public ClientHttpResponse intercept(HttpRequest request, byte[] body,
ClientHttpRequestExecution execution) throws IOException {
public ClientHttpResponse intercept(HttpRequest request, byte[] body, ClientHttpRequestExecution execution) {
return null;
}
}
private class SecondClientHttpRequestInterceptor implements ClientHttpRequestInterceptor, Ordered {
@Override
public ClientHttpResponse intercept(HttpRequest request, byte[] body,
ClientHttpRequestExecution execution) throws IOException {
public ClientHttpResponse intercept(HttpRequest request, byte[] body, ClientHttpRequestExecution execution) {
return null;
}
@@ -80,12 +82,13 @@ public class InterceptingHttpAccessorTests {
}
}
private class ThirdClientHttpRequestInterceptor implements ClientHttpRequestInterceptor {
@Override
public ClientHttpResponse intercept(HttpRequest request, byte[] body,
ClientHttpRequestExecution execution) throws IOException {
public ClientHttpResponse intercept(HttpRequest request, byte[] body, ClientHttpRequestExecution execution) {
return null;
}
}
}
}