Uploaded image for project: 'Sling'
  1. Sling
  2. SLING-9417

Content-type and InputStream are null when accessing nt:file resources with ";v="

    XMLWordPrintableJSON

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Minor
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: JCR Resource 3.0.22
    • Component/s: JCR
    • Labels:
      None

      Description

      When using the methods resource.getMetadata().getContentType() or resource.adaptTo(InputStream.class), both methods return null when:

      1. the resource is a child of a versionable node,
      2. the resource is of type nt:file, and
      3. resource has been looked up with a version identifier in the URL (";v=").

      From my understanding, both methods should return the relevant values from the frozen node. The error occurs because of line 185 in JcrNodeResource.java

      Node content = node.isNodeType(NT_FILE)
      ? node.getNode(JCR_CONTENT)
      : node.isNodeType(NT_LINKEDFILE) ? node.getProperty(JCR_CONTENT).getNode() : node;

      When the resource is looked up with a version modifier, the node type will not nt:file. Instead it is jcr:frozenNode with a property jcr:frozenPrimaryType set to nt:file. Therefore, the above code fails and will not use the jcr:content subnode, but the node itself. In my opinion, it would be better to change this to: 

      {{Node content = (node.isNodeType(NodeType.NT_FILE) || (node.isNodeType("nt:frozenNode") && node.hasProperty("jcr:frozenPrimaryType") }}
       && node.getProperty("jcr:frozenPrimaryType").getString().equals(NT_FILE)))
       ? node.getNode(Node.JCR_CONTENT)}}
       : node.isNodeType(JcrConstants.NT_LINKEDFILE) ? node.getProperty(Node.JCR_CONTENT).getNode() : node;

       

      JcrResourceMetadata has the same issue (line 65):

       if ( (!nodePromotionChecked) && node.isNodeType(NT_FILE)) {

      This could be changed to: 

       if ( (!nodePromotionChecked) && (node.isNodeType(NT_FILE) ||
       (node.isNodeType("nt:frozenNode") && node.hasProperty("jcr:frozenPrimaryType") 
       && node.getProperty("jcr:frozenPrimaryType").getString().equals(NT_FILE)))) {

       

      As I'm still a newbie in Sling, I'm not sure if the proposed solution is completely right. At the moment, I use a ResourceDecorator for my project with these changes and this fixes my problem - but there might be a better way to solve this.

       

       

        Attachments

          Activity

            People

            • Assignee:
              rombert Robert Munteanu
              Reporter:
              alldaysunshine Matthias Herold
            • Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:

                Time Tracking

                Estimated:
                Original Estimate - 1h Original Estimate - 1h
                1h
                Remaining:
                Remaining Estimate - 0h
                0h
                Logged:
                Time Spent - 8h
                8h