Hi,

How did you send a message to the "direct:getRestExternalService" endpoint? 
from() just means it consumes from that URL, so the route won't be executed until a 
message is sent to that endpoint.

Thanks,
Tomo

On 02/28/2017 02:59 AM, rkmohapatra wrote:
Thank you Ravi for the tips.
I did this based on your tips.

- Added camel-http4-2.18.2.jar to my application
- Added following libraries additionallay as I was getting
classnotfoundexception errors.
httpcore-4.3.3.jar
httpclient-4.3.3.jar
commons-logging-1.2.jar
commons-httpclient-3.1.jar

Do we need to add these JARs additionally for 'http4' component?

- Added the following code in configure() method of my RouteBuilder class.

from("direct:getRestExternalService")
.to("http4://...")
.process(new RestProcessor());

- Added RestProcesser as below
        @Override
        public void process(Exchange exchange) throws Exception {
                System.out.println("Processing REST response from external 
service");
                String jsonString = exchange.getIn().getBody(String.class);
                System.out.println(jsonString);
        }
- Client code looks like this.
public void processRestEndPoint() {
                CamelContext ctx = new DefaultCamelContext();
                RestRouteBuilder builder = new RestRouteBuilder();
                try {
                        System.out.println("Building router....");
                        ctx.addRoutes(builder);
                        ctx.start();
                        System.out.println("Routing started....");
                        Thread.sleep(1*60*1000);
                        ctx.stop();
                        System.out.println("Routing stopped....");
                } catch (Exception e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                }
        }

With this code, somehow the process method RestProcessor is not invoked at
all.
Am I missing anything here? It does not throw any exception as well.

Output:
Building router....
Router started....
Router stopped....

Appreciate any clue.

Thanks,
Rajesh



--
View this message in context: 
http://camel.465427.n5.nabble.com/Consuming-data-from-external-REST-service-tp5794514p5794532.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Reply via email to