2
votes

When the Spring Integration does the Http.outboundGateway call with the HttpMethod.PATCH operation there comes the exception:

Caused by: java.net.ProtocolException: Invalid HTTP method: PATCH
at java.base/java.net.HttpURLConnection.setRequestMethod(HttpURLConnection.java:487)
at java.base/sun.net.www.protocol.http.HttpURLConnection.setRequestMethod(HttpURLConnection.java:569)
at java.base/sun.net.www.protocol.https.HttpsURLConnectionImpl.setRequestMethod(HttpsURLConnectionImpl.java:365)
at org.springframework.http.client.SimpleClientHttpRequestFactory.prepareConnection(SimpleClientHttpRequestFactory.java:226)
at org.springframework.http.client.SimpleClientHttpRequestFactory.createRequest(SimpleClientHttpRequestFactory.java:146)
at org.springframework.http.client.support.HttpAccessor.createRequest(HttpAccessor.java:87)
at org.springframework.web.client.RestTemplate.doExecute(RestTemplate.java:719)

This is the problem in the Java class HttpURLConnection, because it doesn't support the PATCH operation.

I must use the PATCH method. What are the best ways to handle this situation?

1

1 Answers

2
votes

The RestTemplate by default uses a SimpleClientHttpRequestFactory based on the Java HttpURLConnection. Consider to use some other ClientHttpRequestFactory, e.g. HttpComponentsClientHttpRequestFactory. When you declare such a bean you can inject it into the Http.outboundGateway().requestFactory():

/**
 * Set the {@link ClientHttpRequestFactory} for the underlying {@link RestTemplate}.
 * @param requestFactory The request factory.
 * @return the spec
 */
public HttpMessageHandlerSpec requestFactory(ClientHttpRequestFactory requestFactory) {