|
17 | 17 | package org.springframework.http.client;
|
18 | 18 |
|
19 | 19 | import java.io.IOException;
|
20 |
| -import java.lang.reflect.Constructor; |
21 | 20 | import java.net.URI;
|
22 | 21 |
|
23 | 22 | import org.apache.http.client.HttpClient;
|
24 | 23 | import org.apache.http.client.methods.HttpDelete;
|
25 | 24 | import org.apache.http.client.methods.HttpGet;
|
26 | 25 | import org.apache.http.client.methods.HttpHead;
|
27 | 26 | import org.apache.http.client.methods.HttpOptions;
|
| 27 | +import org.apache.http.client.methods.HttpPatch; |
28 | 28 | import org.apache.http.client.methods.HttpPost;
|
29 | 29 | import org.apache.http.client.methods.HttpPut;
|
30 | 30 | import org.apache.http.client.methods.HttpTrace;
|
|
56 | 56 | */
|
57 | 57 | public class HttpComponentsClientHttpRequestFactory implements ClientHttpRequestFactory, DisposableBean {
|
58 | 58 |
|
| 59 | + private static final boolean HTTP_PATCH_AVAILABLE = ClassUtils.isPresent( |
| 60 | + "org.apache.http.client.methods.HttpPatch", HttpComponentsClientHttpRequestFactory.class.getClassLoader()); |
| 61 | + |
59 | 62 | private static final int DEFAULT_MAX_TOTAL_CONNECTIONS = 100;
|
60 | 63 |
|
61 | 64 | private static final int DEFAULT_MAX_CONNECTIONS_PER_ROUTE = 5;
|
@@ -164,19 +167,12 @@ protected HttpUriRequest createHttpUriRequest(HttpMethod httpMethod, URI uri) {
|
164 | 167 | }
|
165 | 168 |
|
166 | 169 | private HttpUriRequest createHttpPatch(URI uri) {
|
167 |
| - String className = "org.apache.http.client.methods.HttpPatch"; |
168 |
| - ClassLoader classloader = this.getClass().getClassLoader(); |
169 |
| - if (!ClassUtils.isPresent(className, classloader)) { |
| 170 | + if (!HTTP_PATCH_AVAILABLE) { |
170 | 171 | throw new IllegalArgumentException(
|
171 | 172 | "HTTP method PATCH not available before Apache HttpComponents HttpClient 4.2");
|
172 | 173 | }
|
173 |
| - try { |
174 |
| - Class<?> clazz = classloader.loadClass(className); |
175 |
| - Constructor<?> constructor = clazz.getConstructor(URI.class); |
176 |
| - return (HttpUriRequest) constructor.newInstance(uri); |
177 |
| - } |
178 |
| - catch (Throwable ex) { |
179 |
| - throw new IllegalStateException("Unable to instantiate " + className, ex); |
| 174 | + else { |
| 175 | + return new HttpPatch(uri); |
180 | 176 | }
|
181 | 177 | }
|
182 | 178 |
|
|
0 commit comments