I want to add a scheduling job to cron tab which is like GET request with a url. I wrote following code in my restful application for that endpoint to perform downloads of some xml files from given URLs. I found that it requires user interaction to select save or open from a pop up box. I want the job to be automated without any user interaction from the cron scheduler.
import java.io.File;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.Response;
import javax.ws.rs.core.Response.ResponseBuilder;
@Path("/metadata-management")
public class FileService {
private static final String FILE_PATH = "c:\\file.log";
@GET
@Path("/get")
@Produces("text/plain")
public Response getFile() {
File file = new File(FILE_PATH);
ResponseBuilder response = Response.ok((Object) file);
response.header("Content-Disposition",
"attachment; filename=\"file_from_server.log\"");
return response.build();
}
}
Should I just use HttpURLConnection to download file from an HTTP URL instead to download file within the above code block and return null for response?