452
452

Reputation: 442

How can I get result from curl in Apache Camel?

How can I get result from curl in Apache Camel? Apache Camel have some "curl" component for running curl?

or I only need use camel-exec?

and then I need parse json and "station":"\u041a\u0438\u0457\u0432-\u041f\u0430\u0441\u0430\u0436\u0438\u0440\u0441\u044c\u043a\u0438\u0439"

how to get normal text from this json encoding in Apache Camel?

I have no expirience with Apache Camel..

curl 'http://booking.uz.gov.ua/purchase/search/' -H 'GV-Token: 502c55405bfb82fa16e08278d934c5f1' -H 'Origin: http://booking.uz.gov.ua' -H 'Accept-Encoding: gzip, deflate' -H 'Accept-Language: en-US,en;q=0.8,ru;q=0.6,uk;q=0.4' -H 'Connection: keep-alive' -H 'Cookie: _gv_sessid=3lt3g4org56quapm20ogqs9n33; _gv_lang=uk; HTTPSERVERID=server1; __utmt=1; __utma=31515437.700625198.1438102950.1440172017.1440176787.29; __utmb=31515437.1.10.1440176787; __utmc=31515437; __utmz=31515437.1439982958.17.2.utmcsr=uz.gov.ua|utmccn=(referral)|utmcmd=referral|utmcct=/passengers/reservation_purchase_travel_documents/' -H 'GV-Ajax: 1' -H 'GV-Screen: 1280x800' -H 'GV-Referer: http://booking.uz.gov.ua/' -H 'User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Ubuntu Chromium/44.0.2403.89 Chrome/44.0.2403.89 Safari/537.36' -H 'Content-Type: application/x-www-form-urlencoded' -H 'Accept: */*' -H 'Referer: http://booking.uz.gov.ua/' -H 'GV-Unique-Host: 1' -H 'DNT: 1' --data 'station_id_from=2218020&station_id_till=2200001&station_from=%D0%9A%D0%BE%D0%B2%D0%B5%D0%BB%D1%8C&station_till=%D0%9A%D0%B8%D1%97%D0%B2&date_dep=24.08.2015&time_dep=00%3A00&time_dep_till=&another_ec=0&search=' --compressed

Upvotes: 1

Views: 1795

Answers (1)

mdo
mdo

Reputation: 7111

As a first step, you'll have to fetch the document at the given URL via an HTTP GET request. You could do this in the scope of an Apache Camel route by enriching the exchange but you would have to trigger the route somehow. As far as I know, for HTTP there is no scheduled polling consumer component in Camel. That would be the requirement to simply create a route like 'from("http:...")'.

A simple approach can be to use the component "http4" in order to request the document with an ConsumerTemplate. This can be created via the CamelContext (CamelContext.createConsumerTemplate()). Find an example for this in the Apache Camel tests. Look at the lines with "consumer.receiveBody(...)".

In order to work on the JSON payload, you can use Camel's JSON tools like the JsonPath language.

If you used a ConsumerTemplate to fetch the document, you have to create a route like the following (taken from Camel docs) and trigger it with a ProducerTemplate:

from("direct:start")
.choice()
.when().jsonpath("$.store.book[?(@.price < 10)]")
  .to("jms:queue:book.cheap")
.when().jsonpath("$.store.book[?(@.price < 30)]")
  .to("jms:queue:book.average")
.otherwise()
  .to("jms:queue:book.expensive")

In the example shown you'd send the body to the endpoint "direct:start" by utilizing a ProducerTemplate.

Upvotes: 1

Related Questions