3 Replies Latest reply on Feb 15, 2017 3:05 AM by Horia Chiorean

    Unable to retrieve versioned data of a node

    rohith janga Newbie

      I have created a node that holds MS office word document.( i have posted the exact question on stack overflow: jcr - Unable to retrieve versioned data of a node - Stack Overflow


                             VersionManager versionManager = session.getWorkspace().getVersionManager();

                              File wordFile = new File("DMS.docx");

                               Node documentNode = rootNode.addNode("Documents");

                               Node fileNode = documentNode.addNode(wordFile.getName(),"nt:file");



                               // Upload the file to that node ...

                               Node contentNode = fileNode.addNode("jcr:content", "nt:resource");

                               Binary binary = getFileBinary(wordFile);

                               contentNode.setProperty("jcr:data", binary);


                               Version v1 =   versionManager.checkin(fileNode.getPath());


      now i checkout the file through versionManager and update contents and  then check back in like below.



            fileNode = session.getRootNode().getNode("Documents").getNode(wordFile.getName());


              java.nio.file.Path path = Paths.get("DMSUpdated.docx");

                                   if (!Files.exists(path)) {



                                   Files.write(path, "Text to be added".getBytes(), StandardOpenOption.APPEND);

                                   Binary updatedBinary = getFileBinary(new File(filePath));

                                   contentNode.setProperty("jcr:data", updatedBinary);



          //check - in

           Version updatedVersion =   versionManager.checkin(fileNode.getPath());


      Now i am trying to restore the node to updated version like below:


          Node finalFileNode =   session.getNode("/Documents").getNode(wordFile.getName());


              Node finalContentNode = finalFileNode.getNode("jcr:content");

                           InputStream initialStream = finalContentNode.getProperty("jcr:data").getBinary().getStream();

                              byte[] buffer = new byte[initialStream.available()];


                                File updatedFile = new File("//TestFiles//FinalDMS.docx");

                              OutputStream outStream = new FileOutputStream(updatedFile);




      This gives me contents of version v1 and not updated version, not sure if i am doing something wrong?