IBM FileNet P8, Version 5.2.1            


< Previous | Next >

Adding Connection Code

You define a package and create a class with connection code to the Content Platform Engine.

Defining a Package

  1. In the Project Explorer pane, right-click your project name, and click New > Package.
  2. In the New Java Package dialog box, enter the package name in the Name field. For example, p8.sample.WebSphere.
  3. Click Finish.

Creating a Java Class

  1. In Eclipse, if the src folder is not already open, expand it.
  2. Right-click your package name and click New > Class.
  3. In the New Java Class' dialog box, enter the Java class in the Name field. For example, P8Connector.
  4. Click Finish.
The code pane opens with a template for your class.

Coding the Connection

The following code uses the Enterprise JavaBeans (EJB) transport protocol with WebSphere Application Server.
  1. In the code pane, immediately after the package line (that is, after the first line of code), insert the following code:
    // Import.
    import java.util.Iterator;
    import javax.security.auth.Subject;
    import com.filenet.api.collection.ObjectStoreSet;
    import com.filenet.api.core.Connection;
    import com.filenet.api.core.Domain;
    import com.filenet.api.core.Factory;
    import com.filenet.api.core.ObjectStore;
    import com.filenet.api.util.UserContext;
  2. In the code pane, within the class definition (such as within the public class P8Connector definition), insert the following code, substituting the placeholders with actual values for your environment:
     
    public static void main(String[] args)
    {
        // Set connection parameters; substitute for the placeholders.
            String uri = "iiop://<hostname>:2809/FileNet/Engine";
            String username = "<username>";
            String password = "<password>";
    
        // Make connection.
        Connection conn = Factory.Connection.getConnection(uri);
        Subject subject = UserContext.createSubject(conn, username, password, null);
        UserContext.get().pushSubject(subject);
            
        try
        {
           // Get default domain.
           Domain domain = Factory.Domain.fetchInstance(conn, null, null);
           System.out.println("Domain: " + domain.get_Name());
    
           // Get object stores for domain.
           ObjectStoreSet osSet = domain.get_ObjectStores();
           ObjectStore store;
           Iterator osIter = osSet.iterator();
    
           while (osIter.hasNext() == true) 
           {
              store = (ObjectStore) osIter.next();
              System.out.println("Object store: " + store.get_Name());
           }
           System.out.println("Connection to Content Platform Engine successful");
        }
        finally
        {
           UserContext.get().popSubject();
        }
    }
  3. In the Eclipse menu bar, click File > Save.
  4. If the Problems pane is not already open, click the Show View icon in the lower left corner of Eclipse, and click Problems.
  5. If your workspace preference is not set to build automatically, click Project > Build Project in the Eclipse menu bar.
If your code does not compile, verify that you:
< Previous | Next >



Last updated: October 2015

ss_ecl_ws009.htm



© Copyright IBM Corporation 2015.