0

Using Spring Boot to create API to access FileNet documents. I have it working but ran into this issue with user context not saving. No problem getting Object Store and setting user context. First time I call endpoint it is successful. Subsequent times it fails with can't find user context.

Here is the main code parts:

Login and get object store works fine and push subject.#

... typical login code

com.filenet.api.core.Connection ceConn = Factory.Connection.getConnection(uri);
subject = UserContext.createSubject(ceConn, username, password, "FileNetP8WSI");
UserContext.get().pushSubject(subject);

Method to get document: Error occurs on fetchInstance

public List<String> downloadDocumentFromFileNet(String docId, List<Integer> pages)
    {
        List<String> actualPageFiles = new ArrayList<>();
        try {
            String path = "/opt/UtilDownload/";
            if (docId != null) {
                if (objStore == null) {
                    objStore = getObjectStore();
                } else if (UserContext.get().getSubject() == null) {
                    UserContext.get().pushSubject(subject);
                    logger.debug("Setting Subject: {}", subject.toString());
                }

                if (objStore != null) {
                    logger.debug("User Context During: {}", UserContext.get().getSubject());
                    PropertyFilter pf = new PropertyFilter();
                    pf.addIncludeProperty(new FilterElement(null, null, null, PropertyNames.CONTENT_SIZE, null));
                    pf.addIncludeProperty(new FilterElement(null, null, null, PropertyNames.CONTENT_ELEMENTS, null));
                    pf.addIncludeProperty(new FilterElement(null, null, null, PropertyNames.MIME_TYPE, null));
                    pf.addIncludeProperty(new FilterElement(null, null, null, PropertyNames.NAME, null));
                    Document oDoc = Factory.Document.fetchInstance(objStore, docId, pf); **ERROR HERE**
                    if (oDoc != null) {

Looks like spring boot loads 10 threads to service the API and this is what is causing my issue. First run initializes thead one with context but next time another thread does not have the context. The object store is ok but context is null. I was able to work around it by putting a check on user context and setting it if null but I do not know if this is best practice. Any advice would be appreciated. Seems each thread needs a push subject.

ᄂ ᄀ
  • 5,669
  • 6
  • 43
  • 57

0 Answers0