How to assign path variables to headers in a java dsl http inbound gateway?

北城以北 提交于 2019-12-11 10:24:46

问题


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>

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()

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.

Appreciate the help.


回答1:


private static final SpelExpressionParser PARSER = new SpelExpressionParser();

...

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


来源:https://stackoverflow.com/questions/33587850/how-to-assign-path-variables-to-headers-in-a-java-dsl-http-inbound-gateway

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!