Exception in HttpClientCode
Hi,
We are working on migrating the httpclient verstion to 4.x and we have added dependency with the version 4.5. Here the httpclient get and post call codes throwing an
java.lang.NoClassDefFoundError: org/apache/http/auth/Credentials exception on deploying the bundle though Credentials class is not referenced anywhere in the code. Version of AEM used is 6.2, Please find the code below for get call
public <T> T handleGet(ProxySettings proxySettings, String uri, ResponseMapper<T> responeMapper) {
//CloseableHttpClient client = HttpClients.createDefault();
HttpGet method = new HttpGet(uri);
CloseableHttpClient client = null;
if (AuthType.AUTH_NTLM.equals(proxySettings.getAuthType())) {
// add basic details
CredentialsProvider credentialsProvider = new BasicCredentialsProvider();
credentialsProvider.setCredentials(new AuthScope(proxySettings.getProxyHost(), proxySettings.getProxyPort(), AuthScope.ANY_REALM), new UsernamePasswordCredentials( proxySettings.getUserName(), proxySettings.getPassword()));
client = HttpClientBuilder.create()
.setDefaultCredentialsProvider(credentialsProvider)
.build();
// add proxy details
HttpHost proxy = new HttpHost(proxySettings.getProxyHost(), proxySettings.getProxyPort());
RequestConfig config = RequestConfig.custom()
.setProxy(proxy)
.build();
method.setConfig(config);
}
try {
HttpResponse httpResponse = client.execute(method);
int status = httpResponse.getStatusLine().getStatusCode();
if (status == HttpStatus.SC_OK) {
return responeMapper.mapResponseToEntity(httpResponse.getEntity().getContent());
}
else {
return null;
}
}
catch (Exception e) {
DataException d = new DataException();
d.setCode(ErrorCodes.DATA_ACCESS_EXCEPTION);
d.setMessage(e.getMessage());
throw d;
}
}
Any input on this would be helpful.
Thanks,
Suresh