Merge branch '1.4.x' into 1.5.x

pull/7387/head
Phillip Webb 8 years ago
commit f15e0482c5

@ -16,6 +16,7 @@
package org.springframework.boot.web.client;
import java.lang.reflect.Constructor;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.util.ArrayList;
@ -317,7 +318,19 @@ public class RestTemplateBuilder {
public RestTemplateBuilder requestFactory(
Class<? extends ClientHttpRequestFactory> requestFactory) {
Assert.notNull(requestFactory, "RequestFactory must not be null");
return requestFactory(BeanUtils.instantiate(requestFactory));
return requestFactory(createRequestFactory(requestFactory));
}
private ClientHttpRequestFactory createRequestFactory(
Class<? extends ClientHttpRequestFactory> requestFactory) {
try {
Constructor<?> constructor = requestFactory.getDeclaredConstructor();
constructor.setAccessible(true);
return (ClientHttpRequestFactory) constructor.newInstance();
}
catch (Exception ex) {
throw new IllegalStateException(ex);
}
}
/**

@ -278,6 +278,14 @@ public class RestTemplateBuilderTests {
.isInstanceOf(SimpleClientHttpRequestFactory.class);
}
@Test
public void requestFactoryPackagePrivateClassShouldApply() throws Exception {
RestTemplate template = this.builder
.requestFactory(TestClientHttpRequestFactory.class).build();
assertThat(template.getRequestFactory())
.isInstanceOf(TestClientHttpRequestFactory.class);
}
@Test
public void requestFactoryWhenFactoryIsNullShouldThrowException() throws Exception {
this.thrown.expect(IllegalArgumentException.class);
@ -547,4 +555,8 @@ public class RestTemplateBuilderTests {
}
static class TestClientHttpRequestFactory extends SimpleClientHttpRequestFactory {
}
}

Loading…
Cancel
Save