0

I am new to Apache Camel and I wanted to integrate or merge results of 2 API GET Requests and route their responses to a 3rd API.

1st API - http://localhost:8080/students/Student1 (GET method Returns {"id":"1","name":xyz"})
2nd API - http://localhost:8081/students/Student1 (GET method Returns {"id":"1","subject":"maths"}) 3rd API - http://localhost:8082/students/combine (GET method should produce {"id":"1","subject":"maths","name":"xyz"}

What I actually want to do is hit the 3rd API with a GET request so that it can implicitly call API1 and API2 and return output as: {"id":"1","subject":"maths","name":"xyz"}

This is the code I have written.

CamelContext context = new DefaultCamelContext(); JacksonDataFormat jsonDataFormat = new JacksonDataFormat(Output.class);

    context.addRoutes(new RouteBuilder() {
        @Override
        public void configure() throws Exception {
            from("jetty:http://localhost:8080/students/Student1")
            .to("direct:merge)

             from("jetty:http://localhost:8081/students/Student1")
            .to("direct:merge")
             
             from("direct:merge")
            .to("jetty:http://localhost:8082/students/combine")
        }
    });
    context.start();
}

}

Somit
  • 303
  • 2
  • 10
  • 1
    if you are sending request to the 3rd API, shouldn't it be a post request? – Sneharghya Pathak Sep 17 '20 at 07:54
  • I actually want to hit the 3rd API with a GET method that performs a GET request to the 2 APIs and combines their results. – Somit Sep 17 '20 at 08:12
  • If there is a solution using POST request, that would also work as well. – Somit Sep 18 '20 at 05:23
  • 1
    does this help? https://stackoverflow.com/questions/10610820/apache-camel-to-aggregate-multiple-rest-service-responses – Sneharghya Pathak Sep 21 '20 at 07:37
  • Yes it does help a lot. I have seen this answer before. However, I am getting a "cannot bind to localhost:8082" error. The port is not in use anywhere else. Any idea on that? – Somit Sep 21 '20 at 14:06

0 Answers0