apache camel - How to use $header in routes -


i'm creating route using java dsl in camel.

i'd perform text substitution without creating new processor or bean.

i have this:

.setheader(my_thing,     constant(my_template.replace("{id1}", simple("${header.subs_val}").gettext()))) 

if don't add 'constant' type mismatch errors. if don't put gettext() on simple() part, text mismatch answers. when run route, replaces {id} literal ${header.subs_val} instead of fetching value header. yet if take quotes off, compile errors; java doesn't know ${...} syntax of course.

deployment takes few minutes, experiments expensive.

so, how can simple substitution. nothing finding on web seems work.

edit - template? specifically, string (it's url)

http://this/that/{id1}/another/thing 

i've inherited code, unable to(...) url , apply special .tof() (??) formatting.

interesting case!

if place my_template in header use nested simple expression(camel 2.9 onwards) in example below. setting value subs_val example, suppose header has value in route.

  .setheader("my_template", constant("http://this/that/{id1}/another/thing"))   .setheader("subs_val",constant("22"))   .setheader("my_thing",simple("${in.header.my_template.replaceall(\"\\{id1.?\",${in.header.subs_val.tostring()})}")) 

after step header my_thing has value http://this/that/22/another/thing.

1)in example skip to_string() not know what's type of header "subs_val" .

2) tried first replaceall(\"\{id1\"}\") didn't work } bug...will @ again. that's why in regex used .?

3) when debug application inside processor, exchange available can use simplebuilder evaluate simple expression in ide, without having restart app

 simplebuilder.simple("${in.header.url.replaceall(\"\\{id1.?\",${in.header.subs_val.tostring()})}").evaluate(exchange, string.class); 

hope helped :)


Comments

Popular posts from this blog

java - nested exception is org.hibernate.exception.SQLGrammarException: could not extract ResultSet Hibernate+SpringMVC -

sql - Postgresql tables exists, but getting "relation does not exist" when querying -

asp.net mvc - breakpoint on javascript in CSHTML? -