首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Spring集成http:inbound-channel-adapter error-channel

Spring集成http:inbound-channel-adapter error-channel
EN

Stack Overflow用户
提问于 2016-07-22 18:41:29
回答 1查看 1K关注 0票数 1

我最近从Spring Integration 4.1.3更新到4.2.6,并注意到我开始收到来自http:inbound-gateway的500响应。经调查,这是由于空回复造成的,网关将其解释为MessagingGatewaySupport中的超时

代码语言:javascript
复制
if (reply == null && this.errorOnTimeout) {

这是有意义的,所以我将其更改为http:inbound-channel-adapter,它解决了这个问题,但错误处理不会像预期的那样运行。

我之前在网关上使用了和错误通道

代码语言:javascript
复制
<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"/>

我怀疑它可能不起作用,但我稍微修改了一下

代码语言:javascript
复制
<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响应,其中包含完整的错误堆栈作为响应(我也尝试更改了头中的状态码)。错误是

代码语言:javascript
复制
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)。有没有办法以与网关类似的方式更改入站适配器的错误响应?

EN

回答 1

Stack Overflow用户

发布于 2016-07-22 20:21:15

我认为这是一个错误,请打开一个JIRA Issue

作为一种变通方法,在主流中,紧跟在适配器之后,添加一个中流网关...

代码语言:javascript
复制
<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块。

回复超时非常重要,因为您不希望收到回复。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/38524402

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档