cancel
Showing results for 
Search instead for 
Did you mean: 

Get specific version content

nicocsgamer
Champ in-the-making
Champ in-the-making
Hi !

I have versionable node and I try to retrieve content of a specific version of a content node. For exemple i have a node called text.txt with 3 versions: 1.0, 1.1 and 1.2.

I would retrieve content of version 1.1.

For the moment  :

I create a node with content.
2 add versionnable apsect.
3 update content -> create different versions.
4 try to retrieve content :

            


VersionHistory versionHistory =  WebServiceFactory.getAuthoringService().getVersionHistory(ReferenceFactory.newReference(uuid, nodePath));
           
            Version[] versions = versionHistory.getVersions();
          
          for(Version nodeVersion : versions) {
             if(nodeVersion.getLabel().equals(version)) {
                InputStream result = null;

Reference reference = new Reference(new Store(Constants.WORKSPACE_STORE, "lightWeightVersionStore"), nodeVersion.getId().getUuid(), nodeVersion.getId().getPath());
        Predicate predicate = new Predicate(new Reference[] { reference }, new Store(Constants.WORKSPACE_STORE, "lightWeightVersionStore"), null);

                Content[] contents = WebServiceFactory.getContentService().read(predicate, Constants.TYPE_CONTENT);
                 result = ContentUtils.getContentAsInputStream(contents[0]);
                 return result;
             }
          }


Any suggestions ?

Thanks  a lot Smiley Happy
15 REPLIES 15

kaynezhang
World-Class Innovator
World-Class Innovator
It seems there is nothing wrong with your code,plese print out the content url and check what is in it.

System.out.println(content.getUrl());

ameenulla
Champ in-the-making
Champ in-the-making
content url
I am using alfresco 4.2.f, following is  content.getUrl()
http://10.0.0.162:8081/alfresco/download/direct/workspace/SpacesStore/21c55ab3-02a4-4fae-9943-f70738....

file exist in alfresco with this url.

kaynezhang
World-Class Innovator
World-Class Innovator
Did you use any proxy Server,for example Apache?
And your log file is trimed ,please upload complete log file.

ameenulla
Champ in-the-making
Champ in-the-making
this is my complete log
alfrescoEPhttp://10.0.0.162:8081/alfresco/soapapi
org.alfresco.webservice.util.WebServiceException: Unable to get content as inputStream.
        at org.alfresco.webservice.util.ContentUtils.getContentAsInputStream(ContentUtils.java:139)
        at com.rtq.dms.AlfrescoDmsManagement.fetchFile(AlfrescoDmsManagement.java:215)
        at com.rtq.processinitiator.servlets.downloadServlet.service(downloadServlet.java:41)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
        at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.doFilter(InvokerFilterChain.java:116)
        at sun.reflect.GeneratedMethodAccessor457.invoke(Unknown Source)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:606)
        at com.liferay.portal.kernel.bean.ClassLoaderBeanHandler.invoke(ClassLoaderBeanHandler.java:67)
        at com.sun.proxy.$Proxy527.doFilter(Unknown Source)
        at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.doFilter(InvokerFilterChain.java:116)
        at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.processDirectCallFilter(InvokerFilterChain.java:165)
        at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.doFilter(InvokerFilterChain.java:96)
        at com.liferay.portal.kernel.servlet.PortalClassLoaderFilter.doFilter(PortalClassLoaderFilter.java:74)
        at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.processDoFilter(InvokerFilterChain.java:204)
        at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.doFilter(InvokerFilterChain.java:109)
        at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilter.doFilter(InvokerFilter.java:96)
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
        at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:222)
        at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:123)
        at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:502)
        at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:171)
        at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:99)
        at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:953)
        at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
        at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:408)
        at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1023)
        at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:589)
        at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:310)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
        at java.lang.Thread.run(Thread.java:724)
Caused by: java.lang.NullPointerException
        at org.alfresco.webservice.util.ContentUtils.getContentAsInputStream(ContentUtils.java:132)
        … 34 more

kaynezhang
World-Class Innovator
World-Class Innovator
It seems authentication session is null,you can print out authentication detail information ,and see what you get.

System.out.print(AuthenticationUtils.getAuthenticationDetails().getSessionId());

ameenulla
Champ in-the-making
Champ in-the-making
I am getting following error while fetching file   
public  InputStream fetchFile( String alfrescoPath) throws Exception 
   {
      InputStream is = null;
      if(null!=alfrescoPath )
      {
         AuthenticationDetails details=   WebServiceClient.startSession(getAlfUser(0), getAlfPassword(0));
         try
         {
            Store store = new Store(Constants.WORKSPACE_STORE, "SpacesStore");
            Reference nodeRef = new Reference(store, null, alfrescoPath);
   
            Content[] contArr = WebServiceClient.getContentService(details).read(new Predicate(new Reference[] { nodeRef }, store, null), Constants.PROP_CONTENT);
            Content content = contArr[0];
            
            is = ContentUtils.getContentAsInputStream(content);
            
         }
         finally
         {
            WebServiceClient.endSession(details);
         }
      }
      return is;
   }
   


org.alfresco.webservice.util.WebServiceException: Unable to get content as inputStream.
        at org.alfresco.webservice.util.ContentUtils.getContentAsInputStream(ContentUtils.java:139)
        at com.rtq.dms.AlfrescoDmsManagement.fetchFile(AlfrescoDmsManagement.java:207)
        at com.rtq.processinitiator.servlets.downloadServlet.service(downloadServlet.java:41)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
        at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.doFilter(InvokerFilterChain.java:116)
        at sun.reflect.GeneratedMethodAccessor1466.invoke(Unknown Source)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:606)
        at com.liferay.portal.kernel.bean.ClassLoaderBeanHandler.invoke(ClassLoaderBeanHandler.java:67)
        at com.sun.proxy.$Proxy753.doFilter(Unknown Source)
        at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.doFilter(InvokerFilterChain.java:116)
        at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.processDirectCallFilter(InvokerFilterChain.java:165)
        at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.doFilter(InvokerFilterChain.java:96)
        at com.liferay.portal.kernel.servlet.PortalClassLoaderFilter.doFilter(PortalClassLoaderFilter.java:74)
        at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.processDoFilter(InvokerFilterChain.java:204)