Expand my Community achievements bar.

SOLVED

Retrieve package zip file with PackageManager API

Avatar

Level 1

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.

1 Accepted Solution

Avatar

Correct answer by
Level 2

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);

View solution in original post

3 Replies

Avatar

Community Advisor

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.

https://developer.adobe.com/experience-manager/reference-materials/6-4/javadoc/com/day/cq/replicatio... 

 

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? 

Avatar

Correct answer by
Level 2

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);