Committed by
Gerrit Code Review
Fix for reading remote cluster metadata file
Log exceptions when trying to access metadata file Close connections opened when checking file availability Change-Id: Ibe89e66ba52dba1c47b559bb784fd7376a3319f2
Showing
1 changed file
with
5 additions
and
2 deletions
... | @@ -21,6 +21,7 @@ import static org.slf4j.LoggerFactory.getLogger; | ... | @@ -21,6 +21,7 @@ import static org.slf4j.LoggerFactory.getLogger; |
21 | import java.io.File; | 21 | import java.io.File; |
22 | import java.io.FileInputStream; | 22 | import java.io.FileInputStream; |
23 | import java.io.IOException; | 23 | import java.io.IOException; |
24 | +import java.io.InputStream; | ||
24 | import java.net.URL; | 25 | import java.net.URL; |
25 | import java.net.URLConnection; | 26 | import java.net.URLConnection; |
26 | import java.util.Set; | 27 | import java.util.Set; |
... | @@ -169,13 +170,15 @@ public class ConfigFileBasedClusterMetadataProvider implements ClusterMetadataPr | ... | @@ -169,13 +170,15 @@ public class ConfigFileBasedClusterMetadataProvider implements ClusterMetadataPr |
169 | File file = new File(metadataUrl.replaceFirst("file://", "")); | 170 | File file = new File(metadataUrl.replaceFirst("file://", "")); |
170 | return file.exists(); | 171 | return file.exists(); |
171 | } else if (url.getProtocol().equals("http")) { | 172 | } else if (url.getProtocol().equals("http")) { |
172 | - url.openStream(); | 173 | + try (InputStream file = url.openStream()) { |
173 | - return true; | 174 | + return true; |
175 | + } | ||
174 | } else { | 176 | } else { |
175 | // Unsupported protocol | 177 | // Unsupported protocol |
176 | return false; | 178 | return false; |
177 | } | 179 | } |
178 | } catch (Exception e) { | 180 | } catch (Exception e) { |
181 | + log.warn("Exception accessing metadata file at {}:", metadataUrl, e); | ||
179 | return false; | 182 | return false; |
180 | } | 183 | } |
181 | } | 184 | } | ... | ... |
-
Please register or login to post a comment