How to enrich the message headers with uri variables or parameters in Spring Integration java dsl -


i'm trying enrich headers of messages coming http inbound gateway ; uri looks this:

requestmapping.setpathpatterns("/context/{fooid}"); 

but don't know how use setheaderexpressions method of httprequesthandlingmessaginggateway catch uri variable , put value in header.

i have no more success .enrichheaders(...) since code generates exception:

integrationflows.from(requestnotificationchannel())   .enrichheaders(h -> h.header("fooid", "#pathvariables.fooid") 

what way extract values uri-variables and/or parameters ?

thanks !

well, missunderstood bit how httprequesthandlingmessaginggateway works or missed in documentaiton.

each spel evaluation done withing evaluationcontext , fresh each component. #pathvariables evaluationcontext varialbe available httprequesthandlingmessaginggateway during request processing. other similar variables request , available message building httprequesthandlingmessaginggateway are:

  • requestattributes
  • requestparams
  • requestheaders
  • cookies
  • matrixvariables

what want doesn't work regular .enrichheaders() because uses new fresh evaluationcontext , variable aren't available already. that's why httprequesthandlingmessaginggateway provides setheaderexpressions. , here sample how use case:

private final static spelexpressionparser parser = new spelexpressionparser(); .... @bean public httprequesthandlingmessaginggateway httpinboundgateway() {      ....      httpinboundgateway.setheaderexpressions(collections.singletonmap("fooid", parser.parseexpression("#pathvariables.fooid")));      .... } 

from other side, if requestnotificationchannel() directchannel, don't leave http request thread in .enrichheaders(), therefore can this:

.enrichheaders(h -> h.headerfunction("fooid", m ->                         ((map<string, string>) requestcontextholder.currentrequestattributes()                                         .getattribute(handlermapping.uri_template_variables_attribute, 0)).get("fooid"))) 

Comments

Popular posts from this blog

How to connect android app to App engine -

gcc - MinGW's ld cannot perform PE operations on non PE output file -

php - display validation error message next to the textbox in codeigniter -