Connection with alfresco cmis

依然范特西╮ 提交于 2019-12-02 09:25:51

Use the following method to get session

 public Session getSession() {
    if (session == null) {
        logger.info("Not connected, creating new connection");

        // default factory implementation
        SessionFactory factory = SessionFactoryImpl.newInstance();
        Map<String, String> parameter = new HashMap<String, String>();

        // user credentials
        parameter.put(SessionParameter.USER, "admin");
        parameter.put(SessionParameter.PASSWORD, "admin");

        // connection settings
        parameter.put(SessionParameter.ATOMPUB_URL, "http://localhost:8080/alfresco/api/-default-/public/cmis/versions/1.0/atom"); 
        parameter.put(SessionParameter.BINDING_TYPE, BindingType.ATOMPUB.value()); 

        List<Repository> repositories = factory.getRepositories(parameter);

        if (repositories != null && repositories.size() > 0) {
            logger.info("Found (" + repositories.size() + ") Alfresco repositories");
            this.session = repositories.get(0).createSession();
        } else {
            throw new CmisConnectionException("Could not connect to the Alfresco Server,"
                    + " no repository found!");
        }       
    }
    return this.session;
}

try this worked fine for me

 private static Session getSession(String serverUrl, String username, String password) {
    SessionFactory sessionFactory = SessionFactoryImpl.newInstance();
    Map<String, String> params = new HashMap<String, String>();
    params.put(SessionParameter.USER, username);
    params.put(SessionParameter.PASSWORD, password);
    params.put(SessionParameter.ATOMPUB_URL, serverUrl);
    params.put(SessionParameter.BINDING_TYPE, BindingType.ATOMPUB.value());
    List<Repository> repos = sessionFactory.getRepositories(params);
    if (repos.isEmpty()) {
        throw new RuntimeException("Server has no repositories!");
    }
    return repos.get(0).createSession();
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!