哪个版本的spring集成支持http方法" PATCH"

时间:2014-07-22 15:42:56

标签: spring-integration

我正在尝试使用http-method" PATCH"更新一列。我得到以下错误。代码是 -

<int:chain input-channel="updateChannel">
 <int:service-activator ref="trackingNumberProcessor" method="message"/>
    <int-http:outbound-gateway url="http://test.com/consumerappointment/appointments/1295" http-method="PATCH" expected-response-  type="java.lang.String" charset="UTF-8">
    </int-http:outbound-gateway>     
</int:chain>


Caused by: org.springframework.web.client.ResourceAccessException: I/O error on PATCH request for "http://test.com/consumerappointment/appointments/1295":Invalid HTTP method: PATCH; nested exception is java.net.ProtocolException: Invalid HTTP method: PATCH
    at org.springframework.web.client.RestTemplate.doExecute(RestTemplate.java:561) ~[spring-web-4.0.6.RELEASE.jar:4.0.6.RELEASE]
    at org.springframework.web.client.RestTemplate.execute(RestTemplate.java:521) ~[spring-web-4.0.6.RELEASE.jar:4.0.6.RELEASE]
    at org.springframework.web.client.RestTemplate.exchange(RestTemplate.java:466) ~[spring-web-4.0.6.RELEASE.jar:4.0.6.RELEASE]
    at org.springframework.integration.http.outbound.HttpRequestExecutingMessageHandler.handleRequestMessage(HttpRequestExecutingMessageHandler.java:421) ~[spring-integration-http-4.0.0.RELEASE.jar:na]
    ... 62 common frames omitted
Caused by: java.net.ProtocolException: Invalid HTTP method: PATCH
    at java.net.HttpURLConnection.setRequestMethod(HttpURLConnection.java:428) ~[na:1.7.0_51]
    at org.springframework.http.client.SimpleClientHttpRequestFactory.prepareConnection(SimpleClientHttpRequestFactory.java:213) ~[spring-web-4.0.6.RELEASE.jar:4.0.6.RELEASE]
    at org.springframework.http.client.SimpleClientHttpRequestFactory.createRequest(SimpleClientHttpRequestFactory.java:141) ~[spring-web-4.0.6.RELEASE.jar:4.0.6.RELEASE]
    at org.springframework.http.client.support.HttpAccessor.createRequest(HttpAccessor.java:76) ~[spring-web-4.0.6.RELEASE.jar:4.0.6.RELEASE]

2 个答案:

答案 0 :(得分:2)

  

引起:java.net.ProtocolException:无效的HTTP方法:PATCH       at java.net.HttpURLConnection.setRequestMethod(HttpURLConnection.java:428)〜[na:1.7.0_51]       在org.springframework.http.client.SimpleClientHttpRequestFactory.prepareConnection(SimpleClientHttpRequestFactory.java:213)〜[spring-web-4.0.6.RELEASE.jar:4.0.6.RELEASE]

改为使用HttpComponentsClientHttpRequestFactory

<int-http:outbound-gateway url="http://test.com/consumerappointment/appointments/1295" 
              http-method="PATCH" 
              expected-response-type="java.lang.String" 
              request-factory="clientHttpRequestFactory"
              charset="UTF-8" />

<beans:bean id="clientHttpRequestFactory" class="org.springframework.http.client.HttpComponentsClientHttpRequestFactory"/>

答案 1 :(得分:-1)

我希望有所帮助:

@Bean
public RestTemplate restTemplate(RestTemplateBuilder builder) {
     return builder.build();
}

祝你好运