cancel
Showing results for 
Search instead for 
Did you mean: 

Which WS/API is best for my use case?

syberyan
Champ in-the-making
Champ in-the-making
Hi,

As an alfresco newbie, I'm looking for some advice on the following.
I've been asked to test-drive alfresco as a CMS system, which went great so far. The next step would be to see if the alfresco repository can be integrated with our marketing platform to store digital assets.
The repository would need to be accessed remotely via some WS or other API, preferably an industry standard like JCR-RMI or CMIS. The client is a java (web) application.

So I've been looking at all the available options: The alfresco repository WS API, the CMIS WS API, the CMIS REST API and JCR-RMI.
My experience so far with CMIS is that it seems very premature, there is also very few documentation and examples available. I've been experimenting a bit with the REST api, but can't figure (yet) out how to upload larger binary files (I based myself on this post: http://forums.alfresco.com/en/viewtopic.php?f=36&t=15438) Is that at all possible?

What would be the right choice here? My feeling for now is that Alfresco repository WS API seems best suited… but I don't get the complete picture yet. I'm also quite new to all this web service stuff.

Any advice would be very welcome,
thanks,

Chris
8 REPLIES 8

openpj
Elite Collaborator
Elite Collaborator
I suggest you to try Alfresco Web Service Client, you can download it here:
http://wiki.alfresco.com/wiki/Labs_3_Final_download_files#Alfresco_Web_Service_Client

You can use it in your Java application in a easy way, you only need to set Alfresco endpoint address and you can start to call Alfresco remotely  :wink:

Hope this helps.

syberyan
Champ in-the-making
Champ in-the-making
Thanks, I was thinking to go for that solution too.

The CMIS stuff however is supposed to be an industry standard. So why not choose that then?
Won't it be able to offer the same functionality?
And it's not very clear to me what API to use when talking to the CMIS services. Something like apache axis?

openpj
Elite Collaborator
Elite Collaborator
I remember that CMIS is on a draft state, it is a proposal, so we don't know if it will be used as the standard method to interface our application with standard repositories.
Here you can see more information on Wikipedia:
http://en.wikipedia.org/wiki/Content_Management_Interoperability_Services

Using CMIS interfaces you can access to repository using a RESTful API via HTTP or via Web Services, here you can see Alfresco CMIS implementation status:
http://wiki.alfresco.com/wiki/CMIS

Using CMIS potentially you can change the repository without changing the code of your application.

Hope this helps.

syberyan
Champ in-the-making
Champ in-the-making
The wiki talks about several CMIS client API's:
http://wiki.alfresco.com/wiki/CMIS#CMIS_Consumers_.28Client_APIs.29

Will there be something similar for java clients?
I'm also wondering if this API is flexible enough to access content defined with a custom data model in the alfresco repository?

openpj
Elite Collaborator
Elite Collaborator
You need only to implement a CMIS Web Service Client and then you can use it for all repositories that support CMIS.
Here you can see a Java implementation of a CMIS client:
http://forums.alfresco.com/en/viewtopic.php?f=45&t=15254

I have added here the Java code snippet, so you can easily view with code tags for thread posts:

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();
}
}
}
Hope this helps.

syberyan
Champ in-the-making
Champ in-the-making
To confuse me even further, I've found the following CMIS client sample:
http://svn.alfresco.com/repos/alfresco-open-mirror/alfresco/HEAD/root/projects/remote-api/source/sam...

If I understand correctly, this is implemented using apache cxf, while the one in the previous post uses apache axis. Is that correct?
Does one method have particular advantages over the other?

Sorry for all the questions, but I never worked with WS's until 3 days ago 😉
Chris

openpj
Elite Collaborator
Elite Collaborator
I suggest you where is possible to use Apache CXF.
Apache CXF allows you to generate at runtime web service stubs without generate stub classes as source code in your custom application.
You can integrate in a easy way CXF with Spring.

Hope this helps.

syberyan
Champ in-the-making
Champ in-the-making
Ok, it's all finally starting to make sense 🙂

I'm currently playing with the REST/Atom api, using Apache Abdera. But there is 1 thing that I'm not able to figure out: how to stream files to the repository without having to keep the whole file in memory?
For example, when I use this…

Entry entry = abdera.newEntry();
entry.setTitle("bigfile.bin");
entry.setSummary("something really big …");
entry.setContent(new FileInputStream("c:\\temp\bigfile.bin"), "application/octet-stream");
ClientResponse resp = client.post("http://localhost:8080/alfresco/service/api/path/workspace/SpacesStore/Company%20Home/Folder/children", entry);

…the file is not streamed, but the xml is populated with the content instead. (I kind of expected that…)
How can I stream files using the REST api?

I guess I need something similar to the ContentUtils.put() included in the alfresco repository WS… but I can't figure out what.