public static String getSessionID ( HttpServletRequest req ) { String sessionID = null ; final HttpServletRequest f_req = req ; try { sessionID = AccessController . doPrivileged ( new PrivilegedExceptionAction < String > ( ) { @ Override public String run ( ) throws Exception { HttpSession session = f_req . getSession ( ) ; if ( session != null ) { return session . getId ( ) ; } else { return null ; } } } ) ; } catch ( PrivilegedActionException e ) { if ( ( e . getException ( ) ) instanceof com . ibm . websphere . servlet . session . UnauthorizedSessionRequestException ) { if ( ! req . isRequestedSessionIdFromCookie ( ) ) { sessionID = AccessController . doPrivileged ( new PrivilegedAction < String > ( ) { @ Override public String run ( ) { return f_req . getSession ( ) . getId ( ) ; } } ) ; } else { sessionID = AccessController . doPrivileged ( new PrivilegedAction < String > ( ) { @ Override public String run ( ) { return f_req . getRequestedSessionId ( ) ; } } ) ; } } } catch ( com . ibm . websphere . servlet . session . UnauthorizedSessionRequestException e ) { try { if ( ! req . isRequestedSessionIdFromCookie ( ) ) { sessionID = AccessController . doPrivileged ( new PrivilegedAction < String > ( ) { @ Override public String run ( ) { return f_req . getSession ( ) . getId ( ) ; } } ) ; } else { sessionID = AccessController . doPrivileged ( new PrivilegedAction < String > ( ) { @ Override public String run ( ) { return f_req . getRequestedSessionId ( ) ; } } ) ; } } catch ( java . lang . NullPointerException ee ) { sessionID = "UnauthorizedSessionRequest" ; } catch ( com . ibm . websphere . servlet . session . UnauthorizedSessionRequestException ue ) { sessionID = "UnauthorizedSessionRequest" ; } } return sessionID ; }
Return the session id if the request has an HttpSession otherwise return null .