【发布时间】: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;
}
}
【问题讨论】: