javax.jcr.PathNotFoundException in workflow step
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());
}
}

