談笑有鴻儒,往來無白丁

          在恰當的時間、地點以恰當的方式表達給恰當的人...  閱讀的時候請注意分類,佛曰我日里面是談笑文章,其他是各個分類的文章,積極的熱情投入到寫博的隊伍中來,支持blogjava做大做強!向dudu站長致敬>> > 我的微博敬請收聽
          <2025年6月>
          25262728293031
          1234567
          891011121314
          15161718192021
          22232425262728
          293012345

          技術型的項目管理,才是真正的戰無不勝
          個人微博:http://t.qq.com/badboyryan

          常用鏈接

          留言簿(43)

          隨筆分類

          隨筆檔案

          文章分類

          相冊

          收藏夾

          DELPHI資源

          ORACLE資源

          PHP學習網站

          PYTHON

          學習JAVA網站

          異國風情

          王者歸來

          網上資源

          網友鏈接

          最新隨筆

          搜索

          •  

          積分與排名

          • 積分 - 931244
          • 排名 - 38

          最新評論

          閱讀排行榜

          評論排行榜

          Portal開源實現-Liferay的Portlet Session處理(2)


          二、LIFERAY中的實現

          LIFERAY在構建ActionRequestImpl和RenderRequestImpl時,會設置PORTLET SESSION,如下代碼所示:
          public RenderRequestImpl(HttpServletRequest req, Portlet portlet,
          ??????? CachePortlet cachePortlet,
          ??????? PortletContext portletCtx,
          ??????? WindowState windowState, PortletMode portletMode,
          ??????? PortletPreferences prefs, String layoutId) {
          ?? ...
          ??_req = dynamicReq;
          ??_portlet = portlet;
          ??_cachePortlet = cachePortlet;
          ??_portalCtx = new PortalContextImpl();
          ??_portletCtx = portletCtx;
          ??_windowState = windowState;
          ??_portletMode = portletMode;
          ??_prefs = prefs;
          ??_ses = new PortletSessionImpl(
          ???_req.getSession(), _portletName, _portletCtx);
          ?? ...
          ?}
          從蘭色的部分(? _ses = new PortletSessionImpl(_req.getSession(),_portletName, _portletCtx);? )我們可以看到,這個PORTLET SESSION其實就是PORTAL SYSTEM的 SESSION 對象。
          所以無論request調用getSession()或者getPortletSession()都將獲取Portal 系統的SESSION 對象,而無論該PORTLET? 是或者不是屬于PORTAL SYSTEM上下文。而且即使不同PORTAL APPLICATION的PORTLET也將使用同一個SESSION 對象(PORTAL 系統)。
          也就是說,對于某一個PORTLET來說,如果有對其的SESSION進行的操作,并沒有真正的在該APPLICATION上下文中的SESSION進行操作,而是在PORTAL系統上下文的SESSION中進行操作。

          而且LIFERAY提供getPortletSession來獲取PortletSession對象,而不是getSession()方法,所以即使getPortletSession()可以獲取正確的Session對象,開發人員由于習慣問題,也因使用getSession()而得不到。

          另外如果調用request.getSession(true)還可能會出現錯誤,因為LIFERAY在包含某一個PORTLET內容是,調用PortletRequestDispatcherImpl.include()方法,該方法將生成PortletServletRequest 和PortletServletResponse,請見如下代碼:

          PortletServletRequest portletServletReq = new PortletServletRequest(
          ????httpReq, reqImpl, pathInfo, queryString, requestURI,
          ????servletPath);

          ???PortletServletResponse portletServletRes =
          ????new PortletServletResponse(
          ?????resImpl.getHttpServletResponse(), resImpl);
          而PortletServletRequest的構造函數是如下定義的:
          public PortletServletRequest(HttpServletRequest req,
          ???????? RenderRequest renderRequest, String pathInfo,
          ???????? String queryString, String requestURI,
          ???????? String servletPath) {

          ??super(req);

          ??_ses = req.getSession();
          ??_renderRequest = renderRequest;
          ??_pathInfo = pathInfo;
          ??_queryString = queryString;
          ??_requestURI = requestURI;
          ??_servletPath = servletPath;
          ?}
          所以其SESSION依然是PORTAL系統上下文的。然后問題就出在這里,PortletServletRequest實現了getSession()方法,但是沒有實現getSession(boolen create)方法,如果用戶在此階段調用getSession(true)的話,在某些情況下就會拋出NullPointerException

          原因見如下代碼(請注意我添加的注釋部分)
          //ApplicationHttpRequest:??

          ?public HttpSession getSession(boolean create) {

          ??????? if (crossContext) {
          ???????????
          ??????????? // There cannot be a session if no context has been assigned yet
          ??????????? if (context == null)
          ??????????????? return (null);

          ??????????? // Return the current session if it exists and is valid
          ??????????? if (session != null)
          ??????????????? return (session.getSession());
          ???? // 我的注釋:這里將獲取PORTAL系統的SESSION對象。
          ??????????? HttpSession other = super.getSession(false);
          ??????????? if (create && (other == null)) {
          ??????????????? // First create a session in the first context: the problem is
          ??????????????? // that the top level request is the only one which can
          ??????????????? // create the cookie safely
          ??????????????? other = super.getSession(true);
          ??????????? }
          ??????????? if (other != null) {
          ??????????????? Session localSession = null;
          ??????????????? try {
          ??????????????????? // 我的注釋:this context did not have the session with session id. It can just be found in the Portal
          ??????????????????? // context. So here it will return a null value.
          ??????????????????? localSession =
          ??????????????????????? context.getManager().findSession(other.getId());
          ??????????????????? localSession.access(); //我的注釋:Here, localSession is null. So it throws a NullPointException.
          ??????????????? } catch (IOException e) {
          ??????????????????? // Ignore
          ??????????????? }
          ??????????????? if (localSession == null) {
          ??????????????????? localSession = context.getManager().createEmptySession();
          ??????????????????? localSession.setNew(true);
          ??????????????????? localSession.setValid(true);
          ??????????????????? localSession.setCreationTime(System.currentTimeMillis());
          ??????????????????? localSession.setMaxInactiveInterval
          ??????????????????????? (context.getManager().getMaxInactiveInterval());

          posted on 2006-07-31 10:09 壞男孩 閱讀(1123) 評論(0)  編輯  收藏 所屬分類: Portal相關文檔

          只有注冊用戶登錄后才能發表評論。


          網站導航:
           
          主站蜘蛛池模板: 石楼县| 垦利县| 略阳县| 定州市| 保定市| 遵义县| 东宁县| 玉林市| 始兴县| 江西省| 子长县| 长白| 长沙县| 九龙坡区| 崇信县| 阿瓦提县| 开鲁县| 朝阳县| 辽中县| 江都市| 瑞安市| 门源| 嘉黎县| 石城县| 津南区| 青龙| 岳阳县| 运城市| 原阳县| 罗源县| 北海市| 疏勒县| 郓城县| 县级市| 呼和浩特市| 固镇县| 沂水县| 色达县| 四川省| 西乡县| 云阳县|