【问题标题】:Getting CMIS runtime exception while getting the document in Alfresco在 Alfresco 中获取文档时获取 CMIS 运行时异常
【发布时间】:2018-08-20 08:28:07
【问题描述】:

我正在尝试获取 Alfresco 中存在的文档的内容流。为了达到同样的效果,我首先按如下方式创建了 cmis 会话(我使用的是 CMIS 1.1)

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

parameter.put(SessionParameter.ATOMPUB_URL, getAtomPublicURL(getRequestFactory()));
parameter.put(SessionParameter.BINDING_TYPE, BindingType.ATOMPUB.value());
parameter.put(SessionParameter.AUTH_HTTP_BASIC, "true");
parameter.put(SessionParameter.USER, mUserName);
parameter.put(SessionParameter.PASSWORD, mPassword);

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

cmisSession = repositories.get(0).createSession();

创建会话后,我尝试了两种不同的方法来访问文档

方法一:(给定Alfresco中文档的nodeRef)

String objectId = "f273be7c-9b70-44cf-880f-5945a7857b5d";
CmisObject cmisObject = cmisSession.getObject(objectId);

方法2:(给定文档的路径)

String objectPath = "/Sites/testSite/documentLibrary/testFolder1/testFolder2/testDocument.pdf";
CmisObject cmisObject = cmisSession.getObjectByPath(objectPath);

注意:testSite 是我的文档所在的站点名称。

不幸的是,这两种方法都向我抛出了 CMIS 运行时异常

(org.apache.chemistry.opencmis.commons.exceptions.CmisRuntimeException:内部服务器错误)。

更新: 嘿,杰夫,我在创建文档后调用了 REST api 来添加标签。虽然添加了标签,但我觉得它会为文档创建一些锁定。这就是为什么我无法从 Alfresco 获取 Document 对象(尝试时)获取文档对象给了我内部服务器错误,正如我在问题中提到的那样)。当我删除标签添加逻辑时,我能够毫无问题地从 Alfresco 检索文档对象。下面是我向文档添加标签的方法。

public void setTags(String documentId,ArrayList<String> Tags) throws Exception {
    final String methodName = "setTags";
    try{
        GenericUrl containersUrl = new GenericUrl(getAlfrescoAPIUrl() +
                                             getHomeNetwork() +
                                             mNODES_URL +
                                             documentId +
                                             "/tags");
        mLog.debug(containersUrl);
        String tagName = "";
        String appendTags = "";

        for(int index=0;index<Tags.size();index++){
            tagName = (String) Tags.get(index);
            appendTags = appendTags+"{\"tag\": \""+tagName+"\"}";
            if(index < Tags.size()-1){
                appendTags = appendTags+",";
            }
        }

        String finalTags = "["+appendTags+"]";

        HttpContent body = new ByteArrayContent("application/json", finalTags.getBytes());
        HttpRequest request = getRequestFactory().buildPostRequest(containersUrl, body);
        try{
            request.execute();
        }
        catch(IOException ioException){
            mLog.error("Exception in :: "+mClassName+":: "+methodName+":: "+ioException.getMessage());
            throw ioException;
        }
    }
    catch(Exception exception){
        mLog.error("Exception in :: "+mClassName+":: "+methodName+":: "+exception.getMessage());
        throw exception;
    }
}

【问题讨论】:

    标签: alfresco cmis


    【解决方案1】:

    您似乎正在使用自定义方法来获取 AtomPub URL。你能输出它以确保它看起来像这样: http://alfresco.local:8080/alfresco/api/-default-/public/cmis/versions/1.1/atom

    此外,您可以转储 cmisSession.getRepositoryInfo().getProductName() 和 cmisSession.getRepositoryInfo().getProductVersion() 的值,以确保它们正常工作。我的节目:

    Alfresco Community
    5.2.0 (re21f2be5-b22)
    

    假设这两个调试步骤都有效,那么您的两种方法都可以在我的机器上显示。

    一个小问题是您设置为 objectId 的值不是 CMIS 对象 ID,而是 Alfresco 节点 ref 的一部分(完整的 nodeRef 包括“workspace://SpacesStore/”)。假设节点确实存在,Alfresco 将处理您传入的内容。

    检查 alfresco 日志以查看抛出的异常说明了什么。日志在 /opt/alfresco/tomcat/logs/catalina.out。

    【讨论】:

    • 嘿,杰夫,我已经确保我的自定义方法来获取原子公共 url 像 alfresco.local:8080/alfresco/api/-default-/public/cmis/versions/… 一样返回我使用你提到的方法测试了我的 cmis 会话。 cmisSession.getRepositoryInfo().getProductName() 给了我 Alfresco Community 和 cmisSession.getRepositoryInfo().getProductVersion() 给了我 4.2.0 (r63893-b12)。由此我可以确认创建的 cmis 会话没有问题。但是,当我尝试使用 getObject 方法时,我遇到了同样的错误。
    • 我还确认了该文档存在于 Alfresco 中,即使该文档不存在,如果我没有错,它也会向我抛出 CMISObjectNotFound 异常。我已在下面详细发布了错误原因: org.apache.chemistry.opencmis.commons.exceptions.CmisRuntimeException:org.apache.chemistry.opencmis.client.bindings.spi.atompub.AbstractAtomPubService.convertStatusCode(AbstractAtomPubService.java:487)[chemistry-opencmis-client] -bindings-0.10.0.jar:0.10.0]
    • 在 org.apache.chemistry.opencmis.client.bindings.spi.atompub.AbstractAtomPubService.read(AbstractAtomPubService.java:613) [chemistry-opencmis-client-bindings-0.10.0.jar: 0.10.0] 在 org.apache.chemistry.opencmis.client.bindings.spi.atompub.AbstractAtomPubService.getObjectInternal(AbstractAtomPubService.java:836) [chemistry-opencmis-client-bindings-0.10.0.jar:0.10.0]在 org.apache.chemistry.opencmis.client.bindings.spi.atompub.ObjectServiceImpl.getObject(ObjectServiceImpl.java:619) [chemistry-opencmis-client-bindings-0.10.0.jar:0.10.0]
    • 在 org.apache.chemistry.opencmis.client.runtime.SessionImpl.getObject(SessionImpl.java:410) [chemistry-opencmis-client-impl-0.10.0.jar:0.10.0]在 org.apache.chemistry.opencmis.client.runtime.SessionImpl.getObject(SessionImpl.java:388) [chemistry-opencmis-client-impl-0.10.0.jar:0.10.0]
    • 使用 Chemistry Workbench 访问服务器时一切正常吗?
    猜你喜欢
    • 1970-01-01
    • 2014-08-13
    • 1970-01-01
    • 2012-08-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-07-01
    • 2012-04-28
    相关资源
    最近更新 更多