Hello everyone,
I wanted to know what the suggested method to integrate AEM with Box.com would be. Box is a cloud storage solution.
The use case would be to use AEM Forms as the front end to capture information and generate a PDF upon form submission. Once submitted, the PDF will also be sent from AEM to Box to be stored.
Box provides an API reference, but I am not sure how to start to create this integration with AEM.
https://developer.box.com/reference/
Solved! Go to Solution.
Views
Replies
Total Likes
Hi @techddx,
As a first step, decide on the authentication method. I suggest to read through the entire links under Authentication section and decide based on your project's Box account set up.
Once when we are authenticated, we can make use of the desired APIs
Note : Can make use of Apache commons Http client or jersey client or any related for all the API calls.
For your use case to upload files to Box account,
Please check and let know if you are looking for any specific information in the flow.
Hi @techddx,
As a first step, decide on the authentication method. I suggest to read through the entire links under Authentication section and decide based on your project's Box account set up.
Once when we are authenticated, we can make use of the desired APIs
Note : Can make use of Apache commons Http client or jersey client or any related for all the API calls.
For your use case to upload files to Box account,
Please check and let know if you are looking for any specific information in the flow.
Hi @Vijayalakshmi_S, thank you for this information.
I have created a Box Application to use the Server Side Authentication with JWT to authenticate to the Box API. The current plan is to submit the adaptive form to a custom workflow process that calls the Box API. As per: https://experienceleague.adobe.com/docs/experience-manager-learn/forms/adaptive-forms/custom-process...
However, I am encountering an issue when calling the Box API from within the AEM workflow. I have installed the required dependencies of the Box SDK as an OSGi bundle, but I am not sure how to resolve this issue. I will attach a snippet of the error log.
com.adobe.granite.workflow.WorkflowException: Process execution resulted in an error
at com.adobe.granite.workflow.core.job.HandlerBase.executeProcess(HandlerBase.java:201)
at com.adobe.granite.workflow.core.job.JobHandler.process(JobHandler.java:260)
at org.apache.sling.event.impl.jobs.JobConsumerManager$JobConsumerWrapper.process(JobConsumerManager.java:502)
at org.apache.sling.event.impl.jobs.queues.JobQueueImpl.startJob(JobQueueImpl.java:293)
at org.apache.sling.event.impl.jobs.queues.JobQueueImpl.access$100(JobQueueImpl.java:60)
at org.apache.sling.event.impl.jobs.queues.JobQueueImpl$1.run(JobQueueImpl.java:229)
at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
at java.base/java.lang.Thread.run(Thread.java:834)
Caused by: java.lang.NoClassDefFoundError: com/eclipsesource/json/JsonValue
at dgs.aem.core.BoxConnect.execute(BoxConnect.java:82)
at com.adobe.granite.workflow.core.job.HandlerBase.executeProcess(HandlerBase.java:195)
... 8 more
Caused by: java.lang.ClassNotFoundException: com.eclipsesource.json.JsonValue not found by BoxJavaSDK [729]
at org.apache.felix.framework.BundleWiringImpl.findClassOrResourceByDelegation(BundleWiringImpl.java:1597)
at org.apache.felix.framework.BundleWiringImpl.access$300(BundleWiringImpl.java:79)
at org.apache.felix.framework.BundleWiringImpl$BundleClassLoader.loadClass(BundleWiringImpl.java:1982)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:521)
... 10 more
Views
Replies
Total Likes
ClassNotFound / NoClassDefFoundError from your newly built Box.com OSGI bundle occurs when all of its dependencies are not included as part of the bundle. Can you please let me know how you have created the OSGI bundle out of Box SDK.
Try to create using maven-bundle-plugin.
Views
Replies
Total Likes
I created an OSGi bundle for the Box SDK as per this article in the "Add the org.json.simple.JSONObject data type" section: https://helpx.adobe.com/experience-manager/using/custom-sling-servlets.html
The exported packages in the manifest.mf are all packages from the Box SDK and the bundle is able to be resolved in AEM.
I also installed the minimal-json jar bundle that is a required dependency for the Box SDK.
Views
Replies
Total Likes
Bundles will be resolved and be active. But when the code is executing, dependencies which Box SDK bundle requires might not be available. Try to add the missing ones in Import-Package section of manifest.mf file of Box SDK bundle and build bundle again.
Views
Replies
Total Likes
I have deployed the Box SDK dependencies as their own bundles in AEM, and added them as required bundles in the Box SDK Bundle. However, the workflow still fails when calling the Box API. The following is the manifest.mf of the Box SDK Bundle.
Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: BoxSDK
Bundle-SymbolicName: BoxSDK
Bundle-Version: 1.0.0
Automatic-Module-Name: BoxSDK
Export-Package: com.box.sdk;version="2.53.0";uses:="com.box.sdk.http,com.box.sdk.internal.utils,com.eclipsesource.json"
Import-Package: com.box.sdk;version="2.53.0"
Require-Bundle: minimal-json;bundle-version="1.0.0",
bcpkix-jdk15on;bundle-version="1.0.0",
bcprov-jdk15on;bundle-version="1.0.0",
jose4j;bundle-version="1.0.0"
com.adobe.granite.workflow.WorkflowException: Process execution resulted in an error
at com.adobe.granite.workflow.core.job.HandlerBase.executeProcess(HandlerBase.java:201)
at com.adobe.granite.workflow.core.job.JobHandler.process(JobHandler.java:260)
at org.apache.sling.event.impl.jobs.JobConsumerManager$JobConsumerWrapper.process(JobConsumerManager.java:502)
at org.apache.sling.event.impl.jobs.queues.JobQueueImpl.startJob(JobQueueImpl.java:293)
at org.apache.sling.event.impl.jobs.queues.JobQueueImpl.access$100(JobQueueImpl.java:60)
at org.apache.sling.event.impl.jobs.queues.JobQueueImpl$1.run(JobQueueImpl.java:229)
at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
at java.base/java.lang.Thread.run(Thread.java:834)
Caused by: java.lang.NoClassDefFoundError: Could not initialize class com.box.sdk.BoxAPIRequest
at com.box.sdk.BoxUser.getCurrentUser(BoxUser.java:167)
at dgs.aem.core.BoxConnect.execute(BoxConnect.java:52)
at com.adobe.granite.workflow.core.job.HandlerBase.executeProcess(HandlerBase.java:195)
... 8 more
Views
Replies
Total Likes
Root cause of the issue remains the same. I suggest to use maven-bundle-plugin (to create OSGI bundle out of Box SDK dependency) where we have means to include all compile/run time dependencies.
Till the time we resolve all of its dependencies, we will be getting NoClassDefFound or ClassNotFoundException or its related.
Views
Replies
Total Likes
I have added pom.xml file for creating Box SDK OSGI bundle using maven-bundle-plugin in my GitHub repo.
You can checkout -> amend based on your needs if desired and execute "mvn package" -> use the created bundle.
https://github.com/Viji1304/aemlearnings-samples/tree/master/BOXSDK
Views
Replies
Total Likes
I was able to resolve the dependencies by using the maven bundle plugin for the Box SDK Bundle. Your example pom.xml was very helpful. Thank you, I really appreciate your help on this.
Views
Replies
Total Likes
Views
Replies
Total Likes
I am currently trying to implement the Box File Upload API Call but am encountering an issue accessing the PDF file from the AEM Workflow payload.
The context is when an adaptive form is submitted, the document of record PDF is stored in the payload.
How do you access the PDF from the payload stored in CRX so it can be used with the Box API?
Here is a snippet of my code.
String payloadPath = workItem.getWorkflowData().getPayload().toString();
log.info("\nThe payload path is: " + payloadPath);
String pdfFilePath = payloadPath + "/dor.pdf";
// Box Upload
BoxFolder rootFolder = BoxFolder.getRootFolder(api);
FileInputStream stream = new FileInputStream(pdfFilePath);
BoxFile.Info newFileInfo = rootFolder.uploadFile(stream, "dor.pdf");
stream.close();
Thank you!
Views
Replies
Total Likes
Hi @techddx,
If PDF node available in payload is of type nt:file, then the contents of the file is available in its jcr:content/jcr:data.
So we need to retrieve the stream of PDF/file using this property which should be of type "Binary".
Example : Using JCR API
Node pdfContentNode = path to pdf file/jcr:content;
InputStream pdfStream = pdfContentNode.getProperty("jcr:data").getBinary().getStream();
From your snippet,
String pdfFilePath = payloadPath + "/dor.pdf/jcr:content";
Get Node object or Resource object out of this path and get stream from jcr:data property -> Use this stream in upload call.
Views
Replies
Total Likes
@techddx, Update regarding the bundle created out of box API - You can use maven-sling-plugin along with maven-bundle-plugin to install the bundle directly in Felix console or use this as separate module in your multi module AEM maven project code base. Let me know how you would like to incorporate, will add the respective details accordingly.
Views
Replies
Total Likes
I followed your advice and was able to call the Box Upload File API from AEM. Thank you!
I would like details on how to incorporate the Box SDK Bundle with maven-sling-plugin and maven-bundle-plugin so the bundle can be installed directly in the Felix console.
Views
Replies
Total Likes
@techddx, Updated the pom.xml file, you can use the same.
Had a chance to write blog related to this.
Thanks
Views
Replies
Total Likes
Views
Likes
Replies