Hi there,
i just wondering How to invoke another OSGI bundle servlet from different OSGI bundle?
Thanks a lot.
Best regards,
Brian
Solved! Go to Solution.
Views
Replies
Total Likes
I got this use case to work. The following pic shows an AEM web page that displays data returned from a Sling Servlet (the Sling Servlet invoked by an AEM Service):
[img]SlingInvoke.png[/img]
Here is the community article that steps you through this use case:
https://helpx.adobe.com/experience-manager/using/HttpClient_AEM.html
Only use this use case if you have to invoke a servlet from a service. It better to invoke the servlet from a web page using AJAX - as talked about here:
http://helpx.adobe.com/experience-manager/using/custom-sling-servlets.html
Views
Replies
Total Likes
Servlets are registered services in OSGi so you can access it just like a service. If you have shared logic, its probably better to move that code into a class you can define as an OSGi service.
Views
Replies
Total Likes
IN CQ 5.6 - you have access to this API:
Package org.apache.commons.httpclient
Here is this API showing up the AEM Dependency Finder:
[img]cleinthttp.png[/img]
So you can code a custom service in the OSGi that can use an object of type org.apache.commons.httpclient.HttpClient to send an HTTP request to an AEM Sling Servlet.
Also - here is the Maven dependency you need:
<dependency>
<groupId>com.day.commons.osgi.wrapper</groupId>
<artifactId>com.day.commons.osgi.wrapper.commons-httpclient</artifactId>
<version>3.1.0.018</version>
<scope>provided</scope>
</dependency>
Views
Replies
Total Likes
If you want to invoke an AEM servlet from another OSGi within the same AEM instance (as opposed to using Service injection), you can use Java org.apache.http.client.methods API. See:
Views
Replies
Total Likes
Hi scott,
Thanks for your comments. and the question is if AEM support third party httpclient.jar dependency well?
Thanks a lot.
Best regards,
Brian
Views
Replies
Total Likes
hi scott,
i did it following your suggestion. However, maven can't download the jar com.day.commons.osgi.wrapper.commons-httpclient-3.1.0.018.jar
i don't know how to deal with it. Details please see below screenshot.
[img]httpclient.png[/img]
Thanks a lot.
Views
Replies
Total Likes
What you do is inject service A (defined in bundle X) into service B (defined in bundle Z). If you are not familiar with how to perform dependency injection - see this article:
Injecting a DataSourcePool Service into an Adobe Experience Manager OSGi bundle
Views
Replies
Total Likes
To get the aem http client api to work with maven, you have to add the following elements to your POM file. This pulls from the adobe repos
<repositories>
<repository>
<id>adobe</id>
<name>Adobe Public Repository</name>
<url>http://repo.adobe.com/nexus/content/groups/public/</url>
<layout>default</layout>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>adobe</id>
<name>Adobe Public Repository</name>
<url>http://repo.adobe.com/nexus/content/groups/public/</url>
<layout>default</layout>
</pluginRepository>
</pluginRepositories>
Views
Replies
Total Likes
Hi Scott,
After add that elements to my POM file, it happened the error either as before.
[img]httpclient.png[/img]
So weird here.
Best regards,
Brian
Views
Replies
Total Likes
I will have a community article that shows you HOW TO use org.apache.commons.httpclient APIS in AEM - including how to build the OSGi and how to use it to invoke a Sling Servlet within AEM. This will be posted sometime in the next day.
Views
Replies
Total Likes
I got this use case to work. The following pic shows an AEM web page that displays data returned from a Sling Servlet (the Sling Servlet invoked by an AEM Service):
[img]SlingInvoke.png[/img]
Here is the community article that steps you through this use case:
https://helpx.adobe.com/experience-manager/using/HttpClient_AEM.html
Only use this use case if you have to invoke a servlet from a service. It better to invoke the servlet from a web page using AJAX - as talked about here:
http://helpx.adobe.com/experience-manager/using/custom-sling-servlets.html
Views
Replies
Total Likes
When i delete below element within POM file, run maven command "mvn clean install" very well.
<dependency> <groupId>com.day.commons.osgi.wrapper</groupId> <artifactId>com.day.commons.osgi.wrapper.commons-httpclient</artifactId> <version>3.1.0.018</version> <scope>provided</scope> </dependency>
However, if i add the above element within POM file, run maven command appears error as below immediately.
[img]mvnerror.png[/img]
Views
Replies
Total Likes
Views
Likes
Replies
Views
Like
Replies