I am new to Apache camel, this is what I am trying to figure out. In a sample code below, I am trying to use the property - "value" in the request param in next polling request.
String valueFromTheResponse= ""
m.addRouteBuilder(new RouteBuilder() {
@Override
public void configure() throws Exception {
from("timer://foo?period=2)
.setHeader(Exchange.CONTENT_TYPE, constant("application/json"))
.setHeader("Accept", constant("application/json"))
.to("https4://" + <myrequestURL>?param=<valueFromTheResponse>)
.marshal().json(JsonLibrary.Jackson)
.setProperty("value", jsonpath("$.value"))
.process(new Processor() {
@Override
public void process(final Exchange exchange) throws Exception {
valueFromTheResponse = (String) exchange.getProperty("value");
}
})
}
});
m.run();
What would be the best way to achieve this? or assign the class level variable the property value?
UPDATE: SOLUTION got it working by adding the following:
.process(new Processor() {
@Override
public void process(final Exchange exchange) throws Exception {
exchange.getIn().setHeader("CamelHttpQuery", buildParamQuery());
}
})
You would need to store the value in a shared field in for example the
RouteBuilderclass itself, or a shared class instance. And then in the to http endpoint uri, you need to set the param query as a message header instead where you can get that value via a method call.And then have a method
And then you set this field from the inlined processor with the last value. And mind about the initial value, eg the first poll the value is
nullso you need to maybe to return an empty string/null from thebuildParamQuerymethod or something else.