diff --git a/src/main/java/fr/osug/doi/service/UrlChecker.java b/src/main/java/fr/osug/doi/service/UrlChecker.java index aae62b21695f178a28f66f3557a38b2d62a310ab..167d241657977b7283f85c2030da8f5313a787a0 100644 --- a/src/main/java/fr/osug/doi/service/UrlChecker.java +++ b/src/main/java/fr/osug/doi/service/UrlChecker.java @@ -45,13 +45,13 @@ public class UrlChecker { public String getResource(final String url, final boolean headOnly) { // Note: url must not be encoded (%) if (url.contains("%")) { - logger.info("Url is encoded (may cause problem with HTTP request) : {}", url); + logger.info("getResource: url is encoded (may cause problem with HTTP request) : {}", url); + } else { + logger.debug("getResource: {}", url); } String response = null; - try { - logger.debug("getResource: {}", url); - - if (headOnly) { + if (headOnly) { + try { final HttpHeaders headers = this.restTemplate.headForHeaders(url); if (headers != null) { @@ -60,14 +60,19 @@ public class UrlChecker { } response = headers.getContentType().toString(); } - } else { + } catch (RestClientException rce) { + logger.warn("getResource({}): failed: {}", url, rce.getMessage()); + } + } + // if not headOnly or head failed: + if (response == null) { + try { response = this.restTemplate.getForObject(url, String.class); + } catch (RestClientException rce) { + logger.warn("getResource({}): failed: {}", url, rce.getMessage()); } - } catch (RestClientException rce) { - logger.error("getResource: failed", rce); } - logger.debug("getResource:\n{}", response); + logger.debug("getResource({}):\n{}", url, response); return response; } - }