2

I am trying to access IBM FileNet P8 V5 datastore from a servlet and need help in getting the WebSphere configuration correct.

I have a fresh install of FN P8 on a RedHat 7 server with IBM WebSphere.

I tried the example code given on https://www.ibm.com/support/knowledgecenter/en/SSNW2F_5.0.0/com.ibm.p8.ce.dev.ce.doc/ss_ecl_cews.htm

It works fine from a plain Java class; connects to the server and retrieves the datastore name.

I copied the code over to a servlet but getting the error: " com.filenet.api.exception.EngineRuntimeException: FNRCS0005E: SECURITY_INVALID_CREDENTIALS: Access to the Content Engine was not allowed because the Content Engine API library or the Web Service Interface (WSI) Listener could not find the required security context information. Expected credentials were not found in the security context"

As per the tutorial, I need to set the runtime environment. That's where I'm stuck at. I tried adding jaas.conf.WebSphere in via the WebSphere console in the JVM settings but am obviously not doing it correctly.

package server;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
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;

/**
 * Servlet implementation class FNTest
 * Ref: https://www.ibm.com/support/knowledgecenter/en/SSNW2F_5.0.0/com.ibm.p8.ce.dev.ce.doc/ss_ecl_cews.htm
 */
//@WebServlet(description = "Test for connection to Filenet", urlPatterns = { "/FNTest" })
@WebServlet("/FNTest")
public class FNTest extends HttpServlet {
    private static final long serialVersionUID = 2L;

    /**
     * @see HttpServlet#HttpServlet()
     */
    public FNTest() {
        super();
        // TODO Auto-generated constructor stub
    }

    /**
     * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
     */
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        PrintWriter out = response.getWriter();
        out.println("<html>");
        out.println("<head><title>Filenet Function Test</title></head>");
        out.println("<body>");
        out.println("<h1>Filenet Function Test</h1>");
        out.println("<p>Request server at " + request.getServletPath() + ".</p><hr>");
        out.println("<p>Connecting to Filenet...</p>");
        // Connect to Filenet
        // Set connection parameters; substitute for the placeholders.
        String uri = "http://filenet.myserver.com:9080/wsi/FNCEWS40MTOM/";
        String username = "P8Admin";
        String password = "P8Password";

        // 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()) 
           {
              store = (ObjectStore) osIter.next();
              System.out.println("Object store: " + store.get_Name());
           }
           System.out.println("Connection to Content Engine successful");
        }
        finally
        {
           UserContext.get().popSubject();
        }

        out.println("<p>Completed</p>");
        out.println("</body></html>");
    }

    /**
     * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
     */
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        // TODO Auto-generated method stub
        doGet(request, response);
    }

}

The application with the servlet is installed on the same server.

4
  • 1
    I see you have null for a jaas stanza, this means it will take FileNetP8 as a default stanza. In stead of null try FileNetP8WSI as you are using a WSI endpoint to connect to. this seems to be a similar problem: stackoverflow.com/questions/15404357/… Commented May 3, 2019 at 12:40
  • From another post, I added Java->Process Definition->JVM->JVM Args: -DFileNet.WSI.AutoDetectLTPAToken=true -Dcom.filenet.authentication.token.userid=sso:ltpa. The program started functioning until I noticed that the next day it gave the same error again. Further checks showed that if I log in to Navigator or ACCE in another tab, my servlet starts working. Obviously the wrong way to go. I had previously tried with the FileNetP8 stanza (which according to your link, is the default). Let's try with FileNetP8WSI ... Commented May 4, 2019 at 15:57
  • Using FileNetP8WSI works! Tried it in incognito window and a different browser. Thanks! Why didn't you post this as a solution so it can be marked? Commented May 4, 2019 at 16:08
  • also posted official awnser so it can be accepted Commented May 6, 2019 at 9:08

1 Answer 1

3

I see you have null for a jaas stanza, this means it will take FileNetP8 as a default stanza. In stead of null try FileNetP8WSI as you are using a WSI endpoint to connect to.

Subject subject = UserContext.createSubject(conn, username, password, "FileNetP8WSI");

If you supply null it will use "FileNetP8" this is the jaas stanza to use for an IIOP connection

Not the answer you're looking for? Browse other questions tagged or ask your own question.