MCPcopy Create free account
hub / github.com/apache/tomcat / doGetSession

Method doGetSession

java/org/apache/catalina/connector/Request.java:2749–2856  ·  view source on GitHub ↗

Get the session for this request, optionally creating one. @param create true to create a session if one doesn't exist @return the session, or null if not available

(boolean create)

Source from the content-addressed store, hash-verified

2747 * @return the session, or {@code null} if not available
2748 */
2749 protected Session doGetSession(boolean create) {
2750
2751 // There cannot be a session if no context has been assigned yet
2752 Context context = getContext();
2753 if (context == null) {
2754 return null;
2755 }
2756
2757 // Return the current session if it exists and is valid
2758 if ((session != null) && !session.isValid()) {
2759 session = null;
2760 }
2761 if (session != null) {
2762 return session;
2763 }
2764
2765 // Return the requested session if it exists and is valid
2766 Manager manager = context.getManager();
2767 if (manager == null) {
2768 return null; // Sessions are not supported
2769 }
2770 if (requestedSessionId != null) {
2771 try {
2772 session = manager.findSession(requestedSessionId);
2773 } catch (IOException ioe) {
2774 if (log.isDebugEnabled()) {
2775 log.debug(sm.getString("request.session.failed", requestedSessionId, ioe.getMessage()), ioe);
2776 } else {
2777 log.info(sm.getString("request.session.failed", requestedSessionId, ioe.getMessage()));
2778 }
2779 session = null;
2780 }
2781 if ((session != null) && !session.isValid()) {
2782 session = null;
2783 }
2784 if (session != null) {
2785 session.access();
2786 // The client has chosen to join the session
2787 session.setNew(false);
2788 return session;
2789 }
2790 }
2791
2792 // Create a new session if requested and the response is not committed
2793 if (!create) {
2794 return null;
2795 }
2796 boolean trackModesIncludesCookie =
2797 context.getServletContext().getEffectiveSessionTrackingModes().contains(SessionTrackingMode.COOKIE);
2798 if (trackModesIncludesCookie && response.getResponse().isCommitted()) {
2799 throw new IllegalStateException(sm.getString("coyoteRequest.sessionCreateCommitted"));
2800 }
2801
2802 // Re-use session IDs provided by the client in very limited
2803 // circumstances.
2804 String sessionId = getRequestedSessionId();
2805 if (requestedSessionSSL) {
2806 // If the session ID has been obtained from the SSL handshake then

Callers 2

getSessionMethod · 0.95
getSessionInternalMethod · 0.95

Calls 15

getContextMethod · 0.95
getManagerMethod · 0.95
findSessionMethod · 0.95
getServletContextMethod · 0.95
getRequestedSessionIdMethod · 0.95
getSessionCookiePathMethod · 0.95
getHostMethod · 0.95
createSessionMethod · 0.95
createSessionCookieMethod · 0.95
isSecureMethod · 0.95

Tested by

no test coverage detected