Java 带条件的Spring集成头值路由器

Java 带条件的Spring集成头值路由器,java,spring,spring-integration,Java,Spring,Spring Integration,我有应答通道上http状态代码的头值路由器。如果状态代码为200,我想将原始有效负载重定向到afterSuccessChannel,否则如果标头中有任何其他状态,我想将有效负载发送到afterFailuerChannel。我不确定是否可以使用头值路由器,因为没有表达式字段。是否可以使用头值路由器,或者我必须为此使用通用路由器 <int:header-value-router header-name="#{T(org.springframework.integration.http.Http

我有应答通道上http状态代码的头值路由器。如果状态代码为
200
,我想将原始有效负载重定向到
afterSuccessChannel
,否则如果标头中有任何其他状态,我想将有效负载发送到
afterFailuerChannel
。我不确定是否可以使用
头值路由器
,因为没有表达式字段。是否可以使用
头值路由器
,或者我必须为此使用通用路由器

<int:header-value-router header-name="#{T(org.springframework.integration.http.HttpHeaders).STATUS_CODE}" input-channel="ccChannel" default-output-channel="ccLogger">
        <int:mapping value="200" channel="afterSuccessChannel"/>
</int:header-value-router>

我不知道它为什么要寻找OK频道。

标题是一个
HttpStatus
对象(枚举),而不是一个简单的字符串

您需要映射到枚举上(在本例中为
OK


请注意,第二个是一个常规路由器,它使用运行时表达式提取报头的数值。

Great。不过我有一个问题。这个路由器是有条件的吗?从某种意义上讲,如果值不是
OK
,它是否会路由到
默认输出通道
?实际上,我有一个条件要路由到
成功后通道
是状态值是
200/OK
,否则路由到
ccLogger
ErrorMessage [payload=org.springframework.messaging.MessagingException: failed to resolve channel name 'OK'; nested exception is org.springframework.messaging.core.DestinationResolutionException: failed to look up MessageChannel with name 'OK' in the BeanFactory.; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'OK' is defined, headers={timestamp=1419419964606, id=eea83b65-0e72-bcda-d8fe-6d9bb4619fb4, history=errorChannel}]
<int:mapping value="OK" channel="afterSuccessChannel"/>
<int:header-value-router input-channel="foo" default-output-channel="baz" 
    resolution-required="false"
    header-name="#{T(org.springframework.integration.http.HttpHeaders).STATUS_CODE}">
  <int:mapping value="OK" channel="bar" />
</int:header-value-router>


<int:router input-channel="foo" default-output-channel="baz"
    resolution-required="false"
    expression="headers['#{T(org.springframework.integration.http.HttpHeaders).STATUS_CODE}'].toString()">
  <int:mapping value="200" channel="bar" />
</int:router>