关闭会话CMIS

时间:2016-02-24 12:05:14

标签: web-services alfresco cmis opencmis alfresco-webscripts

我正在尝试访问通过CMIS与Alfresco通信的Web服务。我正在访问此链接:angular.module('myApp', ['ngRoute', 'ngAnimate']); .config(function($urlRouterProvider, $locationProvider, $routeProvider) { // Rest of configurations. function($routeProvider) { $routeProvider.when('/about', { templateUrl: 'assets/javascript/about/about.html', controller: 'AboutCtrl', controllerAs: 'vm' }); } ]);

当我启动Alfresco时,我可以毫无问题地访问Web服务,但是当我关闭Alfresco时 - 它在Web服务中未经授权,即使我登录了,也继续给我未经授权。

获取会话的代码:

http://localhost:8080/Changes/ChangesPDF?filePath=/Documentos/examplepdf.pdf&ticket=TICKET_1dd4951f5d97c72232db40bdc8dceeb7be70aaed

以下错误:

  

请求处理失败;嵌套异常是   org.apache.chemistry.opencmis.commons.exceptions   .CmisUnauthorizedException:Unauthorized

然后输入:

 public Session getSession(
            String connectionName, String token) {
        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<>();
            parameters.put(SessionParameter.USER, "");
            parameters.put(SessionParameter.PASSWORD, token);
            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;
    }

如何关闭与Alfresco的旧连接?

1 个答案:

答案 0 :(得分:2)

您只需在故障单更改时关闭会话。你可以这样做: session.clear(); session=null;