cancel
Showing results for 
Search instead for 
Did you mean: 

Simple example of accessing content

jknotzke
Champ in-the-making
Champ in-the-making
Hi,

  Would someone happen to have an example that shows how to read existing content using a web service ? The examples I have seen show how to read content after creating the content in the same program. I am looking for an example that reads content created by a user outside of my program..

   So the example would be: Create Content from Web Interface, call it test.txt, and then  read it and display it using a web service..

  Thanks!

   J
2 REPLIES 2

jknotzke
Champ in-the-making
Champ in-the-making
I managed to Google up some code from 2004 it appears


public String init() throws Exception
    {
       String downloadURL = null;

       try
       {
          
       String dir = "/app:company_home/cm:sample_folder";
       String fileName = "foobar.txt";

       System.out.println("dir ::" + dir);
       System.out.println("fileName ::" + fileName);


//        Start the session
       AuthenticationUtils.startSession("admin", "admin");
       String ticket = AuthenticationUtils.getTicket();

//        Create a reference to the parent where we want to create content
       Store storeRef = new Store(Constants.WORKSPACE_STORE, "SpacesStore");

//        Create a new Reference to the node you want (variable path here).
       String path = dir+"*[@cm:name=\"" + fileName + "\"]";
       Reference reference = new Reference(storeRef, null, path);
       ContentServiceSoapBindingStub contentService = WebServiceFactory.getContentService();

//        Read the content from the respository
       Content[] readResult = contentService.read(
       new Predicate(new Reference[]{reference}, storeRef, null),
       Constants.PROP_CONTENT);
       Content contentRef = readResult[0];

//        Get the ticket URL as above and the downloadURL here points to the url where the content is present.
       System.out.println("contentRef.getUrl() : " + contentRef.getUrl());
       String ticketURL = "?ticket=" + ticket;
       downloadURL = contentRef.getUrl() + ticketURL;
       System.out.println("downloadURL in webService(): " + downloadURL);
       }
       catch(Throwable e)
       {
       System.out.println(e.toString());
       }
       finally
       {
          // End the session
          AuthenticationUtils.endSession();
       }
       
       return downloadURL;
      }  


  I placed foobar.txt in where SAMPLES_FOLDER was created by the supplied examples code:

protected static final Reference SAMPLE_FOLDER = new Reference(STORE, null, "/app:company_home/cm:sample_folder"); 

  Which points to:

NamedValue[] properties = new NamedValue[]{Utils.createNamedValue(Constants.PROP_NAME, "Web Service Sample Folder")};

  But this above code throws an error saying it cannot find the xpath. What am I doing wrong ?

  Thanks.

  J

aridel
Champ in-the-making
Champ in-the-making
where in this code do you specified the http://localhost:8080/alfresco, where the wsdl is running?