javax.jcr.PathNotFoundException in workflow step | Community
Skip to main content
stiegjo22
February 20, 2024
Solved

javax.jcr.PathNotFoundException in workflow step

  • February 20, 2024
  • 4 replies
  • 1175 views

I'm working on a custom workflow step to convert PDFs into read-only. I keep getting the error message "javax.jcr.PathNotFoundException: jcr:data not found on /content/dam/...". When I run it in debug mode, I can see that the path in the DAM is correct but it still breaks on the "PDF resource not found at path: {}" Any suggestions?

 

private void processPDF(Resource pdfResource, ResourceResolver resourceResolver) { String resourcePath = pdfResource.getPath(); try { Node assetNode = pdfResource.adaptTo(Node.class); if (assetNode != null) { Property jcrDataProperty = assetNode.getProperty("jcr:data"); if (jcrDataProperty != null && jcrDataProperty.getType() == PropertyType.BINARY) { try (InputStream pdfStream = jcrDataProperty.getBinary().getStream()) { byte[] readOnlyPdf = makePdfReadOnly(pdfStream); // Update the original PDF content directly jcrDataProperty.setValue(new ByteArrayInputStream(readOnlyPdf)); resourceResolver.commit(); } catch (Exception e) { log.error("Error accessing PDF data: {}", e.getMessage()); } } else { log.error("jcr:data property is missing or not binary for PDF: {}", resourcePath); } } else { log.error("Failed to adapt PDF resource to a JCR Node: {}", resourcePath); } } catch (PathNotFoundException e) { log.error("PDF resource not found at path: {}", resourcePath); } catch (RepositoryException e) { log.error("Error accessing repository: {}", e.getMessage()); } }

 

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Best answer by AEM_U1

Hi @stiegjo22 - Just check the 'resourcePath' value - if you are resolving it until the PDF path like (/content/dam/sample/sampleTEST.pdf) then you would never get the jcr:data property at that level. It would come  at rendition node - /jcr:content/renditions/original/jcr:content. 

 

Code snippet to add after you are getting assetNode:

 jcrRenditionNode=assetNode.getNode("jcr:content/renditions/original/jcr:content");  Property jcrDataProperty = jcrRenditionNode.getProperty("jcr:data");

 

 

 

4 replies

Imran__Khan
Community Advisor
Community Advisor
February 21, 2024

@stiegjo22 Follow below article to read the asset in correct way will resolve your issue:

https://experienceleaguecommunities.adobe.com/t5/adobe-experience-manager/attach-pdf-with-email/m-p/238864

AEM_U1Accepted solution
February 21, 2024

Hi @stiegjo22 - Just check the 'resourcePath' value - if you are resolving it until the PDF path like (/content/dam/sample/sampleTEST.pdf) then you would never get the jcr:data property at that level. It would come  at rendition node - /jcr:content/renditions/original/jcr:content. 

 

Code snippet to add after you are getting assetNode:

 jcrRenditionNode=assetNode.getNode("jcr:content/renditions/original/jcr:content");  Property jcrDataProperty = jcrRenditionNode.getProperty("jcr:data");

 

 

 

stiegjo22
stiegjo22Author
February 21, 2024

Thank you!

Raja_Reddy
Community Advisor
Community Advisor
February 21, 2024

Hi @stiegjo22 

  1. the pdfResource is not a valid PDF resource. Make sure that the resource you are passing to the processPDF method is indeed a PDF file.

  2. The pdfResource node does not have the jcr:data property. Check if the pdfResource node has the jcr:data property by inspecting it in the CRXDE or by logging the properties of the node.

  3. The pdfResource node is not being adapted to a Node correctly. Verify that the pdfResource is being adapted to a Node successfully by checking if the assetNode variable is null or not.

To troubleshoot the issue, you can add some logging statements to check the values of pdfResource.getPath(), assetNode, and jcrDataProperty. This will help you identify which step is causing the issue.

 

private void processPDF(Resource pdfResource, ResourceResolver resourceResolver) { String resourcePath = pdfResource.getPath(); try { Node assetNode = pdfResource.adaptTo(Node.class); log.debug("Asset Node: {}", assetNode); if (assetNode != null) { Property jcrDataProperty = assetNode.getProperty("jcr:data"); log.debug("jcr:data Property: {}", jcrDataProperty); if (jcrDataProperty != null && jcrDataProperty.getType() == PropertyType.BINARY) { // Rest of the code... } else { log.error("jcr:data property is missing or not binary for PDF: {}", resourcePath); } } else { log.error("Failed to adapt PDF resource to a JCR Node: {}", resourcePath); } } catch (PathNotFoundException e) { log.error("PDF resource not found at path: {}", resourcePath); } catch (RepositoryException e) { log.error("Error accessing repository: {}", e.getMessage()); } }

 

By examining the logs, you should be able to identify the cause of the issue and take appropriate action to resolve it.

kautuk_sahni
Community Manager
Community Manager
February 21, 2024

@stiegjo22 Did you find the suggestions from users helpful? Please let us know if more information is required. Otherwise, please mark the answer as correct for posterity. If you have found out solution yourself, please share it with the community.

Kautuk Sahni