3 Replies Latest reply on Sep 23, 2010 2:34 PM by Tomasz Zarna

    How to fetch file content using IRestClient?

    Tomasz Zarna Newbie

      I set up Modeshape with file system connector which I'm trying to access using IRestClient. Here is a result of a query listing all files in my workspace:

       

      {"types":{"jcr:path":"STRING","jcr:score":"DOUBLE","jcr:primaryType":"STRING"},
      "rows":[
      {"jcr:path":"\/","jcr:score":"1.0","jcr:primaryType":"mode:root"},
      {"jcr:path":"\/test","jcr:score":"1.0","jcr:primaryType":"nt:folder"},
      {"jcr:path":"\/test\/.project","jcr:score":"1.0","jcr:primaryType":"nt:file"},
      {"jcr:path":"\/test\/.project\/jcr:content","jcr:score":"1.0","jcr:primaryType":"mode:resource"}
      ]}

       

      What query should I use to fetch content of a specific file (/test/.project)?

        • 1. Re: How to fetch file content using IRestClient?
          Randall Hauch Master

          The REST service does allow you to query content, and as you show it returns the result set in the form of a JSON response.  So, your question about how to get the file content is a bit of a loaded question.

           

          First of all, the location of each node is given in the JSON response via the "jcr:path" property, and you can easily turn this into a resource URL by appending the path to the "item" resource URL (see Section 11.2.1 of the Reference Guide). You can then obtain each node via a GET request with these URLs. This will return the full JSON representation of the node, with any binary content encoded using Base64. (JSON doesn't really address binary data well.) Thus, using the REST service is not terribly conducive to working with files and folders. If you have any suggestions for improving this, please let us know.

           

          If you are working with files and folders, you could transform the paths in your JSON result set into WebDAV URLs, and could very easily get the content of the file through WebDAV. See Section 11.1 of the Reference Guide for details on configuring the WebDAV server. Any WebDAV Java client library should work.

           

          BTW, none of the query languages are capable of returning binary properties in the result set. This is not required by the spec (and in some of the languages it is not permitted), and in almost all cases (really, in all cases except for one or two records) would perform badly anyway.

          • 2. Re: How to fetch file content using IRestClient?
            Randall Hauch Master

            I just logged two features/enhancements: include resource URL for each node in the result set (MODE-887); and make the RESTful client much more useful and usable (MODE-888). If you want to see something in particular in the REST client library, please add a comment to MODE-888.

            • 3. Re: How to fetch file content using IRestClient?
              Tomasz Zarna Newbie

              Randall Hauch wrote:

              You can then obtain each node via a GET request with these URLs. This will return the full JSON representation of the node, with any binary content encoded using Base64.

              The above worked just fine. Thanks a lot for the quick answer. Keep up the good work!