In my previous post, I explained how to get all the
repositories at given end point using Atom pub binding. In this post, I am
going to explain how to get all the repositories using browser binding.
How to get all the repositories?
By using the getRepositories() method of SessionFactory class, you can get all the repositories at a given endpoint.
Following is the signature of getRepositorie method.
List<Repository> getRepositories(Map<String, String> parameters);
We need to pass basic information like username, password, atom pub url endpoint and type of binding as 'parameters' to the getRepositories method.
Following snippet is used to get all the repositories
using browser binding.
Map<String, String> parameters = new
HashMap<>();
parameters.put(SessionParameter.USER,
this.getUserName());
parameters.put(SessionParameter.PASSWORD,
this.getPassword());
parameters.put(SessionParameter.BROWSER_URL,
this.getUrlToConnect());
parameters.put(SessionParameter.BINDING_TYPE,
BindingType.BROWSER.value());
SessionFactory sessionFactory =
SessionFactoryImpl.newInstance();
List<Repository> repositories =
sessionFactory.getRepositories(parameters);
Find the following working application.
RepositoryUtil.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.SessionFactory; import org.apache.chemistry.opencmis.client.runtime.SessionFactoryImpl; import org.apache.chemistry.opencmis.commons.SessionParameter; /** * Abstrcat super class for all the types of bindings. * * @author Hari Krishna Gurram * */ public abstract class RepositoryUtil { private String userName; private String password; private String urlToConnect; protected Map<String, String> parameters = new HashMap<>(); public RepositoryUtil(String userName, String password, String urlToConnect) { this.userName = userName; this.password = password; this.urlToConnect = urlToConnect; } public void populateProperties() { // user credentials parameters.put(SessionParameter.USER, this.getUserName()); parameters.put(SessionParameter.PASSWORD, this.getPassword()); } /** * Return all the repositories for given end point. * * @param parameters * @return */ public List<Repository> getAllRepositories() { populateProperties(); SessionFactory sessionFactory = SessionFactoryImpl.newInstance(); List<Repository> repositories = sessionFactory.getRepositories(parameters); return repositories; } public String getUserName() { return userName; } public String getPassword() { return password; } public String getUrlToConnect() { return urlToConnect; } }
BrowserBindingRepositoryUtil.java
package com.sample.util; import org.apache.chemistry.opencmis.commons.SessionParameter; import org.apache.chemistry.opencmis.commons.enums.BindingType; public class BrowserBindingRepositoryUtil extends RepositoryUtil { public BrowserBindingRepositoryUtil(String userName, String password, String urlToConnect) { super(userName, password, urlToConnect); } @Override public void populateProperties() { super.populateProperties(); // connection settings parameters.put(SessionParameter.BROWSER_URL, this.getUrlToConnect()); parameters.put(SessionParameter.BINDING_TYPE, BindingType.BROWSER.value()); } }
Test.java
package com.sample.util; import java.util.List; import org.apache.chemistry.opencmis.client.api.Repository; public class Test { public static void main(String args[]){ String urlToConnect = "http://localhost:8080/chemistry-opencmis-server-inmemory-1.1.0/browser"; RepositoryUtil repoUtil = new BrowserBindingRepositoryUtil("", "", urlToConnect); List<Repository> repositories = repoUtil.getAllRepositories(); for(Repository repository : repositories){ System.out.println(repository.getName()); } } }
Output
Apache Chemistry OpenCMIS InMemory Repository
No comments:
Post a Comment