如何将路径变量分配给 java dsl http 入站网关中的标头? [英] How to assign path variables to headers in a java dsl http inbound gateway?

查看:21
本文介绍了如何将路径变量分配给 java dsl http 入站网关中的标头?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嘿,我不太明白如何转换这个:

Hey i can't quite figure out how to convert this:

<int-http:inbound-gateway request-channel="eventSinkPayloadChannel"
                          path="/EventSink/{producer}/{consumer}"
                          supported-methods="POST" >
    <int-http:header name="PRODUCER" expression="#pathVariables.producer"/>
    <int-http:header name="CONSUMER" expression="#pathVariables.consumer"/>
</int-http:inbound-gateway>

进入Java DSL.我认为 headerExpression 方法将是使用的方法,

into the Java DSL. I thought the headerExpression method would be the one to use,

        Http.inboundGateway("/EventSink/{producer}/{consumer}")
                      .headerExpression("PRODUCER", expression)
                      .headerExpression("CONSUMER", expression)
                      .get()

但是我真的不能在第二个参数中传递一个字符串,因为它需要类型 Expression,所以我不知道我是否必须在那里实例化一个 SpelExpression 或者我是否实际上使用了正确的方法.

but i can't really pass a string in the second argument, coz it's expecting the type Expression, so i dunno if i have to instantiate a SpelExpression there or if i'm even using the right method actually.

感谢您的帮助.

推荐答案

private static final SpelExpressionParser PARSER = new SpelExpressionParser();

...

    .headerExpression("PRODUCER", PARSER.parseExpression("#pathVariables.producer"))

这篇关于如何将路径变量分配给 java dsl http 入站网关中的标头?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆