09-23-2015 10:57 AM
package com.mycompany.app;
public class App
{
public static void main( String[] args )
{
CmisClient cmisClient = new CmisClient();
String connectionName = "testeConn";
Session session = cmisClient.getSession(connectionName, "admin", "admin");
}
}
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.mycompany.app</groupId>
<artifactId>my-app</artifactId>
<packaging>jar</packaging>
<version>1.0-SNAPSHOT</version>
<name>my-app</name>
<url>http://maven.apache.org</url>
<dependencies>
<!– Bring in the OpenCMIS library for talking to CMIS
servers –>
<dependency>
<groupId>org.apache.chemistry.opencmis</groupId>
<artifactId>chemistry-opencmis-client-impl
</artifactId>
<version>0.13.0</version>
</dependency>
<dependency>
<groupId>commons-logging</groupId>
<artifactId>commons-logging</artifactId>
<version>1.1.1</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
</dependencies>
</project>
public class CmisClient {
private static Log logger = LogFactory.getLog(CmisClient.class);
private static Map<String, Session> connections = new
ConcurrentHashMap<String, Session>();
public CmisClient() {
}
public Session getSession(
String connectionName, String username, String pwd) {
Session session = connections.get(connectionName);
if (session == null) {
logger.info("Not connected, creating new connection to" +
" Alfresco with the connection id (" + connectionName +
")");
// No connection to Alfresco available, create a new one
SessionFactory sessionFactory =
SessionFactoryImpl.newInstance();
Map<String, String> parameters = new HashMap<String,
String>();
parameters.put(SessionParameter.USER, username);
parameters.put(SessionParameter.PASSWORD, pwd);
parameters.put(SessionParameter.ATOMPUB_URL,
"http://localhost:8080/alfresco/api/-default-/cmis/versions/1.1/atom");
parameters.put(SessionParameter.BINDING_TYPE,
BindingType.ATOMPUB.value());
parameters.put(SessionParameter.COMPRESSION, "true");
parameters.put(SessionParameter.CACHE_TTL_OBJECTS, "0");
// If there is only one repository exposed (e.g. Alfresco),
// these lines will help detect it and its ID
List<Repository> repositories =
sessionFactory.getRepositories(parameters);
Repository alfrescoRepository = null;
if (repositories != null && repositories.size() > 0) {
logger.info("Found (" + repositories.size() +
") Alfresco repositories");
alfrescoRepository = repositories.get(0);
logger.info("Info about the first Alfresco repo [ID=" +
alfrescoRepository.getId() + "][name=" +
alfrescoRepository.getName() + "][CMIS ver supported=" +
alfrescoRepository.getCmisVersionSupported() + "]");
} else {
throw new CmisConnectionException(
"Could not connect to the Alfresco Server, " +
"no repository found!");
}
// Create a new session with the Alfresco repository
session = alfrescoRepository.createSession();
// Save connection for reuse
connections.put(connectionName, session);
} else {
logger.info("Already connected to Alfresco with the " +
"connection id (" + connectionName + ")");
}
return session;
}
}
09-24-2015 11:05 AM
09-25-2015 10:51 AM
Tags
Find what you came for
We want to make your experience in Hyland Connect as valuable as possible, so we put together some helpful links.