내 커뮤니티 업적 표시줄을 확대합니다.

Submissions are now open for the 2026 Adobe Experience Maker Awards.

Mark Solution

활동이 없어 이 대화는 잠겼습니다. 새 게시물을 작성해 주세요.

해결됨

Exception in HttpClientCode

Avatar

Level 2

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

1 채택된 해결책 개

Avatar

정확한 답변 작성자:
Level 10

You can also wrap this JAVA lib into an OSGi bundle and deploy to AEM, Looks like your code is not using the correct version.

You can wrap this Java JAR file using Eclipse plug-in project:

Maven Repository: org.apache.httpcomponents » httpclient » 4.5.2

See how we wrapped the Simple JSON JAR here - Scott's Digital Community: Submitting Adobe Experience Manager form data to custom Sling Servlets

원본 게시물의 솔루션 보기

4 답변 개

Avatar

Level 1

Hi Suresh,

Did your dependency (httpclient v4.5) resolved in AEM 6.2

Avatar

Level 9

For some reason, this jar in not included in your bundle. Use <Import-Package> to import this jar in your core pom.xml.

Avatar

정확한 답변 작성자:
Level 10

You can also wrap this JAVA lib into an OSGi bundle and deploy to AEM, Looks like your code is not using the correct version.

You can wrap this Java JAR file using Eclipse plug-in project:

Maven Repository: org.apache.httpcomponents » httpclient » 4.5.2

See how we wrapped the Simple JSON JAR here - Scott's Digital Community: Submitting Adobe Experience Manager form data to custom Sling Servlets

Avatar

Level 2

Resolved the issue by giving dependency versions of httpclient and httpcore related packages in the <Import-Package> in the Pom.xml

Thanks

Suresh