After introducing how camel handles FTP and JMS interfaces, we will introduce another interface frequently encountered during system integration, HTTP. The following is an example of the requirement: (the image is from camel in action)
This article provides a simple example of how to use camel to implement such an application:
1. Configure the following routes in a Java class: here only the HTTP section is shown. For other functions, see other blogs in the Apache camel framework series.
public class HttpPollWithQuartzCamel { public static void main(String args[]) throws Exception { CamelContext context = new DefaultCamelContext(); context.addRoutes(new RouteBuilder() { public void configure() { from("quartz://report?cron=10 * * * * ?&stateful=true") .to("http://localhost:8080/prjWeb/test.camelreq") .to("file:d:/temp/outbox?fileName=http.csv"); ); } }); context.start(); boolean loop = true; while (loop) { Thread.sleep(25000); } context.stop(); }}
A simple explanation of the above Code: From ("quartz: // report? Cron = 10 ****? & Stateful = true "), configure a quartz job, send an HTTP request every 10 seconds, and save the received content as a file.
Here the http url can be any accessible http url, if you need a proxy during HTTP access, you can configure it like this: "http://www.baidu.com? Proxyhost = proxy.xxx.com & proxyport = 8080"
This example needs to use quartz, and httpclient jar package, can download from here: http://download.csdn.net/detail/kkdelta/4051072