Expand my Community achievements bar.

Don’t miss the AEM Skill Exchange in SF on Nov 14—hear from industry leaders, learn best practices, and enhance your AEM strategy with practical tips.
SOLVED

Error on trying to use HTTPClient in AEM 6

Avatar

Level 6

When my osgi bundle tries to make a connection to a wep api from within my application I get 

 

rg.apache.sling.api.scripting.ScriptEvaluationException: javax.servlet.ServletException: java.lang.NoClassDefFoundError: org/apache/http/HttpRequest at org.apache.sling.scripting.core.impl.DefaultSlingScript.call(DefaultSlingScript.java:388) at org.apache.sling.scripting.core.impl.DefaultSlingScript.eval(DefaultSlingScript.java:171) at org.apache.sling.scripting.core.impl.DefaultSlingScript.service(DefaultSlingScript.java:463) at org.apache.sling.engine.impl.request.RequestData.service(RequestData.java:511) at org.apache.sling.engine.impl.filter.SlingComponentFilterChain.rend at java.lang.Thread.run(Unknown Source) Caused by: org.apache.sling.api.SlingException: javax.servlet.ServletException: java.lang.NoClassDefFoundError: org/apache/http/HttpRequest at org.apache.sling.scripting.jsp.jasper.servlet.JspServletWrapper.handleJspExceptionInternal(JspServletWrapper.java:691) at org.apache.sling.scripting.jsp.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:608) at org.apache.sling.scripting.jsp.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:525) at org.apache.sling.scripting.jsp.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:449) at org.apache.sling.scripting.jsp.JspScriptEngineFactory.callJsp(JspScriptEngineFactory.java:281) at org.apache.sling.scripting.jsp.JspScriptEngineFactory.access$100(JspScriptEngineFactory.java:102) at org.apache.sling.scripting.jsp.JspScriptEngineFactory$JspScriptEngine.eval(JspScriptEngineFactory.java:524) at org.apache.sling.scripting.core.impl.DefaultSlingScript.call(DefaultSlingScript.java:361) ... 129 more Caused by: java.lang.NoClassDefFoundError: org/apache/http/HttpRequest at java.lang.ClassLoader.defineClass1(Native Method) at java.lang.ClassLoader.defineClass(Unknown Source)
1 Accepted Solution

Avatar

Correct answer by
Level 10

Yes - the above article works in AEM 6 - here is the app working in AEM 6 Classic VIew:

[img]RestCode.png[/img]

it is using HTTPClient in the service. It is invoking Google's Restful web service to calculate the distance between 2 cities. 

TO use HTTPClient in AEM - make sure that you create a bundle fragment (just an OSGi that wraps JAR files - it does not contain any services). You need to include:

  • httpclient-4.0.jar (or another version)
  • httpcore-4.3.2.jar(or another version)

​This is all described in Creating Adobe Experience Manager bundles that invoke third party Restful web services.

View solution in original post

4 Replies

Avatar

Level 6

Thank you.

 

I have managed to get HTTPClient working.

 

 

Regards

 

Clive

Avatar

Level 10

Looks like you have not added these packages to CQ within an OSGi bundle fragment. See this section:

Including HTTP client packages to CQ

in this article:

http://helpx.adobe.com/experience-manager/using/restful-services.html

This is a 5.x artilce - I am going to test on AEM 6 and I will report back on the findings. I do not expect any issue on AEM 6. 

Avatar

Correct answer by
Level 10

Yes - the above article works in AEM 6 - here is the app working in AEM 6 Classic VIew:

[img]RestCode.png[/img]

it is using HTTPClient in the service. It is invoking Google's Restful web service to calculate the distance between 2 cities. 

TO use HTTPClient in AEM - make sure that you create a bundle fragment (just an OSGi that wraps JAR files - it does not contain any services). You need to include:

  • httpclient-4.0.jar (or another version)
  • httpcore-4.3.2.jar(or another version)

​This is all described in Creating Adobe Experience Manager bundles that invoke third party Restful web services.

Avatar

Employee

This article should be updated. There is no longer any reason to make bundles for HttpClient 4.x. Apache distributes an OSGi bundle already.

There is an unfortunate bug (https://issues.apache.org/jira/browse/HTTPCLIENT-1547) with the latest release, so you should use 4.3.4 for now.