使用 apache camel 从 http 位置下载
Download from a http location using apache camel
我需要使用 apache camel 从 http 位置将文件下载到我的本地系统。当我给出以下代码时
from("http://url/filename.xml")
.to("file://C:location")
它对 ftp 有效,但在 url 为 "http" 时无效。也就是说,它不会将文件从 http 位置下载到 "to()".
中提供的本地地址
http 组件不能用作消费者,即。你不能有一条路线作为 from("http://...")
您需要使用将启动路由的消费者组件。
你可以试试这样的
from("timer:foo?fixedRate=true&period=5000")
.to("http://url/filename.xml")
.to("file://C:location")
这应该有效。
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
我需要使用 apache camel 从 http 位置将文件下载到我的本地系统。当我给出以下代码时
from("http://url/filename.xml")
.to("file://C:location")
它对 ftp 有效,但在 url 为 "http" 时无效。也就是说,它不会将文件从 http 位置下载到 "to()".
中提供的本地地址http 组件不能用作消费者,即。你不能有一条路线作为 from("http://...")
您需要使用将启动路由的消费者组件。 你可以试试这样的
from("timer:foo?fixedRate=true&period=5000")
.to("http://url/filename.xml")
.to("file://C:location")
这应该有效。
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