CMIS客户端JAVA -露天



我从Alfresco开始。我正在遵循一本教程Alfresco CMIS,并且,为了制作CMIS客户端JAVA,我首先使用Maven快速启动工件:mvn archetype:generate -DgroupId=com.my.company.app -DartifactId=my-app -DarchetypeArtifactId=maven-archetype-quickstart -DinteractiveMode=false,并创建一个目录结构的项目和一个JAVA文件com.my.company.app.App.java,以放置以下代码:

  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");
    }
}

并将pom.xml配置为:

<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>

在App类的同一个包中,我们用下面的代码创建文件CmisClient.java:

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;
    }
}

我试图运行命令mvn compile exec:java -Dexec.mainClass="com.mycompany.app.App"来运行代码,由书指示。但是,我得到了错误:http://pastebin.com/kK3YvPRF

我把粘贴,因为我认为所有的调试更容易理解。我的错误是什么?

编辑:我已经尝试在java文件中导入org.apache.chemistry. openmiss .client.api,但没有成功…

我解决了!我把项目放在IntelliJ IDEA和我导入。jar库,我从这里下载http://chemistry.apache.org/java/opencmis.html,我做所有需要的导入。

package com.mycompany.app;
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;
import org.apache.chemistry.opencmis.commons.exceptions.CmisConnectionException;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

相关内容

  • 没有找到相关文章

最新更新