Alfresco:Stream已经关闭

时间:2016-07-23 06:36:25

标签: alfresco alfresco-share opencmis apache-chemistry

我正试图在露天使用apache-chemistry创建文本文档。我的代码用于创建文档

  

Document document = FileUtils.createTextDocument(“/”,“test.txt”,“test document”,BaseTypeId.CMIS_DOCUMENT.value(),VersioningState.MAJOR,session);

当我执行我的代码时,我遇到了异常

  

org.apache.chemistry.opencmis.commons.exceptions.CmisConnectionException:无法访问“http://localhost:8080/alfresco/api/-default-/public/cmis/versions/1.1/atom/children?id=5717e8a0-61b2-4bcb-8a91-2f4b61ebfefa&versioningState=major”:Stream已经关闭!       在org.apache.chemistry.opencmis.client.bindings.spi.http.DefaultHttpInvoker.invoke(DefaultHttpInvoker.java:233)       在org.apache.chemistry.opencmis.client.bindings.spi.http.DefaultHttpInvoker.invokePOST(DefaultHttpInvoker.java:68)       at org.apache.chemistry.opencmis.client.bindings.spi.atompub.AbstractAtomPubService.post(AbstractAtomPubService.java:713)       at org.apache.chemistry.opencmis.client.bindings.spi.atompub.ObjectServiceImpl.createDocument(ObjectServiceImpl.java:122)       在org.apache.chemistry.opencmis.client.runtime.SessionImpl.createDocument(SessionImpl.java:1165)       在org.apache.chemistry.opencmis.client.runtime.FolderImpl.createDocument(FolderImpl.java:77)       在org.apache.chemistry.opencmis.client.runtime.FolderImpl.createDocument(FolderImpl.java:460)       在org.apache.chemistry.opencmis.client.util.FileUtils.createTextDocument(FileUtils.java:168)

1 个答案:

答案 0 :(得分:1)

试试这个对我来说很好

public static void main(String args[]) {
String serverUrl = args[0];
String username = args[1];
String password = args[2];
Session session = getSession(serverUrl, username, password);
Folder root = session.getRootFolder();
Map<String, Object> properties = new HashMap<String, Object>();
properties.put(PropertyIds.OBJECT_TYPE_ID, BaseTypeId.CMIS_
DOCUMENT.value());
String name = "New Document (" + System.currentTimeMillis() +
").txt";
properties.put(PropertyIds.NAME, name);
List<Ace> addAces = new LinkedList<Ace>();
List<Ace> removeAces = new LinkedList<Ace>();
List<Policy> policies = new LinkedList<Policy>();
String content = "The quick brown fox jumps over the lazy dog.";
ContentStream contentStream = new ContentStreamImpl("text.txt",
BigInteger.valueOf(content.length()),
"text/plain", new ByteArrayInputStream(content.
getBytes()));
Document newDocument = root.createDocument(properties,
contentStream, VersioningState.MAJOR, policies, addAces, removeAces,
session.getDefaultContext());
System.out.println(newDocument.getId());
}