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

morpheus
Champ in-the-making
Champ in-the-making
what´s the problem ? , please more precisely

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

I have this error :

org.alfresco.webservice.util.WebServiceException: Unable to get content as inputStream.
   at org.alfresco.webservice.util.ContentUtils.getContentAsInputStream(ContentUtils.java:128)
   at com.excilys.alfresco.service.impl.ContentService.getContentAsInputStream(ContentService.java:281)
   at com.excilys.alfresco.service.impl.ContentServiceTest.getContentAsInputStreamShouldShould(ContentServiceTest.java:215)
   at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
   at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
   at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
   at java.lang.reflect.Method.invoke(Method.java:616)
   at org.junit.internal.runners.TestMethodRunner.executeMethodBody(TestMethodRunner.java:99)
   at org.junit.internal.runners.TestMethodRunner.runUnprotected(TestMethodRunner.java:81)
   at org.junit.internal.runners.BeforeAndAfterRunner.runProtected(BeforeAndAfterRunner.java:34)
   at org.junit.internal.runners.TestMethodRunner.runMethod(TestMethodRunner.java:75)
   at org.junit.internal.runners.TestMethodRunner.run(TestMethodRunner.java:45)
   at org.junit.internal.runners.TestClassMethodsRunner.invokeTestMethod(TestClassMethodsRunner.java:75)
   at org.junit.internal.runners.TestClassMethodsRunner.run(TestClassMethodsRunner.java:36)
   at org.junit.internal.runners.TestClassRunner$1.runUnprotected(TestClassRunner.java:42)
   at org.junit.internal.runners.BeforeAndAfterRunner.runProtected(BeforeAndAfterRunner.java:34)
   at org.junit.internal.runners.TestClassRunner.run(TestClassRunner.java:52)
   at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:45)
   at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
   at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:460)
   at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:673)
   at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:386)
   at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:196)
Caused by: java.net.MalformedURLException: no protocol: null?ticket=TICKET_ef650f26-6394-11dd-849f-c75dd430314d
   at java.net.URL.<init>(URL.java:583)
   at java.net.URL.<init>(URL.java:480)
   at java.net.URL.<init>(URL.java:429)
   at org.alfresco.webservice.util.ContentUtils.getContentAsInputStream(ContentUtils.java:122)
   … 22 more

morpheus
Champ in-the-making
Champ in-the-making
is the Content[] null ?
or
there is an Malformed URL, look at your References

morpheus
Champ in-the-making
Champ in-the-making
have you tried to get the content with ContentUtils.getContentAsString() ?

nicocsgamer
Champ in-the-making
Champ in-the-making
Its the same thing and my references are right.

morpheus
Champ in-the-making
Champ in-the-making
ok there might an other reason , i recognized yesterday !
look at the URL the read Request receices from the server is this ok ? , you can watch that by capturing the SOAP message with a tool like tcpmon

djenk
Champ in-the-making
Champ in-the-making
I had the same problem and addressed it by changing the type of the store to "versionStore" from Constants.WORKSPACE_STORE.  Note that there is nothing defined in the Constants class for this.  I figured this out by looking at how Alfresco builds the URL based on the URL and what URL is used within the web client for retrieving previous versions.  Not sure if this is the proper way to retrieve version content (I'm a newbie to Alfresco), but it worked for me.

From…
        private Store versionStore = new Store(Constants.WORKSPACE_STORE, "lightWeightVersionStore");

To…
   private Store versionStore = new Store("versionStore", "lightWeightVersionStore");

Hope this helps.

thierensbart
Champ in-the-making
Champ in-the-making
I have the same problem.

The problem is: it downloads some versions of a document without problems, but then it crashes at one specific version (1.0).

my log:

[2009-11-27 06:08:12] exporting version 1.1 for randomdocument.doc (229.50 kB)
[2009-11-27 06:08:12] exporting version 1.0 for randomdocument.doc (0.00 B)
[2009-11-27 06:08:12] ////////// Exception Class: class org.alfresco.webservice.util.WebServiceException
[2009-11-27 06:08:12] ////////// Exception Message: Unable to get content as inputStream.
[2009-11-27 06:08:12] ////////// Exception Cause: java.net.MalformedURLException: no protocol: null?ticket=TICKET_eecd68c090194b694b7ac81aedac32c92fcccc79

It also says the size = 0.00 B, which it isn't.

For some reason it creates a null-url.  Don't know why.

My store is already set to
private Store versionStore = new Store("versionStore", "lightWeightVersionStore");


Anyone have an idea?


edit:
it doesn't give errors for every document.  most versioned documents are downloaded perfectly.

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)