0
votes

I am trying to implement a SessionListener which I plan to use for logging active user sessions (name/time) so that I can let manager know who all are available at anytime. However, when I add it, I see sessionCreated message and then I see this JVM error on server console. No java code is executed after it.

HTTP JVM: com.ibm.xsp.webapp.FacesServlet$ExtendedServletException: java.lang.ExceptionInInitializerError HTTP JVM: Error type not found:java.lang.ExceptionInInitializerError import javax.servlet.http.HttpSessionEvent;

Here is my SessionTracker.java:

import com.ibm.xsp.application.ApplicationEx;
import com.ibm.xsp.application.events.SessionListener;

public class SessionTracker implements SessionListener {

    public void sessionCreated(ApplicationEx arg0, HttpSessionEvent arg1) {
        System.out.println("***session created***");
    }

    public void sessionDestroyed(ApplicationEx arg0, HttpSessionEvent arg1) {
        System.out.println("***session destroyed ***");
    }
}

Here is what I see in xpages_exec*.log under IBM_Technical_Support directory.

Context Path: /igdmnext/igdm.nsf Page Name: /Services.xsp java.lang.ExceptionInInitializerError at java.lang.J9VMInternals.initialize(J9VMInternals.java:221) at java.lang.J9VMInternals.newInstanceImpl(Native Method) at java.lang.Class.newInstance(Class.java:1688) at com.ibm.xsp.util.ManagedBeanUtil.getBean(ManagedBeanUtil.java:61) at com.ibm.xsp.extlib.component.rest.CustomService.findBeanInstance(CustomService.java:225) at com.ibm.xsp.extlib.component.rest.CustomService$ScriptServiceEngine.renderService(CustomService.java:257) at com.ibm.domino.services.HttpServiceEngine.processRequest(HttpServiceEngine.java:170) at com.ibm.xsp.extlib.component.rest.UIBaseRestService._processAjaxRequest(UIBaseRestService.java:259) at com.ibm.xsp.extlib.component.rest.UIBaseRestService.processAjaxRequest(UIBaseRestService.java:236) at com.ibm.xsp.util.AjaxUtilEx.renderAjaxPartialLifecycle(AjaxUtilEx.java:206) at com.ibm.xsp.webapp.FacesServletEx.renderAjaxPartial(FacesServletEx.java:249) at com.ibm.xsp.webapp.FacesServletEx.serviceAjaxPartialView(FacesServletEx.java:200) at com.ibm.xsp.webapp.FacesServletEx.serviceAjaxPartialViewSync(FacesServletEx.java:169) at com.ibm.xsp.webapp.FacesServletEx.serviceView(FacesServletEx.java:155) at com.ibm.xsp.webapp.FacesServlet.service(FacesServlet.java:160) at com.ibm.xsp.webapp.FacesServletEx.service(FacesServletEx.java:138) at com.ibm.xsp.webapp.DesignerFacesServlet.service(DesignerFacesServlet.java:103) at com.ibm.designer.runtime.domino.adapter.ComponentModule.invokeServlet(ComponentModule.java:576) at com.ibm.domino.xsp.module.nsf.NSFComponentModule.invokeServlet(NSFComponentModule.java:1335) at com.ibm.designer.runtime.domino.adapter.ComponentModule$AdapterInvoker.invokeServlet(ComponentModule.java:853) at com.ibm.designer.runtime.domino.adapter.ComponentModule$ServletInvoker.doService(ComponentModule.java:796) at com.ibm.designer.runtime.domino.adapter.ComponentModule.doService(ComponentModule.java:565) at com.ibm.domino.xsp.module.nsf.NSFComponentModule.doService(NSFComponentModule.java:1319) at com.ibm.domino.xsp.module.nsf.NSFService.doServiceInternal(NSFService.java:662) at com.ibm.domino.xsp.module.nsf.NSFService.doService(NSFService.java:482) at com.ibm.designer.runtime.domino.adapter.LCDEnvironment.doService(LCDEnvironment.java:357) at com.ibm.designer.runtime.domino.adapter.LCDEnvironment.service(LCDEnvironment.java:313) at com.ibm.domino.xsp.bridge.http.engine.XspCmdManager.service(XspCmdManager.java:272) Caused by: java.lang.NullPointerException at org.openntf.domino.xsp.session.AbstractXPageSessionFactory.wrapSession(AbstractXPageSessionFactory.java:23) at org.openntf.domino.xsp.session.XPageSignerSessionFactory.createSession(XPageSignerSessionFactory.java:18) at org.openntf.domino.utils.Factory.getSession(Factory.java:952) at com.hcl.igdm.util.EndUserMap.(EndUserMap.java:46) --> this is my custom java class which works if I do not implement SessionTracker above at java.lang.J9VMInternals.initializeImpl(Native Method) at java.lang.J9VMInternals.initialize(J9VMInternals.java:199) ... 27 more

** EndUserMap.java **

package com.hcl.igdm.util;

import java.io.PrintWriter;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.TreeMap;

import javax.faces.context.FacesContext;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.lang.StringUtils;
import org.openntf.domino.Database;
import org.openntf.domino.Session;
import org.openntf.domino.View;
import org.openntf.domino.ViewEntry;
import org.openntf.domino.ViewEntryCollection;
import org.openntf.domino.utils.Factory;
import org.openntf.domino.utils.Factory.SessionType;

import com.hcl.igdm.Activity;
import com.hcl.igdm.Phases;
import com.hcl.igdm.Stages;
import com.ibm.commons.util.StringUtil;
import com.ibm.commons.util.io.json.JsonJavaArray;
import com.ibm.commons.util.io.json.JsonJavaObject;
import com.ibm.domino.services.ServiceException;
import com.ibm.domino.services.rest.RestServiceEngine;
import com.ibm.xsp.extlib.component.rest.CustomService;
import com.ibm.xsp.extlib.component.rest.CustomServiceBean;
import com.ibm.xsp.extlib.util.ExtLibUtil;

/**
 * @author agnihotri.a
 * 
 */
public class EndUserMap extends CustomServiceBean implements Serializable {
    private static final long serialVersionUID = 1L;
    private static String requestedType = "";
    static Session session = Factory.getSession(SessionType.NATIVE);
    static Database db = session.getCurrentDatabase();
    static View allView = db.getView("mapAll");

    public static void setRequestedType(String requestType) {
        requestedType = requestType;
    }

    public static String getRequestedType() {
        return requestedType;
    }

    @Override
    public void renderService(CustomService service, RestServiceEngine engine) throws ServiceException {
        HttpServletRequest request = engine.getHttpRequest();
        HttpServletResponse response = engine.getHttpResponse();

        response.setHeader("Content-Type", "application/json; charset=UTF-8");
        response.setContentType("application/json");
        response.setCharacterEncoding("UTF-8");
        FacesContext faccon = FacesContext.getCurrentInstance();

        /**** read requested type from query string parameters ****/
        String reqType = request.getParameter("type");

        try {
            JsonJavaObject jjo = new JsonJavaObject();
            PrintWriter pw = response.getWriter();
            if (reqType.equalsIgnoreCase("Map") || "".equalsIgnoreCase(reqType)) {
                setRequestedType("Map");
                pw.write(getEndUserMap().toString());

            } else if (reqType.equalsIgnoreCase("Activity")) {
                setRequestedType("Activity");
                request.getParameter("ukey");
                try {
                    jjo = getActivity(request.getParameter("ukey"));
                    // jjo.put("map", getEndUserMap());
                    pw.write(jjo.toString());
                } catch (Exception e) {
                    e.printStackTrace();
                }
            } else if (reqType.equalsIgnoreCase("Phase")) {
                request.getParameter("ukey");
                try {
                    setRequestedType("Phase");
                    jjo = getPhase(request.getParameter("ukey"));
                    jjo.put("map", getEndUserMap());
                    pw.write(jjo.toString());
                } catch (Exception e) {
                    e.printStackTrace();
                }
            } else if (reqType.equalsIgnoreCase("Stage")) {
                request.getParameter("ukey");
                try {
                    setRequestedType("Stage");
                    jjo = getStage(request.getParameter("ukey"));
                    // jjo.put("map", getEndUserMap());
                    pw.write(jjo.toString());
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }

            pw.flush();

        } catch (Exception e) {
            e.printStackTrace();
        }
        faccon.responseComplete();

    }

    public static JsonJavaObject getActivity(String ukey) throws Exception {
        Activity activity = new Activity();
        activity.load(ukey);
        JsonJavaObject jjo = new JsonJavaObject();
        if (!isAdmin() && !StringUtil.equalsIgnoreCase((String) activity.getValue("Status"), "Live")) {
            jjo.put("error", "You are not authorized to view this document.");
            return jjo;
        }
        jjo.put("title", activity.getValue("Title"));
        jjo.put("teaser", activity.getValue("Teaser"));
        jjo.put("ukey", activity.getUnid());
        jjo.put("overview", activity.getValue("Overview"));
        jjo.put("inputs", activity.getValue("Inputs"));
        jjo.put("outputs", activity.getValue("Outputs"));
        jjo.put("order", activity.getValue("SortOrder"));
        jjo.put("artefacts", activity.getArtefacts());
        jjo.put("kmlinks", activity.getValue("KMLinks"));
        jjo.put("kmenabled", activity.getValue("KMEnabled"));
        jjo.put("resources", activity.getResources());
        TreeMap<String, ArrayList<String>> mappings = Mappings.loadMyMap(ukey);
        if (!mappings.isEmpty()) {
            if (mappings.containsKey("Substage")) {
                // jjo.put("substage", mappings.get("Substage").get(0));
                jjo.put("substage", getStage(mappings.get("Substage").get(0)));
            } else if (mappings.containsKey("Stage")) {
                // jjo.put("stage", mappings.get("Stage").get(0));
                jjo.put("stage", getStage(mappings.get("Stage").get(0)));
            }
        }
        return jjo;
    }

    public static JsonJavaObject getStage(String ukey) {

        Stages stage = new Stages();
        stage.load(ukey);
        String stageType = (String) stage.getValue("StageType");
        JsonJavaObject jjo = new JsonJavaObject();
        if (!isAdmin() && !StringUtil.equalsIgnoreCase((String) stage.getValue("Status"), "Live")) {
            jjo.put("error", "You are not authorized to view this document.");
            return jjo;
        }
        TreeMap<String, ArrayList<String>> mappings = Mappings.loadMyMap(ukey);

        jjo.put("title", stage.getValue("Title"));
        jjo.put("ukey", stage.getUnid());
        jjo.put("overview", stage.getValue("Overview"));
        jjo.put("order", stage.getValue("Row"));
        jjo.put("type", stageType);
        jjo.put("status", (String) stage.getValue("Status"));

        if (!mappings.isEmpty()) {

            if (mappings.containsKey("Stream")) {
                JsonJavaArray mapStreamJJA = new JsonJavaArray();
                for (String key : mappings.get("Stream")) {
                    try {
                        Map<String, Object> entryMap = allView.getFirstEntryByKey(key).getColumnValuesMap();
                        if ("Live".equalsIgnoreCase((String) entryMap.get("status")) || isAdmin()) {
                            mapStreamJJA.add(entryMap);
                        }

                    } catch (Exception ex) {
                        // do nothing
                    }
                }
                jjo.put("stream", mapStreamJJA);
            } else {
                jjo.put("stream", "");
            }
            /** below mapping check handles substages */
            if (mappings.containsKey("Stage") && !StringUtils.equalsIgnoreCase(stageType, "Stage")) {
                JsonJavaArray mapStreamJJA = new JsonJavaArray();
                JsonJavaArray mapPhaseJJA = new JsonJavaArray();

                // as this is substage ..we'll get phase from parent stage
                for (String key : mappings.get("Stage")) {
                    try {
                        Map<String, Object> entryMap = allView.getFirstEntryByKey(key).getColumnValuesMap();
                        if ("Live".equalsIgnoreCase((String) entryMap.get("status")) || isAdmin()) {
                            mapStreamJJA.add(entryMap);
                            TreeMap<String, ArrayList<String>> stageMap = Mappings.loadMyMap(key);
                            if (!stageMap.isEmpty() && stageMap.containsKey("Phase")) {
                                for (String phase : stageMap.get("Phase")) {
                                    Map<String, Object> entryMapPhase = allView.getFirstEntryByKey(phase).getColumnValuesMap();
                                    if ("Live".equalsIgnoreCase((String) entryMapPhase.get("status")) || isAdmin()) {
                                        mapPhaseJJA.add(entryMapPhase);
                                    }

                                }
                            }
                        }

                    } catch (Exception ex) {
                        ex.printStackTrace();
                    }
                }
                jjo.put("stage", mapStreamJJA);
                jjo.put("phase", mapPhaseJJA);
            }

            if (mappings.containsKey("Phase") && StringUtils.equalsIgnoreCase(stageType, "Stage")) {
                JsonJavaArray mapPhJJA = new JsonJavaArray();
                for (String key : mappings.get("Phase")) {
                    Map<String, Object> entryMap = allView.getFirstEntryByKey(key).getColumnValuesMap();
                    if ("Live".equalsIgnoreCase((String) entryMap.get("status")) || isAdmin()) {
                        mapPhJJA.add(entryMap);
                    }

                }
                jjo.put("phase", mapPhJJA);
            } else {
                if (!jjo.containsKey("phase")) {
                    jjo.put("phase", "");
                }
            }
            if (mappings.containsKey("Activity")) {
                JsonJavaArray actJJA = new JsonJavaArray();
                for (String key : mappings.get("Activity")) {
                    try {
                        Map<String, Object> entryMap = allView.getFirstEntryByKey(key).getColumnValuesMap();
                        if ("Live".equalsIgnoreCase((String) entryMap.get("status")) || isAdmin()) {
                            actJJA.add(entryMap);
                        }

                    } catch (Exception ex) {
                    }
                }

                jjo.put("child", "Activities");
                jjo.put("activities", actJJA);
            } else if (mappings.containsKey("Substage") && StringUtils.equalsIgnoreCase(stageType, "Stage")) {
                JsonJavaArray ssJJA = new JsonJavaArray();
                for (String key : mappings.get("Substage")) {
                    Map<String, Object> entryMap = allView.getFirstEntryByKey(key).getColumnValuesMap();
                    if ("Live".equalsIgnoreCase((String) entryMap.get("status")) || isAdmin()) {
                        ssJJA.add(entryMap);
                    }
                }
                jjo.put("child", "Substages");
                jjo.put("substages", ssJJA);
            }
        }

        return jjo;
    }

    public static JsonJavaObject getPhase(String ukey) {
        Phases phase = new Phases();
        phase.load(ukey);
        JsonJavaObject jjo = new JsonJavaObject();
        if (!isAdmin() && !StringUtil.equalsIgnoreCase((String) phase.getValue("Status"), "Live")) {
            return null;
        }
        jjo.put("title", phase.getValue("Title"));
        jjo.put("ukey", phase.getUnid());
        jjo.put("status", phase.getValue("Status"));

        jjo.put("overview", phase.getValue("Overview"));
        jjo.put("order", phase.getValue("SortOrder"));
        try {
            jjo.put("artefacts", phase.getArtefacts());
        } catch (Exception e) {
            jjo.put("artefacts", null);
            e.printStackTrace();
        }
        TreeMap<String, ArrayList<String>> mappings = Mappings.loadMyMap(ukey);
        if (!mappings.isEmpty() && mappings.containsKey("Stage")) {
            JsonJavaArray jja = new JsonJavaArray();
            for (String key : mappings.get("Stage")) {
                ViewEntry stage = allView.getFirstEntryByKey(key);
                if (null != stage) {
                    if (isAdmin() || "Live".equalsIgnoreCase((String) stage.getColumnValue("status"))) {
                        Map<String, Object> stg = stage.getColumnValuesMap();
                        TreeMap<String, ArrayList<String>> stgMap = Mappings.loadMyMap(key);
                        if (!stgMap.isEmpty() && stgMap.containsKey("Stream")) {
                            JsonJavaArray stgStreamArr = new JsonJavaArray();
                            for (String stream : stgMap.get("Stream")) {
                                try {
                                    Map<String, Object> entryMap = allView.getFirstEntryByKey(stream).getColumnValuesMap();
                                    if ("Live".equalsIgnoreCase((String) entryMap.get("status")) || isAdmin()) {
                                        stgStreamArr.add(entryMap);
                                    }

                                } catch (Exception ex) {
                                }
                            }
                            stg.put("stream", stgStreamArr);
                        }
                        jja.add(stg);
                    }
                }
            }
            jjo.put("stages", jja);
        }
        return jjo;
    }

    public static JsonJavaObject getEndUserMap() {

        setRequestedType("Map");
        JsonJavaObject endUserMap = new JsonJavaObject();
        try {

            ArrayList<String> docTypes = new ArrayList<String>();
            docTypes.add("Phase");
            docTypes.add("Stream");
            for (String dtype : docTypes) {
                View view = db.getView("map" + dtype);
                JsonJavaArray jja = new JsonJavaArray();
                ViewEntryCollection vec;
                if (isAdmin()) {
                    vec = view.getAllEntries();
                } else {
                    vec = view.getAllEntriesByKey("Live");
                }
                for (ViewEntry ve : vec) {
                    jja.add(ve.getColumnValuesMap());
                }
                endUserMap.put(dtype, jja);

            }

        } catch (Exception e) {
            e.printStackTrace();

        }
        return endUserMap;
    }

    @SuppressWarnings("unchecked")
    public static boolean isAdmin() {

        List<String> roleList = ExtLibUtil.getXspContext().getUser().getRoles();
        if (!roleList.isEmpty() && roleList.contains("[admin]")) {
            return true;
        } else {
            return false;
        }
    }
}
1
provide a snippet of the code in your EndUserMap class, pleaseFrantisek Kossuth
I have added EndUserMap.java code here. I disabled my custom Error page and now I see following entries in log for this class: > HTTP JVM: SEVERE: CLFAD0141E: Error processing XPage request > HTTP JVM: SEVERE: CLFAD0211E: Exception thrown > HTTP JVM: SEVERE: CLFAD0246E: Exception occurred servicing request for: /igdmnext/igdm.nsf/Services.xsp/uiMap - HTTP Code: 500 > HTTP Web Server: Command Not Handled Exception [/igdmnext/igdm.nsf/Services.xsp/uiMap?type=map&ukey=]Arun

1 Answers

2
votes

Caused by: java.lang.NullPointerException at org.openntf.domino.xsp.session.AbstractXPageSessionFactory.wrapSession(AbstractXPageSessionFactory.java:23) at org.openntf.domino.xsp.session.XPageSignerSessionFactory.createSession(XPageSignerSessionFactory.java:18) at org.openntf.domino.utils.Factory.getSession(Factory.java:952) at

It seems to be hitting an error getting the signer session.

This may be a timing issue, caused by it running in a different ClassLoader, before the ODA Factory has initialised the factory's sessions. I'm not sure how to confirm that, but if your error is hitting the logs before the XOTS logging at server startup, that would almost certainly be the case.

Alternatively, it may be specific to not finding the signer. I've tended to use Factory.getSession(SessionType.NATIVE) rather than a signer session. That runs under server's identity, which should be high enough and avoids the issue of multiple signers etc.