== ライン数30行程度で、簡単なファイルダウンロードツールをApache Camelで作ってみました! == 【簡単な解説!】 * http4コンポーネントとfileコンポーネントを使いました。 * uri = "http4://...." でhttp4コンポーネントを使用しています。まちがってhttp:// とすると違う意味になるので注意★ * producer.send(...)の戻り値は処理結果のデータが入っています。 {{{ package jacug.samples.download; import org.apache.camel.CamelContext; import org.apache.camel.Exchange; import org.apache.camel.ProducerTemplate; import org.apache.camel.impl.DefaultCamelContext; import org.apache.camel.impl.DefaultExchange; public class HttpDownload { public static void main(String[] args) throws Exception { for (int i=0; i<100; i++) { download("test" + i + ".bmp"); } } private static void download(String filename) throws Exception{ CamelContext ctx = new DefaultCamelContext(); ctx.start(); ProducerTemplate producer = ctx.createProducerTemplate(); // ダウンロード String uri = "http4://localhost/test/" + filename; Exchange exchange = new DefaultExchange(ctx); exchange = producer.send(uri, exchange); // ダウンロードしたデータの保存ファイル名を決める exchange.setIn(exchange.getOut()); exchange.getIn().setHeader(Exchange.FILE_NAME, filename); // ローカルに保存 uri = "file://C:/test"; producer.send(uri, exchange); } } }}} 【今回使用したライブラリ】(camel2.9.2に同梱) * camel-core-2.9.2.jar * camel-http-2.9.2.jar * camel-http4-2.9.2.jar * log4j-1.2.16.jar * slf4j-log4j12-1.6.1.jar * slf4j-api-1.6.1.jar 【今回使用したライブラリ】(httpcomponents-client-4.1.3に同梱) * 同梱されている全てのjar