Search code examples
filenet-p8

Can anyone tell me the Java utility to download documents to your local PC from Content Engine in filenet?


Hello Guys I am trying to write the java utility to download the documents to local PC from content engine in filenet can anyone help me out?


Solution

  • You should read about FileNet P8 CE API, you can start here:

    You have to know that the FileNet Content Engine has two types of interface that can be used to connect to it: RMI and SOAP. A cmd line app you are planning to write, can connect only by SOAP (I am not sure that this is true for the newest versions, but what is definitely true, that it is much easier to setup the SOAP connection than EJB), so you have to read that part of the documentation, how to establish a connection in this way to your Content Engine.

    On the link above, you can see that first of all you have to collect the required jars for SOAP connection: please check the "Required for a Content Engine Java API CEWS transport client" section for the file names.

    After you collect them, you will need a SOAP WSDL URL and a proper user and password, the user has to have read properties and read content right to the documents you would like to download. You also need to know the ObjectStore name and the identifier or the location of your documents.

    Now we have to continue using this Setting Up a Thick Client Development Environment link (I opened it from the page above.)

    Here you have to scroll down to the "CEWS transport protocol (non-application-server dependent)" section.

    Here you can see, that you have to create a jaas.conf file with the following content:

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

    This file must be added as the following JVM argument when you run the class we will create: java -cp %CREATE_PROPER_CLASSPATH% -Djava.security.auth.login.config=jaas.conf DownloadClient

    Now, on the top-right corner of the page, you can see links that describes what to do in order to get a connection, like "Getting Connection", "Retrieving an EntireNetwork Object" etc. I used that snipplet to create the class below for you.

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

    This code is just shows how can you implement such a thick client, I have created it now using the documentation, not production code. But after specifying the packages to import, and may handle the exceptions it will probably work.

    You have to specify the right URL, user, password and docId of course, and you have to implement the copy from the TransferInputStream to a FileOutputStream, e.g. by using commons.io or java NIO, etc.