0

我正在尝试访问通过 CMIS 与 Alfresco 通信的 Web 服务。我正在访问此链接:http://localhost:8080/Changes/ChangesPDF?filePath=/Documentos/examplepdf.pdf&ticket=TICKET_1dd4951f5d97c72232db40bdc8dceeb7be70aaed

当我启动 Alfresco 时,我可以毫无问题地访问网络服务,但是当我关闭 Alfresco 时 - 它让我在网络服务中未经授权,即使我进行了登录,仍然给我未经授权。

获取会话的代码:

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

以下错误:

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

并在这里输入:

"Already connected to Alfresco with the " +
                    "connection id (" + connectionName + ")"7

如何关闭与 Alfresco 的旧连接?

4

1 回答 1

2

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

于 2016-02-29T12:05:03.343 回答