0

So I am trying to use HttpClient to read from a remote txt file in my companies network. There are no firewalls or anything blocking my request. Here is my code:

try{
    CloseableHttpClient client = HttpClientBuilder.create().build();
    HttpGet request = new HttpGet("file://hostname/facility_data/Facility_Extract.txt");
    HttpResponse response = client.execute(request);
    HttpEntity entity = response.getEntity();
    BufferedReader in = new BufferedReader((new InputStreamReader(entity.getContent())));
    String input;
    while ((input = in.readLine()) != null) {
        LOG.info(input);
    }
    in.close();
}catch(Exception e){
    LOG.error("Could not access files : "+e.getMessage());
}

I think it has something to do with the 'file://' protocol but i am not sure how I would adjust to accommodate that. Any ideas?

JBMac
  • 329
  • 1
  • 6
  • 18
  • No such thing exists. `file://` is used by browsers for the _local_ filesystem. It isn't HTTP, either. – SLaks Jul 26 '18 at 19:32
  • No I tried http:// and and https:// and the file is unreachable. – JBMac Jul 26 '18 at 19:37
  • I also have this code: ['code']URL conn = new URL(url); String input; BufferedReader in = new BufferedReader((new InputStreamReader(conn.openStream()))); while ((input = in.readLine()) != null) { LOG.info(input); } and this works fine when i run it locally but when i deploy it into my cloud environment it fails. – JBMac Jul 26 '18 at 19:37
  • Are you running on Windows? If you put `\\hostname\facility_data` into an explorer window, does it show a listing? – VGR Jul 26 '18 at 19:41
  • I do not own or control the file and this link is the only one that they will provide to access their data. – JBMac Jul 26 '18 at 19:45
  • Some reason I cant get the code in a previous comment to format correctly by i was able to use java's URL and UrlConection class to hit the files and read them when I ran my application locally. but when I deploy the app to my cloud environment it can no longer reach the files. Again there is nothing in the way of the network that can block the request. – JBMac Jul 26 '18 at 19:47
  • 1
    Possible duplicate of [Download file with Apache HttpClient](https://stackoverflow.com/questions/44243615/download-file-with-apache-httpclient) – Gatusko Jul 26 '18 at 19:59
  • 1
    @Gatusko : no this is not a duplicate, my question is trying to understand downloading a file with a non-standard protocol. – JBMac Jul 26 '18 at 20:07

0 Answers0