I'm trying to retrieve the package binary zip file using PackageManager API and not having much success. To elaborate, I have a custom workflow step running on AEM author 6.5.16 on-prem, where the package exists. In that process, I would like to obtain the package binary content programmatically and using HttpClient API POST the package to another instance of AEM using standard AEM REST call. I tried various approaches I found online but none of them seem to work. Is there a recommended, proven approach that anyone can suggest? Thanks in advance.
Solved! Go to Solution.
Views
Replies
Total Likes
Update: I was able to access the binary package content using below code.
Session session = resourceResolver.adaptTo(Session.class);
JcrPackageManager jcrPackageManager = packaging.getPackageManager(session);
JcrPackage pack = jcrPackageManager.open(new PackageId(path));
InputStream binaryStream = pack.getData().getBinary().getStream();
byte[] binaryFile = IOUtils.toByteArray(binaryStream);
could you please explain more about the use case why you want to retrieve the package etc?
If the requirement is just to sync between content between AEM instances, you can check below link to find various options:
https://medium.com/globant/aem-content-synchronization-cb1e15b0c3f8
other option, if you want to move content/pages or package to the other instance through workflow service, you can use Replication API and write custom logic to replicate the content to other instance.
I'm trying to replicate/promote content from source AEM to destination AEM instance. I used the Replication API approach and that is pretty much exactly what I need except I'm not able to uninstall the package from the destination AEM if needed (my prior post on this issue: https://experienceleaguecommunities.adobe.com/t5/adobe-experience-manager/issue-with-acs-replication...). The approach I am taking now is to trigger the package install from within the source AEM via POST to REST API on the destination AEM instance. The process is running within the source AEM instance so in theory I should be able to get the raw content using the API. Perhaps there is a way using lower level APIs?
Update: I was able to access the binary package content using below code.
Session session = resourceResolver.adaptTo(Session.class);
JcrPackageManager jcrPackageManager = packaging.getPackageManager(session);
JcrPackage pack = jcrPackageManager.open(new PackageId(path));
InputStream binaryStream = pack.getData().getBinary().getStream();
byte[] binaryFile = IOUtils.toByteArray(binaryStream);
Views
Likes
Replies