简体   繁体   中英

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

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.

private static final SpelExpressionParser PARSER = new SpelExpressionParser();

...

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM