parent
8e568466dc
commit
4623568bce
|
|
@ -17,7 +17,6 @@
|
|||
package org.springframework.http.client;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.lang.reflect.Constructor;
|
||||
import java.net.URI;
|
||||
|
||||
import org.apache.http.client.HttpClient;
|
||||
|
|
@ -25,6 +24,7 @@ import org.apache.http.client.methods.HttpDelete;
|
|||
import org.apache.http.client.methods.HttpGet;
|
||||
import org.apache.http.client.methods.HttpHead;
|
||||
import org.apache.http.client.methods.HttpOptions;
|
||||
import org.apache.http.client.methods.HttpPatch;
|
||||
import org.apache.http.client.methods.HttpPost;
|
||||
import org.apache.http.client.methods.HttpPut;
|
||||
import org.apache.http.client.methods.HttpTrace;
|
||||
|
|
@ -56,6 +56,9 @@ import org.springframework.util.ClassUtils;
|
|||
*/
|
||||
public class HttpComponentsClientHttpRequestFactory implements ClientHttpRequestFactory, DisposableBean {
|
||||
|
||||
private static final boolean HTTP_PATCH_AVAILABLE = ClassUtils.isPresent(
|
||||
"org.apache.http.client.methods.HttpPatch", HttpComponentsClientHttpRequestFactory.class.getClassLoader());
|
||||
|
||||
private static final int DEFAULT_MAX_TOTAL_CONNECTIONS = 100;
|
||||
|
||||
private static final int DEFAULT_MAX_CONNECTIONS_PER_ROUTE = 5;
|
||||
|
|
@ -164,19 +167,12 @@ public class HttpComponentsClientHttpRequestFactory implements ClientHttpRequest
|
|||
}
|
||||
|
||||
private HttpUriRequest createHttpPatch(URI uri) {
|
||||
String className = "org.apache.http.client.methods.HttpPatch";
|
||||
ClassLoader classloader = this.getClass().getClassLoader();
|
||||
if (!ClassUtils.isPresent(className, classloader)) {
|
||||
if (!HTTP_PATCH_AVAILABLE) {
|
||||
throw new IllegalArgumentException(
|
||||
"HTTP method PATCH not available before Apache HttpComponents HttpClient 4.2");
|
||||
}
|
||||
try {
|
||||
Class<?> clazz = classloader.loadClass(className);
|
||||
Constructor<?> constructor = clazz.getConstructor(URI.class);
|
||||
return (HttpUriRequest) constructor.newInstance(uri);
|
||||
}
|
||||
catch (Throwable ex) {
|
||||
throw new IllegalStateException("Unable to instantiate " + className, ex);
|
||||
else {
|
||||
return new HttpPatch(uri);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -69,6 +69,10 @@ import org.springframework.web.util.UriUtils;
|
|||
* <tr><td>any</td><td>{@link #exchange}</td></tr>
|
||||
* <tr><td></td><td>{@link #execute}</td></tr> </table>
|
||||
*
|
||||
* <p>The {@code exchange} and {@code execute} methods are generalized versions of the more specific methods listed
|
||||
* above them. They support additional, less frequently used combinations including support for requests using the
|
||||
* HTTP PATCH method. However, note that the underlying HTTP library must also support the desired combination.</p>
|
||||
*
|
||||
* <p>For each of these HTTP methods, there are three corresponding Java methods in the {@code RestTemplate}. Two
|
||||
* variant take a {@code String} URI as first argument (eg. {@link #getForObject(String, Class, Object[])}, {@link
|
||||
* #getForObject(String, Class, Map)}), and are capable of substituting any {@linkplain UriTemplate URI templates} in
|
||||
|
|
|
|||
Loading…
Reference in New Issue