在Alfresco中获取文档时获取CMIS运行时异常

时间:2018-03-12 10:41:25

标签: alfresco cmis

我正在尝试获取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();

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

方法1 :(给定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:内部服务器错误)。

更新: 嘿Jeff我已经在创建文档之后做了REST api调用来添加标签。虽然添加了标签但我觉得它会对文档产生一些锁定。这就是为什么我无法从Alfresco获取Document对象(当我试图获取文档对象给我内部服务器错误时,我在问题中提到)。当我删除标签添加逻辑时,我能够从Alfresco中检索Document对象而没有问题。我的方法是向文档中添加标签

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

1 个答案:

答案 0 :(得分:1)

看起来您正在使用自定义方法来获取AtomPub网址。你可以输出它,以确保它看起来像这样: 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包括&#34; workspace:// SpacesStore /&#34;)。假设节点实际存在,Alfresco将处理您传入的内容。

检查alfresco日志,看看抛出的异常是什么。该日志位于/opt/alfresco/tomcat/logs/catalina.out。

相关问题