我最近从Spring Integration 4.1.3更新到4.2.6,并注意到我开始收到来自http:inbound-gateway的500响应。经调查,这是由于空回复造成的,网关将其解释为MessagingGatewaySupport中的超时
if (reply == null && this.errorOnTimeout) {这是有意义的,所以我将其更改为http:inbound-channel-adapter,它解决了这个问题,但错误处理不会像预期的那样运行。
我之前在网关上使用了和错误通道
<int-http:inbound-gateway id="inboundGateway" request-channel="httpInChannel" reply-channel="httpResponseChannel" path="/**/status*" supported-methods="POST" error-channel="httpErrorChannel"/>
<int:chain input-channel="httpInChannel" output-channel="serviceChannel">
...
</int:chain>
<int:chain input-channel="httpErrorChannel">
<int:header-enricher>
<int:header name="http_statusCode" value="500" />
</int:header-enricher>
<int:transformer expression="payload.localizedMessage" />
</int:chain>
<int:service-activator input-channel="serviceChannel" ref="someController" method="someVoidMethod"/>我怀疑它可能不起作用,但我稍微修改了一下
<int-http:inbound-channel-adapter id="inboundAdapter" channel="httpInChannel" path="/**/status*" supported-methods="POST" error-channel="httpErrorChannel"/>
<int:chain input-channel="httpInChannel" output-channel="serviceChannel">
...
</int:chain>
<int:chain input-channel="httpErrorChannel">
<int:header-enricher>
<int:header name="http_statusCode" value="500" />
</int:header-enricher>
<int:transformer expression="payload.localizedMessage" />
</int:chain>
<int:service-activator input-channel="serviceChannel" ref="someController" method="someVoidMethod"/>现在,对于正常有效的POST请求,它工作得很好,但如果我发送一个错误的无效消息,我会得到一个500响应,其中包含完整的错误堆栈作为响应(我也尝试更改了头中的状态码)。错误是
org.springframework.messaging.core.DestinationResolutionException: no output-channel or replyChannel header available这是有意义的,因为error-channel没有输出(尽管文档中也没有http://docs.spring.io/spring-integration/docs/4.3.0.RELEASE/reference/htmlsingle/#http-response-statuscode)。有没有办法以与网关类似的方式更改入站适配器的错误响应?
发布于 2016-07-22 20:21:15
我认为这是一个错误,请打开一个JIRA Issue。
作为一种变通方法,在主流中,紧跟在适配器之后,添加一个中流网关...
<int:service-activator ref="gw" input-channel="httpInChannel" >
<int:gateway id="gw" error-channel="httpErrorChannel"
default-request-channel="nextChannelInMainFlow" default-reply-timeout="0" />网关就像一个围绕着流的try/catch块。
回复超时非常重要,因为您不希望收到回复。
https://stackoverflow.com/questions/38524402
复制相似问题