Connection with alfresco cmis

前端 未结 2 1917
温柔的废话
温柔的废话 2021-01-29 10:03

I am trying to connect alfresco using config parameters but i am getting error:

Config: sessionParameters.put(SessionParameter.USER, \"admin\");
    sessionParam         


        
相关标签:
2条回答
  • 2021-01-29 10:25

    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();
    }
    
    0 讨论(0)
  • 2021-01-29 10:41

    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;
    }
    
    0 讨论(0)
提交回复
热议问题