Commit bed9a4dd authored by bourgesl's avatar bourgesl
Browse files

fixed url checker if HTTP HEAD method is unsupported by web server

parent e62fa236
......@@ -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;
}
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment