/* Create a new HttpSession.
If cookies are being used a set cookie is added to the response.
341726
HttpSession newSession()
    {
        HttpSession session=_servletHandler.newHttpSession(this);
        Cookie cookie=_servletHandler.getSessionManager().getSessionCookie(session,isSecure());
        if (cookie!=null)
            _servletHttpResponse.getHttpResponse().addSetCookie(cookie);
        return session;
    }
265108
@SuppressWarnings("unchecked")
	public void sessionCreated(HttpSessionEvent se) {
		Descriptor<? extends Context> descriptor = container.contexts().get(Session.class);
		
		if (descriptor != null) {
			WebContext<HttpSession> context = (WebContext<HttpSession>) container.component(descriptor);
			context.associate(se.getSession());
		}
	}
1282437
function resp(response) {
        if (!request.session) {
          debug("no session")
          return response
        }

        if (utils.shouldSetCookie(request) === false) {
          return response
        }

        // only send secure cookies via https
        if (request.session.cookie.secure && !utils.issecure(request, trustProxy)) {
          debug("not secured")
          return response
        }
        // touch session
        request.session.touch()
        // set cookie
        utils.setcookie(response, name, request.sessionID, secrets[0], request.session.cookie.data)

        if (utils.shouldDestroy(request)) {
          debug("destroying")
          store.destroy(request.sessionID, function ondestroy(err) {
            if (err) throw err
            debug("destroyed")
          })
        } else if (utils.shouldSave(request)) {
          request.session.save(function onsave(err) {
            if (err) throw err
          })
        } else if (utils.storeImplementsTouch && utils.shouldTouch(request)) {
          // store implements touch method
          debug("touching")
          store.touch(request.sessionID, request.session, function ontouch(err) {
            if (err) throw err
            debug("touched")
          })
        }

        return response
      }
757436
public ISession createSession(String sessionId, boolean newId) {
        //create local variable - JIT performance improvement
        final boolean isTraceOn = com.ibm.websphere.ras.TraceComponent.isAnyTracingEnabled();
        //need some way to checkForDuplicateCreatedIds or synchronize on some object or something ... look at in-memory
        if (isTraceOn && LoggingUtil.SESSION_LOGGER_WAS.isLoggable(Level.FINER)) {
            StringBuffer sb = new StringBuffer("id = ").append(sessionId).append(appNameForLogging);
            LoggingUtil.SESSION_LOGGER_WAS.entering(methodClassName, methodNames[CREATE_SESSION], sb.toString());
        }
        if (inProcessOfStopping) {
            throwException("SessionContext.createWhenStop");
        }
        BackedSession session = null;
        session = createSessionObject(sessionId);
        session.updateLastAccessTime(session.getCreationTime());
        session.setInsert(); // flag new session for insertion into store
        session.setMaxInactiveInterval((int) _smc.getSessionInvalidationTime());
        session.setUserName(ANONYMOUS_USER);
        _sessions.put(sessionId, session);
        //        if (session.duplicateIdDetected) { // could happen on zOS if key is defined incorrectly - perhaps doesn't include appname
        //                                           // other than that, this really should never happen - duplicate ids should not be generated
        //            LoggingUtil.SESSION_LOGGER_CORE.logp(Level.WARNING, methodClassName, methodNames[CREATE_SESSION], "Store.createSessionIdAlreadyExists");
        //            session = null;
        //        }

        if (isTraceOn && LoggingUtil.SESSION_LOGGER_WAS.isLoggable(Level.FINER)) {
            LoggingUtil.SESSION_LOGGER_WAS.exiting(methodClassName, methodNames[CREATE_SESSION], "session = " + session);
        }
        return session;
    }
101016
function sessionCreated(err, session) {
  var agentInfo = {name: ping + "er", title: "a " + ping + "er" }

  session.createAgent(agentInfo, function(err, agent) {
    console.log(ping + " agent created")
    Agent = agent
  })

  session.on("ragentCreated", function(ragent) {
    ragentCreated(ragent, "created")
  })

  session.getRemoteAgents(function(err, ragents){
    ragents.forEach(function(ragent) {
      ragentCreated(ragent, "existed")
    })
  })
}
994176
public void sessionCreated(HttpSessionEvent httpSessionEvent) {
		if (active) {
			if (log.isDebugEnabled()) 
				log.debug("sessionCreated sessionId = "
						+ httpSessionEvent.getSession().getId());
		}
	}
1308887
public final static void addCookie(String name, String value) {
		getServletResponse().addCookie(new Cookie(name, value));
	}
248010
public static Cookie createCookie(String cookieName, @Sensitive String cookieValue, HttpServletRequest req) {
        return createCookie(cookieName, cookieValue, -1, req);
    }
668631
def add_request_session(self):
        """"""
        session = new_request_session(self.config, self.cookies)
        self.request_sessions[thread.get_ident()] = session
1224185
public void sessionCreated(HttpSessionEvent event) {
    if (null == eventMulticaster) {
      eventMulticaster = Containers.getRoot().getBean(EventMulticaster.class).get();
      Assert.notNull(eventMulticaster);
    }
    eventMulticaster.multicast(new HttpSessionCreationEvent(event.getSession()));
  }
1098941
public static void storeSessionDataInCookie(String key, String value, ServletResponse response)
	{
		Cookie cookie = new Cookie(key, value);
		cookie.setPath("/");
		cookie.setMaxAge(-1);//expire when browser closes
		((HttpServletResponse) response).addCookie(cookie);
	}
571977
public HttpResponse addCookie(Collection<HttpCookie> cookies) {
        this.cookies = Utility.append(this.cookies, cookies);
        return this;
    }
904215
public void save(HttpSession httpSession) {
		String sessionSerialized = serializeSession();
		// Finally store the maestrano session
		httpSession.setAttribute(MAESTRANO_SESSION_ID, sessionSerialized);
	}
763835
public void handleHttpSession(Response serverResponse, String headerKey) {
        /** ---------------
         * Session handled
         * ----------------
         */
        if ("Set-Cookie".equals(headerKey)) {
            COOKIE_JSESSIONID_VALUE = serverResponse.getMetadata().get(headerKey);
        }
    }
254513
protected Object adaptAndSetCookie(ServletRequest req, ServletResponse res, SessionAffinityContext sac, ISession isess) {
        Object adaptedSession = null;
        if (isess != null) {
            adaptedSession = _adapter.adapt(isess);
            sac.setResponseSessionID(isess.getId());
            sac.setResponseSessionVersion(isess.getVersion());
            _sam.setCookie(req, res, sac, adaptedSession);
        }
        return adaptedSession;
    }
909588
@Override
    public Object getSession(ServletRequest request, ServletResponse response, SessionAffinityContext affinityContext, boolean create) {

        /*
         * Check to see if the request provides a JSESSIONID cookie
         */
        String sessionID = _sam.getInUseSessionID(request, affinityContext);
        int sessionVersion = _sam.getInUseSessionVersion(request, affinityContext); // affinityContext.getRequestedSessionVersion();
        ISession session = null;

        /*
         * If the sessionID is not null, this may be a request with an existing
         * session.
         */
        if (sessionID != null) {
            session = (ISession) getSession(sessionID, sessionVersion, true, null);
            if (session == null && affinityContext.isRequestedSessionIDFromCookie() // perform allIds call and reset sac
                            && !affinityContext.isAllSessionIdsSetViaSet()){  //PM89885 add another check for isAllSessionIdsSetViaSet since we may have done a set in HttpSessionContextImpl.getIHttpSession
                List allSessionIds = _sam.getAllCookieValues(request);
                affinityContext.setAllSessionIds(allSessionIds);
            }
        }

        while ((session == null) && (_sam.setNextId(affinityContext))) {
            sessionID = _sam.getInUseSessionID(request, affinityContext);
            sessionVersion = _sam.getInUseSessionVersion(request, affinityContext); // affinityContext.getRequestedSessionVersion();
            session = (ISession) getSession(sessionID, sessionVersion, true, null);
        }

        /*
         * If the session is null, create a new one if required. The session manager
         * will check
         * to see if an alternate webmodule has a session created using
         * this session id. If not, the session object returned may have a different
         * session id from the one supplied.
         */
        if ((session == null) && create) {
            boolean reuseThisID = false;
            if (_store.getShouldReuseId() || affinityContext.isResponseIdSet() || affinityContext.isRequestedSessionIDFromSSL()) {
                reuseThisID = true;
            }
            session = createISession(sessionID, sessionVersion, reuseThisID);
        }

        return adaptAndSetCookie(request, response, affinityContext, session);

    }
628073
private HttpSession2 buildSession(String id, boolean refresh) {
        HttpSession2 session = new HttpSession2(id, sessionManager, request.getServletContext());
        session.setMaxInactiveInterval(maxInactiveInterval);
        if (refresh) {
            WebUtil.addCookie(this, response, getSessionCookieName(), id,
                    getCookieDomain(), getCookieContextPath(), cookieMaxAge, true);
        }
        return session;
    }