cancel
Showing results for 
Search instead for 
Did you mean: 

A stand alone Java client for CMIS

biswajitbiswal
Champ in-the-making
Champ in-the-making
Hi,

For all those who are struggling with it, here it goes:

import org.apache.axis.client.Call;
import org.apache.axis.client.Service;
import javax.xml.namespace.QName;
import javax.xml.rpc.ParameterMode;
import org.apache.axis.message.SOAPHeaderElement;
import org.apache.axis.message.SOAPEnvelope;
import org.apache.ws.security.message.token.UsernameToken;
import org.apache.ws.security.WSConstants;
import org.apache.ws.security.message.WSSecHeader;
import org.apache.ws.security.util.WSSecurityUtil;
import org.w3c.dom.Document;
import org.apache.ws.security.message.token.Timestamp;

public class CMISTest {
public static void main(String [] args) {
try {
   
String endpoint = "http://localhost:8080/alfresco/cmis/RepositoryService";
String repID = "33405a73-54c4-4fcf-92c5-2a7bb4a4568f";

Service serv = new Service();
Call call = (Call) serv.createCall();
call.setTargetEndpointAddress( new java.net.URL(endpoint) );
call.setOperationName(new QName("http://www.cmis.org/2008/05", "getRepositoryInfo"));
call.addParameter( "id",new QName("http://www.w3.org/2001/XMLSchema','string"),ParameterMode.IN);
call.setReturnType(   new QName("http://www.w3.org/2001/XMLSchema','string"));
//call.setUsername("admin");
//call.setPassword("admin");

SOAPEnvelope se = new SOAPEnvelope(); // dummy envelope to create Header
Document doc = se.getAsDocument();

WSSecHeader secHeader = new WSSecHeader();
secHeader.setMustUnderstand(true);
secHeader.insertSecurityHeader(doc);

UsernameToken username = new UsernameToken(Boolean.TRUE,doc,WSConstants.PASSWORD_DIGEST);
username.setName("admin");
username.setPassword("admin");

Timestamp ts = new Timestamp(true, doc,300);

WSSecurityUtil.prependChildElement(doc, secHeader.getSecurityHeader(), username.getElement(), false);
WSSecurityUtil.prependChildElement(doc, secHeader.getSecurityHeader(), ts.getElement(), false);

SOAPHeaderElement she = new SOAPHeaderElement(secHeader.getSecurityHeader());
call.addHeader(she);

String ret = call.invoke(new Object[] {repID}).toString();
System.out.println(ret);

} catch (Exception e) {
e.printStackTrace();
}
}
}

cheers Smiley Happy
Biswajit
2 REPLIES 2

shivam
Champ in-the-making
Champ in-the-making
Hi Biswajit,
I am new to CMIS. I installed Alfresco 3.2r2 and tried making CMIS webservices call but I am not able too. I used your code to make a start but it didn't help. Apart from URL (I replaced by server IP) what else I need to custmize to make the below code work for me? I want to use the getRepositories method of CMIS, how can I do that?

In your code you have used repId, how can I get the repID from my Alfresco installation?

Regards,
Shivam

rmorant
Champ in-the-making
Champ in-the-making
In your code you have used repId, how can I get the repID from my Alfresco installation?
curl -uadmin:admin "http://192.168.0.166:8080/alfresco/service/cmis"

and look for root collection or cmisra:repositoryInfo/cmis:rootFolderId