ddsultan
ddsultan

Reputation: 2287

Sending multiple http requests with Apache Camel

I am trying to send GET HTTP requests to a paginated endpoint. The challenge is I do not know the page size beforehand therefore I have to send a request to get page number and interate till the end. I have tried Camel HTTP but I was not able to make it send dynamic requests based on first (or previous) response. I am currently testing recipientList to generate HTTP URLs by sending the first request and use the simple method as processor. Since Camel is really new for me, I am not sure if this is the best way to do like this.

I would be really grateful if someone could show some direction on this. Thank you

Upvotes: 0

Views: 1299

Answers (1)

burki
burki

Reputation: 7015

When I understood your question correct, you have to make an initial request to get the first page.

In the response you probably get the number of pages and then you want to get all remaining pages.

You could give the Camel Loop EIP a try for the remaining pages.

Pseudo-Route:

.from("whatever triggers the page retrieval")
    .setHeader("currentPage", constant(1))
    .to("http:target/page/1")
    // dont know what you want to do with the pages
    ... continue processing of the first page
    .setHeader("numberOfPages", simple("extract the number of pages somehow"))
    .loopDoWhile(simple("${header.currentPage} <= ${header.numberOfPages}"))
        .toD("http:target/page/${header.currentPage}")
        // dont know what you want to do with the pages
        ... continue processing of the current page
    .end

It really depends on what you need to do with the pages you retrieve. For example if you have to aggregate them, I am not sure if you can access an aggregated result from inside the loop.

Upvotes: 1

Related Questions