java - 过滤消息的 HTTP 响应

标签 java spring spring-integration

我是 Spring 和 Spring 集成的新手,我决定全力以赴 - 现在,我陷入了困境。

考虑以下 Spring 配置 - 一个将请求发送到 AMQP 代理进行处理的入站网关:

<int:channel id="requestChannel" />
<int:channel id="responseChannel"/>
<int:channel id="myDiscardChannel"/>
<int-http:inbound-gateway id="myInboundGateway" 
                            request-channel="requestChannel"
                            reply-channel="responseChannel"
                            mapped-request-headers="*"
                            mapped-response-headers="Return-Status, Return-Status-Msg, HTTP_RESPONSE_HEADERS"       
                            path="/foo"
                            reply-timeout="50000"/>

<int:chain input-channel="requestChannel" output-channel="responseChannel">
    <int:filter expression="someExpression" discard-channel="myDiscardChannel" />
    <int-amqp:outbound-gateway amqp-template="amqpTemplate" exchange-name-expression="fooexchange" reply-timeout="50000" />
</int:chain>        

我希望能够做的是,当人为的“someExpression”表达式对表示 HTTP 请求的消息求值为 false 时,使用适当的 HTTP 状态代码和有效负载完成原始请求。

我研究了几种方法:

1)设置过滤器来生成异常,并在错误 channel 上处理它们,但我似乎无法正确理解这一点 - 很难找到这种技术的正确示例。

2)设置过滤器以将丢弃的消息发送到丢弃 channel - 我尚未弄清楚如何生成消息并将其发送回入站网关以完成原始请求。

任何帮助将不胜感激!

最佳答案

只需将转换器订阅到丢弃 channel 即可;省略转换器上的输出 channel ,转换结果将返回入站网关。

您可以从入站网关和链(输出 channel )中删除responseChannel(回复 channel );在这种情况下不需要它。

关于java - 过滤消息的 HTTP 响应,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19062117/

相关文章:

java - Spring Security accountNonExpired凭据NonExpired实现

java - 包括所有 Sun 专有类

java - Lambda 表达式不工作,被终止

java - 在 IntegrationFlow 服务激活器方法成功返回之前不确认 RabbitMQ 消息?

java - 如何使用 Spring Batch 对输入数据进行分组?

java - GWT 模块 ... 在项目源或资源中找不到

java - 如何在Spring中编写基于注解的servlet映射?

java - 在开发模式下运行 spring-GWT 应用程序时出现 XML 错误

java - Spring Boot 使用 1.5.6 发布重新打包的子模块 jar

java - SpringIntegration Poller 复制文件