|
21 | 21 | import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; |
22 | 22 | import java.io.File; |
23 | 23 | import java.io.FileInputStream; |
| 24 | +import java.io.IOException; |
24 | 25 | import java.io.InputStream; |
25 | 26 | import java.net.URI; |
26 | 27 | import java.util.ArrayList; |
@@ -425,38 +426,49 @@ private static ConfigResult getConfig( |
425 | 426 | final PropertyEnvironment props, |
426 | 427 | final SslConfiguration sslConfiguration) { |
427 | 428 | final File inputFile = source.getFile(); |
| 429 | + final ConfigResult configResult = new ConfigResult(); |
428 | 430 | InputStream inputStream = null; |
429 | 431 | HttpInputStreamUtil.Result result = null; |
430 | 432 | final long lastModified = source.getLastModified(); |
431 | | - if (inputFile != null && inputFile.exists()) { |
432 | | - try { |
433 | | - final long modified = inputFile.lastModified(); |
434 | | - if (modified > lastModified) { |
435 | | - source.setLastModified(modified); |
436 | | - inputStream = new FileInputStream(inputFile); |
437 | | - result = new HttpInputStreamUtil.Result(Status.SUCCESS); |
438 | | - } else { |
439 | | - result = new HttpInputStreamUtil.Result(Status.NOT_MODIFIED); |
| 433 | + try { |
| 434 | + if (inputFile != null && inputFile.exists()) { |
| 435 | + try { |
| 436 | + final long modified = inputFile.lastModified(); |
| 437 | + if (modified > lastModified) { |
| 438 | + source.setLastModified(modified); |
| 439 | + inputStream = new FileInputStream(inputFile); |
| 440 | + result = new HttpInputStreamUtil.Result(Status.SUCCESS); |
| 441 | + } else { |
| 442 | + result = new HttpInputStreamUtil.Result(Status.NOT_MODIFIED); |
| 443 | + } |
| 444 | + } catch (Exception ex) { |
| 445 | + result = new HttpInputStreamUtil.Result(Status.ERROR); |
| 446 | + } |
| 447 | + } else if (source.getURI() != null) { |
| 448 | + try { |
| 449 | + result = HttpInputStreamUtil.getInputStream(source, props, authorizationProvider, sslConfiguration); |
| 450 | + inputStream = result.getInputStream(); |
| 451 | + } catch (ConfigurationException ex) { |
| 452 | + result = new HttpInputStreamUtil.Result(Status.ERROR); |
440 | 453 | } |
441 | | - } catch (Exception ex) { |
442 | | - result = new HttpInputStreamUtil.Result(Status.ERROR); |
| 454 | + } else { |
| 455 | + result = new HttpInputStreamUtil.Result(Status.NOT_FOUND); |
443 | 456 | } |
444 | | - } else if (source.getURI() != null) { |
445 | | - try { |
446 | | - result = HttpInputStreamUtil.getInputStream(source, props, authorizationProvider, sslConfiguration); |
447 | | - inputStream = result.getInputStream(); |
448 | | - } catch (ConfigurationException ex) { |
449 | | - result = new HttpInputStreamUtil.Result(Status.ERROR); |
| 457 | + if (result.getStatus() == Status.SUCCESS) { |
| 458 | + LOGGER.debug("Processing Debug key/value pairs from: {}", source.toString()); |
| 459 | + parseJsonConfiguration(inputStream, configResult); |
| 460 | + } else { |
| 461 | + configResult.status = result.getStatus(); |
| 462 | + } |
| 463 | + } finally{ |
| 464 | + if (inputStream != null) { |
| 465 | + try { |
| 466 | + inputStream.close(); |
| 467 | + } catch (IOException e) { |
| 468 | + LOGGER.warn("Failed to close {}.", source, e); |
| 469 | + configResult.status = Status.ERROR; |
| 470 | + } |
450 | 471 | } |
451 | | - } else { |
452 | | - result = new HttpInputStreamUtil.Result(Status.NOT_FOUND); |
453 | | - } |
454 | | - final ConfigResult configResult = new ConfigResult(); |
455 | | - if (result.getStatus() == Status.SUCCESS) { |
456 | | - LOGGER.debug("Processing Debug key/value pairs from: {}", source.toString()); |
457 | | - parseJsonConfiguration(inputStream, configResult); |
458 | | - } else { |
459 | | - configResult.status = result.getStatus(); |
460 | 472 | } |
461 | 473 | return configResult; |
462 | 474 | } |
|
0 commit comments