Sunday, 24 March 2019

openCMIS: Get the session from repository object


If you have the reference to repository object, you can create the session to the repository using ‘createSession()’ method.

Example
Session session = repository.createSession();

Following application creates session to all the repositories at given end point.

TestCmis.java
package com.sample.util;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.apache.chemistry.opencmis.client.api.Repository;
import org.apache.chemistry.opencmis.client.api.Session;
import org.apache.chemistry.opencmis.client.api.SessionFactory;
import org.apache.chemistry.opencmis.client.runtime.SessionFactoryImpl;
import org.apache.chemistry.opencmis.commons.SessionParameter;
import org.apache.chemistry.opencmis.commons.enums.BindingType;

public class TestCmis {

 public static List<Repository> getRepositories(String serverURL) {
  Map<String, String> parameters = new HashMap<>();
  parameters.put(SessionParameter.BINDING_TYPE, BindingType.BROWSER.value());

  parameters.put(SessionParameter.USER, "");
  parameters.put(SessionParameter.PASSWORD, "");

  parameters.put(SessionParameter.BROWSER_URL, serverURL);

  SessionFactory sessionFactory = SessionFactoryImpl.newInstance();
  List<Repository> repositories = sessionFactory.getRepositories(parameters);
  return repositories;
 }

 public static void main(String args[]) {
  String serverURL = "http://localhost:8080/chemistry-opencmis-server-inmemory-1.1.0/browser";
  List<Repository> repositories = getRepositories(serverURL);

  for (Repository repository : repositories) {
   Session session = repository.createSession();
   System.out.println(repository.getId() + " " + session.getRepositoryInfo().getName());
  }
 }
}




Previous                                                 Next                                                 Home

No comments:

Post a Comment