How to download zip file from http with camel?

996 Views Asked by At

I am a beginner with Camel. I am trying to download a zip file for which I have http path and trying to store the file in the local file system. I managed to read the file but instead of reading it once and downloading it in local folder my code is running into an infinite loop and creating many copies of the file so I get outOfMemoryError. I did the investigation and using a timer component should solve the problem, but I don't know how to use timer component and direct components together... I tried something as code below , but nothing is happening

Here is my code:

private static final String ROUTE_ID = "route.DownloadZipFileRoute";
private static final String URI = "direct:getZipFile";
private static final String ZIP_PATH = "/zipFiles";

@Override
public void configure() throws Exception {
    rest().get(ZIP_PATH).to(URI);

    from("timer:getZipFile?repeatCount=1").to("direct:getZipFile");
    from("direct:getZipFile")
            .routeId(ROUTE_ID)
            .setHeader(Exchange.HTTP_METHOD, constant("GET"))
            .to("http://example.zip?bridgeEndpoint=true")
            .to("file://D://outputFolder")
            .log("file is downloaded ..........");


}
0

There are 0 best solutions below