2016-04-25 56 views
0

我想實現一個SessionListener,我計劃用它來記錄活動用戶會話(名稱/時間),以便我可以讓經理知道誰在任何時候都可用。但是,當我添加它時,會看到sessionCreated消息,然後在服務器控制檯上看到此JVM錯誤。之後沒有執行java代碼。SessionListener導致ExceptionInInitializerError

HTTP JVM:com.ibm.xsp.webapp.FacesServlet $ ExtendedServletException: java.lang.ExceptionInInitializerError HTTP JVM:錯誤類型不 發現:java.lang.ExceptionInInitializerError進口 javax.servlet.http.HttpSessionEvent ;

這裏是我的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 ***"); 
    } 
} 

這是我在xpages_exec看到* .LOG IBM_TECHNICAL_SUPPORT目錄下。

上下文路徑:/igdmnext/igdm.nsf頁面名稱:在以 java.lang中 java.lang.J9VMInternals.initialize(J9VMInternals.java:221)/Services.xsp java.lang.ExceptionInInitializerError。 J9VMInternals.newInstanceImpl(本機方法)維持在 com.ibm.xsp.util.ManagedBeanUtil.getBean(ManagedBeanUtil.java:61) java.lang.Class.newInstance(Class.java:1688)在 com.ibm.xsp .extlib.component.rest.CustomService.findBeanInstance(CustomService.java:225) at com.ibm.xsp.extlib.component.rest.CustomService $ ScriptServiceEngine.renderService(CustomService.java:257) com.ibm.domino.services.HttpServiceEngine.processRequest(HttpServiceEngine.java:170) 在 com.ibm.xsp.extlib.component.rest.UIBaseRestService._processAjaxRequest(UIBaseRestService.java:259) 在 COM .ibm.xsp.extlib.component.rest.UIBaseRestService.processAjaxRequest(UIBaseRestService.java:236) 在 com.ibm.xsp.util.AjaxUtilEx.renderAjaxPartialLifecycle(AjaxUtilEx.java:206) 在 com.ibm.xsp .webapp.FacesServletEx.renderAjaxPartial(FacesServletEx.java:249) 在 com.ibm.xsp.webapp.FacesServletEx.serviceAjaxPartialView(FacesServletEx.java:200) 在 com.ibm.xsp.webapp.FacesServletEx .serviceAjaxPartialViewSync(FacesServletEx.java:169) 在 com.ibm.xsp.webapp.FacesServletEx.serviceView(FacesServletEx.java:155) 在com.ibm.xsp.webapp.FacesServlet.service(FacesServlet.java:160)在 com.ibm.xsp.webapp.FacesServletEx.service(FacesServletEx.java:138)在 com.ibm.xsp.webapp.DesignerFacesServlet.service(DesignerFacesServlet.java:103) 在 com.ibm.designer.runtime .domino.adapter.ComponentModule.invokeServlet(ComponentModule.java:576) 在 com.ibm.domino.xsp.module.nsf.NSFComponentModule.invokeServlet(NSFComponentModule.java:1335) 在 com.ibm.designer.runtime .domino.adapter.ComponentModule $ AdapterInvoker.invokeServlet(ComponentModule的.java:853) 在 com.ibm.designer.runtime.domino.adapter.ComponentModule $ ServletInvoker.doService(ComponentModule.java:796) 在 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) 引起:java.lang.NullPointerException在 org.openntf.domino.xsp。 session.AbstractXPageSessionFactory.wrapSession(AbstractXPageSessionFactory.java:23) 在 org.openntf.domino.xsp.session.XPageSignerSessionFactory.createSession(XPageSignerSessionFactory.java:18) 在org.openntf.domino.utils.Factory.getSession(Factory.java:952)在 com.hcl。 igdm.util.EndUserMap。(EndUserMap.java:46) - >這是我的自定義Java類,如果我沒有實現SessionTracker上面的在 java.lang.J9VMInternals.initializeImpl(本地方法)在 java.lang .J9VMInternals.initialize(J9VMInternals.java:199)... 27 更多

** ** 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; 
     } 
    } 
} 
+0

看看是否有幫助:http://stackoverflow.com/questions/11177842/xpages-get-number-of-active- sessions-lotus-domino-8-5-2 – Giuseppe

+0

在EndUserMap類中提供了代碼片段,請 –

+0

我在這裏添加了EndUserMap.java代碼。我禁用了自定義錯誤頁面,現在我在該日誌中看到以下條目: > HTTP JVM:SEVERE:CLFAD0141E:處理XPage請求時出錯 > HTTP JVM:SEVERE:CLFAD0211E:拋出異常 > HTTP JVM:SEVERE: CLFAD0246E:發生異常服務請求:/igdmnext/igdm.nsf/Services.xsp/uiMap - HTTP代碼:500 > HTTP Web服務器:命令未處理異常[/igdmnext/igdm.nsf/Services.xsp/uiMap?type = map&ukey =] – Arun

回答

2

產生的原因:在org.openntf.domino.xsp.session.XPageSignerSessionFactory.createSession在org.openntf.domino.xsp.session.AbstractXPageSessionFactory.wrapSession(AbstractXPageSessionFactory.java:23)顯示java.lang.NullPointerException (XPageSignerSessionFactory.java:18)在org.openntf.domino.utils.Factory.getSession(Factory.java:952)在

好像被擊中的錯誤得到簽名者會議。

在ODA Factory初始化工廠會話之前,這可能是一個計時問題,它由運行在不同ClassLoader中引起。我不確定如何確認,但如果在服務器啓動時XOTS記錄之前,您的錯誤正在觸發日誌,那幾乎肯定會是這種情況。

或者,它可能是特定於找不到簽名者。我傾向於使用Factory.getSession(SessionType.NATIVE)而不是簽署者會話。這運行在服務器的身份,這應該是足夠高,並避免多個簽名者的問題等。

+0

謝謝保羅。我想出了上面的問題。獲得會話後,session.getCurrentDatabase()爲空。它是由不同的ClassLoaders引起的嗎? – Arun

+0

ODA在'org.openntf.domino.xsp'插件中使用'getCurrentDatabase()'很多,所以它應該是可用的。堆棧跟蹤引用NSFComponentModule - 我相信它是運行它的NSF上下文。所以它應該有一個當前的數據庫上下文。堆棧跟蹤也意味着它發生在部分刷新中,這將排除不同的ClassLoader。可能需要進行一些調試才能確定在哪裏初始化了什麼,然後嘗試在「顯示」視圖中運行Java代碼(窗口>顯示視圖>其他>顯示,如果以前沒有使用它 - 默認情況下是隱藏的)。 –

+0

我是否需要添加ODA會話修正godmode/khan等到XSP.properties?我怎麼做? 此外,只是檢查,SessionType.Current工作得很好。 – Arun

相關問題