spring - Pass query parameters through a route -


camel learner here. there ability store incoming query parameters , set various headers/query parameters various routes?
want build proxy-like service authentication option. example :
1) receive http on http://foo.bar/path?login=admin&password=admin&action=delete
2) i'd use <to uri="direct:auth"/> send request http://auth.foo.bar/login?login=admin&password=admin , receive authentication token answer
3) then, perform action token : going http://action.foo.bar/perform?authtoken=sometoken&action=delete

finally - there option "cut" "action" param before going auth route , append before going action. thanks.

you'll want use camel jetty component receive http request , camel http4 component make requests other web services.

the jetty component take query parameters client's call , put them in headers of in exchange same names http query.

you can set query parameters used other http calls setting "camelhttpquery" header (the exchange.http_query static final variable string). below i've used simple language camel provides allows put headers , body strings can used set headers. response http calls set in body of exchange.

for example:

from("jetty:http://0.0.0.0:1234/path")     .setheader(exchange.http_query,  simple("?login=${header.login}&password=${header.password}"))     .to("http4://auth.foo.bar/login")     .setheader("authtoken", simple("${body}")) //assuming token in response body     .setbody("")     .setheader(exchange.http_query,  simple("?authtoken=${header.authtoken}&action=${header.action}"))     .to("http4://action.foo.bar/perform"); 

this simple example shows headers , responses put. may want wrap of header setting , response processing camel processors if it's not simple keep route easy read.

further response:

to filter headers being sent http endpoint create instance of org.apache.camel.spi.headerfilterstrategy in spring beans definition , add .to("http://auth.foo.bar/?headerfilterstrategy=authheaderfilterimpl") so. (this http4 page)

the reason suggested http4 it's more customisable feel free stick jetty if can find equivalent functionality http4 need.

but reading exposing post request functionality sounds auth endpoint more of "enrich" enterprise integration pattern. have @ camel-enricher allows hit endpoint , aggregate response original exchange (or use recipient list aggregation strategy if you're using camel 2.15 or less).

otherwise store original post request body in header , use later real action call.


Comments

Popular posts from this blog

php - Invalid Cofiguration - yii\base\InvalidConfigException - Yii2 -

How to show in django cms breadcrumbs full path? -

ruby on rails - npm error: tunneling socket could not be established, cause=connect ETIMEDOUT -