cancel
Showing results for 
Search instead for 
Did you mean: 

CMIS ADN WebScripts

imran
Champ on-the-rise
Champ on-the-rise
Hello Experts,
Is it possible to invoke an alfresco restful web service (web script) from within CMIS client session?
I have some requirements that can't be done using cmis, but it is possible with web scripts. Now, the problem is that I have cmis session and now I also need a way to invoke custom script. What can you suggest me to do?

Thanks in advance
1 REPLY 1

jpotts
World-Class Innovator
World-Class Innovator

Both CMIS and web scripts can use tickets for authentication. So the answer is that you should grab a ticket and then use that to hit either CMIS or web script end points.

I do this a lot with little groovy utilities. You call /api/login to get a ticket, like this:

// Login to Alfresco
def client = new RESTClient(url)
def resp = client.get(path : ALF_SERVICE + '/api/login', query: ['u': userName, 'pw': password.toString(), 'format': 'json'])
assert resp.status == 200
def ticket = resp.data.data.ticket
println "Successfully logged in to Alfresco..."

Then once you have that ticket you can use it to make other calls.

For example, you might use CMIS to check for a folder:

// Leave the username as an empty string to auth with a ticketSession session = createCMISSession(url + CMIS_SERVICE, CMIS_BINDING, "", ticket);
Folder folder = findFolder(session, folderPath)

if (folder == null) {
  println "ERROR: Could not find: " + folderPath
  System.exit(0)
}

Folder findFolder(Session session, String folderPath) {
  Folder result = null;

  try {
    CmisObject folder = session.getObjectByPath(folderPath);
    if (folder != null && BaseTypeId.CMIS_FOLDER.equals(folder.getBaseTypeId())) {
      result = (Folder) folder;
    }
  } catch (CmisObjectNotFoundException confe) {
    println "ERROR: getObjectByPath threw a CmisObjectNotFoundException"
  }

  return result;
}

Or you might use the Alfresco API to look for a site:

// Checking for presence of site
resp = client.get(path : ALF_SERVICE + '/api/sites/' + siteId, query: ['alf_ticket': ticket])
assert resp.status == 200