【发布时间】:2016-02-19 11:04:54
【问题描述】:
我不知道我是否正确地关注了这个问题 - 我通过 RestTemplate 发送了一个 PUT 请求,如下所示:
restTemplate.exchange(getBaseUrl() + "/api/getVoid", HttpMethod.PUT, new HttpEntity<String>("someMessage"), Void.class);
或:
restTemplate.put(getBaseUrl() + "/api/getVoid", "someMessage");
PUT 所以这意味着我不期待回复内容。我的 HTTP PUT 服务由 Spring Integration 组件公开:
<int-http:inbound-gateway supported-methods="PUT" reply-timeout="5000"
path="/api/getVoid"
request-channel="some-request-channel1" reply-channel="some-reply-channel1">
<int:channel id="some-request-channel1"/>
<int:channel id="some-reply-channel1"/>
<int:service-activator input-channel="some-request-channel1" output-channel="some-reply-channel1" ref="someService"
method="restMethodVoid"/>
我的入站网关集上有一个回复通道,但处理请求的服务“返回”无效(某些 PUT 操作)。
@ServiceActivator
public void restMethodVoid(Message<String> request) {
log.info("DONE! But you will get 500");
}
现在的问题 - 我可以看到将 PUT 请求发送到入站网关以使用 void 返回方法进行处理会在回复超时时引发 500 内部服务器错误。
这是否意味着不可能向“由”无效服务方法操作的 SI http 入站网关发送 PUT 或任何其他请求?
这是 1.3.2 版本中的行为,但它在 1.2.3 中的行为有所不同 - 网关行为似乎相同 - 它超时但没有抛出 500 - 只是回到仍在等待请求线程并释放它“很好”(仍然只是超时)。
我认为这两种行为都不是完美的,但 1.3.2 更糟糕,因为假设我将 PUT(或以 Void.class 作为返回类型的 POST...)发送为进程并且处理得很好 - 一些关键的事务操作被提交等等 - 方法返回非常好,但调用者得到 500。所以这个 500 被传播给它的调用者......可能以 UI 上的错误结束(这真的会吓到用户;))。但一切都很顺利。
在 1.2.3 行为中 - 即使超时但线程可以返回到其调用者并返回 200 状态,因此接下来传播正确的响应代码。
Gary,Artem - 你能在这里给点建议吗?
【问题讨论】:
-
这是来自 1.2.3.RELEASE 版本的响应:
11:16:01.882 [Thread-3] DEBUG o.s.web.client.RestTemplate - PUT request for "http://localhost:64526/api/getVoid" resulted in 200 (OK)(仍然是超时)。从 1.3.2.RELEASE 开始:org.springframework.web.client.HttpServerErrorException: 500 Internal Server Error。嗯 -
我不确定你指的是凋零版本 1.2.3 和 1.3.2;这些版本不存在;该行为在 4.2 版中已更改(已修复) - 请参阅下面的答案。
-
对不起,我指的是 Spring Boot 版本。