Java 如何使用CMIS REST API访问Alfresco中的文件?

Java 如何使用CMIS REST API访问Alfresco中的文件?,java,rest,alfresco,cmis,Java,Rest,Alfresco,Cmis,我安装了Alfresco Community v4.1,以便在我的应用程序中使用。我想使用cmisrestapi访问它的内容(列出文件、添加、删除等)。我没有找到需要使用的端点的任何示例。我使用Apache Chemistry实现了一个小型CMIS客户端,并列出了我的用户空间的内容,我得到了以下结果: [Folder] workspace://SpacesStore/624914c7-3ca2-4937-a612-96f1df928cc1 - Dictionnaire de données

我安装了Alfresco Community v4.1,以便在我的应用程序中使用。我想使用
cmisrestapi
访问它的内容(列出文件、添加、删除等)。我没有找到需要使用的端点的任何示例。我使用
Apache Chemistry
实现了一个小型
CMIS
客户端,并列出了我的用户空间的内容,我得到了以下结果:

[Folder] workspace://SpacesStore/624914c7-3ca2-4937-a612-96f1df928cc1 - Dictionnaire de données
    [Folder] workspace://SpacesStore/846c69d4-4ec2-44c8-972d-f975d9b98d41 - Modèles d'espace
        [Folder] workspace://SpacesStore/09fe45df-9cba-4843-a1cb-944807e44267 - Projet de conception logicielle
....

[Folder] workspace://SpacesStore/ab5cab42-2b47-4042-a8f5-57bb06007cc3 - Espaces Utilisateurs
            [Folder] workspace://SpacesStore/86f1c760-905e-4920-98a8-a6bdd10aa732 - ombinte
                [Folder] workspace://SpacesStore/2dbc6156-fdfa-4ddc-9187-481992570369 - MonProjet
                    [Folder] workspace://SpacesStore/fb3bb96f-3eb0-40a5-a890-3d06d6e781cf - Carnet 200
                    [Folder] workspace://SpacesStore/b9acaf70-d5d5-4dba-a354-bae63ba96072 - Carnet 100
                            [Docment] workspace://SpacesStore/9c3c6e63-e217-47a8-8216-298d2419cffa;1.0 - file.pdf
 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();
}
当我试图列出一个节点的内容时,我总是得到一个
404
错误

http://127.0.0.1:8080/alfresco/service/api/node/content/workspace/SpacesStore/ab5cab42-2b47-4042-a8f5-57bb06007cc3
 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();
}
在哪里可以找到关于如何为Alfresco实现CMIS REST API的文档?

很好地解释了这一点。您不应该将CMIS本身看作RESTAPI。CMIS是一个旨在提供一种通用的、与供应商无关的数据查询方法的应用程序

 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();
}
无论如何。。。您的问题似乎是您正在使用的节点用于文件夹,而您正在使用的服务不适用于该文件夹。试着用…来代替

http://127.0.0.1:8080/alfresco/service/api/node/content/workspace/SpacesStore/9c3c6e63-e217-47a8-8216-298d2419cffa
 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();
}
…看看你是否找到了你的内容

 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();
}
对于文件夹,请尝试一个链接,例如:

链接可以很好地解释这一点。您不应该将CMIS本身看作RESTAPI。CMIS是一个旨在提供一种通用的、与供应商无关的数据查询方法的应用程序

 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();
}
无论如何。。。您的问题似乎是您正在使用的节点用于文件夹,而您正在使用的服务不适用于该文件夹。试着用…来代替

http://127.0.0.1:8080/alfresco/service/api/node/content/workspace/SpacesStore/9c3c6e63-e217-47a8-8216-298d2419cffa
 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();
}
…看看你是否找到了你的内容

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

对于文件夹,请尝试链接,例如:

您可以使用此方法访问存储库

 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();
}
试试这个对我很管用

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

希望这对你有帮助

您可以使用此方法访问存储库

 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();
}
试试这个对我很管用

 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();
}
希望这对你有帮助

请看这篇文章请看这篇文章
 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();
}