我需要使用apache camel将文件从http位置下载到我的本地系统。当我提供以下代码时
from("http://url/filename.xml")
.to("file://C:location")
它适用于ftp,但当网址为" http"时无效。也就是说,它不会将文件从http位置下载到"到()"中提供的本地地址。
答案 0 :(得分:0)
http组件不能用作消费者ie。你不能拥有一条路线(“http:// ...”)
您需要使用将启动路线的消费者组件。 你可以试试这样的东西
from("timer:foo?fixedRate=true&period=5000")
.to("http://url/filename.xml")
.to("file://C:location")
答案 1 :(得分:0)
这应该有效。
from("direct:abc")
.setHeader("Accept", simple("application/xml"))//Change it according to the file content
.setHeader(Exchange.HTTP_METHOD, constant("GET"))
.to("http://url/filename.xml")
.to("file:///tmp/?fileName=yourFileName.xml");
您无法使用from("Some url")
。只要在direct:abc端点上有消息,就会触发上面的路由。您可以将yourFileName.xml更改为您希望将其存储为的任何文件名。
您可以使用计时器或任何其他自触发方式,而不是来自路线的触发器。
你无法从像这样的休息点消费的原因
from("http://url/filename.xml")
是你无法从http端点消费。所以需要有一个触发器。事实上,当您这样做时,异常消息非常清楚。它说
org.apache.camel.spring.boot.CamelSpringBootInitializationException: org.apache.camel.FailedToCreateRouteException: Failed to create route route1: Route(route1)[[From[http://url/filename.xml]] -> [To[... because of Cannot consume from http endpoint