session=base_request.recoverNewSession(_sessionManager); if (session!=null) base_request.setSession(session);
session=request.getSession(false); if (session==null) { if(session!=old_session) _sessionManager.access(session); } else { session=base_request.recoverNewSession(_sessionManager); if (session!=null) base_request.setSession(session); }
    public void handle(String target, HttpServletRequest request, HttpServletResponse response, int dispatch)            throws IOException, ServletException    {        Request base_request = (request instanceof Request) ? (Request)request:HttpConnection.getCurrentConnection().getRequest();        SessionManager old_session_manager=null;        HttpSession old_session=null;                try        {            String requested_session_id=request.getRequestedSessionId();                        if (dispatch==REQUEST && requested_session_id==null)            {                boolean requested_session_id_from_cookie=false;                                // Look for session id cookie                     Cookie[] cookies=request.getCookies();                if (cookies!=null && cookies.length>0)                {                    for (int i=0;i<cookies.length;i++)                    {                        if (SessionManager.__SessionCookie.equalsIgnoreCase(cookies[i].getName()))                        {                            if (requested_session_id!=null)                            {                                // Multiple jsessionid cookies. Probably due to                                // multiple paths and/or domains. Pick the first                                // known session or the last defined cookie.                                if (_sessionManager.getHttpSession(requested_session_id)!=null)                                    break;                            }                                                        requested_session_id=cookies[i].getValue();                            requested_session_id_from_cookie = true;                            if(Log.isDebugEnabled())Log.debug("Got Session ID "+requested_session_id+" from cookie");                        }                    }                }                                if (requested_session_id==null)                {                    String uri = request.getRequestURI();                                        int semi = uri.lastIndexOf(';');                    if (semi>=0)                    {	                        String path_params=uri.substring(semi+1);                                                // check if there is a url encoded session param.                        if (path_params!=null && path_params.startsWith(SessionManager.__SessionURL))                        {                            requested_session_id = path_params.substring(SessionManager.__SessionURL.length()+1);                            if(Log.isDebugEnabled())Log.debug("Got Session ID "+requested_session_id+" from URL");                        }                    }                }                                base_request.setRequestedSessionId(requested_session_id);                base_request.setRequestedSessionIdFromCookie(requested_session_id!=null && requested_session_id_from_cookie);            }                        old_session_manager = base_request.getSessionManager();            old_session = base_request.getSession(false);                        if (old_session_manager != _sessionManager)            {                // new session context                base_request.setSessionManager(_sessionManager);                base_request.setSession(null);            }                        // access any existing session            HttpSession session=request.getSession(false);            if (session!=null)                getSessionManager().access(session);            else if (_sessionManager!=null)            {                session=base_request.recoverNewSession(_sessionManager);                if (session!=null)                    base_request.setSession(session);            }                        if(Log.isDebugEnabled())            {                Log.debug("sessionManager="+base_request.getSessionManager());                Log.debug("session="+session);            }                    getHandler().handle(target, request, response, dispatch);        }        catch (RetryRequest r)        {            HttpSession session=base_request.getSession(false);            if (session!=null && session.isNew())                base_request.saveNewSession(_sessionManager,session);            throw r;        }        finally        {            base_request.setSessionManager(old_session_manager);            base_request.setSession(old_session);        }    }