谁能告诉我从文件网络中的内容引擎将文档下载到本地 PC 的 Java 实用程序?

塔伦·戈达

大家好,我正在尝试编写 java 实用程序,将文件从 filenet 中的内容引擎下载到本地 PC 上,有人可以帮助我吗?

m4gic

你应该阅读 FileNet P8 CE API,你可以从这里开始

您必须知道 FileNet 内容引擎有两种类型的接口可用于连接到它:RMI 和 SOAP。您计划编写的 cmd 行应用程序只能通过 SOAP 连接(我不确定最新版本是否如此,但绝对正确的是,设置 SOAP 连接比 EJB 容易得多),所以你必须阅读文档的那部分,如何以这种方式建立到你的内容引擎的连接。

在上面的链接中,您可以看到首先您必须收集 SOAP 连接所需的 jar:请检查文件名的“Content Engine Java API CEWS 传输客户端所需”部分。

收集它们后,您将需要一个 SOAP WSDL URL 和正确的用户名和密码,用户必须具有读取属性和读取您想要下载的文档的内容的权利。您还需要知道 ObjectStore 名称和标识符或文档的位置。

现在我们必须继续使用这个设置胖客户端开发环境链接(我从上面的页面打开它。)

在这里,您必须向下滚动到“CEWS 传输协议(非应用程序服务器相关)”部分。

在这里您可以看到,您必须创建一个包含以下内容的 jaas.conf 文件:

FileNetP8WSI  {
   com.filenet.api.util.WSILoginModule  required;
};

当您运行我们将创建的类时,必须将此文件添加为以下 JVM 参数: java -cp %CREATE_PROPER_CLASSPATH% -Djava.security.auth.login.config=jaas.conf DownloadClient

现在,在页面的右上角,您可以看到描述如何获取连接的链接,例如“获取连接”、“检索整个网络对象”等。我使用该片段创建了类下面给你。

    public class DownloadClient {

    public static void main(String[] args) throws Exception{
        String uri = "http://filenetcehost:9080/wsi/FNCEWS40MTOM";
        String userId = "ceadmin";
        String password = "password";
        String osName = "Test";
        UserContext uc = UserContext.get();

        try {

            //Get the connection and default domain
            Connection conn = Factory.Connection.getConnection(uri); 
            Domain domain = Factory.Domain.getInstance(conn, null);
            ObjectStore os = Factory.ObjectStore.fetchInstance(domain, osName, null);
            // the last value (jaas samza name) must match with the name of the login module in jaas.conf
            Subject subject =UserContext.createSubject(connection, userId, password, "FileNetP8WSI");
            // set the subject to the local thread via threadlocal
            uc.pushSubject(subject);

            // from now, we are connected to FileNet CE, and objectStore "Test"
            //https://www.ibm.com/support/knowledgecenter/en/SSNW2F_5.2.0/com.ibm.p8.ce.dev.ce.doc/document_procedures.htm
            Document doc = Factory.Document.getInstance(os, ClassNames.DOCUMENT, new Id("{F4DD983C-B845-4255-AC7A-257202B557EC}") );
            // because in FileNet a document can have more that one associated content element
            // (e.g. stores single page tifs and handle it as a multipaged document), we have to
            // get the content elements and iterate list.
            ContentElementList docContentList = doc.get_ContentElements();
            Iterator iter = docContentList.iterator();
            while (iter.hasNext() )
            {   
                ContentTransfer ct = (ContentTransfer) iter.next();
                // Print element sequence number and content type of the element.
                // Get and print the content of the element.
                InputStream stream = ct.accessContentStream();
                // now you have an inputstream to the document content, you can save it local file,
                // or you can do what you want with it, just do not forget to close the stream at the end.
                stream.close();
            }
        } finally {
            uc.popSubject(); 
        }
    }
}

这段代码只是展示了如何实现这样一个胖客户端,我现在使用文档创建了它,而不是生产代码。但是在指定要导入的包之后,可能会处理异常,它可能会起作用。

当然,您必须指定正确的 URL、用户、密码和 docId,并且您必须实现从 TransferInputStream 到 FileOutputStream 的复制,例如使用 commons.io 或 java NIO 等。

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章