使用apache camel从http位置下载

使用apache camel从http位置下载,apache,apache-camel,apache-httpclient-4.x,Apache,Apache Camel,Apache Httpclient 4.x,我需要使用ApacheCamel将一个文件从http位置下载到本地系统。当我给出下面的代码时 from("http://url/filename.xml") .to("file://C:location") 它对ftp有效,但在url为“http”时不起作用。也就是说,它没有将文件从http位置下载到“to()”中提供的本地地址。http组件不能用作使用者ie。您不能有路由作为from(“http://...)) 您需要使用

我需要使用ApacheCamel将一个文件从http位置下载到本地系统。当我给出下面的代码时

    from("http://url/filename.xml")                         
    .to("file://C:location")  

它对ftp有效,但在url为“http”时不起作用。也就是说,它没有将文件从http位置下载到“to()”中提供的本地地址。

http组件不能用作使用者ie。您不能有路由作为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");
您不能从(“某些url”)使用
。只要direct:abc端点上有消息,就会触发上述路由。您可以将yourFileName.xml更改为希望存储为的任何文件名

您也可以使用计时器或任何其他自触发方式,而不是使用route的触发器

你不能从这样的休息点消费的原因

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位置下载到本地的代码。谢谢,但是下载的文件被重命名为其他名称。即使url被指定为.to(“url/?filename=filename.xml”),它也是以另一个文件名和其他格式类型下载的。如何添加计时器以便文件以一定的间隔下载?而不是从(“direct:abc”)
添加这一行(“timer:foo?fixedRate=true&period=5000”)如何每月或每周下载一次文件?我想知道我可以设定的时间间隔类型。任何参考文件都将不胜感激。请查看此计时器文件。若您想要复杂的触发器,那个么您应该检查quartz组件,在这里您可以使用cron表达式指定触发器。