I have called a REST api through apache camel and deserialized the same. I need to call another API with the number as the parameter that I have received from calling the previous api. I did it in the following way -
public Collection<String> nos;
from("direct:further").tracing()
.log("body: " + body().toString())
.setBody().constant(null)
.setHeader("CamelHttpMethod")
.simple("GET")
.setHeader("Authorization")
.simple("Bearer "+"${header.jwt}")
.to("https://call/api/that/returns/numbers")
.choice()
.when().simple("${header.CamelHttpResponseCode} == 200").unmarshal().json(JsonLibrary.Jackson, Abc.class)
.process(
ex->{
Quantity quantity = ex.getIn().getBody(Abc.class);
List<Variations> variationsList = Arrays.stream(quantity.getResources().getVariations()).toList();
nos=variationsList.stream().map(Variations::getNo).collect(
Collectors.toList());
nos.forEach(s -> { //Since nos is a collection of String I would like to iterate through it
String url="https://call/another/api/with/number"+"?"+s;//the link with the number as the parameter
from("direct:start") //This is not working. I not able to call the url
.setHeader("CamelHttpHeader")
.simple("GET")
.setHeader("Authorization")
.simple("Bearer "+"${header.jwt}")
.log("I did call the numbers") //This is also not getting printed
.to(url);
});
}).log("I am out of the loop" + body())
.otherwise()
.log("Error!!!");
I am unable to call another api with the number that I received adter calling the first api. How should I do it? I also tried to call it like
from("rest:get:"+url).tracing()
.setHeader("CamelHttpHeader")
.simple("GET")
.setHeader("Authorization")
.simple("Bearer "+"${header.jwt}")
.log("I did call the numbers").to(url);
But unfortunately the above code also did not work inside the loop. I declared the collection nos outside the method definition. How should I call another API from the numbers stored in nos collection? Should I call another Api outside the lambda function or inside?