Skip to main content
Level 6
Oct 16, 2015 2:26 AM UTC
Solved

Error on trying to use HTTPClient in AEM 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)
This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
smacdonald2008
smacdonald2008Accepted solution
Level 10
Oct 16, 2015 2:26 AM UTC

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.

4 replies

Adobe Employee
Oct 16, 2015 2:26 AM UTC

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.

Translate
smacdonald2008
smacdonald2008Accepted solution
Level 10
Oct 16, 2015 2:26 AM UTC

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.

Translate
smacdonald2008
Level 10
Oct 16, 2015 2:26 AM UTC

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. 

Translate
Level 6
Oct 16, 2015 2:26 AM UTC

Thank you.

 

I have managed to get HTTPClient working.

 

 

Regards

 

Clive

Translate