Example usage for org.apache.wicket.protocol.http IRequestLogger sessionCreated

List of usage examples for org.apache.wicket.protocol.http IRequestLogger sessionCreated

Introduction

In this page you can find the example usage for org.apache.wicket.protocol.http IRequestLogger sessionCreated.

Prototype

void sessionCreated(String id);

Source Link

Document

called when the session is created and has an id.

Usage

From source file:RedisSessionStore.java

License:Apache License

@Override
public String getSessionId(Request request, boolean create) {
    String id = null;/* www  .j av a 2 s .  c o m*/
    HttpSession httpSession = getHttpSession(request, false);
    if (httpSession != null) {
        id = httpSession.getId();
    } else {
        //Just because this server doesn't have a session doesn't mean the session doesn't already exist
        //see if the jsession id is being passed in 
        String uri = ((HttpServletRequest) request.getContainerRequest()).getRequestURI();
        String[] split = uri.split(";");
        String jsessionid = null;
        if (split.length > 1 && split[1].contains("jsessionid=")) {
            //session exists, first check if it's already mapped:
            jsessionid = split[1].replace("jsessionid=", "");
        }
        if (create || jsessionid != null) {
            //create a new session on this server
            httpSession = getHttpSession(request, true);
            id = httpSession.getId();
            //now check whether this is a real new session or just a session that needs to be mapped
            if (jsessionid != null) {
                //session already exist in redis, but this tomcat needs to map back to it, so look up
                //the original session
                Object o = redisCache.getCacheObject(getKeyMapKey(jsessionid));
                while (o != null) {
                    //make sure this is the top jsessionid
                    jsessionid = (String) o;
                    o = redisCache.getCacheObject(getKeyMapKey(jsessionid));
                }
                //we have the top session, so map it to this server's session id
                redisCache.storeCacheObject(getKeyMapKey(id), jsessionid);
                httpSession.setAttribute(KEY_REDIS_SESSION, jsessionid);
            } else {
                //no session being passed in and no existing session on this server, create a new one!
                log.info("New SessionId: " + id);
                IRequestLogger logger = Application.get().getRequestLogger();
                if (logger != null) {
                    logger.sessionCreated(id);
                }
                httpSession.setAttribute(KEY_REDIS_SESSION, id);
            }
        }
    }
    return id;
}

From source file:bugs.HttpSessionStoreModified.java

License:Apache License

/**
 * @see org.apache.wicket.session.ISessionStore#getSessionId(org.apache.wicket.request.Request,
 *      boolean)//from w ww.  j av a  2s. c om
 */
@Override
public String getSessionId(final Request request, final boolean create) {
    String id = null;

    HttpSession httpSession = getHttpSession(request, false);
    if (httpSession != null) {
        id = httpSession.getId();
    } else if (create) {
        httpSession = getHttpSession(request, true);
        id = httpSession.getId();

        IRequestLogger logger = Application.get().getRequestLogger();
        if (logger != null) {
            logger.sessionCreated(id);
        }
    }
    return id;
}

From source file:com.mastfrog.acteur.wicket.EnsureSessionId.java

License:Open Source License

@Inject
EnsureSessionId(HttpEvent evt, Application app, Settings settings) {
    SessionId id = findSessionId(evt);//  ww  w . java 2 s  .c  o  m
    if (id == null) {
        id = new SessionId();
        DefaultCookie ck = new DefaultCookie(ActeurSessionStore.COOKIE_NAME, id.toString());
        long maxAge = Duration.standardHours(settings.getLong(SETTINGS_KEY_SESSION_COOKIE_MAX_AGE_HOURS,
                DEFAULT_SESSION_COOKIE_MAX_AGE_HOURS)).toStandardSeconds().getSeconds();
        ck.setMaxAge(maxAge);
        add(Headers.SET_COOKIE, ck);
        String sv = Headers.COOKIE.toString(new Cookie[] { ck });
        evt.getRequest().headers().add(Headers.SET_COOKIE.name(), sv);
        IRequestLogger logger = app.getRequestLogger();
        if (logger != null) {
            logger.sessionCreated(id.toString());
        }
    }
    setState(new ConsumedLockedState(id));
}