Spring Integration Java DSL:带有HttpMethod.PATCH的Http.outboundGateway无法正常工作

时间:2018-11-21 13:05:08

标签: spring-integration spring-integration-dsl

当Spring Integration使用Http.outboundGateway操作进行HttpMethod.PATCH调用时,会出现以下异常:

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)

这是Java类HttpURLConnection中的问题,因为它不支持PATCH操作。

我必须使用PATCH方法。处理这种情况的最佳方法是什么?

1 个答案:

答案 0 :(得分:2)

RestTemplate默认使用基于Java SimpleClientHttpRequestFactory的{​​{1}}。考虑使用其他一些HttpURLConnection,例如ClientHttpRequestFactory。声明此类bean时,可以将其注入HttpComponentsClientHttpRequestFactory

Http.outboundGateway().requestFactory()