Skip to content

Commit 0480981

Browse files
committed
PATCH does not work with the standard JDK HTTP library
Issue: SPR-15052
1 parent 6a850ee commit 0480981

File tree

2 files changed

+33
-10
lines changed

2 files changed

+33
-10
lines changed

spring-web/src/main/java/org/springframework/http/client/support/HttpAccessor.java

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2009 the original author or authors.
2+
* Copyright 2002-2016 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -33,33 +33,39 @@
3333
* and other HTTP accessing gateway helpers, defining common properties
3434
* such as the {@link ClientHttpRequestFactory} to operate on.
3535
*
36-
* <p>Not intended to be used directly. See {@link org.springframework.web.client.RestTemplate}.
36+
* <p>Not intended to be used directly.
37+
* See {@link org.springframework.web.client.RestTemplate}.
3738
*
3839
* @author Arjen Poutsma
40+
* @author Juergen Hoeller
3941
* @since 3.0
4042
* @see org.springframework.web.client.RestTemplate
4143
*/
4244
public abstract class HttpAccessor {
4345

44-
/**
45-
* Logger available to subclasses.
46-
*/
46+
/** Logger available to subclasses */
4747
protected final Log logger = LogFactory.getLog(getClass());
4848

4949
private ClientHttpRequestFactory requestFactory = new SimpleClientHttpRequestFactory();
5050

5151

5252
/**
53-
* Set the request factory that this accessor uses for obtaining
54-
* {@link ClientHttpRequest HttpRequests}.
53+
* Set the request factory that this accessor uses for obtaining client request handles.
54+
* <p>The default is a {@link SimpleClientHttpRequestFactory} based on the JDK's own
55+
* HTTP libraries ({@link java.net.HttpURLConnection}).
56+
* <p><b>Note that the standard JDK HTTP library does not support the HTTP PATCH method.
57+
* Configure the Apache HttpComponents or OkHttp request factory to enable PATCH.</b>
58+
* @see #createRequest(URI, HttpMethod)
59+
* @see org.springframework.http.client.HttpComponentsAsyncClientHttpRequestFactory
60+
* @see org.springframework.http.client.OkHttp3ClientHttpRequestFactory
5561
*/
5662
public void setRequestFactory(ClientHttpRequestFactory requestFactory) {
57-
Assert.notNull(requestFactory, "'requestFactory' must not be null");
63+
Assert.notNull(requestFactory, "ClientHttpRequestFactory must not be null");
5864
this.requestFactory = requestFactory;
5965
}
6066

6167
/**
62-
* Return the request factory that this accessor uses for obtaining {@link ClientHttpRequest HttpRequests}.
68+
* Return the request factory that this accessor uses for obtaining client request handles.
6369
*/
6470
public ClientHttpRequestFactory getRequestFactory() {
6571
return this.requestFactory;
@@ -69,9 +75,11 @@ public ClientHttpRequestFactory getRequestFactory() {
6975
/**
7076
* Create a new {@link ClientHttpRequest} via this template's {@link ClientHttpRequestFactory}.
7177
* @param url the URL to connect to
72-
* @param method the HTTP method to exectute (GET, POST, etc.)
78+
* @param method the HTTP method to execute (GET, POST, etc)
7379
* @return the created request
7480
* @throws IOException in case of I/O errors
81+
* @see #getRequestFactory()
82+
* @see ClientHttpRequestFactory#createRequest(URI, HttpMethod)
7583
*/
7684
protected ClientHttpRequest createRequest(URI url, HttpMethod method) throws IOException {
7785
ClientHttpRequest request = getRequestFactory().createRequest(url, method);

spring-web/src/main/java/org/springframework/web/client/RestOperations.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -314,13 +314,18 @@ <T> ResponseEntity<T> postForEntity(String url, Object request, Class<T> respons
314314
* <p>URI Template variables are expanded using the given URI variables, if any.
315315
* <p>The {@code request} parameter can be a {@link HttpEntity} in order to
316316
* add additional HTTP headers to the request.
317+
* <p><b>NOTE: The standard JDK HTTP library does not support HTTP PATCH.
318+
* You need to use the Apache HttpComponents or OkHttp request factory.</b>
317319
* @param url the URL
318320
* @param request the object to be PATCHed (may be {@code null})
319321
* @param responseType the type of the return value
320322
* @param uriVariables the variables to expand the template
321323
* @return the converted object
322324
* @since 4.3.5
323325
* @see HttpEntity
326+
* @see RestTemplate#setRequestFactory
327+
* @see org.springframework.http.client.HttpComponentsAsyncClientHttpRequestFactory
328+
* @see org.springframework.http.client.OkHttp3ClientHttpRequestFactory
324329
*/
325330
<T> T patchForObject(String url, Object request, Class<T> responseType, Object... uriVariables)
326331
throws RestClientException;
@@ -331,13 +336,18 @@ <T> T patchForObject(String url, Object request, Class<T> responseType, Object..
331336
* <p>URI Template variables are expanded using the given map.
332337
* <p>The {@code request} parameter can be a {@link HttpEntity} in order to
333338
* add additional HTTP headers to the request.
339+
* <p><b>NOTE: The standard JDK HTTP library does not support HTTP PATCH.
340+
* You need to use the Apache HttpComponents or OkHttp request factory.</b>
334341
* @param url the URL
335342
* @param request the object to be PATCHed (may be {@code null})
336343
* @param responseType the type of the return value
337344
* @param uriVariables the variables to expand the template
338345
* @return the converted object
339346
* @since 4.3.5
340347
* @see HttpEntity
348+
* @see RestTemplate#setRequestFactory
349+
* @see org.springframework.http.client.HttpComponentsAsyncClientHttpRequestFactory
350+
* @see org.springframework.http.client.OkHttp3ClientHttpRequestFactory
341351
*/
342352
<T> T patchForObject(String url, Object request, Class<T> responseType, Map<String, ?> uriVariables)
343353
throws RestClientException;
@@ -347,12 +357,17 @@ <T> T patchForObject(String url, Object request, Class<T> responseType, Map<Stri
347357
* and return the representation found in the response.
348358
* <p>The {@code request} parameter can be a {@link HttpEntity} in order to
349359
* add additional HTTP headers to the request.
360+
* <p><b>NOTE: The standard JDK HTTP library does not support HTTP PATCH.
361+
* You need to use the Apache HttpComponents or OkHttp request factory.</b>
350362
* @param url the URL
351363
* @param request the object to be PATCHed (may be {@code null})
352364
* @param responseType the type of the return value
353365
* @return the converted object
354366
* @since 4.3.5
355367
* @see HttpEntity
368+
* @see RestTemplate#setRequestFactory
369+
* @see org.springframework.http.client.HttpComponentsAsyncClientHttpRequestFactory
370+
* @see org.springframework.http.client.OkHttp3ClientHttpRequestFactory
356371
*/
357372
<T> T patchForObject(URI url, Object request, Class<T> responseType) throws RestClientException;
358373

0 commit comments

Comments
 (0)