use of org.xdi.util.EasySSLProtocolSocketFactory in project oxCore by GluuFederation.
the class HTTPFileDownloader method getResource.
public static String getResource(String path, String contentType, String user, String password) {
boolean isUseAuthentication = (user != null) && (password != null);
if (!path.contains("://")) {
path = "http://" + path;
}
String result = null;
GetMethod method = new GetMethod(path);
try {
method.setRequestHeader("Accept", contentType);
if (getEasyhttps() == null) {
setEasyhttps(new Protocol("https", new EasySSLProtocolSocketFactory(), 443));
}
Protocol.registerProtocol("https", getEasyhttps());
final HttpClient httpClient;
if (isUseAuthentication) {
httpClient = createHttpClientWithBasicAuth(user, password);
} else {
httpClient = new HttpClient();
}
httpClient.executeMethod(method);
if (method.getStatusCode() == HttpStatus.SC_OK) {
result = method.getResponseBodyAsString();
}
} catch (IOException ex) {
result = null;
log.error(String.format("Failed to get resource %s", path), ex);
} catch (Exception ex) {
result = null;
log.error(String.format("Failed to get resource %s", path), ex);
} finally {
method.releaseConnection();
}
return result;
}
Aggregations