Web services 如何使用RESTAPI签出和签入alfresco之外的任何文档?

Web services 如何使用RESTAPI签出和签入alfresco之外的任何文档?,web-services,servlets,alfresco,cmis,alfresco-webscripts,Web Services,Servlets,Alfresco,Cmis,Alfresco Webscripts,我使用servlet和JSP创建了一个Web应用程序。通过它,我连接到alfresco存储库。我也能够上传文件在露天和查看文件在外部网络应用程序 现在我的要求是,我必须为这些文档提供签入和签出选项 我找到了以下用于此用途的RESTAPI。 但是我不知道如何在servlet中使用这些API来满足我的需求 POST /alfresco/service/slingshot/doclib/action/cancel-checkout/site/{site}/{container}/{path} PO

我使用servlet和JSP创建了一个Web应用程序。通过它,我连接到alfresco存储库。我也能够上传文件在露天和查看文件在外部网络应用程序

现在我的要求是,我必须为这些文档提供签入和签出选项

我找到了以下用于此用途的RESTAPI。 但是我不知道如何在servlet中使用这些API来满足我的需求

POST /alfresco/service/slingshot/doclib/action/cancel-checkout/site/{site}/{container}/{path}


POST /alfresco/service/slingshot/doclib/action/cancel-checkout/node/{store_type}/{store_id}/{id}
任何人都可以提供一些简单的步骤或代码来完成这项任务吗


提前感谢。

请不要为此使用内部slingshot URL。相反,使用Apache Chemistry。它将为您节省大量的时间和麻烦,而且它更便于移植到除Alfresco之外的其他存储库

下面的示例按路径获取现有文档,执行签出,然后签入纯文本文档的新主版本

package com.someco.cmis.examples;

import java.io.ByteArrayInputStream;
import java.io.InputStream;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.apache.chemistry.opencmis.client.api.Document;
import org.apache.chemistry.opencmis.client.api.ObjectId;
import org.apache.chemistry.opencmis.client.api.Repository;
import org.apache.chemistry.opencmis.client.api.Session;
import org.apache.chemistry.opencmis.client.api.SessionFactory;
import org.apache.chemistry.opencmis.client.runtime.SessionFactoryImpl;
import org.apache.chemistry.opencmis.commons.SessionParameter;
import org.apache.chemistry.opencmis.commons.data.ContentStream;
import org.apache.chemistry.opencmis.commons.enums.BindingType;

public class CheckoutCheckinExample {
    private String serviceUrl = "http://localhost:8080/alfresco/api/-default-/public/cmis/versions/1.1/atom"; // Uncomment for Atom Pub binding
    private Session session = null;

    public static void main(String[] args) {
        CheckoutCheckinExample cce = new CheckoutCheckinExample();
        cce.doExample();
    }

    public void doExample() {
        Document doc = (Document) getSession().getObjectByPath("/test/test-plain-1.txt");
        String fileName = doc.getName();
        ObjectId pwcId = doc.checkOut(); // Checkout the document
        Document pwc = (Document) getSession().getObject(pwcId); // Get the working copy

        // Set up an updated content stream
        String docText = "This is a new major version.";
        byte[] content = docText.getBytes();
        InputStream stream = new ByteArrayInputStream(content);
        ContentStream contentStream = session.getObjectFactory().createContentStream(fileName, Long.valueOf(content.length), "text/plain", stream);

        // Check in the working copy as a major version with a comment
        ObjectId updatedId = pwc.checkIn(true, null, contentStream, "My new version comment");
        doc = (Document) getSession().getObject(updatedId);
        System.out.println("Doc is now version: " + doc.getProperty("cmis:versionLabel").getValueAsString());
    }

    public Session getSession() {

        if (session == null) {
            // default factory implementation
            SessionFactory factory = SessionFactoryImpl.newInstance();
            Map<String, String> parameter = new HashMap<String, String>();

            // user credentials
            parameter.put(SessionParameter.USER, "admin"); // <-- Replace
            parameter.put(SessionParameter.PASSWORD, "admin"); // <-- Replace

            // connection settings
            parameter.put(SessionParameter.ATOMPUB_URL, this.serviceUrl); // Uncomment for Atom Pub binding
            parameter.put(SessionParameter.BINDING_TYPE, BindingType.ATOMPUB.value()); // Uncomment for Atom Pub binding

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

            this.session = repositories.get(0).createSession();
        }
        return this.session;
    }
}
package com.someco.cmis.examples;
导入java.io.ByteArrayInputStream;
导入java.io.InputStream;
导入java.util.HashMap;
导入java.util.List;
导入java.util.Map;
导入org.apache.chemistry.opencmis.client.api.Document;
导入org.apache.chemistry.opencmis.client.api.ObjectId;
导入org.apache.chemistry.opencmis.client.api.Repository;
导入org.apache.chemistry.opencmis.client.api.Session;
导入org.apache.chemistry.opencmis.client.api.SessionFactory;
导入org.apache.chemistry.opencmis.client.runtime.SessionFactoryImpl;
导入org.apache.chemistry.opencmis.commons.SessionParameter;
导入org.apache.chemistry.opencmis.commons.data.ContentStream;
导入org.apache.chemistry.opencmis.commons.enums.BindingType;
公共类签出签出示例{
专用字符串serviceUrl=”http://localhost:8080/alfresco/api/-默认值-/public/cmis/versions/1.1/atom;//取消对atom发布绑定的注释
私有会话=null;
公共静态void main(字符串[]args){
CheckoutCheckinExample cce=新的CheckoutCheckinExample();
cce.doExample();
}
public void doExample(){
Document doc=(Document)getSession().getObjectByPath(“/test/test-plain-1.txt”);
字符串文件名=doc.getName();
ObjectId pwcId=doc.checkOut();//签出文档
Document pwc=(Document)getSession().getObject(pwcId);//获取工作副本
//设置更新的内容流
String docText=“这是一个新的主要版本。”;
byte[]content=docText.getBytes();
InputStream=新的ByteArrayInputStream(内容);
ContentStream ContentStream=session.getObjectFactory().createContentStream(文件名,Long.valueOf(content.length),“text/plain”,stream);
//将工作副本作为主要版本签入,并附上注释
ObjectId updateId=pwc.checkIn(true,null,contentStream,“我的新版本注释”);
doc=(文档)getSession().getObject(updateId);
System.out.println(“Doc现在是版本:”+Doc.getProperty(“cmis:versionLabel”).getValueAsString());
}
公共会话getSession(){
if(会话==null){
//默认工厂实现
SessionFactory工厂=SessionFactoryImpl.newInstance();
Map参数=new HashMap();
//用户凭据

parameter.put(SessionParameter.USER,“admin”);//请不要为此使用内部弹弓URL。相反,请使用来自Apache Chemistry的URL。它将为您节省大量时间和麻烦,并且更易于移植到Alfresco以外的其他存储库

下面的示例按路径获取现有文档,执行签出,然后签入纯文本文档的新主版本

package com.someco.cmis.examples;

import java.io.ByteArrayInputStream;
import java.io.InputStream;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.apache.chemistry.opencmis.client.api.Document;
import org.apache.chemistry.opencmis.client.api.ObjectId;
import org.apache.chemistry.opencmis.client.api.Repository;
import org.apache.chemistry.opencmis.client.api.Session;
import org.apache.chemistry.opencmis.client.api.SessionFactory;
import org.apache.chemistry.opencmis.client.runtime.SessionFactoryImpl;
import org.apache.chemistry.opencmis.commons.SessionParameter;
import org.apache.chemistry.opencmis.commons.data.ContentStream;
import org.apache.chemistry.opencmis.commons.enums.BindingType;

public class CheckoutCheckinExample {
    private String serviceUrl = "http://localhost:8080/alfresco/api/-default-/public/cmis/versions/1.1/atom"; // Uncomment for Atom Pub binding
    private Session session = null;

    public static void main(String[] args) {
        CheckoutCheckinExample cce = new CheckoutCheckinExample();
        cce.doExample();
    }

    public void doExample() {
        Document doc = (Document) getSession().getObjectByPath("/test/test-plain-1.txt");
        String fileName = doc.getName();
        ObjectId pwcId = doc.checkOut(); // Checkout the document
        Document pwc = (Document) getSession().getObject(pwcId); // Get the working copy

        // Set up an updated content stream
        String docText = "This is a new major version.";
        byte[] content = docText.getBytes();
        InputStream stream = new ByteArrayInputStream(content);
        ContentStream contentStream = session.getObjectFactory().createContentStream(fileName, Long.valueOf(content.length), "text/plain", stream);

        // Check in the working copy as a major version with a comment
        ObjectId updatedId = pwc.checkIn(true, null, contentStream, "My new version comment");
        doc = (Document) getSession().getObject(updatedId);
        System.out.println("Doc is now version: " + doc.getProperty("cmis:versionLabel").getValueAsString());
    }

    public Session getSession() {

        if (session == null) {
            // default factory implementation
            SessionFactory factory = SessionFactoryImpl.newInstance();
            Map<String, String> parameter = new HashMap<String, String>();

            // user credentials
            parameter.put(SessionParameter.USER, "admin"); // <-- Replace
            parameter.put(SessionParameter.PASSWORD, "admin"); // <-- Replace

            // connection settings
            parameter.put(SessionParameter.ATOMPUB_URL, this.serviceUrl); // Uncomment for Atom Pub binding
            parameter.put(SessionParameter.BINDING_TYPE, BindingType.ATOMPUB.value()); // Uncomment for Atom Pub binding

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

            this.session = repositories.get(0).createSession();
        }
        return this.session;
    }
}
package com.someco.cmis.examples;
导入java.io.ByteArrayInputStream;
导入java.io.InputStream;
导入java.util.HashMap;
导入java.util.List;
导入java.util.Map;
导入org.apache.chemistry.opencmis.client.api.Document;
导入org.apache.chemistry.opencmis.client.api.ObjectId;
导入org.apache.chemistry.opencmis.client.api.Repository;
导入org.apache.chemistry.opencmis.client.api.Session;
导入org.apache.chemistry.opencmis.client.api.SessionFactory;
导入org.apache.chemistry.opencmis.client.runtime.SessionFactoryImpl;
导入org.apache.chemistry.opencmis.commons.SessionParameter;
导入org.apache.chemistry.opencmis.commons.data.ContentStream;
导入org.apache.chemistry.opencmis.commons.enums.BindingType;
公共类签出签出示例{
专用字符串serviceUrl=”http://localhost:8080/alfresco/api/-默认值-/public/cmis/versions/1.1/atom;//取消对atom发布绑定的注释
私有会话=null;
公共静态void main(字符串[]args){
CheckoutCheckinExample cce=新的CheckoutCheckinExample();
cce.doExample();
}
public void doExample(){
Document doc=(Document)getSession().getObjectByPath(“/test/test-plain-1.txt”);
字符串文件名=doc.getName();
ObjectId pwcId=doc.checkOut();//签出文档
Document pwc=(Document)getSession().getObject(pwcId);//获取工作副本
//设置更新的内容流
String docText=“这是一个新的主要版本。”;
byte[]content=docText.getBytes();
InputStream=新的ByteArrayInputStream(内容);
ContentStream ContentStream=session.getObjectFactory().createContentStream(文件名,Long.valueOf(content.length),“text/plain”,stream);
//将工作副本作为主要版本签入,并附上注释
ObjectId updateId=pwc.checkIn(true,null,contentStream,“我的新版本注释”);
doc=(文档)getSession().getObject(updateId);
System.out.println(“Doc现在是版本:”+Doc.getProperty(“cmis:versionLabel”).getValueAsString());
}
公共会话getSession(){
if(会话==null){
//默认工厂实现