cancel
Showing results for 
Search instead for 
Did you mean: 

How to get the Content from Repository

rameshbelli
Champ in-the-making
Champ in-the-making
Hi all, I tried the getContentStream method in the ObjectService and my request is like this

<getContentStream xmlns="http://docs.oasis-open.org/ns/cmis/messaging/200908/">
  <repositoryId>84ccfe80-b325-4d79-ab4d-080a4bdd045b</repositoryId>
  <objectId>workspace://SpacesStore/4dd547c7-e13f-41cf-83b8-ee508843917c;1.0</objectId>
</getContentStream>

and I got a response back like this

<getContentStreamResponse xmlns:ns2="http://docs.oasis-open.org/ns/cmis/core/200908/" xmlns="http://docs.oasis-open.org/ns/cmis/messaging/200908/" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
  <contentStream>
    <length>482</length>
    <mimeType>text/xml</mimeType>
    <filename>gfaith-XML</filename>
    <stream>
      <xop:Include href="cid:4c4c6129-bc9b-413e-814f-3f22de3ed830-6@docs.oasis-open.org" xmlns:xop="http://www.w3.org/2004/08/xop/include'/>
    </stream>
  </contentStream>
</getContentStreamResponse>

My question is how to get the Content  in bytes[].

I called getStream() method which was in CmisContentStream object and I get null value.

Any help is greatly appreciated.

Ramesh
3 REPLIES 3

nikes
Champ on-the-rise
Champ on-the-rise
Hi ramesh,

I have written below code using Axis2 ADB client.


package cmis;


import java.awt.BorderLayout;
import java.awt.Image;
import java.io.BufferedReader;
import java.io.DataInputStream;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.math.BigInteger;
import java.util.Iterator;

import javax.activation.DataHandler;
import javax.imageio.ImageIO;
import javax.swing.ImageIcon;
import javax.swing.JFrame;
import javax.swing.JLabel;

import org.apache.axiom.om.OMAbstractFactory;
import org.apache.axiom.om.OMElement;
import org.apache.axiom.om.OMFactory;
import org.apache.axiom.om.OMNamespace;
import org.apache.axis2.addressing.EndpointReference;
import org.apache.axis2.client.Options;
import org.apache.axis2.client.ServiceClient;
import org.apache.axis2.context.ConfigurationContext;
import org.apache.axis2.context.ConfigurationContextFactory;
import org.apache.axis2.databinding.types.xsd.QName;
import org.apache.axis2.jaxws.description.xml.handler.ObjectFactory;
import org.oasis_open.docs.ns.cmis.ws._200908.ObjectServiceStub;
import org.oasis_open.docs.ns.cmis.ws._200908.ObjectServiceStub.CmisContentStreamType;
import org.oasis_open.docs.ns.cmis.ws._200908.ObjectServiceStub.CmisExtensionType;
import org.oasis_open.docs.ns.cmis.ws._200908.ObjectServiceStub.CmisPropertiesType;
import org.oasis_open.docs.ns.cmis.ws._200908.ObjectServiceStub.CmisProperty;
import org.oasis_open.docs.ns.cmis.ws._200908.ObjectServiceStub.CmisPropertyString;
import org.oasis_open.docs.ns.cmis.ws._200908.ObjectServiceStub.CreateFolder;
import org.oasis_open.docs.ns.cmis.ws._200908.ObjectServiceStub.CreateFolderResponse;
import org.oasis_open.docs.ns.cmis.ws._200908.ObjectServiceStub.GetContentStream;
import org.oasis_open.docs.ns.cmis.ws._200908.ObjectServiceStub.GetContentStreamResponse;


import com.sun.org.apache.bcel.internal.Constants;

public class ObjectClient {
   private static EndpointReference targetEPR =
        new EndpointReference("http://172.22.41.129:8080/alfresco/cmis/NavigationService");
    public static void main(String[] args) throws Exception
    {
  
        ConfigurationContext ctx = ConfigurationContextFactory.createConfigurationContextFromFileSystem("D:\\Softwares\\axis2-1.5.1-bin\\axis2-1.5.1\\repository","D:\\Softwares\\axis2-1.5.1-bin\\axis2-1.5.1\\repository\\modules\\client.axis2.xml");

        ObjectServiceStub stub = new ObjectServiceStub(ctx, "http://localhost:8080/alfresco/cmis/ObjectService");
    
       
      GetContentStream cs = new ObjectServiceStub.GetContentStream();
      cs.setRepositoryId("46f8b242-9f61-423b-b824-c6118f470f01");
      //cs.setObjectId("workspace://SpacesStore/31defa0d-991a-48bf-8300-8e4a6b83d7ba");
      cs.setObjectId("workspace://SpacesStore/b6d8dfd2-8afe-467e-9764-3bfd26bd829f");
      //cs.setObjectId("f7912a3d-1bc2-4cbd-9ab5-4960c8720bd7");
     
     
     
      cs.setStreamId("");
      cs.setOffset(BigInteger.ZERO);
      cs.setLength(BigInteger.valueOf(500000));
      CmisExtensionType et = new CmisExtensionType();
      cs.setExtension(et);
     
     
      GetContentStreamResponse csr = stub.getContentStream(cs);
     
      CmisContentStreamType cst = csr.getContentStream();
      System.out.println("File Name : " + cst.getFilename());
     
      DataHandler dh = cst.getStream();
      System.out.println("Content type " + dh.getContentType());
      int x;
     InputStream is = dh.getInputStream();
     /*while ((x = is.read())!= -1) {
         System.out.print(x);
     }*/
    
     /*DataInputStream in = new DataInputStream(is);
     BufferedReader br = new BufferedReader(new InputStreamReader(in));
String strLine;
//Read File Line By Line
while ((strLine = br.readLine()) != null)   {
   // Print the content on the console
   System.out.println (strLine);
}*/
     
      Image img = ImageIO.read(is);
     
     
     
      JFrame frame = new JFrame();
      JLabel label = new JLabel(new ImageIcon(img));
      frame.getContentPane().add(label, BorderLayout.CENTER);
      frame.pack();
      frame.setVisible(true);
     
       

       
    }//end main

}//end class


Hope this helps.

rameshbelli
Champ in-the-making
Champ in-the-making
Thanks Nike.
I tried your code and I was getting some error

private void test(){
      try {
         org.cmis.www._2008._05.ObjectServiceStub stub =
            new org.cmis.www._2008._05.ObjectServiceStub(SERVICE_URL);
         stub._getServiceClient().addHeader(securityHeader);
         org.cmis.www._2008._05.ObjectServiceStub.GetContentStream cs =
            new org.cmis.www._2008._05.ObjectServiceStub.GetContentStream();
         cs.setRepositoryId(repositoryId);
         cs.setDocumentId("workspace://SpacesStore/4dd547c7-e13f-41cf-83b8-ee508843917c");
         
          org.cmis.www._2008._05.ObjectServiceStub.GetContentStreamResponse contResp =
                   stub.getContentStream(cs);
          DataHandler dh = contResp.getContentStream().getStream();
          //dh.getContent();
      }catch(AxisFault af){
         System.out.println(af.getMessage());
      }catch(RemoteException rex){
         
      }catch(PermissionDeniedException pex){
         
      }catch(OperationNotSupportedException oex){
         
      }catch(org.cmis.www._2008._05.RuntimeException ruex){
         
      }catch(ObjectNotFoundException onex){
         
      }catch(UpdateConflictException uex){
         
      }catch(StorageException sex){
         
      }catch(InvalidArgumentException tex){
         
      }catch(StreamNotSupportedException stex){
         
      }catch(OffsetException ofex){
         
      }
            
   }


The SOAP Request look good to me

<?xml version="1.0" encoding="utf-8"?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
   <soapenv:Header>
   <wsse:Security xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd" soapenv:mustUnderstand="1"><wsu:Timestamp xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd"></wsu:Timestamp><wsse:UsernameToken xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd"><wsse:Username>admin</wsse:Username><wsse:Password Type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText">admin</wsse:Password></wsse:UsernameToken></wsse:Security></soapenv:Header>
<soapenv:Body>
   <ns1:getContentStream xmlns:ns1="http://www.cmis.org/2008/05">
      <ns1:repositoryId>84ccfe80-b325-4d79-ab4d-080a4bdd045b</ns1:repositoryId>
      <ns1:documentId>workspace://SpacesStore/4dd547c7-e13f-41cf-83b8-ee508843917c</ns1:documentId>
   </ns1:getContentStream>
</soapenv:Body>
</soapenv:Envelope>

but I get this error


INFO: OMException in getSOAPBuilder
org.apache.axiom.om.OMException: SOAP message MUST NOT contain a Document Type Declaration(DTD)
   at org.apache.axiom.soap.impl.builder.StAXSOAPModelBuilder.createDTD(StAXSOAPModelBuilder.java:423)
   at org.apache.axiom.om.impl.builder.StAXOMBuilder.next(StAXOMBuilder.java:244)
   at org.apache.axiom.soap.impl.builder.StAXSOAPModelBuilder.getSOAPEnvelope(StAXSOAPModelBuilder.java:161)
   at org.apache.axiom.soap.impl.builder.StAXSOAPModelBuilder.<init>(StAXSOAPModelBuilder.java:110)
   at org.apache.axis2.builder.BuilderUtil.getSOAPBuilder(BuilderUtil.java:682)
   at org.apache.axis2.transport.TransportUtils.createDocumentElement(TransportUtils.java:215)
   at org.apache.axis2.transport.TransportUtils.createSOAPMessage(TransportUtils.java:145)
   at org.apache.axis2.transport.TransportUtils.createSOAPMessage(TransportUtils.java:108)
   at org.apache.axis2.transport.TransportUtils.createSOAPMessage(TransportUtils.java:67)
   at org.apache.axis2.description.OutInAxisOperationClient.handleResponse(OutInAxisOperation.java:354)
   at org.apache.axis2.description.OutInAxisOperationClient.send(OutInAxisOperation.java:417)
   at org.apache.axis2.description.OutInAxisOperationClient.executeImpl(OutInAxisOperation.java:229)
   at org.apache.axis2.client.OperationClient.execute(OperationClient.java:165)
   at org.cmis.www._2008._05.ObjectServiceStub.getContentStream(ObjectServiceStub.java:2190)
   at com.asconline.CMISFrame.test(CMISFrame.java:1070)
   at com.asconline.CMISFrame.<init>(CMISFrame.java:158)
   at com.asconline.CMISFrame.main(CMISFrame.java:389)

Still getting the null value when I called the GetContentStreamResponse.getContentStream().getStream() method

Ramesh

nikes
Champ on-the-rise
Champ on-the-rise
Hi Rmaesh,

I am able to fetch document properly.

Following is my Axis2 environment.

Alfresco version   - 3.2r2 (community)
Axis2 version       - axis2-1.5.1-bin
Rampart version  - rampart-dist-1.5
Java version        - 1.6

I have generated stub classes using Apache ADB binding, I have not tried XmlBeans binding.
I have configured client.axis2.xml for security configuration. So no need to set security header programatically.

I will try using XmlBeans binding stub and see if I get same error on my side or not.