Expand my Community achievements bar.

SOLVED

javax.jcr.PathNotFoundException in workflow step

Avatar

Level 4

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

 

1 Accepted Solution

Avatar

Correct answer by
Level 2

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

 

 

 

View solution in original post

5 Replies

Avatar

Correct answer by
Level 2

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

 

 

 

Avatar

Community Advisor

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.



Avatar

Administrator

@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