Remove SessionManager; refactor names of session classes; add start modules for new session arch

This commit is contained in:
Jan Bartel 2016-04-15 09:18:23 +10:00
parent b3fa4abaa0
commit d28dffb16e
104 changed files with 3532 additions and 3782 deletions

View File

@ -0,0 +1,13 @@
<?xml version="1.0"?>
<!DOCTYPE Configure PUBLIC "-//Jetty//Configure//EN" "http://www.eclipse.org/jetty/configure_9_3.dtd">
<Configure id="Server" class="org.eclipse.jetty.server.Server">
<!-- ============================================================================================== -->
<!-- GCloud configuration when running in the cloud -->
<!-- ============================================================================================== -->
<New id="gconf" class="org.eclipse.jetty.gcloud.session.GCloudConfiguration">
<!-- All configuration information is provided by the cloud environment -->
</New>
</Configure>

View File

@ -0,0 +1,14 @@
<?xml version="1.0"?>
<!DOCTYPE Configure PUBLIC "-//Jetty//Configure//EN" "http://www.eclipse.org/jetty/configure_9_3.dtd">
<Configure id="Server" class="org.eclipse.jetty.server.Server">
<!-- ============================================================================================== -->
<!-- GCloud configuration for interacting with a local dev gcloud server for testing -->
<!-- ============================================================================================== -->
<New id="gconf" class="org.eclipse.jetty.gcloud.session.GCloudConfiguration">
<Set name="projectId"><Property name="jetty.gcloudSession.projectId"><Default><Env name="DATASTORE_DATASET"/></Default></Property></Set>
<!-- ensure DATASTORE_HOST System property/environment variable to the url of the dev server -->
</New>
</Configure>

View File

@ -0,0 +1,19 @@
<?xml version="1.0"?>
<!DOCTYPE Configure PUBLIC "-//Jetty//Configure//EN" "http://www.eclipse.org/jetty/configure_9_3.dtd">
<Configure id="Server" class="org.eclipse.jetty.server.Server">
<!-- ============================================================================================== -->
<!-- GCloud configuration. -->
<!-- Note: passwords can use jetty obfuscation. See -->
<!-- https://www.eclipse.org/jetty/documentation/current/configuring-security-secure-passwords.html -->
<!-- See your start.ini or gcloud-session-store.ini file for more configuration information. -->
<!-- ============================================================================================== -->
<New id="gconf" class="org.eclipse.jetty.gcloud.session.GCloudConfiguration">
<Set name="projectId"><Property name="jetty.gcloudSession.projectId"><Default><Env name="DATASTORE_DATASET"/></Default></Property></Set>
<Set name="p12File"><Property name="jetty.gcloudSession.p12File"/></Set>
<Set name="serviceAccount"><Property name="jetty.gcloudSession.serviceAccount"/></Set>
<Set name="password"><Property name="jetty.gcloudSession.password"/></Set>
</New>
</Configure>

View File

@ -0,0 +1,18 @@
<?xml version="1.0"?>
<!DOCTYPE Configure PUBLIC "-//Jetty//Configure//EN" "http://www.eclipse.org/jetty/configure_9_3.dtd">
<Configure id="Server" class="org.eclipse.jetty.server.Server">
<!-- ===================================================================== -->
<!-- Configure a factory for GCloudSessionStores -->
<!-- ===================================================================== -->
<Call name="addBean">
<New class="org.eclipse.jetty.server.session.GCloudSessionStoreFactory">
<Set name="gcloudConfiguration"><Ref id="gconf"/></Set>
<Set name="gracePeriod"><Property name="jetty.session.gracePeriod.seconds" default="3600" /></Set>
</New>
</Call>
</Configure>

View File

@ -1,13 +0,0 @@
<?xml version="1.0"?>
<!DOCTYPE Configure PUBLIC "-//Jetty//Configure//EN" "http://www.eclipse.org/jetty/configure_9_3.dtd">
<Configure id="Server" class="org.eclipse.jetty.server.Server">
<!-- ===================================================================== -->
<!-- Configure a GCloudSessionIdManager -->
<!-- ===================================================================== -->
<Get name="sessionIdManager">
<Set name="workerName"><Property name="jetty.sessionIdManager.workerName"><Default>node<Env name="GAE_MODULE_INSTANCE" default="0"/></Default></Property></Set>
</Get>
</Configure>

View File

@ -0,0 +1,9 @@
[description]
Enables session storage when running inside the cloud.
[name]
gcloud-embedded
[xml]
etc/jetty-gcloud-embedded.xml

View File

@ -0,0 +1,9 @@
[description]
Enables session storage on a local GCloudDataStore dev server.
[name]
gcloud-local
[xml]
etc/jetty-gcloud-local.xml

View File

@ -0,0 +1,15 @@
[description]
Enables session storage on a remote GCloudDataStore service.
[name]
gcloud-remote
[xml]
etc/jetty-gcloud-remote.xml
[ini-template]
#jetty.gcloudSession.projectId=
#jetty.gcloudSession.p12File=
#jetty.gcloudSession.serviceAccount=
#jetty.gcloudSession.password=

View File

@ -1,12 +1,16 @@
[description]
Enables GCloudDatastore session management.
[name]
gcloud-session-store
[depend]
annotations
webapp
sessions
gcloud-${type}
[files]
maven://com.google.gcloud/gcloud-java-datastore/0.0.7|lib/gcloud/gcloud-java-datastore-0.0.7.jar
maven://com.google.gcloud/gcloud-java-core/0.0.7|lib/gcloud/gcloud-java-core-0.0.7.jar
maven://com.google.auth/google-auth-library-credentials/0.1.0|lib/gcloud/google-auth-library-credentials-0.1.0.jar
@ -49,28 +53,16 @@ GCloudDatastore is an open source project hosted on Github and released under th
https://github.com/GoogleCloudPlatform/gcloud-java
http://www.apache.org/licenses/LICENSE-2.0.html
[xml]
etc/jetty-gcloud-sessions.xml
[ini]
type=remote
[ini-template]
#type=local
#type=embedded
## GCloudDatastore Session config
## If running inside Google cloud all configuration is provided by
## environment variables and you do not need to set anything in this file.
##
## If running externally to Google:
## To contact the remote gcloud datastore:
## 1. set the DATASTORE_DATASET System property/environment variable to the name of your project
## or alternatively set the jetty.gcloudSession.projectId property below.
## 2. set the jetty.gcloudSession.p12File, jetty.gcloudSession.serviceAccount and
## jetty.gcloudSession.password (supports obfuscation) below.
##
## To contact a local dev gcloud datastore server:
## 1. set the DATASTORE_DATASET System property/environment variable to the name of your project.
## 2. set the DATASTORE_HOST System property/environment variable to the url of the dev server
## as described at https://cloud.google.com/datastore/docs/tools/devserver#setting_environment_variables
## The gcloud projectId
## Set this property to connect to remote gcloud datastore.
@ -78,13 +70,13 @@ etc/jetty-gcloud-sessions.xml
#jetty.gcloudSession.projectId=
## The p12 file associated with the project.
## Set this property to connect to remote gcloud datastore
## Set this property only when connecting to remote gcloud datastore
#jetty.gcloudSession.p12File=
## The serviceAccount for the Datastore.
## Set this property to connect to to remote gcloud datastore
## Set this property only when connecting to remote gcloud datastore
#jetty.gcloudSession.serviceAccount=
## The password (can be obfuscated).
## Set this property to connect to remote gcloud datastore
## Set this property only when connecting to remote gcloud datastore
#jetty.gcloudSession.password=

View File

@ -1,42 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE Configure PUBLIC "-//Jetty//Configure//EN" "http://www.eclipse.org/jetty/configure_9_3.dtd">
<Configure class="org.eclipse.jetty.webapp.WebAppContext">
<!-- ============================================================================================== -->
<!-- GCloud configuration. -->
<!-- Note: passwords can use jetty obfuscation. See -->
<!-- https://www.eclipse.org/jetty/documentation/current/configuring-security-secure-passwords.html -->
<!-- See your start.ini or gcloud-sessions.ini file for more configuration information. -->
<!-- ============================================================================================== -->
<New id="gconf" class="org.eclipse.jetty.gcloud.session.GCloudConfiguration">
<!-- Either set jetty.gcloudSession.projectId or use system property/env var DATASTORE_DATASET-->
<Set name="projectId"><Property name="jetty.gcloudSession.projectId"/></Set>
<!-- To contact remote gclouddatastore set the following properties in start.ini -->
<Set name="p12File"><Property name="jetty.gcloudSession.p12File"/></Set>
<Set name="serviceAccount"><Property name="jetty.gcloudSession.serviceAccount"/></Set>
<Set name="password"><Property name="jetty.gcloudSession.password"/></Set>
</New>
<Get name="sessionHandler">
<Set name="sessionManager">
<New class="org.eclipse.jetty.gcloud.session.GCloudSessionManager">
<Set name="maxInactiveInterval">seconds</Set>
<Get name="sessionDataStore">
<Set name="gcloudConfiguration">
<Ref id="gconf"/>
</Set>
<Set name="maxResults">integer</Set>
</Get>
<Get name="sessionStore">
<Set name="idlePassivationTimeoutSec">seconds</Set>
<Set name="expiryTimeoutSec">seconds</Set>
</Get>
</New>
</Set>
</Get>
</Configure>

View File

@ -1,87 +0,0 @@
//
// ========================================================================
// Copyright (c) 1995-2016 Mort Bay Consulting Pty. Ltd.
// ------------------------------------------------------------------------
// All rights reserved. This program and the accompanying materials
// are made available under the terms of the Eclipse Public License v1.0
// and Apache License v2.0 which accompanies this distribution.
//
// The Eclipse Public License is available at
// http://www.eclipse.org/legal/epl-v10.html
//
// The Apache License v2.0 is available at
// http://www.opensource.org/licenses/apache2.0.php
//
// You may elect to redistribute this code under either of these licenses.
// ========================================================================
//
package org.eclipse.jetty.gcloud.session;
import org.eclipse.jetty.server.session.AbstractSessionStore;
import org.eclipse.jetty.server.session.MemorySessionStore;
import org.eclipse.jetty.server.session.SessionManager;
import org.eclipse.jetty.util.log.Log;
import org.eclipse.jetty.util.log.Logger;
/**
* GCloudSessionManager
*
* Convenience class to link up a MemorySessionStore with the GCloudSessionDataStore.
*
*/
public class GCloudSessionManager extends SessionManager
{
private final static Logger LOG = Log.getLogger("org.eclipse.jetty.server.session");
private GCloudSessionDataStore _sessionDataStore = null;
/**
*
*/
public GCloudSessionManager()
{
_sessionDataStore = new GCloudSessionDataStore();
setSessionStore(new MemorySessionStore(this));
}
public GCloudSessionDataStore getSessionDataStore()
{
return _sessionDataStore;
}
/**
* Start the session manager.
*
* @see org.eclipse.jetty.server.session.SessionManager#doStart()
*/
@Override
public void doStart() throws Exception
{
((AbstractSessionStore)_sessionStore).setSessionDataStore(_sessionDataStore);
super.doStart();
}
/**
* Stop the session manager.
*
* @see org.eclipse.jetty.server.session.SessionManager#doStop()
*/
@Override
public void doStop() throws Exception
{
super.doStop();
}
}

View File

@ -42,7 +42,7 @@ import java.util.Map;
import java.util.Set;
import java.util.concurrent.atomic.AtomicReference;
import org.eclipse.jetty.server.session.AbstractSessionDataStore;
import org.eclipse.jetty.server.session.AbstractSessionStore;
import org.eclipse.jetty.server.session.SessionContext;
import org.eclipse.jetty.server.session.SessionData;
import org.eclipse.jetty.util.ClassLoadingObjectInputStream;
@ -51,11 +51,11 @@ import org.eclipse.jetty.util.log.Log;
import org.eclipse.jetty.util.log.Logger;
/**
* GCloudSessionDataStore
* GCloudSessionStore
*
*
*/
public class GCloudSessionDataStore extends AbstractSessionDataStore
public class GCloudSessionStore extends AbstractSessionStore
{
private final static Logger LOG = Log.getLogger("org.eclipse.jetty.server.session");
@ -85,7 +85,7 @@ public class GCloudSessionDataStore extends AbstractSessionDataStore
/**
* @see org.eclipse.jetty.server.session.AbstractSessionDataStore#doStart()
* @see org.eclipse.jetty.server.session.AbstractSessionStore#doStart()
*/
@Override
protected void doStart() throws Exception
@ -138,7 +138,7 @@ public class GCloudSessionDataStore extends AbstractSessionDataStore
/**
* @see org.eclipse.jetty.server.session.SessionDataStore#load(java.lang.String)
* @see org.eclipse.jetty.server.session.SessionStore#load(java.lang.String)
*/
@Override
public SessionData load(String id) throws Exception
@ -159,7 +159,7 @@ public class GCloudSessionDataStore extends AbstractSessionDataStore
}
/**
* @see org.eclipse.jetty.server.session.SessionDataStore#delete(java.lang.String)
* @see org.eclipse.jetty.server.session.SessionStore#delete(java.lang.String)
*/
@Override
public boolean delete(String id) throws Exception
@ -170,7 +170,7 @@ public class GCloudSessionDataStore extends AbstractSessionDataStore
}
/**
* @see org.eclipse.jetty.server.session.SessionDataStore#getExpired(Set)
* @see org.eclipse.jetty.server.session.SessionStore#getExpired(Set)
*/
@Override
public Set<String> doGetExpired(Set<String> candidates)
@ -264,7 +264,7 @@ public class GCloudSessionDataStore extends AbstractSessionDataStore
/**
* @see org.eclipse.jetty.server.session.SessionDataStore#exists(java.lang.String)
* @see org.eclipse.jetty.server.session.SessionStore#exists(java.lang.String)
*/
@Override
public boolean exists(String id) throws Exception
@ -290,7 +290,7 @@ public class GCloudSessionDataStore extends AbstractSessionDataStore
}
/**
* @see org.eclipse.jetty.server.session.AbstractSessionDataStore#doStore(java.lang.String, org.eclipse.jetty.server.session.SessionData, long)
* @see org.eclipse.jetty.server.session.AbstractSessionStore#doStore(java.lang.String, org.eclipse.jetty.server.session.SessionData, long)
*/
@Override
public void doStore(String id, SessionData data, long lastSaveTime) throws Exception
@ -431,7 +431,7 @@ public class GCloudSessionDataStore extends AbstractSessionDataStore
}
/**
* @see org.eclipse.jetty.server.session.SessionDataStore#isPassivating()
* @see org.eclipse.jetty.server.session.SessionStore#isPassivating()
*/
@Override
public boolean isPassivating()

View File

@ -25,6 +25,7 @@ import org.eclipse.jetty.security.HashLoginService;
import org.eclipse.jetty.server.Server;
import org.eclipse.jetty.server.handler.AllowSymLinkAliasChecker;
import org.eclipse.jetty.server.session.DefaultSessionIdManager;
import org.eclipse.jetty.server.session.DefaultSessionCache;
import org.eclipse.jetty.server.session.SessionHandler;
import org.eclipse.jetty.webapp.WebAppContext;
@ -58,10 +59,12 @@ public class GCloudSessionTester
webapp.setContextPath("/");
webapp.setWar("../../jetty-distribution/target/distribution/demo-base/webapps/test.war");
webapp.addAliasCheck(new AllowSymLinkAliasChecker());
GCloudSessionManager mgr = new GCloudSessionManager();
mgr.getSessionDataStore().setGCloudConfiguration(config);
mgr.setSessionIdManager(idmgr);
webapp.setSessionHandler(new SessionHandler(mgr));
GCloudSessionStore ds = new GCloudSessionStore();
ds.setGCloudConfiguration(config);
DefaultSessionCache ss = new DefaultSessionCache(webapp.getSessionHandler());
webapp.getSessionHandler().setSessionStore(ss);
ss.setSessionStore(ds);
webapp.getSessionHandler().setSessionIdManager(idmgr);
// A WebAppContext is a ContextHandler as well so it needs to be set to
// the server so it is aware of where to send the appropriate requests.

View File

@ -0,0 +1,26 @@
<?xml version="1.0"?>
<!DOCTYPE Configure PUBLIC "-//Jetty//Configure//EN" "http://www.eclipse.org/jetty/configure_9_3.dtd">
<Configure id="Server" class="org.eclipse.jetty.server.Server">
<!-- ===================================================================== -->
<!-- Get a reference to the default local cache. -->
<!-- ===================================================================== -->
<New id="local" class="org.infinispan.manager.DefaultCacheManager">
<Get id="cache" name="cache"></Get>
</New>
<!-- ===================================================================== -->
<!-- Configure a factory for InfinispanSessionStore using the -->
<!-- Infinispan DefaultCache -->
<!-- ===================================================================== -->
<Call name="addBean">
<New class="org.eclipse.jetty.server.session.InfinispanSessionStoreFactory">
<Set name="cache"><Ref id="cache"/></Set>
<Set name="infinispanIdleTimeoutSec"><Property name="jetty.session.infinispanIdleTimeout.seconds" default="0" /></Set>
<Set name="gracePeriod"><Property name="jetty.session.gracePeriod.seconds" default="3600" /></Set>
</New>
</Call>
</Configure>

View File

@ -0,0 +1,28 @@
<?xml version="1.0"?>
<!DOCTYPE Configure PUBLIC "-//Jetty//Configure//EN" "http://www.eclipse.org/jetty/configure_9_3.dtd">
<Configure id="Server" class="org.eclipse.jetty.server.Server">
<!-- ===================================================================== -->
<!-- Get a reference to the remote cache. -->
<!-- ===================================================================== -->
<New id="hotrodMgr" class="org.infinispan.client.hotrod.RemoteCacheManager">
<Call id="remoteCache" name="getCache">
<Arg><Property name="jetty.session.remoteInfinispanCache.name" default="sessions"/></Arg>
</Call>
</New>
<!-- ===================================================================== -->
<!-- Configure a factory for InfinispanSessionStore using the -->
<!-- Infinispan DefaultCache -->
<!-- ===================================================================== -->
<Call name="addBean">
<New class="org.eclipse.jetty.server.session.InfinispanSessionStoreFactory">
<Set name="cache"><Ref id="remoteCache"/></Set>
<Set name="infinispanIdleTimeoutSec"><Property name="jetty.session.infinispanIdleTimeout.seconds" default="0" /></Set>
<Set name="gracePeriod"><Property name="jetty.session.gracePeriod.seconds" default="3600" /></Set>
</New>
</Call>
</Configure>

View File

@ -0,0 +1,10 @@
[description]
Enable use of DefaultCache for session data storage
[name]
infinispan-session-default
[xml]
etc/jetty-default-infinispan-session-store.xml

View File

@ -0,0 +1,12 @@
[description]
Enable use of HotRod remote cache for session data storage
[name]
infinispan-session-remote
[files]
https://raw.githubusercontent.com/eclipse/jetty.project/master/jetty-infinispan/src/main/infinispan-resources/hotrod-client.properties?id=${jetty.tag.version}|resources/hotrod-client.properties
[xml]
etc/jetty-remote-infinispan-session-store.xml

View File

@ -1,10 +1,12 @@
[description]
Enables an Infinispan Session Manager for session
persistance and/or clustering
Enables session data store in a remote Infinispan cache
[name]
infinispan-session-store
[depend]
annotations
webapp
session
infinispan-session-${cache-type}
[files]
maven://org.infinispan/infinispan-core/7.1.1.Final|lib/infinispan/infinispan-core-7.1.1.Final.jar
@ -23,3 +25,12 @@ Infinispan is an open source project hosted on Github and released under the Apa
http://infinispan.org/
http://www.apache.org/licenses/LICENSE-2.0.html
[ini]
cache-type=default
[ini-template]
#cache-type=remote
#jetty.session.remoteInfinispanCache.name=sessions
#jetty.session.infinispanIdleTimeout.seconds=0
#jetty.session.gracePeriod.seconds=3600

View File

@ -1,44 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE Configure PUBLIC "-//Jetty//Configure//EN" "http://www.eclipse.org/jetty/configure_9_3.dtd">
<Configure class="org.eclipse.jetty.webapp.WebAppContext">
<!-- ===================================================================== -->
<!-- Get a reference to the default local cache. -->
<!-- ===================================================================== -->
<New id="local" class="org.infinispan.manager.DefaultCacheManager">
<Get id="cache" name="cache"></Get>
</New>
<!-- ===================================================================== -->
<!-- Get a reference to a hotrod client for a remote cache. -->
<!-- Change the name of the cache to match your setup. -->
<!-- ===================================================================== -->
<!--
<New id="hotrodMgr" class="org.infinispan.client.hotrod.RemoteCacheManager">
<Call id="cache" name="getCache">
<Arg>sessions</Arg>
</Call>
</New>
-->
<Get name="sessionHandler">
<Set name="sessionManager">
<New class="org.eclipse.jetty.server.session.infinispan.InfinispanSessionManager">
<Set name="maxInactiveInterval">seconds</Set>
<Get name="sessionDataStore">
<Set name="cache">
<Ref id="cache"/>
</Set>
</Get>
<Get name="sessionStore">
<Set name="idlePassivationTimeoutSec">seconds</Set>
<Set name="expiryTimeoutSec">seconds</Set>
</Get>
</New>
</Set>
</Get>
</Configure>

View File

@ -0,0 +1 @@
infinispan.client.hotrod.marshaller=org.eclipse.jetty.session.infinispan.WebAppMarshaller

View File

@ -1,88 +0,0 @@
//
// ========================================================================
// Copyright (c) 1995-2016 Mort Bay Consulting Pty. Ltd.
// ------------------------------------------------------------------------
// All rights reserved. This program and the accompanying materials
// are made available under the terms of the Eclipse Public License v1.0
// and Apache License v2.0 which accompanies this distribution.
//
// The Eclipse Public License is available at
// http://www.eclipse.org/legal/epl-v10.html
//
// The Apache License v2.0 is available at
// http://www.opensource.org/licenses/apache2.0.php
//
// You may elect to redistribute this code under either of these licenses.
// ========================================================================
//
package org.eclipse.jetty.session.infinispan;
import org.eclipse.jetty.server.session.AbstractSessionStore;
import org.eclipse.jetty.server.session.MemorySessionStore;
import org.eclipse.jetty.server.session.SessionManager;
import org.eclipse.jetty.util.log.Log;
import org.eclipse.jetty.util.log.Logger;
/**
* InfinispanSessionManager
*
* Convenience class to create a MemorySessionStore and an InfinispanSessionDataStore.
*
*/
public class InfinispanSessionManager extends SessionManager
{
private final static Logger LOG = Log.getLogger("org.eclipse.jetty.server.session");
protected InfinispanSessionDataStore _sessionDataStore;
public InfinispanSessionManager()
{
setSessionStore(new MemorySessionStore(this));
_sessionDataStore = new InfinispanSessionDataStore();
}
/**
* Start the session manager.
*
* @see org.eclipse.jetty.server.session.SessionManager#doStart()
*/
@Override
public void doStart() throws Exception
{
if (_sessionIdManager == null)
throw new IllegalStateException("No session id manager defined");
((AbstractSessionStore)_sessionStore).setSessionDataStore(_sessionDataStore);
_sessionDataStore.setSessionIdManager(_sessionIdManager);
super.doStart();
}
/**
* Stop the session manager.
*
* @see org.eclipse.jetty.server.session.SessionManager#doStop()
*/
@Override
public void doStop() throws Exception
{
super.doStop();
}
public InfinispanSessionDataStore getSessionDataStore()
{
return _sessionDataStore;
}
}

View File

@ -25,18 +25,18 @@ import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicReference;
import org.eclipse.jetty.server.SessionIdManager;
import org.eclipse.jetty.server.session.AbstractSessionDataStore;
import org.eclipse.jetty.server.session.AbstractSessionStore;
import org.eclipse.jetty.server.session.SessionData;
import org.eclipse.jetty.util.log.Log;
import org.eclipse.jetty.util.log.Logger;
import org.infinispan.commons.api.BasicCache;
/**
* InfinispanSessionDataStore
* InfinispanSessionStore
*
*
*/
public class InfinispanSessionDataStore extends AbstractSessionDataStore
public class InfinispanSessionStore extends AbstractSessionStore
{
private final static Logger LOG = Log.getLogger("org.eclipse.jetty.server.session");
@ -47,7 +47,6 @@ public class InfinispanSessionDataStore extends AbstractSessionDataStore
*/
private BasicCache<String, Object> _cache;
private SessionIdManager _idMgr = null;
private int _infinispanIdleTimeoutSec;
@ -74,14 +73,10 @@ public class InfinispanSessionDataStore extends AbstractSessionDataStore
this._cache = cache;
}
public void setSessionIdManager (SessionIdManager idMgr)
{
_idMgr = idMgr;
}
/**
* @see org.eclipse.jetty.server.session.SessionDataStore#load(String)
* @see org.eclipse.jetty.server.session.SessionStore#load(String)
*/
@Override
public SessionData load(String id) throws Exception
@ -119,7 +114,7 @@ public class InfinispanSessionDataStore extends AbstractSessionDataStore
}
/**
* @see org.eclipse.jetty.server.session.SessionDataStore#delete(String)
* @see org.eclipse.jetty.server.session.SessionStore#delete(String)
*/
@Override
public boolean delete(String id) throws Exception
@ -130,7 +125,7 @@ public class InfinispanSessionDataStore extends AbstractSessionDataStore
}
/**
* @see org.eclipse.jetty.server.session.SessionDataStore#getExpired(Set)
* @see org.eclipse.jetty.server.session.SessionStore#getExpired(Set)
*/
@Override
public Set<String> doGetExpired(Set<String> candidates)
@ -201,7 +196,7 @@ public class InfinispanSessionDataStore extends AbstractSessionDataStore
}
/**
* @see org.eclipse.jetty.server.session.AbstractSessionDataStore#doStore(String, SessionData, long)
* @see org.eclipse.jetty.server.session.AbstractSessionStore#doStore(String, SessionData, long)
*/
@Override
public void doStore(String id, SessionData data, long lastSaveTime) throws Exception
@ -229,7 +224,7 @@ public class InfinispanSessionDataStore extends AbstractSessionDataStore
/**
* @see org.eclipse.jetty.server.session.SessionDataStore#isPassivating()
* @see org.eclipse.jetty.server.session.SessionStore#isPassivating()
*/
@Override
public boolean isPassivating()
@ -253,7 +248,7 @@ public class InfinispanSessionDataStore extends AbstractSessionDataStore
/**
* @see org.eclipse.jetty.server.session.SessionDataStore#exists(java.lang.String)
* @see org.eclipse.jetty.server.session.SessionStore#exists(java.lang.String)
*/
@Override
public boolean exists(String id) throws Exception

View File

@ -0,0 +1,90 @@
//
// ========================================================================
// Copyright (c) 1995-2016 Mort Bay Consulting Pty. Ltd.
// ------------------------------------------------------------------------
// All rights reserved. This program and the accompanying materials
// are made available under the terms of the Eclipse Public License v1.0
// and Apache License v2.0 which accompanies this distribution.
//
// The Eclipse Public License is available at
// http://www.eclipse.org/legal/epl-v10.html
//
// The Apache License v2.0 is available at
// http://www.opensource.org/licenses/apache2.0.php
//
// You may elect to redistribute this code under either of these licenses.
// ========================================================================
//
package org.eclipse.jetty.session.infinispan;
import org.eclipse.jetty.server.session.AbstractSessionStoreFactory;
import org.eclipse.jetty.server.session.SessionHandler;
import org.eclipse.jetty.server.session.SessionStore;
import org.infinispan.commons.api.BasicCache;
/**
* InfinispanSessionStoreFactory
*
*
*/
public class InfinispanSessionStoreFactory extends AbstractSessionStoreFactory
{
int _infinispanIdleTimeoutSec;
BasicCache<String, Object> _cache;
/**
* @return the infinispanIdleTimeoutSec
*/
public int getInfinispanIdleTimeoutSec()
{
return _infinispanIdleTimeoutSec;
}
/**
* @param infinispanIdleTimeoutSec the infinispanIdleTimeoutSec to set
*/
public void setInfinispanIdleTimeoutSec(int infinispanIdleTimeoutSec)
{
_infinispanIdleTimeoutSec = infinispanIdleTimeoutSec;
}
/**
* @see org.eclipse.jetty.server.session.SessionStoreFactory#getSessionStore(org.eclipse.jetty.server.session.SessionHandler)
*/
@Override
public SessionStore getSessionStore (SessionHandler handler) throws Exception
{
InfinispanSessionStore store = new InfinispanSessionStore();
store.setGracePeriodSec(getGracePeriodSec());
store.setInfinispanIdleTimeoutSec(getInfinispanIdleTimeoutSec());
store.setCache(getCache());
return store;
}
/**
* Get the clustered cache instance.
*
* @return the cache
*/
public BasicCache<String, Object> getCache()
{
return _cache;
}
/**
* Set the clustered cache instance.
*
* @param cache the cache
*/
public void setCache (BasicCache<String, Object> cache)
{
this._cache = cache;
}
}

View File

@ -0,0 +1,18 @@
<?xml version="1.0"?>
<!DOCTYPE Configure PUBLIC "-//Jetty//Configure//EN" "http://www.eclipse.org/jetty/configure_9_3.dtd">
<Configure id="Server" class="org.eclipse.jetty.server.Server">
<!-- ===================================================================== -->
<!-- Configure a factory for MongoSessionStores -->
<!-- ===================================================================== -->
<Call name="addBean">
<New class="org.eclipse.jetty.server.session.MongoSessionStoreFactory">
<Set name="dbName"><Property name="jetty.session.dbName" default="HttpSessions" /></Set>
<Set name="collectionName"><Property name="jetty.session.collectionName" default="jettySessions" /></Set>
<Set name="gracePeriod"><Property name="jetty.session.gracePeriod.seconds" default="3600" /></Set>
</New>
</Call>
</Configure>

View File

@ -1,8 +1,11 @@
[description]
Enables NoSql session management with a MongoDB driver.
[name]
mongo-session-store
[depend]
webapp
sessions
[files]
maven://org.mongodb/mongo-java-driver/2.6.1|lib/nosql/mongo-java-driver-2.6.1.jar
@ -17,3 +20,12 @@ The java driver for the MongoDB document-based database system is hosted on GitH
http://www.mongodb.org/
http://www.apache.org/licenses/LICENSE-2.0.html
[xml]
etc/jetty-mongo-session-store.xml
[ini]
#jetty.session.dbName=HttpSessions
#jetty.session.collectionName=jettySessions
#jetty.session.gracePeriod.seconds=3600

View File

@ -1,37 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE Configure PUBLIC "-//Jetty//Configure//EN" "http://www.eclipse.org/jetty/configure_9_3.dtd">
<Configure class="org.eclipse.jetty.webapp.WebAppContext">
<!-- ===================================================================== -->
<!-- Get a reference to the session collection -->
<!-- ===================================================================== -->
<New class="com.mongodb.Mongo">
<Call id="sessiondb" name="getDB">
<Arg>HttpSessions</Arg>
<Call id="sessioncollection" name="getCollection">
<Arg>sessions</Arg>
</Call>
</Call>
</New>
<Get name="sessionHandler">
<Set name="sessionManager">
<New class="org.eclipse.jetty.nosql.mongodb.MongoSessionManager">
<Set name="maxInactiveInterval">seconds</Set>
<Get name="sessionDataStore">
<Set name="dBCollection">
<Ref id="sessioncollection"/>
</Set>
</Get>
<Get name="sessionStore">
<Set name="idlePassivationTimeoutSec">seconds</Set>
<Set name="expiryTimeoutSec">seconds</Set>
</Get>
</New>
</Set>
</Get>
</Configure>

View File

@ -22,16 +22,16 @@ package org.eclipse.jetty.nosql;
import java.util.HashSet;
import java.util.Set;
import org.eclipse.jetty.server.session.AbstractSessionDataStore;
import org.eclipse.jetty.server.session.AbstractSessionStore;
import org.eclipse.jetty.server.session.SessionData;
/**
* NoSqlSessionDataStore
* NoSqlSessionStore
*
*
*/
public abstract class NoSqlSessionDataStore extends AbstractSessionDataStore
public abstract class NoSqlSessionStore extends AbstractSessionStore
{
public class NoSqlSessionData extends SessionData

View File

@ -1,138 +0,0 @@
//
// ========================================================================
// Copyright (c) 1995-2016 Mort Bay Consulting Pty. Ltd.
// ------------------------------------------------------------------------
// All rights reserved. This program and the accompanying materials
// are made available under the terms of the Eclipse Public License v1.0
// and Apache License v2.0 which accompanies this distribution.
//
// The Eclipse Public License is available at
// http://www.eclipse.org/legal/epl-v10.html
//
// The Apache License v2.0 is available at
// http://www.opensource.org/licenses/apache2.0.php
//
// You may elect to redistribute this code under either of these licenses.
// ========================================================================
//
package org.eclipse.jetty.nosql.mongodb;
import com.mongodb.DBCollection;
import com.mongodb.MongoException;
import java.net.UnknownHostException;
import org.eclipse.jetty.server.SessionIdManager;
import org.eclipse.jetty.server.session.AbstractSessionStore;
import org.eclipse.jetty.server.session.MemorySessionStore;
import org.eclipse.jetty.server.session.SessionManager;
import org.eclipse.jetty.util.annotation.ManagedAttribute;
import org.eclipse.jetty.util.annotation.ManagedObject;
import org.eclipse.jetty.util.log.Log;
import org.eclipse.jetty.util.log.Logger;
/**
* MongoSessionManager
* <p>
* Clustered session manager using MongoDB as the shared DB instance.
* The document model is an outer object that contains the elements:
* <ul>
* <li>"id" : session_id </li>
* <li>"created" : create_time </li>
* <li>"accessed": last_access_time </li>
* <li>"maxIdle" : max_idle_time setting as session was created </li>
* <li>"expiry" : time at which session should expire </li>
* <li>"valid" : session_valid </li>
* <li>"context" : a nested object containing 1 nested object per context for which the session id is in use
* </ul>
* Each of the nested objects inside the "context" element contains:
* <ul>
* <li>unique_context_name : nested object containing name:value pairs of the session attributes for that context</li>
* </ul>
* <p>
* One of the name:value attribute pairs will always be the special attribute "__metadata__". The value
* is an object representing a version counter which is incremented every time the attributes change.
* </p>
* <p>
* For example:
* <pre>
* { "_id" : ObjectId("52845534a40b66410f228f23"),
* "accessed" : NumberLong("1384818548903"),
* "maxIdle" : 1,
* "context" : { "::/contextA" : { "A" : "A",
* "__metadata__" : { "version" : NumberLong(2) }
* },
* "::/contextB" : { "B" : "B",
* "__metadata__" : { "version" : NumberLong(1) }
* }
* },
* "created" : NumberLong("1384818548903"),
* "expiry" : NumberLong("1384818549903"),
* "id" : "w01ijx2vnalgv1sqrpjwuirprp7",
* "valid" : true
* }
* </pre>
* <p>
* In MongoDB, the nesting level is indicated by "." separators for the key name. Thus to
* interact with a session attribute, the key is composed of:
* <code>"context".unique_context_name.attribute_name</code>
* Eg <code>"context"."::/contextA"."A"</code>
*/
@ManagedObject("Mongo Session Manager")
public class MongoSessionManager extends SessionManager
{
private final static Logger LOG = Log.getLogger("org.eclipse.jetty.server.session");
/**
* Access to MongoDB
*/
private DBCollection _dbSessions;
private MongoSessionDataStore _sessionDataStore;
/* ------------------------------------------------------------ */
public MongoSessionManager() throws UnknownHostException, MongoException
{
setSessionStore(new MemorySessionStore(this));
_sessionDataStore = new MongoSessionDataStore();
}
/*------------------------------------------------------------ */
@Override
public void doStart() throws Exception
{
((AbstractSessionStore)_sessionStore).setSessionDataStore(_sessionDataStore);
super.doStart();
}
public MongoSessionDataStore getSessionDataStore()
{
return _sessionDataStore;
}
/*------------------------------------------------------------ */
/**
* returns the total number of session objects in the session store
*
* the count() operation itself is optimized to perform on the server side
* and avoid loading to client side.
* @return the session store count
*/
@ManagedAttribute("total number of known sessions in the store")
public long getSessionStoreCount()
{
return _dbSessions.find().count();
}
}

View File

@ -36,14 +36,14 @@ import java.util.Map;
import java.util.Set;
import java.util.concurrent.atomic.AtomicReference;
import org.eclipse.jetty.nosql.NoSqlSessionDataStore;
import org.eclipse.jetty.nosql.NoSqlSessionStore;
import org.eclipse.jetty.server.session.SessionData;
import org.eclipse.jetty.util.ClassLoadingObjectInputStream;
import org.eclipse.jetty.util.log.Log;
import org.eclipse.jetty.util.log.Logger;
/**
* MongoSessionDataStore
* MongoSessionStore
*
* The document model is an outer object that contains the elements:
* <ul>
@ -88,7 +88,7 @@ import org.eclipse.jetty.util.log.Logger;
* <code>"context".unique_context_name.attribute_name</code>
* Eg <code>"context"."::/contextA"."A"</code>
*/
public class MongoSessionDataStore extends NoSqlSessionDataStore
public class MongoSessionStore extends NoSqlSessionStore
{
private final static Logger LOG = Log.getLogger("org.eclipse.jetty.server.session");
@ -166,7 +166,7 @@ public class MongoSessionDataStore extends NoSqlSessionDataStore
/**
* @see org.eclipse.jetty.server.session.SessionDataStore#load(String)
* @see org.eclipse.jetty.server.session.SessionStore#load(String)
*/
@Override
public SessionData load(String id) throws Exception
@ -258,7 +258,7 @@ public class MongoSessionDataStore extends NoSqlSessionDataStore
}
/**
* @see org.eclipse.jetty.server.session.SessionDataStore#delete(String)
* @see org.eclipse.jetty.server.session.SessionStore#delete(String)
*/
@Override
public boolean delete(String id) throws Exception
@ -318,7 +318,7 @@ public class MongoSessionDataStore extends NoSqlSessionDataStore
/**
* @see org.eclipse.jetty.server.session.SessionDataStore#exists(java.lang.String)
* @see org.eclipse.jetty.server.session.SessionStore#exists(java.lang.String)
*/
@Override
public boolean exists(String id) throws Exception
@ -345,7 +345,7 @@ public class MongoSessionDataStore extends NoSqlSessionDataStore
/**
* @see org.eclipse.jetty.server.session.SessionDataStore#getExpired(Set)
* @see org.eclipse.jetty.server.session.SessionStore#getExpired(Set)
*/
@Override
public Set<String> doGetExpired(Set<String> candidates)
@ -409,7 +409,7 @@ public class MongoSessionDataStore extends NoSqlSessionDataStore
}
/**
* @see org.eclipse.jetty.server.session.AbstractSessionDataStore#doStore(String, SessionData, long)
* @see org.eclipse.jetty.server.session.AbstractSessionStore#doStore(String, SessionData, long)
*/
@Override
public void doStore(String id, SessionData data, long lastSaveTime) throws Exception
@ -648,7 +648,7 @@ public class MongoSessionDataStore extends NoSqlSessionDataStore
/**
* @see org.eclipse.jetty.server.session.SessionDataStore#isPassivating()
* @see org.eclipse.jetty.server.session.SessionStore#isPassivating()
*/
@Override
public boolean isPassivating()

View File

@ -0,0 +1,90 @@
//
// ========================================================================
// Copyright (c) 1995-2016 Mort Bay Consulting Pty. Ltd.
// ------------------------------------------------------------------------
// All rights reserved. This program and the accompanying materials
// are made available under the terms of the Eclipse Public License v1.0
// and Apache License v2.0 which accompanies this distribution.
//
// The Eclipse Public License is available at
// http://www.eclipse.org/legal/epl-v10.html
//
// The Apache License v2.0 is available at
// http://www.opensource.org/licenses/apache2.0.php
//
// You may elect to redistribute this code under either of these licenses.
// ========================================================================
//
package org.eclipse.jetty.nosql.mongodb;
import java.net.UnknownHostException;
import org.eclipse.jetty.server.session.AbstractSessionStoreFactory;
import org.eclipse.jetty.server.session.SessionHandler;
import org.eclipse.jetty.server.session.SessionStore;
import com.mongodb.Mongo;
import com.mongodb.MongoException;
/**
* MongoSessionStoreFactory
*
*
*/
public class MongoSessionStoreFactory extends AbstractSessionStoreFactory
{
String _dbName;
String _collectionName;
/**
* @return the dbName
*/
public String getDbName()
{
return _dbName;
}
/**
* @param dbName the dbName to set
*/
public void setDbName(String dbName)
{
_dbName = dbName;
}
/**
* @return the collectionName
*/
public String getCollectionName()
{
return _collectionName;
}
/**
* @param collectionName the collectionName to set
*/
public void setCollectionName(String collectionName)
{
_collectionName = collectionName;
}
/**
* @throws MongoException
* @throws UnknownHostException
* @see org.eclipse.jetty.server.session.SessionStoreFactory#getSessionStore(org.eclipse.jetty.server.session.SessionHandler)
*/
@Override
public SessionStore getSessionStore(SessionHandler handler) throws Exception
{
MongoSessionStore store = new MongoSessionStore();
store.setGracePeriodSec(getGracePeriodSec());
store.setDBCollection(new Mongo().getDB(getDbName()).getCollection(getCollectionName()));
return store;
}
}

View File

@ -1,64 +0,0 @@
//
// ========================================================================
// Copyright (c) 1995-2016 Mort Bay Consulting Pty. Ltd.
// ------------------------------------------------------------------------
// All rights reserved. This program and the accompanying materials
// are made available under the terms of the Eclipse Public License v1.0
// and Apache License v2.0 which accompanies this distribution.
//
// The Eclipse Public License is available at
// http://www.eclipse.org/legal/epl-v10.html
//
// The Apache License v2.0 is available at
// http://www.opensource.org/licenses/apache2.0.php
//
// You may elect to redistribute this code under either of these licenses.
// ========================================================================
//
package org.eclipse.jetty.nosql.mongodb.jmx;
import org.eclipse.jetty.nosql.mongodb.MongoSessionManager;
import org.eclipse.jetty.server.handler.AbstractHandlerContainer;
import org.eclipse.jetty.server.handler.ContextHandler;
import org.eclipse.jetty.server.session.SessionHandler;
import org.eclipse.jetty.server.session.jmx.SessionManagerMBean;
import org.eclipse.jetty.util.annotation.ManagedObject;
@ManagedObject("Mongo Session Manager MBean")
public class MongoSessionManagerMBean extends SessionManagerMBean
{
public MongoSessionManagerMBean(Object managedObject)
{
super(managedObject);
}
/* ------------------------------------------------------------ */
public String getObjectContextBasis()
{
if (_managed != null && _managed instanceof MongoSessionManager)
{
MongoSessionManager manager = (MongoSessionManager)_managed;
String basis = null;
SessionHandler handler = manager.getSessionHandler();
if (handler != null)
{
ContextHandler context =
AbstractHandlerContainer.findContainerOf(handler.getServer(),
ContextHandler.class,
handler);
if (context != null)
basis = getContextName(context);
}
if (basis != null)
return basis;
}
return super.getObjectContextBasis();
}
}

View File

@ -1,23 +0,0 @@
//
// ========================================================================
// Copyright (c) 1995-2016 Mort Bay Consulting Pty. Ltd.
// ------------------------------------------------------------------------
// All rights reserved. This program and the accompanying materials
// are made available under the terms of the Eclipse Public License v1.0
// and Apache License v2.0 which accompanies this distribution.
//
// The Eclipse Public License is available at
// http://www.eclipse.org/legal/epl-v10.html
//
// The Apache License v2.0 is available at
// http://www.opensource.org/licenses/apache2.0.php
//
// You may elect to redistribute this code under either of these licenses.
// ========================================================================
//
/**
* Jetty NoSql : MongoDB Sessions JMX Integration
*/
package org.eclipse.jetty.nosql.mongodb.jmx;

View File

@ -329,15 +329,15 @@ public class QuickStartDescriptorGenerator
}
//session-config
if (_webApp.getSessionHandler().getSessionManager() != null)
if (_webApp.getSessionHandler() != null)
{
out.openTag("session-config");
int maxInactiveSec = _webApp.getSessionHandler().getSessionManager().getMaxInactiveInterval();
int maxInactiveSec = _webApp.getSessionHandler().getMaxInactiveInterval();
out.tag("session-timeout", (maxInactiveSec==0?"0":Integer.toString(maxInactiveSec/60)));
//cookie-config
SessionCookieConfig cookieConfig = _webApp.getSessionHandler().getSessionManager().getSessionCookieConfig();
SessionCookieConfig cookieConfig = _webApp.getSessionHandler().getSessionCookieConfig();
if (cookieConfig != null)
{
out.openTag("cookie-config");
@ -360,7 +360,7 @@ public class QuickStartDescriptorGenerator
}
// tracking-modes
Set<SessionTrackingMode> modes =_webApp. getSessionHandler().getSessionManager().getEffectiveSessionTrackingModes();
Set<SessionTrackingMode> modes =_webApp. getSessionHandler().getEffectiveSessionTrackingModes();
if (modes != null)
{
for (SessionTrackingMode mode:modes)

View File

@ -118,7 +118,7 @@ public abstract class LoginAuthenticator implements Authenticator
s.renewId(request);
s.setAttribute(Session.SESSION_CREATED_SECURE, Boolean.TRUE);
if (s.isIdChanged() && response != null && (response instanceof Response))
((Response)response).addCookie(s.getSessionManager().getSessionCookie(s, request.getContextPath(), request.isSecure()));
((Response)response).addCookie(s.getSessionHandler().getSessionCookie(s, request.getContextPath(), request.isSecure()));
LOG.debug("renew {}->{}",oldId,s.getId());
}
else

View File

@ -0,0 +1,17 @@
<?xml version="1.0"?>
<!DOCTYPE Configure PUBLIC "-//Jetty//Configure//EN" "http://www.eclipse.org/jetty/configure_9_3.dtd">
<Configure id="Server" class="org.eclipse.jetty.server.Server">
<!-- ===================================================================== -->
<!-- Configure a factory for in-memory Session objects -->
<!-- ===================================================================== -->
<Call name="addBean">
<New class="org.eclipse.jetty.server.session.DefaultSessionCacheFactory">
<Set name="idlePassivationTimeoutSec"><Property name="jetty.session.idlePassivationTimeout.seconds" default="0" /></Set>
<Set name="passivateOnComplete"><Property name="jetty.session.passivateOnComplete" default="false" /></Set>
</New>
</Call>
</Configure>

View File

@ -0,0 +1,16 @@
<?xml version="1.0"?>
<!DOCTYPE Configure PUBLIC "-//Jetty//Configure//EN" "http://www.eclipse.org/jetty/configure_9_3.dtd">
<Configure id="Server" class="org.eclipse.jetty.server.Server">
<!-- ===================================================================== -->
<!-- Configure a factory for FileSessionStores -->
<!-- ===================================================================== -->
<Call name="addBean">
<New class="org.eclipse.jetty.server.session.FileSessionStoreFactory">
<Set name="deleteUnrestorableFiles"><Property name="jetty.session.deleteUnrestorableFiles" default="false" /></Set>
<Set name="storeDir"><Property name="jetty.session.storeDir"/></Set>
</New>
</Call>
</Configure>

View File

@ -0,0 +1,11 @@
<?xml version="1.0"?>
<!DOCTYPE Configure PUBLIC "-//Jetty//Configure//EN" "http://www.eclipse.org/jetty/configure_9_3.dtd">
<Configure id="Server" class="org.eclipse.jetty.server.Server">
<New id="databaseAdaptor" class="org.eclipse.jetty.server.session.DatabaseAdaptor">
<Set name="DatasourceName"><Property name="jetty.session.datasourceName" default="/jdbc/sessions" /></Set>
</New>
</Configure>

View File

@ -0,0 +1,13 @@
<?xml version="1.0"?>
<!DOCTYPE Configure PUBLIC "-//Jetty//Configure//EN" "http://www.eclipse.org/jetty/configure_9_3.dtd">
<Configure id="Server" class="org.eclipse.jetty.server.Server">
<New id="databaseAdaptor" class="org.eclipse.jetty.server.session.DatabaseAdaptor">
<Call name="setDriverInfo">
<Arg><Property name="jetty.session.driverClass"/></Arg>
<Arg><Property name="jetty.session.driverUrl"/></Arg>
</Call>
</New>
</Configure>

View File

@ -0,0 +1,63 @@
<?xml version="1.0"?>
<!DOCTYPE Configure PUBLIC "-//Jetty//Configure//EN" "http://www.eclipse.org/jetty/configure_9_3.dtd">
<Configure id="Server" class="org.eclipse.jetty.server.Server">
<!-- ===================================================================== -->
<!-- Configure a factory for JDBCSessionStores -->
<!-- ===================================================================== -->
<Call name="addBean">
<New class="org.eclipse.jetty.server.session.JDBCSessionStoreFactory">
<Set name="gracePeriod"><Property name="jetty.session.gracePeriod.seconds" default="3600" /></Set>
<Set name="databaseAdaptor">
<Ref id="databaseAdaptor"/>
</Set>
<Set name="sessionTableSchema">
<New
class="org.eclipse.jetty.server.session.JDBCSessionStore.SessionTableSchema">
<Set name="accessTimeColumn">
<Property name="jetty.sessionTableSchema.accessTimeColumn" default="accessTime" />
</Set>
<Set name="contextPathColumn">
<Property name="jetty.sessionTableSchema.contextPathColumn" default="contextPath" />
</Set>
<Set name="cookieTimeColumn">
<Property name="jetty.sessionTableSchema.cookieTimeColumn" default="cookieTime" />
</Set>
<Set name="createTimeColumn">
<Property name="jetty.sessionTableSchema.createTimeColumn" default="createTime" />
</Set>
<Set name="expiryTimeColumn">
<Property name="jetty.sessionTableSchema.expiryTimeColumn" default="expiryTime" />
</Set>
<Set name="lastAccessTimeColumn">
<Property name="jetty.sessionTableSchema.lastAccessTimeColumn" default="lastAccessTime" />
</Set>
<Set name="lastSavedTimeColumn">
<Property name="jetty.sessionTableSchema.lastSavedTimeColumn" default="lastSavedTime" />
</Set>
<Set name="idColumn">
<Property name="jetty.sessionTableSchema.idColumn" default="sessionId" />
</Set>
<Set name="lastNodeColumn">
<Property name="jetty.sessionTableSchema.lastNodeColumn" default="lastNode" />
</Set>
<Set name="virtualHostColumn">
<Property name="jetty.sessionTableSchema.virtualHostColumn" default="virtualHost" />
</Set>
<Set name="maxIntervalColumn">
<Property name="jetty.sessionTableSchema.maxIntervalColumn" default="maxInterval" />
</Set>
<Set name="mapColumn">
<Property name="jetty.sessionTableSchema.mapColumn" default="map" />
</Set>
<Set name="tableName">
<Property name="jetty.sessionTableSchema.table" default="JettySessions" />
</Set>
</New>
</Set>
</New>
</Call>
</Configure>

View File

@ -12,14 +12,14 @@
<Arg>
<Ref refid="Server"/>
</Arg>
<Set name="workerName"><Property name="jetty.sessionIdManager.workerName" default="node1"/></Set>
<Set name="workerName"><Property name="jetty.sessionIdManager.workerName"><Default>node<Env name="JETTY_WORKER_INSTANCE" default="0"/></Default></Property></Set>
<!-- ===================================================================== -->
<!-- Configure a session inspector to help with scavenging -->
<!-- Configure a session housekeeper to help with scavenging -->
<!-- ===================================================================== -->
<Set name="sessionInspector">
<New id="idMgr" class="org.eclipse.jetty.server.session.PeriodicSessionInspector">
<Set name="intervalSec"><Property name="jetty.sessionInspectionInterval.seconds" default="60"/></Set>
<Set name="sessionHouseKeeper">
<New class="org.eclipse.jetty.server.session.HouseKeeper">
<Set name="intervalSec"><Property name="jetty.sessionScavengeInterval.seconds" default="600"/></Set>
</New>
</Set>
</New>

View File

@ -0,0 +1,16 @@
[description]
Always in memory session objects.
[name]
default-session-cache
[xml]
etc/jetty-default-session-cache.xml
[ini-template]
#jetty.session.idlePassivationTimeout.seconds=0
#jetty.session.passivateOnComplete=false

View File

@ -0,0 +1,21 @@
[description]
Enables session storage in files.
[name]
file-session-store
[xml]
etc/jetty-file-session-store.xml
[depend]
sessions
[ini-template]
#jetty.session.storeDir=
#jetty.session.deleteUnrestorableFiles=false

View File

@ -0,0 +1,57 @@
[description]
Enables JDBC session storage.
[name]
jdbc-session-store
[xml]
etc/jetty-jdbc-session-store.xml
[depend]
sessions
sessions/jdbc/${db-connection-type}
[ini]
db-connection-type=datasource
##
##JDBC Session properties
##
#jetty.session.gracePeriod.seconds=3600
## Connection type:driver
#db-connection-type=driver
#jetty.session.driverClass=
#jetty.session.driverUrl=
## Connection type:Datasource
#db-connection-type=datasource
#jetty.session.datasourceName=/jdbc/sessions
## Session table schema
#jetty.sessionTableSchema.accessTimeColumn=accessTime
#jetty.sessionTableSchema.contextPathColumn=contextPath
#jetty.sessionTableSchema.cookieTimeColumn=cookieTime
#jetty.sessionTableSchema.createTimeColumn=createTime
#jetty.sessionTableSchema.expiryTimeColumn=expiryTime
#jetty.sessionTableSchema.lastAccessTimeColumn=lastAccessTime
#jetty.sessionTableSchema.lastSavedTimeColumn=lastSavedTime
#jetty.sessionTableSchema.idColumn="sessionId
#jetty.sessionTableSchema.lastNodeColumn=lastNode
#jetty.sessionTableSchema.virtualHostColumn=virtualHost
#jetty.sessionTableSchema.maxIntervalColumn=maxInterval
#jetty.sessionTableSchema.mapColumn=map
#jetty.sessionTableSchema.table=JettySessions

View File

@ -1,13 +1,20 @@
[description]
Enables basic sessions.
Enables session id management and scavenging.
[name]
sessions
[xml]
etc/jetty-sessions.xml
[ini-template]
## The name to uniquely identify this server instance
#jetty.sssionIdManager.workerName=node1
#jetty.sessionIdManager.workerName=node1
## How frequently sessions are inspected
#jetty.sessionInspectionInterval.seconds=60
## Period between runs of the session scavenger (in seconds)
#jetty.sessionScavengeInterval.seconds=60

View File

@ -0,0 +1,9 @@
[description]
JDBC Datasource connections for session storage
[name]
datasource
[xml]
etc/jetty-jdbc-session-store-datasource.xml

View File

@ -0,0 +1,9 @@
[description]
JDBC Driver connections for session storage
[name]
driver
[xml]
etc/jetty-jdbc-session-store-driver.xml

View File

@ -1,23 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE Configure PUBLIC "-//Jetty//Configure//EN" "http://www.eclipse.org/jetty/configure_9_3.dtd">
<Configure class="org.eclipse.jetty.webapp.WebAppContext">
<Get name="sessionHandler">
<Set name="sessionManager">
<New class="org.eclipse.jetty.server.session.FileSessionManager">
<Set name="maxInactiveInterval">seconds</Set>
<Get name="sessionDataStore">
<Set name="storeDir">filename</Set>
<Set name="deleteUnrestorableFiles">boolean</Set>
</Get>
<Get name="sessionStore">
<Set name="idlePassivationTimeoutSec">seconds</Set>
<Set name="expiryTimeoutSec">seconds</Set>
</Get>
</New>
</Set>
</Get>
</Configure>

View File

@ -1,50 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE Configure PUBLIC "-//Jetty//Configure//EN" "http://www.eclipse.org/jetty/configure_9_3.dtd">
<Configure class="org.eclipse.jetty.webapp.WebAppContext">
<Get name="sessionHandler">
<Set name="sessionManager">
<New class="org.eclipse.jetty.server.session.JDBCSessionManager">
<Set name="maxInactiveInterval">seconds</Set>
<Get name="sessionDataStore">
<Set name="gracePeriod">seconds</Set>
<Set name="loadAttempts">integer</Set>
<Set name="deleteUnloadableSessions">boolean</Set>
<Set name="databaseAdaptor">
<New class="org.eclipse.jetty.server.session.DatabaseAdaptor">
<!-- or alternative -->
<Call name="setDriverInfo">
<Arg>driver class</Arg>
<Arg>URL</Arg>
</Call>
</New>
</Set>
<Set name="sessionTableSchema">
<New class="org.eclipse.jetty.server.session.JDBCSessionDataStore.SessionTableSchema">
<Set name="tableName">JettySessions</Set>
<Set name="idColumn">sessionId</Set>
<Set name="accessTimeColumn">accessTime</Set>
<Set name="contextPathColumn">contextPath</Set>
<Set nmae="cookieTimeColumn">cookieTime</Set>
<Set name="createTimeColumn">createTime</Set>
<Set name="expiryTimeColumn">expiryTime</Set>
<Set name="lastAccessTimeColumn">lastAccessTime</Set>
<Set name="lastNodeColumn">lastNode</Set>
<Set name="lastSavedTimeColumn">lastSavedTime</Set>
<Set name="mapColumn">map</Set>
<Set name="maxIntervalColumn">maxInterval</Set>
<Set name="virtualHostColumn">virtualHost</Set>
</New>
</Get>
<Get name="sessionStore">
<Set name="idlePassivationTimeoutSec">seconds</Set>
<Set name="expiryTimeoutSec">seconds</Set>
</Get>
</New>
</Set>
</Get>
</Configure>

View File

@ -78,7 +78,7 @@ import org.eclipse.jetty.http.MimeTypes;
import org.eclipse.jetty.server.handler.ContextHandler;
import org.eclipse.jetty.server.handler.ContextHandler.Context;
import org.eclipse.jetty.server.session.Session;
import org.eclipse.jetty.server.session.SessionManager;
import org.eclipse.jetty.server.session.SessionHandler;
import org.eclipse.jetty.util.Attributes;
import org.eclipse.jetty.util.AttributesMap;
import org.eclipse.jetty.util.IO;
@ -194,7 +194,7 @@ public class Request implements HttpServletRequest
private Map<Object, HttpSession> _savedNewSessions;
private UserIdentity.Scope _scope;
private HttpSession _session;
private SessionManager _sessionManager;
private SessionHandler _sessionHandler;
private long _timeStamp;
private MultiPartInputStreamParser _multiPartInputStream; //if the request is a multi-part mime
private AsyncContextState _async;
@ -1478,7 +1478,7 @@ public class Request implements HttpServletRequest
if (getRemoteUser() != null)
s.setAttribute(Session.SESSION_CREATED_SECURE, Boolean.TRUE);
if (s.isIdChanged())
_channel.getResponse().addCookie(_sessionManager.getSessionCookie(s, getContextPath(), isSecure()));
_channel.getResponse().addCookie(_sessionHandler.getSessionCookie(s, getContextPath(), isSecure()));
}
return session.getId();
@ -1503,7 +1503,7 @@ public class Request implements HttpServletRequest
{
if (_session != null)
{
if (_sessionManager != null && !_sessionManager.isValid(_session))
if (_sessionHandler != null && !_sessionHandler.isValid(_session))
_session = null;
else
return _session;
@ -1515,11 +1515,11 @@ public class Request implements HttpServletRequest
if (getResponse().isCommitted())
throw new IllegalStateException("Response is committed");
if (_sessionManager == null)
if (_sessionHandler == null)
throw new IllegalStateException("No SessionManager");
_session = _sessionManager.newHttpSession(this);
HttpCookie cookie = _sessionManager.getSessionCookie(_session,getContextPath(),isSecure());
_session = _sessionHandler.newHttpSession(this);
HttpCookie cookie = _sessionHandler.getSessionCookie(_session,getContextPath(),isSecure());
if (cookie != null)
_channel.getResponse().addCookie(cookie);
@ -1530,9 +1530,9 @@ public class Request implements HttpServletRequest
/**
* @return Returns the sessionManager.
*/
public SessionManager getSessionManager()
public SessionHandler getSessionHandler()
{
return _sessionManager;
return _sessionHandler;
}
/* ------------------------------------------------------------ */
@ -1682,7 +1682,7 @@ public class Request implements HttpServletRequest
return false;
HttpSession session = getSession(false);
return (session != null && _sessionManager.getSessionIdManager().getId(_requestedSessionId).equals(_sessionManager.getId(session)));
return (session != null && _sessionHandler.getSessionIdManager().getId(_requestedSessionId).equals(_sessionHandler.getId(session)));
}
/* ------------------------------------------------------------ */
@ -1831,7 +1831,7 @@ public class Request implements HttpServletRequest
_requestedSessionIdFromCookie = false;
_secure=false;
_session = null;
_sessionManager = null;
_sessionHandler = null;
_scope = null;
_servletPath = null;
_timeStamp = 0;
@ -2185,9 +2185,9 @@ public class Request implements HttpServletRequest
* @param sessionManager
* The sessionManager to set.
*/
public void setSessionManager(SessionManager sessionManager)
public void setSessionHandler(SessionHandler sessionHandler)
{
_sessionManager = sessionManager;
_sessionHandler = sessionHandler;
}
/* ------------------------------------------------------------ */

View File

@ -53,7 +53,7 @@ import org.eclipse.jetty.http.PreEncodedHttpField;
import org.eclipse.jetty.io.RuntimeIOException;
import org.eclipse.jetty.server.handler.ContextHandler;
import org.eclipse.jetty.server.handler.ErrorHandler;
import org.eclipse.jetty.server.session.SessionManager;
import org.eclipse.jetty.server.session.SessionHandler;
import org.eclipse.jetty.util.QuotedStringTokenizer;
import org.eclipse.jetty.util.StringUtil;
import org.eclipse.jetty.util.URIUtil;
@ -391,7 +391,8 @@ public class Response implements HttpServletResponse
public String encodeURL(String url)
{
final Request request = _channel.getRequest();
SessionManager sessionManager = request.getSessionManager();
SessionHandler sessionManager = request.getSessionHandler();
if (sessionManager == null)
return url;

View File

@ -22,7 +22,7 @@ import java.util.Set;
import javax.servlet.http.HttpServletRequest;
import org.eclipse.jetty.server.session.SessionManager;
import org.eclipse.jetty.server.session.SessionHandler;
import org.eclipse.jetty.util.component.LifeCycle;
/**
@ -109,8 +109,8 @@ public interface SessionIdManager extends LifeCycle
/* ------------------------------------------------------------ */
/**
* Get the set of all session managers for this node
* @return the set of session managers
* Get the set of all session handlers for this node
* @return the set of session handlers
*/
public Set<SessionManager> getSessionManagers();
public Set<SessionHandler> getSessionHandlers();
}

View File

@ -0,0 +1,639 @@
//
// ========================================================================
// Copyright (c) 1995-2016 Mort Bay Consulting Pty. Ltd.
// ------------------------------------------------------------------------
// All rights reserved. This program and the accompanying materials
// are made available under the terms of the Eclipse Public License v1.0
// and Apache License v2.0 which accompanies this distribution.
//
// The Eclipse Public License is available at
// http://www.eclipse.org/legal/epl-v10.html
//
// The Apache License v2.0 is available at
// http://www.opensource.org/licenses/apache2.0.php
//
// You may elect to redistribute this code under either of these licenses.
// ========================================================================
//
package org.eclipse.jetty.server.session;
import java.util.Collections;
import java.util.Set;
import javax.servlet.http.HttpServletRequest;
import org.eclipse.jetty.util.StringUtil;
import org.eclipse.jetty.util.component.AbstractLifeCycle;
import org.eclipse.jetty.util.log.Log;
import org.eclipse.jetty.util.log.Logger;
import org.eclipse.jetty.util.thread.Locker.Lock;
/**
* AbstractSessionCache
*
* Basic behaviour for maintaining an in-memory store of Session objects and
* making sure that any backing SessionDataStore is kept in sync.
*/
public abstract class AbstractSessionCache extends AbstractLifeCycle implements SessionCache
{
final static Logger LOG = Log.getLogger("org.eclipse.jetty.server.session");
protected SessionStore _sessionStore;
protected final SessionHandler _handler;
protected SessionContext _context;
protected int _idlePassivationTimeoutSec;
private boolean _passivateOnComplete;
/**
* Create a new Session object from pre-existing session data
* @param data the session data
* @return a new Session object
*/
public abstract Session newSession (SessionData data);
/**
* Create a new Session for a request.
*
* @param request the request
* @param data the session data
* @return the new session
*/
public abstract Session newSession (HttpServletRequest request, SessionData data);
/**
* Get the session matching the key
* @param id session id
* @return the Session object matching the id
*/
public abstract Session doGet(String id);
/**
* Put the session into the map if it wasn't already there
*
* @param id the identity of the session
* @param session the session object
* @return null if the session wasn't already in the map, or the existing entry otherwise
*/
public abstract Session doPutIfAbsent (String id, Session session);
/**
* Replace the mapping from id to oldValue with newValue
* @param id the id
* @param oldValue the old value
* @param newValue the new value
* @return true if replacement was done
*/
public abstract boolean doReplace (String id, Session oldValue, Session newValue);
/**
* Remove the session with this identity from the store
* @param id the id
* @return true if removed false otherwise
*/
public abstract Session doDelete (String id);
/**
* PlaceHolder
*/
protected class PlaceHolderSession extends Session
{
/**
* @param data the session data
*/
public PlaceHolderSession(SessionData data)
{
super(data);
}
}
/**
*
*/
public AbstractSessionCache (SessionHandler manager)
{
_handler = manager;
}
/**
* @return the SessionManger
*/
public SessionHandler getSessionHandler()
{
return _handler;
}
/**
* @see org.eclipse.jetty.server.session.SessionCache#initialize(org.eclipse.jetty.server.session.SessionContext)
*/
public void initialize (SessionContext context)
{
if (isStarted())
throw new IllegalStateException("Context set after session store started");
_context = context;
}
/**
* @see org.eclipse.jetty.util.component.AbstractLifeCycle#doStart()
*/
@Override
protected void doStart() throws Exception
{
if (_sessionStore == null)
throw new IllegalStateException ("No session data store configured");
if (_handler == null)
throw new IllegalStateException ("No session manager");
if (_context == null)
throw new IllegalStateException ("No ContextId");
_sessionStore.initialize(_context);
_sessionStore.start();
super.doStart();
}
/**
* @see org.eclipse.jetty.util.component.AbstractLifeCycle#doStop()
*/
@Override
protected void doStop() throws Exception
{
_sessionStore.stop();
super.doStop();
}
/**
* @return the SessionStore or null if there isn't one
*/
public SessionStore getSessionStore()
{
return _sessionStore;
}
/**
* @see org.eclipse.jetty.server.session.SessionCache#setSessionStore(org.eclipse.jetty.server.session.SessionStore)
*/
public void setSessionStore(SessionStore sessionStore)
{
_sessionStore = sessionStore;
}
/**
* @see org.eclipse.jetty.server.session.SessionCache#getIdlePassivationTimeoutSec()
*/
public int getIdlePassivationTimeoutSec()
{
return _idlePassivationTimeoutSec;
}
/**
* @see org.eclipse.jetty.server.session.SessionCache#setIdlePassivationTimeoutSec(int)
*/
public void setIdlePassivationTimeoutSec(int idleTimeoutSec)
{
_idlePassivationTimeoutSec = idleTimeoutSec;
}
/**
* Get a session object.
*
* If the session object is not in this session store, try getting
* the data for it from a SessionDataStore associated with the
* session manager.
*
* @see org.eclipse.jetty.server.session.SessionCache#get(java.lang.String)
*/
@Override
public Session get(String id) throws Exception
{
Session session = null;
Exception ex = null;
while (true)
{
session = doGet(id);
if (_sessionStore == null)
break; //can't load any session data so just return null or the session object
if (session == null)
{
if (LOG.isDebugEnabled())
LOG.debug("Session not found locally, attempting to load");
//didn't get a session, try and create one and put in a placeholder for it
PlaceHolderSession phs = new PlaceHolderSession (new SessionData(id, null, null,0,0,0,0));
Lock phsLock = phs.lock();
Session s = doPutIfAbsent(id, phs);
if (s == null)
{
//My placeholder won, go ahead and load the full session data
try
{
session = loadSession(id);
if (session == null)
{
//session does not exist, remove the placeholder
doDelete(id);
phsLock.close();
break;
}
try (Lock lock = session.lock())
{
//swap it in instead of the placeholder
boolean success = doReplace(id, phs, session);
if (!success)
{
//something has gone wrong, it should have been our placeholder
doDelete(id);
session = null;
LOG.warn("Replacement of placeholder for session {} failed", id);
phsLock.close();
break;
}
else
{
//successfully swapped in the session
session.setTimeout (); //TODO start the session timer
phsLock.close();
break;
}
}
}
catch (Exception e)
{
ex = e; //remember a problem happened loading the session
doDelete(id); //remove the placeholder
phsLock.close();
session = null;
break;
}
}
else
{
//my placeholder didn't win, check the session returned
phsLock.close();
try (Lock lock = s.lock())
{
//is it a placeholder? or is it passivated? In both cases, chuck it away and start again
if (s.isPassivated() || s instanceof PlaceHolderSession)
{
session = null;
continue;
}
session = s;
break;
}
}
}
else
{
//check the session returned
try (Lock lock = session.lock())
{
//is it a placeholder? or is it passivated? In both cases, chuck it away and start again
if (session.isPassivated() || session instanceof PlaceHolderSession)
{
session = null;
continue;
}
//got the session
break;
}
}
}
if (ex != null)
throw ex;
return session;
}
/**
* Load the info for the session from the session data store
*
* @param id the id
* @return a Session object filled with data or null if the session doesn't exist
* @throws Exception
*/
private Session loadSession (String id)
throws Exception
{
SessionData data = null;
Session session = null;
if (_sessionStore == null)
return null; //can't load it
try
{
data =_sessionStore.load(id);
if (data == null) //session doesn't exist
return null;
session = newSession(data);
session.setSessionHandler(_handler);
return session;
}
catch (UnreadableSessionDataException e)
{
//can't load the session, delete it
_sessionStore.delete(id);
throw e;
}
}
/**
* Put the Session object back into the session store.
*
* This should be called by Session.complete when a request exists the session.
*
* If the session manager supports a session data store, write the
* session data through to the session data store.
*
* @see org.eclipse.jetty.server.session.SessionCache#put(java.lang.String, org.eclipse.jetty.server.session.Session)
*/
@Override
public void put(String id, Session session) throws Exception
{
if (id == null || session == null)
throw new IllegalArgumentException ("Put key="+id+" session="+(session==null?"null":session.getId()));
//if the session is new or data has changed write it to any backing store
try (Lock lock = session.lock())
{
session.setSessionHandler(_handler);
if (session.isPassivated())
throw new IllegalStateException ("Session "+id+" is passivated and cannot be saved");
if (!session.isValid())
return;
if (_sessionStore == null)
{
doPutIfAbsent(id, session); //ensure it is in our map
return;
}
if ((session.getRequests() <= 0))
{
//only save if all requests have finished
if (!_sessionStore.isPassivating())
{
//if our backing datastore isn't the passivating kind, just save the session
_sessionStore.store(id, session.getSessionData());
}
else
{
//backing store supports passivation
session.willPassivate();
_sessionStore.store(id, session.getSessionData());
session.setPassivated();
if (isPassivateOnComplete())
{
//throw out the passivated session object from the map
doDelete(id);
}
else
{
//reactivate the session
session.setActive();
session.didActivate();
}
}
}
doPutIfAbsent(id,session); //ensure it is in our map
}
}
/**
* Check to see if a session corresponding to the id exists.
*
* This method will first check with the object store. If it
* doesn't exist in the object store (might be passivated etc),
* it will check with the data store.
* @throws Exception
*
* @see org.eclipse.jetty.server.session.SessionCache#exists(java.lang.String)
*/
@Override
public boolean exists(String id) throws Exception
{
//try the object store first
Session s = doGet(id);
if (s != null)
{
try (Lock lock = s.lock())
{
//wait for the lock and check the validity of the session
return s.isValid();
}
}
//not there, so find out if session data exists for it
return _sessionStore.exists (id);
}
/**
* Remove a session object from this store and from any backing store.
*
*
* @see org.eclipse.jetty.server.session.SessionCache#delete(java.lang.String)
*/
@Override
public Session delete(String id) throws Exception
{
//get the session, if its not in memory, this will load it
Session session = get(id);
//Always delete it from the backing data store
if (_sessionStore != null)
{
boolean dsdel = _sessionStore.delete(id);
if (LOG.isDebugEnabled()) LOG.debug("Session {} deleted in db {}",id, dsdel);
}
//delete it from the session object store
if (session != null)
session.stopTimeout();
return doDelete(id);
}
/**
* @see org.eclipse.jetty.server.session.SessionCache#checkExpiration(Set)
*/
@Override
public Set<String> checkExpiration(Set<String> candidates)
{
if (!isStarted())
return Collections.emptySet();
if (LOG.isDebugEnabled())
LOG.debug("SessionStore checking expiration on {}", candidates);
return _sessionStore.getExpired(candidates);
}
/**
* If the SessionDataStore supports passivation,
* write the session to the backing data store.
*
* @param id identity of session to passivate
*/
@Override
public void passivateIdleSession(String id)
{
if (!isStarted())
return;
if (_sessionStore == null || !_sessionStore.isPassivating())
return; //no data store to passivate or it doesn't passivate
//get the session locally
Session s = doGet(id);
if (s == null)
{
LOG.warn("Session {} not in this session store", s);
return;
}
//lock the session during passivation
try (Lock lock = s.lock())
{
//check the session is still idle and that it doesn't have requests using it
if (s.isValid() && s.isIdleLongerThan(_idlePassivationTimeoutSec) && s.isActive() && (s.getRequests() <= 0))
{
//TODO - do we need to check that the session exists in the session data store
//before we passivate it? If it doesn't exist, we can assume another node
//invalidated it. If the session was new, it shouldn't have been idle passivated.
try
{
if (LOG.isDebugEnabled())
LOG.debug("Passivating idle session {}", id);
s.willPassivate();
_sessionStore.store(id, s.getSessionData());
s.setPassivated();
s.stopTimeout();
doDelete(id); //Take the session object of this session store
}
catch (Exception e)
{
LOG.warn("Passivation of idle session {} failed", id, e);
s.setPassivated(); //set it as passivated so it can't be used
doDelete(id); //detach it
}
}
}
}
/**
* @see org.eclipse.jetty.server.session.SessionCache#renewSessionId(java.lang.String, java.lang.String)
*/
public Session renewSessionId (String oldId, String newId)
throws Exception
{
if (StringUtil.isBlank(oldId))
throw new IllegalArgumentException ("Old session id is null");
if (StringUtil.isBlank(newId))
throw new IllegalArgumentException ("New session id is null");
Session session = get(oldId);
if (session == null)
return null;
try (Lock lock = session.lock())
{
session.checkValidForWrite(); //can't change id on invalid session
session.getSessionData().setId(newId);
session.getSessionData().setLastSaved(0); //pretend that the session has never been saved before to get a full save
session.getSessionData().setDirty(true); //ensure we will try to write the session out
doPutIfAbsent(newId, session); //put the new id into our map
doDelete (oldId); //take old out of map
if (_sessionStore != null)
{
_sessionStore.delete(oldId); //delete the session data with the old id
_sessionStore.store(newId, session.getSessionData()); //save the session data with the new id
}
LOG.info("Session id {} swapped for new id {}", oldId, newId);
return session;
}
}
public void setPassivateOnComplete (boolean passivateOnComplete)
{
_passivateOnComplete = passivateOnComplete;
}
public boolean isPassivateOnComplete ()
{
return _passivateOnComplete;
}
/**
* @see org.eclipse.jetty.server.session.SessionCache#newSession(javax.servlet.http.HttpServletRequest, java.lang.String, long, long)
*/
@Override
public Session newSession(HttpServletRequest request, String id, long time, long maxInactiveMs)
{
Session session = newSession(request, _sessionStore.newSessionData(id, time, time, time, maxInactiveMs));
session.setSessionHandler(_handler);
return session;
}
}

View File

@ -1,149 +0,0 @@
//
// ========================================================================
// Copyright (c) 1995-2016 Mort Bay Consulting Pty. Ltd.
// ------------------------------------------------------------------------
// All rights reserved. This program and the accompanying materials
// are made available under the terms of the Eclipse Public License v1.0
// and Apache License v2.0 which accompanies this distribution.
//
// The Eclipse Public License is available at
// http://www.eclipse.org/legal/epl-v10.html
//
// The Apache License v2.0 is available at
// http://www.opensource.org/licenses/apache2.0.php
//
// You may elect to redistribute this code under either of these licenses.
// ========================================================================
//
package org.eclipse.jetty.server.session;
import java.util.Set;
import org.eclipse.jetty.util.component.AbstractLifeCycle;
/**
* AbstractSessionDataStore
*
*
*/
public abstract class AbstractSessionDataStore extends AbstractLifeCycle implements SessionDataStore
{
protected SessionContext _context; //context associated with this session data store
protected int _gracePeriodSec = 60 * 60; //default of 1hr
protected long _lastExpiryCheckTime = 0; //last time in ms that getExpired was called
/**
* Store the session data persistently.
*
* @param id identity of session to store
* @param data info of the session
* @param lastSaveTime time of previous save or 0 if never saved
* @throws Exception if unable to store data
*/
public abstract void doStore(String id, SessionData data, long lastSaveTime) throws Exception;
/**
* Implemented by subclasses to resolve which sessions this node
* should attempt to expire.
*
* @param candidates the ids of sessions the SessionStore thinks has expired
* @return the reconciled set of session ids that this node should attempt to expire
*/
public abstract Set<String> doGetExpired (Set<String> candidates);
/**
* @see org.eclipse.jetty.server.session.SessionDataStore#initialize(org.eclipse.jetty.server.session.SessionContext)
*/
public void initialize (SessionContext context)
{
if (isStarted())
throw new IllegalStateException("Context set after SessionDataStore started");
_context = context;
}
/**
* @see org.eclipse.jetty.server.session.SessionDataStore#store(java.lang.String, org.eclipse.jetty.server.session.SessionData)
*/
@Override
public void store(String id, SessionData data) throws Exception
{
long lastSave = data.getLastSaved();
//set the last saved time to now
data.setLastSaved(System.currentTimeMillis());
try
{
//call the specific store method, passing in previous save time
doStore(id, data, lastSave);
data.setDirty(false); //only undo the dirty setting if we saved it
}
catch (Exception e)
{
//reset last save time if save failed
data.setLastSaved(lastSave);
throw e;
}
}
/**
* @see org.eclipse.jetty.server.session.SessionDataStore#getExpired(java.util.Set)
*/
@Override
public Set<String> getExpired(Set<String> candidates)
{
try
{
return doGetExpired (candidates);
}
finally
{
_lastExpiryCheckTime = System.currentTimeMillis();
}
}
/**
* @see org.eclipse.jetty.server.session.SessionDataStore#newSessionData(java.lang.String, long, long, long, long)
*/
@Override
public SessionData newSessionData(String id, long created, long accessed, long lastAccessed, long maxInactiveMs)
{
return new SessionData(id, _context.getCanonicalContextPath(), _context.getVhost(), created, accessed, lastAccessed, maxInactiveMs);
}
protected void checkStarted () throws IllegalStateException
{
if (isStarted())
throw new IllegalStateException("Already started");
}
@Override
protected void doStart() throws Exception
{
if (_context == null)
throw new IllegalStateException ("No SessionContext");
super.doStart();
}
public int getGracePeriodSec()
{
return _gracePeriodSec;
}
public void setGracePeriodSec(int sec)
{
_gracePeriodSec = sec;
}
}

View File

@ -19,621 +19,131 @@
package org.eclipse.jetty.server.session;
import java.util.Collections;
import java.util.Set;
import javax.servlet.http.HttpServletRequest;
import org.eclipse.jetty.util.StringUtil;
import org.eclipse.jetty.util.component.AbstractLifeCycle;
import org.eclipse.jetty.util.log.Log;
import org.eclipse.jetty.util.log.Logger;
import org.eclipse.jetty.util.thread.Locker.Lock;
/**
* AbstractSessionStore
*
* Basic behaviour for maintaining an in-memory store of Session objects and
* making sure that any backing SessionDataStore is kept in sync.
*
*/
public abstract class AbstractSessionStore extends AbstractLifeCycle implements SessionStore
{
final static Logger LOG = Log.getLogger("org.eclipse.jetty.server.session");
protected SessionDataStore _sessionDataStore;
protected final SessionManager _manager;
protected SessionContext _context;
protected int _idlePassivationTimeoutSec;
private boolean _passivateOnComplete;
protected SessionContext _context; //context associated with this session data store
protected int _gracePeriodSec = 60 * 60; //default of 1hr
protected long _lastExpiryCheckTime = 0; //last time in ms that getExpired was called
/**
* Create a new Session object from pre-existing session data
* @param data the session data
* @return a new Session object
*/
public abstract Session newSession (SessionData data);
/**
* Create a new Session for a request.
* Store the session data persistently.
*
* @param request the request
* @param data the session data
* @return the new session
* @param id identity of session to store
* @param data info of the session
* @param lastSaveTime time of previous save or 0 if never saved
* @throws Exception if unable to store data
*/
public abstract Session newSession (HttpServletRequest request, SessionData data);
public abstract void doStore(String id, SessionData data, long lastSaveTime) throws Exception;
/**
* Get the session matching the key
* @param id session id
* @return the Session object matching the id
*/
public abstract Session doGet(String id);
/**
* Put the session into the map if it wasn't already there
* Implemented by subclasses to resolve which sessions this node
* should attempt to expire.
*
* @param id the identity of the session
* @param session the session object
* @return null if the session wasn't already in the map, or the existing entry otherwise
* @param candidates the ids of sessions the SessionStore thinks has expired
* @return the reconciled set of session ids that this node should attempt to expire
*/
public abstract Session doPutIfAbsent (String id, Session session);
/**
* Replace the mapping from id to oldValue with newValue
* @param id the id
* @param oldValue the old value
* @param newValue the new value
* @return true if replacement was done
*/
public abstract boolean doReplace (String id, Session oldValue, Session newValue);
public abstract Set<String> doGetExpired (Set<String> candidates);
/**
* Remove the session with this identity from the store
* @param id the id
* @return true if removed false otherwise
*/
public abstract Session doDelete (String id);
/**
* PlaceHolder
*/
protected class PlaceHolderSession extends Session
{
/**
* @param data the session data
*/
public PlaceHolderSession(SessionData data)
{
super(data);
}
}
/**
*
*/
public AbstractSessionStore (SessionManager manager)
{
_manager = manager;
}
/**
* @return the SessionManger
*/
public SessionManager getSessionManager()
{
return _manager;
}
/**
* @see org.eclipse.jetty.server.session.SessionStore#initialize(org.eclipse.jetty.server.session.SessionContext)
*/
public void initialize (SessionContext context)
{
if (isStarted())
throw new IllegalStateException("Context set after session store started");
throw new IllegalStateException("Context set after SessionDataStore started");
_context = context;
}
/**
* @see org.eclipse.jetty.util.component.AbstractLifeCycle#doStart()
* @see org.eclipse.jetty.server.session.SessionStore#store(java.lang.String, org.eclipse.jetty.server.session.SessionData)
*/
@Override
public void store(String id, SessionData data) throws Exception
{
long lastSave = data.getLastSaved();
//set the last saved time to now
data.setLastSaved(System.currentTimeMillis());
try
{
//call the specific store method, passing in previous save time
doStore(id, data, lastSave);
data.setDirty(false); //only undo the dirty setting if we saved it
}
catch (Exception e)
{
//reset last save time if save failed
data.setLastSaved(lastSave);
throw e;
}
}
/**
* @see org.eclipse.jetty.server.session.SessionStore#getExpired(java.util.Set)
*/
@Override
public Set<String> getExpired(Set<String> candidates)
{
try
{
return doGetExpired (candidates);
}
finally
{
_lastExpiryCheckTime = System.currentTimeMillis();
}
}
/**
* @see org.eclipse.jetty.server.session.SessionStore#newSessionData(java.lang.String, long, long, long, long)
*/
@Override
public SessionData newSessionData(String id, long created, long accessed, long lastAccessed, long maxInactiveMs)
{
return new SessionData(id, _context.getCanonicalContextPath(), _context.getVhost(), created, accessed, lastAccessed, maxInactiveMs);
}
protected void checkStarted () throws IllegalStateException
{
if (isStarted())
throw new IllegalStateException("Already started");
}
@Override
protected void doStart() throws Exception
{
if (_sessionDataStore == null)
throw new IllegalStateException ("No session data store configured");
if (_manager == null)
throw new IllegalStateException ("No session manager");
if (_context == null)
throw new IllegalStateException ("No ContextId");
_sessionDataStore.initialize(_context);
_sessionDataStore.start();
throw new IllegalStateException ("No SessionContext");
super.doStart();
}
/**
* @see org.eclipse.jetty.util.component.AbstractLifeCycle#doStop()
*/
@Override
protected void doStop() throws Exception
public int getGracePeriodSec()
{
_sessionDataStore.stop();
super.doStop();
return _gracePeriodSec;
}
/**
* @return the SessionDataStore or null if there isn't one
*/
public SessionDataStore getSessionDataStore()
public void setGracePeriodSec(int sec)
{
return _sessionDataStore;
_gracePeriodSec = sec;
}
/**
* @param sessionDataStore the session datastore
*/
public void setSessionDataStore(SessionDataStore sessionDataStore)
{
_sessionDataStore = sessionDataStore;
}
/**
* @see org.eclipse.jetty.server.session.SessionStore#getIdlePassivationTimeoutSec()
*/
public int getIdlePassivationTimeoutSec()
{
return _idlePassivationTimeoutSec;
}
/**
* @see org.eclipse.jetty.server.session.SessionStore#setIdlePassivationTimeoutSec(int)
*/
public void setIdlePassivationTimeoutSec(int idleTimeoutSec)
{
_idlePassivationTimeoutSec = idleTimeoutSec;
}
/**
* Get a session object.
*
* If the session object is not in this session store, try getting
* the data for it from a SessionDataStore associated with the
* session manager.
*
* @see org.eclipse.jetty.server.session.SessionStore#get(java.lang.String)
*/
@Override
public Session get(String id) throws Exception
{
Session session = null;
Exception ex = null;
while (true)
{
session = doGet(id);
if (_sessionDataStore == null)
break; //can't load any session data so just return null or the session object
if (session == null)
{
if (LOG.isDebugEnabled())
LOG.debug("Session not found locally, attempting to load");
//didn't get a session, try and create one and put in a placeholder for it
PlaceHolderSession phs = new PlaceHolderSession (new SessionData(id, null, null,0,0,0,0));
Lock phsLock = phs.lock();
Session s = doPutIfAbsent(id, phs);
if (s == null)
{
//My placeholder won, go ahead and load the full session data
try
{
session = loadSession(id);
if (session == null)
{
//session does not exist, remove the placeholder
doDelete(id);
phsLock.close();
break;
}
try (Lock lock = session.lock())
{
//swap it in instead of the placeholder
boolean success = doReplace(id, phs, session);
if (!success)
{
//something has gone wrong, it should have been our placeholder
doDelete(id);
session = null;
LOG.warn("Replacement of placeholder for session {} failed", id);
phsLock.close();
break;
}
else
{
//successfully swapped in the session
session.setTimeout (); //TODO start the session timer
phsLock.close();
break;
}
}
}
catch (Exception e)
{
ex = e; //remember a problem happened loading the session
doDelete(id); //remove the placeholder
phsLock.close();
session = null;
break;
}
}
else
{
//my placeholder didn't win, check the session returned
phsLock.close();
try (Lock lock = s.lock())
{
//is it a placeholder? or is it passivated? In both cases, chuck it away and start again
if (s.isPassivated() || s instanceof PlaceHolderSession)
{
session = null;
continue;
}
session = s;
break;
}
}
}
else
{
//check the session returned
try (Lock lock = session.lock())
{
//is it a placeholder? or is it passivated? In both cases, chuck it away and start again
if (session.isPassivated() || session instanceof PlaceHolderSession)
{
session = null;
continue;
}
//got the session
break;
}
}
}
if (ex != null)
throw ex;
return session;
}
/**
* Load the info for the session from the session data store
*
* @param id the id
* @return a Session object filled with data or null if the session doesn't exist
* @throws Exception
*/
private Session loadSession (String id)
throws Exception
{
SessionData data = null;
Session session = null;
if (_sessionDataStore == null)
return null; //can't load it
try
{
data =_sessionDataStore.load(id);
if (data == null) //session doesn't exist
return null;
session = newSession(data);
session.setSessionManager(_manager);
return session;
}
catch (UnreadableSessionDataException e)
{
//can't load the session, delete it
_sessionDataStore.delete(id);
throw e;
}
}
/**
* Put the Session object back into the session store.
*
* This should be called by Session.complete when a request exists the session.
*
* If the session manager supports a session data store, write the
* session data through to the session data store.
*
* @see org.eclipse.jetty.server.session.SessionStore#put(java.lang.String, org.eclipse.jetty.server.session.Session)
*/
@Override
public void put(String id, Session session) throws Exception
{
if (id == null || session == null)
throw new IllegalArgumentException ("Put key="+id+" session="+(session==null?"null":session.getId()));
//if the session is new or data has changed write it to any backing store
try (Lock lock = session.lock())
{
session.setSessionManager(_manager);
if (session.isPassivated())
throw new IllegalStateException ("Session "+id+" is passivated and cannot be saved");
if (!session.isValid())
return;
if (_sessionDataStore == null)
{
doPutIfAbsent(id, session); //ensure it is in our map
return;
}
if ((session.getRequests() <= 0))
{
//only save if all requests have finished
if (!_sessionDataStore.isPassivating())
{
//if our backing datastore isn't the passivating kind, just save the session
_sessionDataStore.store(id, session.getSessionData());
}
else
{
//backing store supports passivation
session.willPassivate();
_sessionDataStore.store(id, session.getSessionData());
session.setPassivated();
if (isPassivateOnComplete())
{
//throw out the passivated session object from the map
doDelete(id);
}
else
{
//reactivate the session
session.setActive();
session.didActivate();
}
}
}
doPutIfAbsent(id,session); //ensure it is in our map
}
}
/**
* Check to see if a session corresponding to the id exists.
*
* This method will first check with the object store. If it
* doesn't exist in the object store (might be passivated etc),
* it will check with the data store.
* @throws Exception
*
* @see org.eclipse.jetty.server.session.SessionStore#exists(java.lang.String)
*/
@Override
public boolean exists(String id) throws Exception
{
//try the object store first
Session s = doGet(id);
if (s != null)
{
try (Lock lock = s.lock())
{
//wait for the lock and check the validity of the session
return s.isValid();
}
}
//not there, so find out if session data exists for it
return _sessionDataStore.exists (id);
}
/**
* Remove a session object from this store and from any backing store.
*
*
* @see org.eclipse.jetty.server.session.SessionStore#delete(java.lang.String)
*/
@Override
public Session delete(String id) throws Exception
{
//get the session, if its not in memory, this will load it
Session session = get(id);
//Always delete it from the backing data store
if (_sessionDataStore != null)
{
boolean dsdel = _sessionDataStore.delete(id);
if (LOG.isDebugEnabled()) LOG.debug("Session {} deleted in db {}",id, dsdel);
}
//delete it from the session object store
if (session != null)
session.stopTimeout();
return doDelete(id);
}
/**
* @see org.eclipse.jetty.server.session.SessionStore#checkExpiration(Set)
*/
@Override
public Set<String> checkExpiration(Set<String> candidates)
{
if (!isStarted())
return Collections.emptySet();
if (LOG.isDebugEnabled())
LOG.debug("SessionStore checking expiration on {}", candidates);
return _sessionDataStore.getExpired(candidates);
}
/**
* If the SessionDataStore supports passivation,
* write the session to the backing data store.
*
* @param id identity of session to passivate
*/
@Override
public void passivateIdleSession(String id)
{
if (!isStarted())
return;
if (_sessionDataStore == null || !_sessionDataStore.isPassivating())
return; //no data store to passivate or it doesn't passivate
//get the session locally
Session s = doGet(id);
if (s == null)
{
LOG.warn("Session {} not in this session store", s);
return;
}
//lock the session during passivation
try (Lock lock = s.lock())
{
//check the session is still idle and that it doesn't have requests using it
if (s.isValid() && s.isIdleLongerThan(_idlePassivationTimeoutSec) && s.isActive() && (s.getRequests() <= 0))
{
//TODO - do we need to check that the session exists in the session data store
//before we passivate it? If it doesn't exist, we can assume another node
//invalidated it. If the session was new, it shouldn't have been idle passivated.
try
{
if (LOG.isDebugEnabled())
LOG.debug("Passivating idle session {}", id);
s.willPassivate();
_sessionDataStore.store(id, s.getSessionData());
s.setPassivated();
s.stopTimeout();
doDelete(id); //Take the session object of this session store
}
catch (Exception e)
{
LOG.warn("Passivation of idle session {} failed", id, e);
s.setPassivated(); //set it as passivated so it can't be used
doDelete(id); //detach it
}
}
}
}
/**
* @see org.eclipse.jetty.server.session.SessionStore#renewSessionId(java.lang.String, java.lang.String)
*/
public Session renewSessionId (String oldId, String newId)
throws Exception
{
if (StringUtil.isBlank(oldId))
throw new IllegalArgumentException ("Old session id is null");
if (StringUtil.isBlank(newId))
throw new IllegalArgumentException ("New session id is null");
Session session = get(oldId);
if (session == null)
return null;
try (Lock lock = session.lock())
{
session.checkValidForWrite(); //can't change id on invalid session
session.getSessionData().setId(newId);
session.getSessionData().setLastSaved(0); //pretend that the session has never been saved before to get a full save
session.getSessionData().setDirty(true); //ensure we will try to write the session out
doPutIfAbsent(newId, session); //put the new id into our map
doDelete (oldId); //take old out of map
if (_sessionDataStore != null)
{
_sessionDataStore.delete(oldId); //delete the session data with the old id
_sessionDataStore.store(newId, session.getSessionData()); //save the session data with the new id
}
LOG.info("Session id {} swapped for new id {}", oldId, newId);
return session;
}
}
public void setPassivateOnComplete (boolean passivateOnComplete)
{
_passivateOnComplete = passivateOnComplete;
}
public boolean isPassivateOnComplete ()
{
return _passivateOnComplete;
}
/**
* @see org.eclipse.jetty.server.session.SessionStore#newSession(javax.servlet.http.HttpServletRequest, java.lang.String, long, long)
*/
@Override
public Session newSession(HttpServletRequest request, String id, long time, long maxInactiveMs)
{
Session session = newSession(request, _sessionDataStore.newSessionData(id, time, time, time, maxInactiveMs));
session.setSessionManager(_manager);
return session;
}
}

View File

@ -20,20 +20,33 @@
package org.eclipse.jetty.server.session;
/**
* AlwaysStale
* AbstractSessionStoreFactory
*
*
*/
public class AlwaysStaleStrategy implements StalenessStrategy
public abstract class AbstractSessionStoreFactory implements SessionStoreFactory
{
/**
* @see org.eclipse.jetty.server.session.StalenessStrategy#isStale(org.eclipse.jetty.server.session.Session)
int _gracePeriodSec;
/**
* @return the gracePeriodSec
*/
@Override
public boolean isStale(Session session)
public int getGracePeriodSec()
{
return true;
return _gracePeriodSec;
}
/**
* @param gracePeriodSec the gracePeriodSec to set
*/
public void setGracePeriodSec(int gracePeriodSec)
{
_gracePeriodSec = gracePeriodSec;
}
}

View File

@ -32,7 +32,7 @@ import java.util.Set;
* can increase performance. The cache implementation can either be a local cache,
* a remote cache, or a clustered cache.
*/
public class CachingSessionDataStore extends AbstractSessionDataStore
public class CachingSessionDataStore extends AbstractSessionStore
{
public interface SessionDataCache
@ -45,17 +45,17 @@ public class CachingSessionDataStore extends AbstractSessionDataStore
}
protected SessionDataStore _delegateDataStore;
protected SessionStore _delegateDataStore;
protected SessionDataCache _cache;
public void setSessionDataStore (SessionDataStore store)
public void setSessionDataStore (SessionStore store)
{
checkStarted();
_delegateDataStore = store;
}
public SessionDataStore getSessionDataStore()
public SessionStore getSessionDataStore()
{
return _delegateDataStore;
}
@ -74,7 +74,7 @@ public class CachingSessionDataStore extends AbstractSessionDataStore
/**
* @see org.eclipse.jetty.server.session.SessionDataStore#load(java.lang.String)
* @see org.eclipse.jetty.server.session.SessionStore#load(java.lang.String)
*/
@Override
public SessionData load(String id) throws Exception
@ -103,7 +103,7 @@ public class CachingSessionDataStore extends AbstractSessionDataStore
/**
* @see org.eclipse.jetty.server.session.SessionDataStore#delete(java.lang.String)
* @see org.eclipse.jetty.server.session.SessionStore#delete(java.lang.String)
*/
@Override
public boolean delete(String id) throws Exception
@ -116,7 +116,7 @@ public class CachingSessionDataStore extends AbstractSessionDataStore
}
/**
* @see org.eclipse.jetty.server.session.SessionDataStore#getExpired(Set)
* @see org.eclipse.jetty.server.session.SessionStore#getExpired(Set)
*/
@Override
public Set<String> doGetExpired(Set<String> candidates)
@ -127,14 +127,14 @@ public class CachingSessionDataStore extends AbstractSessionDataStore
/**
* @see org.eclipse.jetty.server.session.AbstractSessionDataStore#doStore(java.lang.String, org.eclipse.jetty.server.session.SessionData, long)
* @see org.eclipse.jetty.server.session.AbstractSessionStore#doStore(java.lang.String, org.eclipse.jetty.server.session.SessionData, long)
*/
@Override
public void doStore(String id, SessionData data, long lastSaveTime) throws Exception
{
//write to the SessionDataStore first
if (_delegateDataStore instanceof AbstractSessionDataStore)
((AbstractSessionDataStore)_delegateDataStore).doStore(id, data, lastSaveTime);
if (_delegateDataStore instanceof AbstractSessionStore)
((AbstractSessionStore)_delegateDataStore).doStore(id, data, lastSaveTime);
//else??????
@ -159,7 +159,7 @@ public class CachingSessionDataStore extends AbstractSessionDataStore
}
/**
* @see org.eclipse.jetty.server.session.SessionDataStore#isPassivating()
* @see org.eclipse.jetty.server.session.SessionStore#isPassivating()
*/
@Override
public boolean isPassivating()
@ -168,7 +168,7 @@ public class CachingSessionDataStore extends AbstractSessionDataStore
}
/**
* @see org.eclipse.jetty.server.session.SessionDataStore#exists(java.lang.String)
* @see org.eclipse.jetty.server.session.SessionStore#exists(java.lang.String)
*/
@Override
public boolean exists(String id) throws Exception

View File

@ -19,10 +19,7 @@
package org.eclipse.jetty.server.session;
import java.util.HashSet;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
import java.util.stream.Stream;
import javax.servlet.http.HttpServletRequest;
@ -31,11 +28,11 @@ import org.eclipse.jetty.util.log.Logger;
import org.eclipse.jetty.util.statistic.CounterStatistic;
/**
* MemorySessionStore
* DefaultSessionCache
*
* A session store that keeps its sessions in memory in a hashmap
*/
public class MemorySessionStore extends AbstractSessionStore
public class DefaultSessionCache extends AbstractSessionCache
{
private final static Logger LOG = Log.getLogger("org.eclipse.jetty.server.session");
@ -73,7 +70,7 @@ public class MemorySessionStore extends AbstractSessionStore
public MemorySessionStore (SessionManager manager)
public DefaultSessionCache (SessionHandler manager)
{
super (manager);
}
@ -103,7 +100,7 @@ public class MemorySessionStore extends AbstractSessionStore
/**
* @see org.eclipse.jetty.server.session.AbstractSessionStore#doGet(java.lang.String)
* @see org.eclipse.jetty.server.session.AbstractSessionCache#doGet(java.lang.String)
*/
@Override
public Session doGet(String id)
@ -118,7 +115,7 @@ public class MemorySessionStore extends AbstractSessionStore
/**
* @see org.eclipse.jetty.server.session.AbstractSessionStore#doPutIfAbsent(java.lang.String, org.eclipse.jetty.server.session.Session)
* @see org.eclipse.jetty.server.session.AbstractSessionCache#doPutIfAbsent(java.lang.String, org.eclipse.jetty.server.session.Session)
*/
@Override
public Session doPutIfAbsent(String id, Session session)
@ -132,7 +129,7 @@ public class MemorySessionStore extends AbstractSessionStore
/**
* @see org.eclipse.jetty.server.session.AbstractSessionStore#doDelete(java.lang.String)
* @see org.eclipse.jetty.server.session.AbstractSessionCache#doDelete(java.lang.String)
*/
@Override
public Session doDelete(String id)
@ -158,14 +155,14 @@ public class MemorySessionStore extends AbstractSessionStore
for (Session session: _sessions.values())
{
//if we have a backing store and the session is dirty make sure it is written out
if (_sessionDataStore != null)
if (_sessionStore != null)
{
if (session.getSessionData().isDirty())
{
session.willPassivate();
try
{
_sessionDataStore.store(session.getId(), session.getSessionData());
_sessionStore.store(session.getId(), session.getSessionData());
}
catch (Exception e)
{
@ -193,7 +190,7 @@ public class MemorySessionStore extends AbstractSessionStore
/**
* @see org.eclipse.jetty.server.session.AbstractSessionStore#newSession(javax.servlet.http.HttpServletRequest, org.eclipse.jetty.server.session.SessionData)
* @see org.eclipse.jetty.server.session.AbstractSessionCache#newSession(javax.servlet.http.HttpServletRequest, org.eclipse.jetty.server.session.SessionData)
*/
@Override
public Session newSession(HttpServletRequest request, SessionData data)
@ -206,7 +203,7 @@ public class MemorySessionStore extends AbstractSessionStore
/**
* @see org.eclipse.jetty.server.session.AbstractSessionStore#newSession(org.eclipse.jetty.server.session.SessionData)
* @see org.eclipse.jetty.server.session.AbstractSessionCache#newSession(org.eclipse.jetty.server.session.SessionData)
*/
@Override
public Session newSession(SessionData data)
@ -219,7 +216,7 @@ public class MemorySessionStore extends AbstractSessionStore
/**
* @see org.eclipse.jetty.server.session.AbstractSessionStore#doReplace(java.lang.String, org.eclipse.jetty.server.session.Session, org.eclipse.jetty.server.session.Session)
* @see org.eclipse.jetty.server.session.AbstractSessionCache#doReplace(java.lang.String, org.eclipse.jetty.server.session.Session, org.eclipse.jetty.server.session.Session)
*/
@Override
public boolean doReplace(String id, Session oldValue, Session newValue)

View File

@ -0,0 +1,80 @@
//
// ========================================================================
// Copyright (c) 1995-2016 Mort Bay Consulting Pty. Ltd.
// ------------------------------------------------------------------------
// All rights reserved. This program and the accompanying materials
// are made available under the terms of the Eclipse Public License v1.0
// and Apache License v2.0 which accompanies this distribution.
//
// The Eclipse Public License is available at
// http://www.eclipse.org/legal/epl-v10.html
//
// The Apache License v2.0 is available at
// http://www.opensource.org/licenses/apache2.0.php
//
// You may elect to redistribute this code under either of these licenses.
// ========================================================================
//
package org.eclipse.jetty.server.session;
/**
* MemorySessionStoreFactory
*
*
*/
public class DefaultSessionCacheFactory implements SessionCacheFactory
{
int _idlePassivationTimeoutSec;
boolean _passivateOnComplete;
/**
* @return the passivateOnComplete
*/
public boolean isPassivateOnComplete()
{
return _passivateOnComplete;
}
/**
* @param passivateOnComplete the passivateOnComplete to set
*/
public void setPassivateOnComplete(boolean passivateOnComplete)
{
_passivateOnComplete = passivateOnComplete;
}
/**
* @return the idlePassivationTimeoutSec
*/
public int getIdlePassivationTimeoutSec()
{
return _idlePassivationTimeoutSec;
}
/**
* @param idlePassivationTimeoutSec the idlePassivationTimeoutSec to set
*/
public void setIdlePassivationTimeoutSec(int idlePassivationTimeoutSec)
{
_idlePassivationTimeoutSec = idlePassivationTimeoutSec;
}
/**
* @see org.eclipse.jetty.server.session.SessionCacheFactory#getSessionStore(org.eclipse.jetty.server.session.SessionHandler)
*/
@Override
public SessionCache getSessionCache (SessionHandler handler)
{
DefaultSessionCache cache = new DefaultSessionCache(handler);
cache.setIdlePassivationTimeoutSec(_idlePassivationTimeoutSec);
cache.setPassivateOnComplete(_passivateOnComplete);
return cache;
}
}

View File

@ -58,7 +58,7 @@ public class DefaultSessionIdManager extends AbstractLifeCycle implements Sessio
protected String _workerAttr;
protected long _reseed=100000L;
protected Server _server;
protected HouseKeeper _inspector;
protected HouseKeeper _houseKeeper;
/* ------------------------------------------------------------ */
@ -106,10 +106,10 @@ public class DefaultSessionIdManager extends AbstractLifeCycle implements Sessio
/**
* @param inspector inspector of sessions
*/
public void setSessionInspector (HouseKeeper inspector)
public void setSessionHouseKeeper (HouseKeeper houseKeeper)
{
_inspector = inspector;
_inspector.setSessionIdManager(this);
_houseKeeper = houseKeeper;
_houseKeeper.setSessionIdManager(this);
}
@ -291,7 +291,7 @@ public class DefaultSessionIdManager extends AbstractLifeCycle implements Sessio
try
{
for (SessionManager manager:getSessionManagers())
for (SessionHandler manager:getSessionHandlers())
{
if (manager.isIdInUse(id))
{
@ -327,14 +327,14 @@ public class DefaultSessionIdManager extends AbstractLifeCycle implements Sessio
initRandom();
_workerAttr=(_workerName!=null && _workerName.startsWith("$"))?_workerName.substring(1):null;
if (_inspector == null)
if (_houseKeeper == null)
{
LOG.warn("No SessionScavenger set, using defaults");
_inspector = new HouseKeeper();
_inspector.setSessionIdManager(this);
_houseKeeper = new HouseKeeper();
_houseKeeper.setSessionIdManager(this);
}
_inspector.start();
_houseKeeper.start();
}
/* ------------------------------------------------------------ */
@ -344,7 +344,7 @@ public class DefaultSessionIdManager extends AbstractLifeCycle implements Sessio
@Override
protected void doStop() throws Exception
{
_inspector.stop();
_houseKeeper.stop();
}
/* ------------------------------------------------------------ */
@ -424,7 +424,7 @@ public class DefaultSessionIdManager extends AbstractLifeCycle implements Sessio
if (LOG.isDebugEnabled())
LOG.debug("Expiring {}",id);
for (SessionManager manager:getSessionManagers())
for (SessionHandler manager:getSessionHandlers())
{
manager.invalidate(id);
}
@ -435,7 +435,7 @@ public class DefaultSessionIdManager extends AbstractLifeCycle implements Sessio
{
//tell all contexts that may have a session object with this id to
//get rid of them
for (SessionManager manager:getSessionManagers())
for (SessionHandler manager:getSessionHandlers())
{
manager.invalidate(id);
}
@ -457,7 +457,7 @@ public class DefaultSessionIdManager extends AbstractLifeCycle implements Sessio
//TODO how to handle request for old id whilst id change is happening?
//tell all contexts to update the id
for (SessionManager manager:getSessionManagers())
for (SessionHandler manager:getSessionHandlers())
{
manager.renewSessionId(oldClusterId, oldNodeId, newClusterId, getExtendedId(newClusterId, request));
}
@ -470,9 +470,9 @@ public class DefaultSessionIdManager extends AbstractLifeCycle implements Sessio
*
* @return all session managers
*/
public Set<SessionManager> getSessionManagers()
public Set<SessionHandler> getSessionHandlers()
{
Set<SessionManager> managers = new HashSet<>();
Set<SessionHandler> handlers = new HashSet<>();
Handler[] contexts = _server.getChildHandlersByClass(ContextHandler.class);
for (int i=0; contexts!=null && i<contexts.length; i++)
@ -480,12 +480,9 @@ public class DefaultSessionIdManager extends AbstractLifeCycle implements Sessio
SessionHandler sessionHandler = ((ContextHandler)contexts[i]).getChildHandlerByClass(SessionHandler.class);
if (sessionHandler != null)
{
SessionManager manager = (SessionManager)sessionHandler.getSessionManager();
if (manager != null)
managers.add(manager);
handlers.add(sessionHandler);
}
}
return managers;
return handlers;
}
}

View File

@ -46,7 +46,7 @@ import org.eclipse.jetty.util.log.Logger;
*
* A file-based store of session data.
*/
public class FileSessionDataStore extends AbstractSessionDataStore
public class FileSessionDataStore extends AbstractSessionStore
{
private final static Logger LOG = Log.getLogger("org.eclipse.jetty.server.session");
private File _storeDir;
@ -92,7 +92,7 @@ public class FileSessionDataStore extends AbstractSessionDataStore
/**
* @see org.eclipse.jetty.server.session.SessionDataStore#delete(java.lang.String)
* @see org.eclipse.jetty.server.session.SessionStore#delete(java.lang.String)
*/
@Override
public boolean delete(String id) throws Exception
@ -112,7 +112,7 @@ public class FileSessionDataStore extends AbstractSessionDataStore
/**
* @see org.eclipse.jetty.server.session.SessionDataStore#getExpired(Set)
* @see org.eclipse.jetty.server.session.SessionStore#getExpired(Set)
*/
@Override
public Set<String> doGetExpired(final Set<String> candidates)
@ -166,7 +166,7 @@ public class FileSessionDataStore extends AbstractSessionDataStore
/**
* @see org.eclipse.jetty.server.session.SessionDataStore#load(java.lang.String)
* @see org.eclipse.jetty.server.session.SessionStore#load(java.lang.String)
*/
@Override
public SessionData load(String id) throws Exception
@ -220,7 +220,7 @@ public class FileSessionDataStore extends AbstractSessionDataStore
/**
* @see org.eclipse.jetty.server.session.AbstractSessionDataStore#doStore(java.lang.String, org.eclipse.jetty.server.session.SessionData, long)
* @see org.eclipse.jetty.server.session.AbstractSessionStore#doStore(java.lang.String, org.eclipse.jetty.server.session.SessionData, long)
*/
@Override
public void doStore(String id, SessionData data, long lastSaveTime) throws Exception
@ -262,7 +262,7 @@ public class FileSessionDataStore extends AbstractSessionDataStore
}
/**
* @see org.eclipse.jetty.server.session.SessionDataStore#isPassivating()
* @see org.eclipse.jetty.server.session.SessionStore#isPassivating()
*/
@Override
public boolean isPassivating()
@ -274,7 +274,7 @@ public class FileSessionDataStore extends AbstractSessionDataStore
/**
* @see org.eclipse.jetty.server.session.SessionDataStore#exists(java.lang.String)
* @see org.eclipse.jetty.server.session.SessionStore#exists(java.lang.String)
*/
@Override
public boolean exists(String id) throws Exception

View File

@ -1,64 +0,0 @@
//
// ========================================================================
// Copyright (c) 1995-2016 Mort Bay Consulting Pty. Ltd.
// ------------------------------------------------------------------------
// All rights reserved. This program and the accompanying materials
// are made available under the terms of the Eclipse Public License v1.0
// and Apache License v2.0 which accompanies this distribution.
//
// The Eclipse Public License is available at
// http://www.eclipse.org/legal/epl-v10.html
//
// The Apache License v2.0 is available at
// http://www.opensource.org/licenses/apache2.0.php
//
// You may elect to redistribute this code under either of these licenses.
// ========================================================================
//
package org.eclipse.jetty.server.session;
/**
* FileHashSessionManager
*
* Session manager that stores its sessions in files on disk
*
*/
public class FileSessionManager extends SessionManager
{
protected FileSessionDataStore _sessionDataStore;
/**
*
*/
public FileSessionManager ()
{
setSessionStore(new MemorySessionStore(this));
_sessionDataStore = new FileSessionDataStore();
}
@Override
public void doStart() throws Exception
{
((AbstractSessionStore)_sessionStore).setSessionDataStore(_sessionDataStore);
super.doStart();
}
@Override
public void doStop() throws Exception
{
super.doStop();
}
/**
* Get the SessionDataStore to configure it
* @return the session datastore
*/
public FileSessionDataStore getSessionDataStore()
{
return _sessionDataStore;
}
}

View File

@ -0,0 +1,84 @@
//
// ========================================================================
// Copyright (c) 1995-2016 Mort Bay Consulting Pty. Ltd.
// ------------------------------------------------------------------------
// All rights reserved. This program and the accompanying materials
// are made available under the terms of the Eclipse Public License v1.0
// and Apache License v2.0 which accompanies this distribution.
//
// The Eclipse Public License is available at
// http://www.eclipse.org/legal/epl-v10.html
//
// The Apache License v2.0 is available at
// http://www.opensource.org/licenses/apache2.0.php
//
// You may elect to redistribute this code under either of these licenses.
// ========================================================================
//
package org.eclipse.jetty.server.session;
import java.io.File;
/**
* FileSessionStoreFactory
*
*
*/
public class FileSessionStoreFactory extends AbstractSessionStoreFactory
{
boolean _deleteUnrestorableFiles;
File _storeDir;
/**
* @return the deleteUnrestorableFiles
*/
public boolean isDeleteUnrestorableFiles()
{
return _deleteUnrestorableFiles;
}
/**
* @param deleteUnrestorableFiles the deleteUnrestorableFiles to set
*/
public void setDeleteUnrestorableFiles(boolean deleteUnrestorableFiles)
{
_deleteUnrestorableFiles = deleteUnrestorableFiles;
}
/**
* @return the storeDir
*/
public File getStoreDir()
{
return _storeDir;
}
/**
* @param storeDir the storeDir to set
*/
public void setStoreDir(File storeDir)
{
_storeDir = storeDir;
}
/**
* @see org.eclipse.jetty.server.session.SessionStoreFactory#getSessionDataStore(org.eclipse.jetty.server.session.SessionHandler)
*/
@Override
public SessionStore getSessionStore(SessionHandler handler)
{
FileSessionDataStore fsds = new FileSessionDataStore();
fsds.setDeleteUnrestorableFiles(isDeleteUnrestorableFiles());
fsds.setStoreDir(getStoreDir());
fsds.setGracePeriodSec(getGracePeriodSec());
return fsds;
}
}

View File

@ -1,55 +0,0 @@
//
// ========================================================================
// Copyright (c) 1995-2016 Mort Bay Consulting Pty. Ltd.
// ------------------------------------------------------------------------
// All rights reserved. This program and the accompanying materials
// are made available under the terms of the Eclipse Public License v1.0
// and Apache License v2.0 which accompanies this distribution.
//
// The Eclipse Public License is available at
// http://www.eclipse.org/legal/epl-v10.html
//
// The Apache License v2.0 is available at
// http://www.opensource.org/licenses/apache2.0.php
//
// You may elect to redistribute this code under either of these licenses.
// ========================================================================
//
package org.eclipse.jetty.server.session;
/**
* HashSessionManager
*
* In memory-only session manager.
*
*/
public class HashSessionManager extends SessionManager
{
protected NullSessionDataStore _sessionDataStore = new NullSessionDataStore();
/**
*
*/
public HashSessionManager ()
{
setSessionStore(new MemorySessionStore(this));
}
@Override
public void doStart() throws Exception
{
((AbstractSessionStore)_sessionStore).setSessionDataStore(_sessionDataStore);
super.doStart();
}
@Override
public void doStop() throws Exception
{
super.doStop();
}
}

View File

@ -155,7 +155,7 @@ public class HouseKeeper extends AbstractLifeCycle
_intervalMs += tenPercent;
if (LOG.isDebugEnabled())
LOG.debug("Inspecting every "+_intervalMs+" ms");
LOG.debug("Scavenging every "+_intervalMs+" ms");
synchronized (this)
{
@ -173,7 +173,7 @@ public class HouseKeeper extends AbstractLifeCycle
/**
* Get the period between inspection cycles.
* Get the period between scavenge cycles.
*
* @return the interval (in seconds)
*/
@ -194,10 +194,10 @@ public class HouseKeeper extends AbstractLifeCycle
return;
if (LOG.isDebugEnabled())
LOG.debug("Inspecting sessions");
LOG.debug("Scavenging sessions");
//find the session managers
for (SessionManager manager:_sessionIdManager.getSessionManagers())
for (SessionHandler manager:_sessionIdManager.getSessionHandlers())
{
if (manager != null)
{

View File

@ -46,7 +46,7 @@ import org.eclipse.jetty.util.log.Logger;
*
* Session data stored in database
*/
public class JDBCSessionDataStore extends AbstractSessionDataStore
public class JDBCSessionDataStore extends AbstractSessionStore
{
final static Logger LOG = Log.getLogger("org.eclipse.jetty.server.session");
@ -662,7 +662,7 @@ public class JDBCSessionDataStore extends AbstractSessionDataStore
/**
* @see org.eclipse.jetty.server.session.SessionDataStore#load(java.lang.String)
* @see org.eclipse.jetty.server.session.SessionStore#load(java.lang.String)
*/
@Override
public SessionData load(String id) throws Exception
@ -758,7 +758,7 @@ public class JDBCSessionDataStore extends AbstractSessionDataStore
/**
* @see org.eclipse.jetty.server.session.SessionDataStore#delete(java.lang.String)
* @see org.eclipse.jetty.server.session.SessionStore#delete(java.lang.String)
*/
@Override
public boolean delete(String id) throws Exception
@ -779,7 +779,7 @@ public class JDBCSessionDataStore extends AbstractSessionDataStore
/**
* @see org.eclipse.jetty.server.session.AbstractSessionDataStore#doStore(String, SessionData, long)
* @see org.eclipse.jetty.server.session.AbstractSessionStore#doStore(String, SessionData, long)
*/
@Override
public void doStore(String id, SessionData data, long lastSaveTime) throws Exception
@ -884,7 +884,7 @@ public class JDBCSessionDataStore extends AbstractSessionDataStore
/**
* @see org.eclipse.jetty.server.session.SessionDataStore#getExpired(Set)
* @see org.eclipse.jetty.server.session.SessionStore#getExpired(Set)
*/
@Override
public Set<String> doGetExpired(Set<String> candidates)
@ -1083,7 +1083,7 @@ public class JDBCSessionDataStore extends AbstractSessionDataStore
/**
* @see org.eclipse.jetty.server.session.SessionDataStore#isPassivating()
* @see org.eclipse.jetty.server.session.SessionStore#isPassivating()
*/
@Override
public boolean isPassivating()
@ -1096,7 +1096,7 @@ public class JDBCSessionDataStore extends AbstractSessionDataStore
/**
* @see org.eclipse.jetty.server.session.SessionDataStore#exists(java.lang.String)
* @see org.eclipse.jetty.server.session.SessionStore#exists(java.lang.String)
*/
@Override
public boolean exists(String id)

View File

@ -1,64 +0,0 @@
//
// ========================================================================
// Copyright (c) 1995-2016 Mort Bay Consulting Pty. Ltd.
// ------------------------------------------------------------------------
// All rights reserved. This program and the accompanying materials
// are made available under the terms of the Eclipse Public License v1.0
// and Apache License v2.0 which accompanies this distribution.
//
// The Eclipse Public License is available at
// http://www.eclipse.org/legal/epl-v10.html
//
// The Apache License v2.0 is available at
// http://www.opensource.org/licenses/apache2.0.php
//
// You may elect to redistribute this code under either of these licenses.
// ========================================================================
//
package org.eclipse.jetty.server.session;
/**
* JDBCSessionManager
*
*/
public class JDBCSessionManager extends SessionManager
{
protected JDBCSessionDataStore _sessionDataStore;
public JDBCSessionManager()
{
setSessionStore(new MemorySessionStore(this));
_sessionDataStore = new JDBCSessionDataStore();
}
@Override
public void doStart() throws Exception
{
((AbstractSessionStore)_sessionStore).setSessionDataStore(_sessionDataStore);
super.doStart();
}
@Override
public void doStop() throws Exception
{
super.doStop();
}
/**
* Get the SessionDataStore to configure it
* @return the session data store
*/
public JDBCSessionDataStore getSessionDataStore ()
{
return _sessionDataStore;
}
}

View File

@ -0,0 +1,68 @@
//
// ========================================================================
// Copyright (c) 1995-2016 Mort Bay Consulting Pty. Ltd.
// ------------------------------------------------------------------------
// All rights reserved. This program and the accompanying materials
// are made available under the terms of the Eclipse Public License v1.0
// and Apache License v2.0 which accompanies this distribution.
//
// The Eclipse Public License is available at
// http://www.eclipse.org/legal/epl-v10.html
//
// The Apache License v2.0 is available at
// http://www.opensource.org/licenses/apache2.0.php
//
// You may elect to redistribute this code under either of these licenses.
// ========================================================================
//
package org.eclipse.jetty.server.session;
/**
* JDBCSessionStoreFactory
*
*
*/
public class JDBCSessionStoreFactory extends AbstractSessionStoreFactory
{
DatabaseAdaptor _adaptor;
JDBCSessionDataStore.SessionTableSchema _schema;
boolean _deleteUnloadableSessions;
int _loadAttempts;
/**
* @see org.eclipse.jetty.server.session.SessionStoreFactory#getSessionDataStore(org.eclipse.jetty.server.session.SessionHandler)
*/
@Override
public SessionStore getSessionStore(SessionHandler handler)
{
JDBCSessionDataStore ds = new JDBCSessionDataStore();
ds.setDatabaseAdaptor(_adaptor);
ds.setSessionTableSchema(_schema);
ds.setDeleteUnloadableSessions(_deleteUnloadableSessions);
ds.setGracePeriodSec(_gracePeriodSec);
ds.setLoadAttempts(_loadAttempts);
return ds;
}
/**
* @param adaptor
*/
public void setDatabaseAdaptor (DatabaseAdaptor adaptor)
{
_adaptor = adaptor;
}
/**
* @param schema
*/
public void setSessionTableSchema (JDBCSessionDataStore.SessionTableSchema schema)
{
_schema = schema;
}
}

View File

@ -1,40 +0,0 @@
//
// ========================================================================
// Copyright (c) 1995-2016 Mort Bay Consulting Pty. Ltd.
// ------------------------------------------------------------------------
// All rights reserved. This program and the accompanying materials
// are made available under the terms of the Eclipse Public License v1.0
// and Apache License v2.0 which accompanies this distribution.
//
// The Eclipse Public License is available at
// http://www.eclipse.org/legal/epl-v10.html
//
// The Apache License v2.0 is available at
// http://www.opensource.org/licenses/apache2.0.php
//
// You may elect to redistribute this code under either of these licenses.
// ========================================================================
//
package org.eclipse.jetty.server.session;
/**
* NeverStale
*
* This strategy says that a session never needs to be refreshed by the cluster.
*
*/
public class NeverStaleStrategy implements StalenessStrategy
{
/**
* @see org.eclipse.jetty.server.session.StalenessStrategy#isStale(org.eclipse.jetty.server.session.Session)
*/
@Override
public boolean isStale(Session session)
{
return false;
}
}

View File

@ -22,15 +22,15 @@ package org.eclipse.jetty.server.session;
import java.util.Set;
/**
* NullSessionDataStore
* NullSessionStore
*
*
*/
public class NullSessionDataStore extends AbstractSessionDataStore
public class NullSessionStore extends AbstractSessionStore
{
/**
* @see org.eclipse.jetty.server.session.SessionDataStore#load(java.lang.String)
* @see org.eclipse.jetty.server.session.SessionStore#load(java.lang.String)
*/
@Override
public SessionData load(String id) throws Exception
@ -40,7 +40,7 @@ public class NullSessionDataStore extends AbstractSessionDataStore
/**
* @see org.eclipse.jetty.server.session.AbstractSessionDataStore#newSessionData(java.lang.String, long, long, long, long)
* @see org.eclipse.jetty.server.session.AbstractSessionStore#newSessionData(java.lang.String, long, long, long, long)
*/
@Override
public SessionData newSessionData(String id, long created, long accessed, long lastAccessed, long maxInactiveMs)
@ -49,7 +49,7 @@ public class NullSessionDataStore extends AbstractSessionDataStore
}
/**
* @see org.eclipse.jetty.server.session.SessionDataStore#delete(java.lang.String)
* @see org.eclipse.jetty.server.session.SessionStore#delete(java.lang.String)
*/
@Override
public boolean delete(String id) throws Exception
@ -59,7 +59,7 @@ public class NullSessionDataStore extends AbstractSessionDataStore
/**
* @see org.eclipse.jetty.server.session.AbstractSessionDataStore#doStore(java.lang.String, org.eclipse.jetty.server.session.SessionData, long)
* @see org.eclipse.jetty.server.session.AbstractSessionStore#doStore(java.lang.String, org.eclipse.jetty.server.session.SessionData, long)
*/
@Override
public void doStore(String id, SessionData data, long lastSaveTime) throws Exception
@ -69,7 +69,7 @@ public class NullSessionDataStore extends AbstractSessionDataStore
/**
* @see org.eclipse.jetty.server.session.SessionDataStore#getExpired(Set)
* @see org.eclipse.jetty.server.session.SessionStore#getExpired(Set)
*/
@Override
public Set<String> doGetExpired(Set<String> candidates)
@ -79,7 +79,7 @@ public class NullSessionDataStore extends AbstractSessionDataStore
/**
* @see org.eclipse.jetty.server.session.SessionDataStore#isPassivating()
* @see org.eclipse.jetty.server.session.SessionStore#isPassivating()
*/
@Override
public boolean isPassivating()
@ -89,7 +89,7 @@ public class NullSessionDataStore extends AbstractSessionDataStore
/**
* @see org.eclipse.jetty.server.session.SessionDataStore#exists(java.lang.String)
* @see org.eclipse.jetty.server.session.SessionStore#exists(java.lang.String)
*/
@Override
public boolean exists(String id)

View File

@ -49,7 +49,7 @@ import org.eclipse.jetty.util.thread.Locker.Lock;
*
*
*/
public class Session implements SessionManager.SessionIf
public class Session implements SessionHandler.SessionIf
{
private final static Logger LOG = Log.getLogger("org.eclipse.jetty.server.session");
@ -77,7 +77,7 @@ public class Session implements SessionManager.SessionIf
protected SessionData _sessionData; //the actual data associated with a session
protected SessionManager _manager; //the manager of the session
protected SessionHandler _handler; //the manager of the session
protected String _extendedId; //the _id plus the worker name
protected long _requests;
private boolean _idChanged;
@ -101,7 +101,7 @@ public class Session implements SessionManager.SessionIf
public InspectionTimeout()
{
super(getSessionManager().getScheduler());
super(getSessionHandler().getScheduler());
}
/**
@ -112,7 +112,7 @@ public class Session implements SessionManager.SessionIf
{
//called when the timer goes off
if (LOG.isDebugEnabled()) LOG.debug("Timer expired for session {}", getId());
getSessionManager().inspect(Session.this);
getSessionHandler().inspect(Session.this);
}
/**
@ -190,9 +190,9 @@ public class Session implements SessionManager.SessionIf
/* ------------------------------------------------------------- */
public void setSessionManager (SessionManager manager)
public void setSessionHandler (SessionHandler manager)
{
_manager = manager;
_handler = manager;
}
@ -287,9 +287,9 @@ public class Session implements SessionManager.SessionIf
if (newValue!=null)
bindValue(name,newValue);
if (_manager == null)
if (_handler == null)
throw new IllegalStateException ("No session manager for session "+ _sessionData.getId());
_manager.doSessionAttributeListeners(this,name,oldValue,newValue);
_handler.doSessionAttributeListeners(this,name,oldValue,newValue);
}
}
@ -441,9 +441,9 @@ public class Session implements SessionManager.SessionIf
@Override
public ServletContext getServletContext()
{
if (_manager == null)
if (_handler == null)
throw new IllegalStateException ("No session manager for session "+ _sessionData.getId());
return _manager._context;
return _handler._context;
}
/**
@ -478,7 +478,7 @@ public class Session implements SessionManager.SessionIf
{
if (LOG.isDebugEnabled())LOG.debug("Set timeout called");
long maxInactive = _sessionData.getMaxInactiveMs();
long maxIdle = TimeUnit.SECONDS.toMillis(getSessionManager().getSessionStore().getIdlePassivationTimeoutSec());
long maxIdle = TimeUnit.SECONDS.toMillis(getSessionHandler().getSessionStore().getIdlePassivationTimeoutSec());
if (maxInactive <= 0 && maxIdle <=0)
@ -541,13 +541,13 @@ public class Session implements SessionManager.SessionIf
public HttpSessionContext getSessionContext()
{
checkValidForRead();
return SessionManager.__nullSessionContext;
return SessionHandler.__nullSessionContext;
}
public SessionManager getSessionManager()
public SessionHandler getSessionHandler()
{
return _manager;
return _handler;
}
@ -746,7 +746,7 @@ public class Session implements SessionManager.SessionIf
/* ------------------------------------------------------------ */
public void renewId(HttpServletRequest request)
{
if (_manager == null)
if (_handler == null)
throw new IllegalStateException ("No session manager for session "+ _sessionData.getId());
String id = null;
@ -758,7 +758,7 @@ public class Session implements SessionManager.SessionIf
extendedId = getExtendedId();
}
_manager._sessionIdManager.renewSessionId(id, extendedId, request);
_handler._sessionIdManager.renewSessionId(id, extendedId, request);
setIdChanged(true);
}
@ -799,7 +799,7 @@ public class Session implements SessionManager.SessionIf
@Override
public void invalidate()
{
if (_manager == null)
if (_handler == null)
throw new IllegalStateException ("No session manager for session "+ _sessionData.getId());
boolean result = false;
@ -832,7 +832,7 @@ public class Session implements SessionManager.SessionIf
if (result)
{
//tell id mgr to remove session from all other contexts
((DefaultSessionIdManager)_manager.getSessionIdManager()).invalidateAll(_sessionData.getId());
((DefaultSessionIdManager)_handler.getSessionIdManager()).invalidateAll(_sessionData.getId());
}
}
catch (Exception e)

View File

@ -0,0 +1,55 @@
//
// ========================================================================
// Copyright (c) 1995-2016 Mort Bay Consulting Pty. Ltd.
// ------------------------------------------------------------------------
// All rights reserved. This program and the accompanying materials
// are made available under the terms of the Eclipse Public License v1.0
// and Apache License v2.0 which accompanies this distribution.
//
// The Eclipse Public License is available at
// http://www.eclipse.org/legal/epl-v10.html
//
// The Apache License v2.0 is available at
// http://www.opensource.org/licenses/apache2.0.php
//
// You may elect to redistribute this code under either of these licenses.
// ========================================================================
//
package org.eclipse.jetty.server.session;
import java.util.Set;
import javax.servlet.http.HttpServletRequest;
import org.eclipse.jetty.util.component.LifeCycle;
/**
* SessionStore
*
* A store of Session objects. This store of Session objects can be backed by
* a SessionDataStore to persist/distribute the data contained in the Session objects.
*
* This store of Session objects ensures that all threads within the same context on
* the same node with the same session id will share exactly the same Session object.
*/
public interface SessionCache extends LifeCycle
{
void initialize(SessionContext context);
SessionHandler getSessionHandler();
Session newSession (HttpServletRequest request, String id, long time, long maxInactiveMs);
Session newSession (SessionData data);
Session renewSessionId (String oldId, String newId) throws Exception;
Session get(String id) throws Exception;
void put(String id, Session session) throws Exception;
boolean exists (String id) throws Exception;
Session delete (String id) throws Exception;
void shutdown ();
Set<String> checkExpiration (Set<String> candidates);
void setIdlePassivationTimeoutSec(int sec);
int getIdlePassivationTimeoutSec();
SessionStore getSessionStore();
void setSessionStore(SessionStore sds);
void passivateIdleSession(String id);
}

View File

@ -20,11 +20,11 @@
package org.eclipse.jetty.server.session;
/**
* StalenessStrategy
* SessionCacheFactory
*
*
*/
public interface StalenessStrategy
public interface SessionCacheFactory
{
boolean isStale (Session session);
SessionCache getSessionCache (SessionHandler handler);
}

View File

@ -1,119 +0,0 @@
//
// ========================================================================
// Copyright (c) 1995-2016 Mort Bay Consulting Pty. Ltd.
// ------------------------------------------------------------------------
// All rights reserved. This program and the accompanying materials
// are made available under the terms of the Eclipse Public License v1.0
// and Apache License v2.0 which accompanies this distribution.
//
// The Eclipse Public License is available at
// http://www.eclipse.org/legal/epl-v10.html
//
// The Apache License v2.0 is available at
// http://www.opensource.org/licenses/apache2.0.php
//
// You may elect to redistribute this code under either of these licenses.
// ========================================================================
//
package org.eclipse.jetty.server.session;
import java.util.Set;
import org.eclipse.jetty.util.component.LifeCycle;
/**
* SessionDataStore
*
* A store for the data contained in a Session object. The store
* would usually be persistent.
*/
public interface SessionDataStore extends LifeCycle
{
/**
* Initialize this session data store for the
* given context. A SessionDataStore can only
* be used by one context(/session manager).
*
* @param context context associated
*/
void initialize(SessionContext context);
/**
* Read in session data from storage
* @param id identity of session to load
* @return the SessionData matching the id
* @throws Exception if unable to load session data
*/
public SessionData load (String id) throws Exception;
/**
* Create a new SessionData
* @param id the id
* @param created the timestamp when created
* @param accessed the timestamp when accessed
* @param lastAccessed the timestamp when last accessed
* @param maxInactiveMs the max inactive time in milliseconds
* @return a new SessionData object
*/
public SessionData newSessionData (String id, long created, long accessed, long lastAccessed, long maxInactiveMs);
/**
* Write out session data to storage
* @param id identity of session to store
* @param data info of session to store
* @throws Exception if unable to write session data
*/
public void store (String id, SessionData data) throws Exception;
/**
* Delete session data from storage
* @param id identity of session to delete
* @return true if the session was deleted from the permanent store
* @throws Exception if unable to delete session data
*/
public boolean delete (String id) throws Exception;
/**
* Called periodically, this method should search the data store
* for sessions that have been expired for a 'reasonable' amount
* of time.
* @param candidates if provided, these are keys of sessions that
* the SessionStore thinks has expired and should be verified by the
* SessionDataStore
* @return set of session ids
*/
public Set<String> getExpired (Set<String> candidates);
/**
* True if this type of datastore will passivate session objects
* @return true if this store can passivate sessions, false otherwise
*/
public boolean isPassivating ();
/**
* Test if data exists for a given session id.
*
* @param id Identity of session whose existance should be checked
*
* @return true if valid, non-expired session exists
* @throws Exception if problem checking existance with persistence layer
*/
public boolean exists (String id) throws Exception;
}

View File

@ -20,36 +20,100 @@
package org.eclipse.jetty.server.session;
import java.util.Set;
import java.util.stream.Stream;
import javax.servlet.http.HttpServletRequest;
import org.eclipse.jetty.util.component.LifeCycle;
/**
* SessionStore
*
* A store of Session objects. This store of Session objects can be backed by
* a SessionDataStore to persist/distribute the data contained in the Session objects.
*
* This store of Session objects ensures that all threads within the same context on
* the same node with the same session id will share exactly the same Session object.
* A store for the data contained in a Session object. The store
* would usually be persistent.
*/
public interface SessionStore extends LifeCycle
{
/**
* Initialize this session data store for the
* given context. A SessionDataStore can only
* be used by one context(/session manager).
*
* @param context context associated
*/
void initialize(SessionContext context);
SessionManager getSessionManager();
Session newSession (HttpServletRequest request, String id, long time, long maxInactiveMs);
Session newSession (SessionData data);
Session renewSessionId (String oldId, String newId) throws Exception;
Session get(String id) throws Exception;
void put(String id, Session session) throws Exception;
boolean exists (String id) throws Exception;
Session delete (String id) throws Exception;
void shutdown ();
Set<String> checkExpiration (Set<String> candidates);
void setIdlePassivationTimeoutSec(int sec);
int getIdlePassivationTimeoutSec();
SessionDataStore getSessionDataStore();
void passivateIdleSession(String id);
/**
* Read in session data from storage
* @param id identity of session to load
* @return the SessionData matching the id
* @throws Exception if unable to load session data
*/
public SessionData load (String id) throws Exception;
/**
* Create a new SessionData
* @param id the id
* @param created the timestamp when created
* @param accessed the timestamp when accessed
* @param lastAccessed the timestamp when last accessed
* @param maxInactiveMs the max inactive time in milliseconds
* @return a new SessionData object
*/
public SessionData newSessionData (String id, long created, long accessed, long lastAccessed, long maxInactiveMs);
/**
* Write out session data to storage
* @param id identity of session to store
* @param data info of session to store
* @throws Exception if unable to write session data
*/
public void store (String id, SessionData data) throws Exception;
/**
* Delete session data from storage
* @param id identity of session to delete
* @return true if the session was deleted from the permanent store
* @throws Exception if unable to delete session data
*/
public boolean delete (String id) throws Exception;
/**
* Called periodically, this method should search the data store
* for sessions that have been expired for a 'reasonable' amount
* of time.
* @param candidates if provided, these are keys of sessions that
* the SessionStore thinks has expired and should be verified by the
* SessionDataStore
* @return set of session ids
*/
public Set<String> getExpired (Set<String> candidates);
/**
* True if this type of datastore will passivate session objects
* @return true if this store can passivate sessions, false otherwise
*/
public boolean isPassivating ();
/**
* Test if data exists for a given session id.
*
* @param id Identity of session whose existance should be checked
*
* @return true if valid, non-expired session exists
* @throws Exception if problem checking existance with persistence layer
*/
public boolean exists (String id) throws Exception;
}

View File

@ -16,8 +16,15 @@
// ========================================================================
//
/**
* Jetty Server : Session Management JMX Integration
*/
package org.eclipse.jetty.server.session.jmx;
package org.eclipse.jetty.server.session;
/**
* SessionStoreFactory
*
*
*/
public interface SessionStoreFactory
{
SessionStore getSessionStore (SessionHandler handler) throws Exception;
}

View File

@ -1,76 +0,0 @@
//
// ========================================================================
// Copyright (c) 1995-2016 Mort Bay Consulting Pty. Ltd.
// ------------------------------------------------------------------------
// All rights reserved. This program and the accompanying materials
// are made available under the terms of the Eclipse Public License v1.0
// and Apache License v2.0 which accompanies this distribution.
//
// The Eclipse Public License is available at
// http://www.eclipse.org/legal/epl-v10.html
//
// The Apache License v2.0 is available at
// http://www.opensource.org/licenses/apache2.0.php
//
// You may elect to redistribute this code under either of these licenses.
// ========================================================================
//
package org.eclipse.jetty.server.session;
/**
* StalePeriodStrategy
*
* A session is regarded as being stale if it has been
* x seconds since it was last read from the cluster.
*/
public class StalePeriodStrategy implements StalenessStrategy
{
protected long _staleMs = 0;
/**
* @see org.eclipse.jetty.server.session.StalenessStrategy#isStale(org.eclipse.jetty.server.session.Session)
*/
@Override
public boolean isStale (Session session)
{
if (session == null)
return false;
//never persisted, must be fresh session
if (session.getSessionData().getLastSaved() == 0)
return false;
if (_staleMs <= 0)
{
//TODO always stale, never stale??
return false;
}
else
{
// return (session.getSessionData().getAccessed() - session.getSessionData().getLastSaved() >= _staleMs);
return (System.currentTimeMillis() - session.getSessionData().getLastSaved() >= _staleMs);
}
}
public long getStaleSec ()
{
return (_staleMs<=0?0L:_staleMs/1000L);
}
/**
* The amount of time in seconds that a session can be held
* in memory without being refreshed from the cluster.
* @param sec the time in seconds
*/
public void setStaleSec (long sec)
{
if (sec == 0)
_staleMs = 0L;
else
_staleMs = sec * 1000L;
}
}

View File

@ -1,58 +0,0 @@
//
// ========================================================================
// Copyright (c) 1995-2016 Mort Bay Consulting Pty. Ltd.
// ------------------------------------------------------------------------
// All rights reserved. This program and the accompanying materials
// are made available under the terms of the Eclipse Public License v1.0
// and Apache License v2.0 which accompanies this distribution.
//
// The Eclipse Public License is available at
// http://www.eclipse.org/legal/epl-v10.html
//
// The Apache License v2.0 is available at
// http://www.opensource.org/licenses/apache2.0.php
//
// You may elect to redistribute this code under either of these licenses.
// ========================================================================
//
package org.eclipse.jetty.server.session.jmx;
import org.eclipse.jetty.server.handler.AbstractHandlerContainer;
import org.eclipse.jetty.server.handler.ContextHandler;
import org.eclipse.jetty.server.handler.jmx.AbstractHandlerMBean;
import org.eclipse.jetty.server.session.SessionManager;
import org.eclipse.jetty.server.session.SessionHandler;
public class SessionManagerMBean extends AbstractHandlerMBean
{
public SessionManagerMBean(Object managedObject)
{
super(managedObject);
}
/* ------------------------------------------------------------ */
public String getObjectContextBasis()
{
if (_managed != null && _managed instanceof SessionManager)
{
SessionManager manager = (SessionManager)_managed;
String basis = null;
SessionHandler handler = manager.getSessionHandler();
if (handler != null)
{
ContextHandler context =
AbstractHandlerContainer.findContainerOf(handler.getServer(),
ContextHandler.class,
handler);
if (context != null)
basis = getContextName(context);
}
if (basis != null)
return basis;
}
return super.getObjectContextBasis();
}
}

View File

@ -55,9 +55,11 @@ import org.eclipse.jetty.server.handler.AbstractHandler;
import org.eclipse.jetty.server.handler.ContextHandler;
import org.eclipse.jetty.server.handler.ErrorHandler;
import org.eclipse.jetty.server.session.DefaultSessionIdManager;
import org.eclipse.jetty.server.session.HashSessionManager;
import org.eclipse.jetty.server.session.DefaultSessionCache;
import org.eclipse.jetty.server.session.NullSessionStore;
import org.eclipse.jetty.server.session.Session;
import org.eclipse.jetty.server.session.SessionData;
import org.eclipse.jetty.server.session.SessionHandler;
import org.eclipse.jetty.util.Callback;
import org.eclipse.jetty.util.thread.Scheduler;
import org.eclipse.jetty.util.thread.TimerScheduler;
@ -510,21 +512,24 @@ public class ResponseTest
request.setRequestedSessionId("12345");
request.setRequestedSessionIdFromCookie(false);
HashSessionManager manager = new HashSessionManager();
manager.setSessionIdManager(new DefaultSessionIdManager(_server));
request.setSessionManager(manager);
TestSession tsession = new TestSession(manager, "12345");
tsession.setExtendedId(manager.getSessionIdManager().getExtendedId("12345", null));
SessionHandler handler = new SessionHandler();
DefaultSessionCache ss = new DefaultSessionCache(handler);
NullSessionStore ds = new NullSessionStore();
ss.setSessionStore(ds);
handler.setSessionIdManager(new DefaultSessionIdManager(_server));
request.setSessionHandler(handler);
TestSession tsession = new TestSession(handler, "12345");
tsession.setExtendedId(handler.getSessionIdManager().getExtendedId("12345", null));
request.setSession(tsession);
manager.setCheckingRemoteSessionIdEncoding(false);
handler.setCheckingRemoteSessionIdEncoding(false);
assertEquals("http://myhost:8888/path/info;param;jsessionid=12345?query=0&more=1#target", response.encodeURL("http://myhost:8888/path/info;param?query=0&more=1#target"));
assertEquals("http://other:8888/path/info;param;jsessionid=12345?query=0&more=1#target", response.encodeURL("http://other:8888/path/info;param?query=0&more=1#target"));
assertEquals("http://myhost/path/info;param;jsessionid=12345?query=0&more=1#target", response.encodeURL("http://myhost/path/info;param?query=0&more=1#target"));
assertEquals("http://myhost:8888/other/info;param;jsessionid=12345?query=0&more=1#target", response.encodeURL("http://myhost:8888/other/info;param?query=0&more=1#target"));
manager.setCheckingRemoteSessionIdEncoding(true);
handler.setCheckingRemoteSessionIdEncoding(true);
assertEquals("http://myhost:8888/path/info;param;jsessionid=12345?query=0&more=1#target", response.encodeURL("http://myhost:8888/path/info;param?query=0&more=1#target"));
assertEquals("http://other:8888/path/info;param?query=0&more=1#target", response.encodeURL("http://other:8888/path/info;param?query=0&more=1#target"));
assertEquals("http://myhost/path/info;param?query=0&more=1#target", response.encodeURL("http://myhost/path/info;param?query=0&more=1#target"));
@ -538,7 +543,7 @@ public class ResponseTest
assertEquals("http://myhost:8888/;jsessionid=12345", response.encodeURL("http://myhost:8888/;jsessionid=7777"));
assertEquals("http://myhost:8888/;param;jsessionid=12345?query=0&more=1#target", response.encodeURL("http://myhost:8888/;param?query=0&more=1#target"));
assertEquals("http://other:8888/path/info;param?query=0&more=1#target", response.encodeURL("http://other:8888/path/info;param?query=0&more=1#target"));
manager.setCheckingRemoteSessionIdEncoding(false);
handler.setCheckingRemoteSessionIdEncoding(false);
assertEquals("/foo;jsessionid=12345", response.encodeURL("/foo"));
assertEquals("/;jsessionid=12345", response.encodeURL("/"));
assertEquals("/foo.html;jsessionid=12345#target", response.encodeURL("/foo.html#target"));
@ -587,11 +592,16 @@ public class ResponseTest
request.setContextPath("/path");
request.setRequestedSessionId("12345");
request.setRequestedSessionIdFromCookie(i>2);
HashSessionManager manager = new HashSessionManager();
manager.setSessionIdManager(new DefaultSessionIdManager(_server));
request.setSessionManager(manager);
request.setSession(new TestSession(manager, "12345"));
manager.setCheckingRemoteSessionIdEncoding(false);
SessionHandler handler = new SessionHandler();
NullSessionStore ds = new NullSessionStore();
DefaultSessionCache ss = new DefaultSessionCache(handler);
handler.setSessionStore(ss);
ss.setSessionStore(ds);
handler.setSessionIdManager(new DefaultSessionIdManager(_server));
request.setSessionHandler(handler);
request.setSession(new TestSession(handler, "12345"));
handler.setCheckingRemoteSessionIdEncoding(false);
response.sendRedirect(tests[i][0]);
@ -886,10 +896,10 @@ public class ResponseTest
private static class TestSession extends Session
{
protected TestSession(HashSessionManager hashSessionManager, String id)
protected TestSession(SessionHandler handler, String id)
{
super(new SessionData(id, "", "0.0.0.0", 0, 0, 0, 300));
setSessionManager(hashSessionManager);
setSessionHandler(handler);
}
}
}

View File

@ -65,15 +65,17 @@ public class FileSessionManagerTest
idmgr.setServer(server);
server.setSessionIdManager(idmgr);
final FileSessionManager manager = new FileSessionManager();
manager.getSessionDataStore().setDeleteUnrestorableFiles(true);
FileSessionDataStore ds = new FileSessionDataStore();
ds.setDeleteUnrestorableFiles(true);
DefaultSessionCache ss = new DefaultSessionCache(handler);
handler.setSessionStore(ss);
ss.setSessionStore(ds);
//manager.setLazyLoad(true);
File testDir = MavenTestingUtils.getTargetTestingDir("hashes");
testDir.mkdirs();
manager.getSessionDataStore().setStoreDir(testDir);
manager.setSessionIdManager(idmgr);
handler.setSessionManager(manager);
manager.start();
ds.setStoreDir(testDir);
handler.setSessionIdManager(idmgr);
handler.start();
//Create a file that is in the parent dir of the session storeDir
String expectedFilename = "_0.0.0.0_dangerFile";
@ -82,7 +84,7 @@ public class FileSessionManagerTest
//Verify that passing in the relative filename of an unrecoverable session does not lead
//to deletion of file outside the session dir (needs deleteUnrecoverableFiles(true))
Session session = manager.getSession("../_0.0.0.0_dangerFile");
Session session = handler.getSession("../_0.0.0.0_dangerFile");
Assert.assertTrue(session == null);
Assert.assertTrue("File should exist!", MavenTestingUtils.getTargetFile(expectedFilename).exists());
@ -97,15 +99,19 @@ public class FileSessionManagerTest
final DefaultSessionIdManager idmgr = new DefaultSessionIdManager(server);
idmgr.setServer(server);
server.setSessionIdManager(idmgr);
final FileSessionManager manager = new FileSessionManager();
manager.getSessionDataStore().setDeleteUnrestorableFiles(true);
manager.setSessionIdManager(idmgr);
handler.setSessionManager(manager);
DefaultSessionCache ss = new DefaultSessionCache(handler);
FileSessionDataStore ds = new FileSessionDataStore();
ss.setSessionStore(ds);
handler.setSessionStore(ss);
ds.setDeleteUnrestorableFiles(true);
handler.setSessionIdManager(idmgr);
File testDir = MavenTestingUtils.getTargetTestingDir("hashes");
FS.ensureEmpty(testDir);
manager.getSessionDataStore().setStoreDir(testDir);
manager.start();
ds.setStoreDir(testDir);
handler.start();
String expectedFilename = "_0.0.0.0_validFile123";
@ -113,7 +119,7 @@ public class FileSessionManagerTest
Assert.assertTrue("File should exist!", new File(testDir, expectedFilename).exists());
Session session = manager.getSession("validFile123");
Session session = handler.getSession("validFile123");
Assert.assertTrue("File shouldn't exist!", !new File(testDir,expectedFilename).exists());
}
@ -128,31 +134,35 @@ public class FileSessionManagerTest
Server server = new Server();
SessionHandler handler = new SessionHandler();
handler.setServer(server);
FileSessionManager manager = new FileSessionManager();
manager.getSessionDataStore().setStoreDir(testDir);
manager.setMaxInactiveInterval(5);
DefaultSessionCache ss = new DefaultSessionCache(handler);
FileSessionDataStore ds = new FileSessionDataStore();
ss.setSessionStore(ds);
handler.setSessionStore(ss);
ds.setStoreDir(testDir);
handler.setMaxInactiveInterval(5);
Assert.assertTrue(testDir.exists());
Assert.assertTrue(testDir.canWrite());
handler.setSessionManager(manager);
DefaultSessionIdManager idManager = new DefaultSessionIdManager(server);
idManager.setServer(server);
idManager.setWorkerName("foo");
manager.setSessionIdManager(idManager);
handler.setSessionIdManager(idManager);
server.setSessionIdManager(idManager);
server.start();
manager.start();
handler.start();
Session session = (Session)manager.newHttpSession(new Request(null, null));
Session session = (Session)handler.newHttpSession(new Request(null, null));
String sessionId = session.getId();
session.setAttribute("one", new Integer(1));
session.setAttribute("two", new Integer(2));
//stop will persist sessions
manager.setMaxInactiveInterval(30); // change max inactive interval for *new* sessions
manager.stop();
handler.setMaxInactiveInterval(30); // change max inactive interval for *new* sessions
handler.stop();
final String expectedFilename = "_0.0.0.0_"+session.getId();
@ -171,10 +181,10 @@ public class FileSessionManagerTest
manager.start();
handler.start();
//restore session
Session restoredSession = (Session)manager.getSession(sessionId);
Session restoredSession = (Session)handler.getSession(sessionId);
Assert.assertNotNull(restoredSession);
Object o = restoredSession.getAttribute("one");

View File

@ -36,17 +36,17 @@ public class SessionCookieTest
public class MockSessionStore extends AbstractSessionStore
public class MockSessionStore extends AbstractSessionCache
{
public MockSessionStore(SessionManager manager)
public MockSessionStore(SessionHandler manager)
{
super(manager);
}
/**
* @see org.eclipse.jetty.server.session.SessionStore#shutdown()
* @see org.eclipse.jetty.server.session.SessionCache#shutdown()
*/
@Override
public void shutdown()
@ -56,7 +56,7 @@ public class SessionCookieTest
}
/**
* @see org.eclipse.jetty.server.session.AbstractSessionStore#newSession(org.eclipse.jetty.server.session.SessionData)
* @see org.eclipse.jetty.server.session.AbstractSessionCache#newSession(org.eclipse.jetty.server.session.SessionData)
*/
@Override
public Session newSession(SessionData data)
@ -66,7 +66,7 @@ public class SessionCookieTest
}
/**
* @see org.eclipse.jetty.server.session.AbstractSessionStore#doGet(String)
* @see org.eclipse.jetty.server.session.AbstractSessionCache#doGet(String)
*/
@Override
public Session doGet(String key)
@ -76,7 +76,7 @@ public class SessionCookieTest
}
/**
* @see org.eclipse.jetty.server.session.AbstractSessionStore#doPutIfAbsent(String, Session)
* @see org.eclipse.jetty.server.session.AbstractSessionCache#doPutIfAbsent(String, Session)
*/
@Override
public Session doPutIfAbsent(String key, Session session)
@ -87,7 +87,7 @@ public class SessionCookieTest
/**
* @see org.eclipse.jetty.server.session.AbstractSessionStore#doDelete(String)
* @see org.eclipse.jetty.server.session.AbstractSessionCache#doDelete(String)
*/
@Override
public Session doDelete(String key)
@ -98,7 +98,7 @@ public class SessionCookieTest
/**
* @see org.eclipse.jetty.server.session.AbstractSessionStore#doReplace(java.lang.String, org.eclipse.jetty.server.session.Session, org.eclipse.jetty.server.session.Session)
* @see org.eclipse.jetty.server.session.AbstractSessionCache#doReplace(java.lang.String, org.eclipse.jetty.server.session.Session, org.eclipse.jetty.server.session.Session)
*/
@Override
public boolean doReplace(String id, Session oldValue, Session newValue)
@ -108,7 +108,7 @@ public class SessionCookieTest
}
/**
* @see org.eclipse.jetty.server.session.AbstractSessionStore#newSession(javax.servlet.http.HttpServletRequest, org.eclipse.jetty.server.session.SessionData)
* @see org.eclipse.jetty.server.session.AbstractSessionCache#newSession(javax.servlet.http.HttpServletRequest, org.eclipse.jetty.server.session.SessionData)
*/
@Override
public Session newSession(HttpServletRequest request, SessionData data)
@ -163,9 +163,9 @@ public class SessionCookieTest
Server server = new Server();
MockSessionIdManager idMgr = new MockSessionIdManager(server);
idMgr.setWorkerName("node1");
SessionManager mgr = new SessionManager();
SessionHandler mgr = new SessionHandler();
MockSessionStore store = new MockSessionStore(mgr);
store.setSessionDataStore(new NullSessionDataStore());
store.setSessionStore(new NullSessionStore());
mgr.setSessionStore(store);
mgr.setSessionIdManager(idMgr);

View File

@ -1338,7 +1338,7 @@ public class ServletContextHandler extends ContextHandler
public Set<SessionTrackingMode> getDefaultSessionTrackingModes()
{
if (_sessionHandler!=null)
return _sessionHandler.getSessionManager().getDefaultSessionTrackingModes();
return _sessionHandler.getDefaultSessionTrackingModes();
return null;
}
@ -1346,7 +1346,7 @@ public class ServletContextHandler extends ContextHandler
public Set<SessionTrackingMode> getEffectiveSessionTrackingModes()
{
if (_sessionHandler!=null)
return _sessionHandler.getSessionManager().getEffectiveSessionTrackingModes();
return _sessionHandler.getEffectiveSessionTrackingModes();
return null;
}
@ -1411,7 +1411,7 @@ public class ServletContextHandler extends ContextHandler
throw new UnsupportedOperationException();
if (_sessionHandler!=null)
return _sessionHandler.getSessionManager().getSessionCookieConfig();
return _sessionHandler.getSessionCookieConfig();
return null;
}
@ -1425,7 +1425,7 @@ public class ServletContextHandler extends ContextHandler
if (_sessionHandler!=null)
_sessionHandler.getSessionManager().setSessionTrackingModes(sessionTrackingModes);
_sessionHandler.setSessionTrackingModes(sessionTrackingModes);
}
@Override

View File

@ -651,10 +651,10 @@ public class StandardDescriptorProcessor extends IterativeDescriptorProcessor
if (tNode != null)
{
java.math.BigDecimal asDecimal = new java.math.BigDecimal(tNode.toString(false, true));
if (asDecimal.compareTo(org.eclipse.jetty.server.session.SessionManager.MAX_INACTIVE_MINUTES) > 0)
throw new IllegalStateException ("Max session-timeout in minutes is "+org.eclipse.jetty.server.session.SessionManager.MAX_INACTIVE_MINUTES);
if (asDecimal.compareTo(org.eclipse.jetty.server.session.SessionHandler.MAX_INACTIVE_MINUTES) > 0)
throw new IllegalStateException ("Max session-timeout in minutes is "+org.eclipse.jetty.server.session.SessionHandler.MAX_INACTIVE_MINUTES);
context.getSessionHandler().getSessionManager().setMaxInactiveInterval(asDecimal.intValueExact() * 60);
context.getSessionHandler().setMaxInactiveInterval(asDecimal.intValueExact() * 60);
}
//Servlet Spec 3.0
@ -683,7 +683,7 @@ public class StandardDescriptorProcessor extends IterativeDescriptorProcessor
if (descriptor instanceof OverrideDescriptor)
modes = new HashSet<SessionTrackingMode>();
else
modes = new HashSet<SessionTrackingMode>(context.getSessionHandler().getSessionManager().getEffectiveSessionTrackingModes());
modes = new HashSet<SessionTrackingMode>(context.getSessionHandler().getEffectiveSessionTrackingModes());
context.getMetaData().setOrigin("session.tracking-mode", descriptor);
break;
}
@ -697,7 +697,7 @@ public class StandardDescriptorProcessor extends IterativeDescriptorProcessor
String trackMode = mNode.toString(false, true);
modes.add(SessionTrackingMode.valueOf(trackMode));
}
context.getSessionHandler().getSessionManager().setSessionTrackingModes(modes);
context.getSessionHandler().setSessionTrackingModes(modes);
}
@ -715,7 +715,7 @@ public class StandardDescriptorProcessor extends IterativeDescriptorProcessor
case NotSet:
{
//no <cookie-config><name> set yet, accept it
context.getSessionHandler().getSessionManager().getSessionCookieConfig().setName(name);
context.getSessionHandler().getSessionCookieConfig().setName(name);
context.getMetaData().setOrigin("cookie-config.name", descriptor);
break;
}
@ -726,7 +726,7 @@ public class StandardDescriptorProcessor extends IterativeDescriptorProcessor
//<cookie-config><name> set in a web xml, only allow web-default/web-override to change
if (!(descriptor instanceof FragmentDescriptor))
{
context.getSessionHandler().getSessionManager().getSessionCookieConfig().setName(name);
context.getSessionHandler().getSessionCookieConfig().setName(name);
context.getMetaData().setOrigin("cookie-config.name", descriptor);
}
break;
@ -734,7 +734,7 @@ public class StandardDescriptorProcessor extends IterativeDescriptorProcessor
case WebFragment:
{
//a web-fragment set the value, all web-fragments must have the same value
if (!context.getSessionHandler().getSessionManager().getSessionCookieConfig().getName().equals(name))
if (!context.getSessionHandler().getSessionCookieConfig().getName().equals(name))
throw new IllegalStateException("Conflicting cookie-config name "+name+" in "+descriptor.getResource());
break;
}
@ -752,7 +752,7 @@ public class StandardDescriptorProcessor extends IterativeDescriptorProcessor
case NotSet:
{
//no <cookie-config><domain> set yet, accept it
context.getSessionHandler().getSessionManager().getSessionCookieConfig().setDomain(domain);
context.getSessionHandler().getSessionCookieConfig().setDomain(domain);
context.getMetaData().setOrigin("cookie-config.domain", descriptor);
break;
}
@ -763,7 +763,7 @@ public class StandardDescriptorProcessor extends IterativeDescriptorProcessor
//<cookie-config><domain> set in a web xml, only allow web-default/web-override to change
if (!(descriptor instanceof FragmentDescriptor))
{
context.getSessionHandler().getSessionManager().getSessionCookieConfig().setDomain(domain);
context.getSessionHandler().getSessionCookieConfig().setDomain(domain);
context.getMetaData().setOrigin("cookie-config.domain", descriptor);
}
break;
@ -771,7 +771,7 @@ public class StandardDescriptorProcessor extends IterativeDescriptorProcessor
case WebFragment:
{
//a web-fragment set the value, all web-fragments must have the same value
if (!context.getSessionHandler().getSessionManager().getSessionCookieConfig().getDomain().equals(domain))
if (!context.getSessionHandler().getSessionCookieConfig().getDomain().equals(domain))
throw new IllegalStateException("Conflicting cookie-config domain "+domain+" in "+descriptor.getResource());
break;
}
@ -789,7 +789,7 @@ public class StandardDescriptorProcessor extends IterativeDescriptorProcessor
case NotSet:
{
//no <cookie-config><domain> set yet, accept it
context.getSessionHandler().getSessionManager().getSessionCookieConfig().setPath(path);
context.getSessionHandler().getSessionCookieConfig().setPath(path);
context.getMetaData().setOrigin("cookie-config.path", descriptor);
break;
}
@ -800,7 +800,7 @@ public class StandardDescriptorProcessor extends IterativeDescriptorProcessor
//<cookie-config><domain> set in a web xml, only allow web-default/web-override to change
if (!(descriptor instanceof FragmentDescriptor))
{
context.getSessionHandler().getSessionManager().getSessionCookieConfig().setPath(path);
context.getSessionHandler().getSessionCookieConfig().setPath(path);
context.getMetaData().setOrigin("cookie-config.path", descriptor);
}
break;
@ -808,7 +808,7 @@ public class StandardDescriptorProcessor extends IterativeDescriptorProcessor
case WebFragment:
{
//a web-fragment set the value, all web-fragments must have the same value
if (!context.getSessionHandler().getSessionManager().getSessionCookieConfig().getPath().equals(path))
if (!context.getSessionHandler().getSessionCookieConfig().getPath().equals(path))
throw new IllegalStateException("Conflicting cookie-config path "+path+" in "+descriptor.getResource());
break;
}
@ -826,7 +826,7 @@ public class StandardDescriptorProcessor extends IterativeDescriptorProcessor
case NotSet:
{
//no <cookie-config><comment> set yet, accept it
context.getSessionHandler().getSessionManager().getSessionCookieConfig().setComment(comment);
context.getSessionHandler().getSessionCookieConfig().setComment(comment);
context.getMetaData().setOrigin("cookie-config.comment", descriptor);
break;
}
@ -837,7 +837,7 @@ public class StandardDescriptorProcessor extends IterativeDescriptorProcessor
//<cookie-config><comment> set in a web xml, only allow web-default/web-override to change
if (!(descriptor instanceof FragmentDescriptor))
{
context.getSessionHandler().getSessionManager().getSessionCookieConfig().setComment(comment);
context.getSessionHandler().getSessionCookieConfig().setComment(comment);
context.getMetaData().setOrigin("cookie-config.comment", descriptor);
}
break;
@ -845,7 +845,7 @@ public class StandardDescriptorProcessor extends IterativeDescriptorProcessor
case WebFragment:
{
//a web-fragment set the value, all web-fragments must have the same value
if (!context.getSessionHandler().getSessionManager().getSessionCookieConfig().getComment().equals(comment))
if (!context.getSessionHandler().getSessionCookieConfig().getComment().equals(comment))
throw new IllegalStateException("Conflicting cookie-config comment "+comment+" in "+descriptor.getResource());
break;
}
@ -864,7 +864,7 @@ public class StandardDescriptorProcessor extends IterativeDescriptorProcessor
case NotSet:
{
//no <cookie-config><http-only> set yet, accept it
context.getSessionHandler().getSessionManager().getSessionCookieConfig().setHttpOnly(httpOnly);
context.getSessionHandler().getSessionCookieConfig().setHttpOnly(httpOnly);
context.getMetaData().setOrigin("cookie-config.http-only", descriptor);
break;
}
@ -875,7 +875,7 @@ public class StandardDescriptorProcessor extends IterativeDescriptorProcessor
//<cookie-config><http-only> set in a web xml, only allow web-default/web-override to change
if (!(descriptor instanceof FragmentDescriptor))
{
context.getSessionHandler().getSessionManager().getSessionCookieConfig().setHttpOnly(httpOnly);
context.getSessionHandler().getSessionCookieConfig().setHttpOnly(httpOnly);
context.getMetaData().setOrigin("cookie-config.http-only", descriptor);
}
break;
@ -883,7 +883,7 @@ public class StandardDescriptorProcessor extends IterativeDescriptorProcessor
case WebFragment:
{
//a web-fragment set the value, all web-fragments must have the same value
if (context.getSessionHandler().getSessionManager().getSessionCookieConfig().isHttpOnly() != httpOnly)
if (context.getSessionHandler().getSessionCookieConfig().isHttpOnly() != httpOnly)
throw new IllegalStateException("Conflicting cookie-config http-only "+httpOnly+" in "+descriptor.getResource());
break;
}
@ -902,7 +902,7 @@ public class StandardDescriptorProcessor extends IterativeDescriptorProcessor
case NotSet:
{
//no <cookie-config><secure> set yet, accept it
context.getSessionHandler().getSessionManager().getSessionCookieConfig().setSecure(secure);
context.getSessionHandler().getSessionCookieConfig().setSecure(secure);
context.getMetaData().setOrigin("cookie-config.secure", descriptor);
break;
}
@ -913,7 +913,7 @@ public class StandardDescriptorProcessor extends IterativeDescriptorProcessor
//<cookie-config><secure> set in a web xml, only allow web-default/web-override to change
if (!(descriptor instanceof FragmentDescriptor))
{
context.getSessionHandler().getSessionManager().getSessionCookieConfig().setSecure(secure);
context.getSessionHandler().getSessionCookieConfig().setSecure(secure);
context.getMetaData().setOrigin("cookie-config.secure", descriptor);
}
break;
@ -921,7 +921,7 @@ public class StandardDescriptorProcessor extends IterativeDescriptorProcessor
case WebFragment:
{
//a web-fragment set the value, all web-fragments must have the same value
if (context.getSessionHandler().getSessionManager().getSessionCookieConfig().isSecure() != secure)
if (context.getSessionHandler().getSessionCookieConfig().isSecure() != secure)
throw new IllegalStateException("Conflicting cookie-config secure "+secure+" in "+descriptor.getResource());
break;
}
@ -940,7 +940,7 @@ public class StandardDescriptorProcessor extends IterativeDescriptorProcessor
case NotSet:
{
//no <cookie-config><max-age> set yet, accept it
context.getSessionHandler().getSessionManager().getSessionCookieConfig().setMaxAge(maxAge);
context.getSessionHandler().getSessionCookieConfig().setMaxAge(maxAge);
context.getMetaData().setOrigin("cookie-config.max-age", descriptor);
break;
}
@ -951,7 +951,7 @@ public class StandardDescriptorProcessor extends IterativeDescriptorProcessor
//<cookie-config><max-age> set in a web xml, only allow web-default/web-override to change
if (!(descriptor instanceof FragmentDescriptor))
{
context.getSessionHandler().getSessionManager().getSessionCookieConfig().setMaxAge(maxAge);
context.getSessionHandler().getSessionCookieConfig().setMaxAge(maxAge);
context.getMetaData().setOrigin("cookie-config.max-age", descriptor);
}
break;
@ -959,7 +959,7 @@ public class StandardDescriptorProcessor extends IterativeDescriptorProcessor
case WebFragment:
{
//a web-fragment set the value, all web-fragments must have the same value
if (context.getSessionHandler().getSessionManager().getSessionCookieConfig().getMaxAge() != maxAge)
if (context.getSessionHandler().getSessionCookieConfig().getMaxAge() != maxAge)
throw new IllegalStateException("Conflicting cookie-config max-age "+maxAge+" in "+descriptor.getResource());
break;
}

View File

@ -139,6 +139,7 @@ public class WebAppContext extends ServletContextHandler implements WebAppClassL
// with a more automatic distributed mechanism
public final static String[] __dftServerClasses =
{
"-org.eclipse.jetty.session.infinispan.", //don't hide infinispan support classes
"-org.eclipse.jetty.jmx.", // don't hide jmx classes
"-org.eclipse.jetty.util.annotation.", // don't hide jmx annotation
"-org.eclipse.jetty.continuation.", // don't hide continuation classes

View File

@ -137,16 +137,17 @@ public class FileTestServer extends AbstractTestServer
return mgr;
}
public SessionManager newSessionManager()
{
FileSessionManager manager = new FileSessionManager();
manager.getSessionDataStore().setStoreDir(_tmpDir);
return manager;
}
public SessionHandler newSessionHandler(SessionManager sessionManager)
public SessionHandler newSessionHandler()
{
return new SessionHandler(sessionManager);
SessionHandler handler = new SessionHandler();
DefaultSessionCache ss = new DefaultSessionCache(handler);
handler.setSessionStore(ss);
FileSessionDataStore ds = new FileSessionDataStore();
ds.setStoreDir(_tmpDir);
ss.setSessionStore(ds);
return handler;
}
}

View File

@ -297,7 +297,7 @@ public class GCloudSessionTestSupport
public void listSessions () throws Exception
{
ensureDatastore();
GqlQuery.Builder builder = Query.gqlQueryBuilder(ResultType.ENTITY, "select * from "+GCloudSessionDataStore.KIND);
GqlQuery.Builder builder = Query.gqlQueryBuilder(ResultType.ENTITY, "select * from "+GCloudSessionStore.KIND);
Query<Entity> query = builder.build();
@ -317,7 +317,7 @@ public class GCloudSessionTestSupport
{
HashSet<String> ids = new HashSet<String>();
ensureDatastore();
GqlQuery.Builder builder = Query.gqlQueryBuilder(ResultType.ENTITY, "select * from "+GCloudSessionDataStore.KIND);
GqlQuery.Builder builder = Query.gqlQueryBuilder(ResultType.ENTITY, "select * from "+GCloudSessionStore.KIND);
Query<Entity> query = builder.build();
@ -336,7 +336,7 @@ public class GCloudSessionTestSupport
{
ensureDatastore();
StructuredQuery<ProjectionEntity> keyOnlyProjectionQuery = Query.projectionEntityQueryBuilder()
.kind(GCloudSessionDataStore.KIND)
.kind(GCloudSessionStore.KIND)
.projection(Projection.property("__key__"))
.limit(100)
.build();
@ -355,7 +355,7 @@ public class GCloudSessionTestSupport
{
ensureDatastore();
StructuredQuery<ProjectionEntity> keyOnlyProjectionQuery = Query.projectionEntityQueryBuilder()
.kind(GCloudSessionDataStore.KIND)
.kind(GCloudSessionStore.KIND)
.projection(Projection.property("__key__"))
.limit(100)
.build();

View File

@ -19,16 +19,9 @@
package org.eclipse.jetty.gcloud.session;
import org.eclipse.jetty.server.SessionIdManager;
import org.eclipse.jetty.server.session.AbstractSessionStore;
import org.eclipse.jetty.server.session.AbstractTestServer;
import org.eclipse.jetty.server.session.DefaultSessionIdManager;
import org.eclipse.jetty.server.session.DefaultSessionCache;
import org.eclipse.jetty.server.session.SessionHandler;
import org.eclipse.jetty.server.session.SessionManager;
import org.eclipse.jetty.server.session.StalePeriodStrategy;
import com.google.gcloud.datastore.Datastore;
import com.google.gcloud.datastore.DatastoreFactory;
/**
* GCloudTestServer
@ -64,27 +57,20 @@ public class GCloudTestServer extends AbstractTestServer
}
/**
* @see org.eclipse.jetty.server.session.AbstractTestServer#newSessionManager()
*/
@Override
public SessionManager newSessionManager()
{
GCloudSessionManager sessionManager = new GCloudSessionManager();
sessionManager.setSessionIdManager(_sessionIdManager);
sessionManager.getSessionDataStore().setGCloudConfiguration((GCloudConfiguration)_config);
return sessionManager;
}
/**
* @see org.eclipse.jetty.server.session.AbstractTestServer#newSessionHandler(org.eclipse.jetty.server.SessionManager)
*/
@Override
public SessionHandler newSessionHandler(SessionManager sessionManager)
public SessionHandler newSessionHandler()
{
return new SessionHandler(sessionManager);
SessionHandler handler = new SessionHandler();
handler.setSessionIdManager(_sessionIdManager);
GCloudSessionStore ds = new GCloudSessionStore();
ds.setGCloudConfiguration((GCloudConfiguration)_config);
DefaultSessionCache ss = new DefaultSessionCache(handler);
ss.setSessionStore(ds);
handler.setSessionStore(ss);
return handler;
}
}

View File

@ -19,9 +19,10 @@
package org.eclipse.jetty.gcloud.session;
import org.eclipse.jetty.server.session.SessionManager;
import org.eclipse.jetty.server.session.AbstractInvalidationSessionTest;
import org.eclipse.jetty.server.session.AbstractTestServer;
import org.eclipse.jetty.server.session.SessionHandler;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Ignore;
@ -61,11 +62,11 @@ public class InvalidationSessionTest extends AbstractInvalidationSessionTest
* @see org.eclipse.jetty.gcloud.session.GCloudTestServer#newSessionManager()
*/
@Override
public SessionManager newSessionManager()
public SessionHandler newSessionHandler()
{
GCloudSessionManager manager = (GCloudSessionManager)super.newSessionManager();
manager.getSessionStore().setIdlePassivationTimeoutSec(IDLE_PASSIVATE_SEC);
return manager;
SessionHandler handler = super.newSessionHandler();
handler.getSessionStore().setIdlePassivationTimeoutSec(IDLE_PASSIVATE_SEC);
return handler;
}
};

View File

@ -39,15 +39,14 @@ public class HashTestServer extends AbstractTestServer
}
public SessionManager newSessionManager()
{
HashSessionManager manager = new HashSessionManager();
return manager;
}
public SessionHandler newSessionHandler(SessionManager sessionManager)
public SessionHandler newSessionHandler()
{
return new SessionHandler(sessionManager);
SessionHandler handler = new SessionHandler();
DefaultSessionCache ss = new DefaultSessionCache(handler);
handler.setSessionStore(ss);
ss.setSessionStore(new NullSessionStore());
return handler;
}
}

View File

@ -20,8 +20,7 @@
package org.eclipse.jetty.server.session;
import org.eclipse.jetty.server.SessionIdManager;
import org.eclipse.jetty.session.infinispan.InfinispanSessionDataStore;
import org.eclipse.jetty.session.infinispan.InfinispanSessionManager;
import org.eclipse.jetty.session.infinispan.InfinispanSessionStore;
import org.eclipse.jetty.webapp.WebAppContext;
import org.infinispan.Cache;
import org.infinispan.commons.api.BasicCache;
@ -43,20 +42,18 @@ public class InfinispanTestSessionServer extends AbstractTestServer
super(port, maxInactivePeriod, scavengePeriod, idlePassivatePeriod, config);
}
@Override
public SessionManager newSessionManager()
public SessionHandler newSessionHandler()
{
InfinispanSessionManager sessionManager = new InfinispanSessionManager();
sessionManager.getSessionDataStore().setCache((BasicCache)_config);
return sessionManager;
}
@Override
public SessionHandler newSessionHandler(SessionManager sessionManager)
{
return new SessionHandler(sessionManager);
SessionHandler handler = new SessionHandler();
InfinispanSessionStore sds = new InfinispanSessionStore();
sds.setCache((BasicCache)_config);
DefaultSessionCache ss = new DefaultSessionCache(handler);
ss.setSessionStore(sds);
handler.setSessionStore(ss);
return handler;
}
public boolean exists (WebAppContext context, String id)
@ -64,7 +61,7 @@ public class InfinispanTestSessionServer extends AbstractTestServer
BasicCache cache = (BasicCache)_config;
if (cache != null)
{
return cache.containsKey(((InfinispanSessionDataStore)(context.getSessionHandler().getSessionManager().getSessionStore().getSessionDataStore())).getCacheKey(id));
return cache.containsKey(((InfinispanSessionStore)(context.getSessionHandler().getSessionStore().getSessionStore())).getCacheKey(id));
}
return false;
@ -75,7 +72,7 @@ public class InfinispanTestSessionServer extends AbstractTestServer
BasicCache cache = (BasicCache)_config;
if (cache != null)
{
return cache.get(((InfinispanSessionDataStore)(context.getSessionHandler().getSessionManager().getSessionStore().getSessionDataStore())).getCacheKey(id));
return cache.get(((InfinispanSessionStore)(context.getSessionHandler().getSessionStore().getSessionStore())).getCacheKey(id));
}
return null;

View File

@ -99,23 +99,13 @@ public class JdbcTestServer extends AbstractTestServer
* @see org.eclipse.jetty.server.session.AbstractTestServer#newSessionHandler(org.eclipse.jetty.server.SessionManager)
*/
@Override
public SessionHandler newSessionHandler(SessionManager sessionManager)
public SessionHandler newSessionHandler()
{
return new SessionHandler(sessionManager);
}
/**
* @see org.eclipse.jetty.server.session.AbstractTestServer#newSessionManager()
*/
/**
* @see org.eclipse.jetty.server.session.AbstractTestServer#newSessionManager()
*/
@Override
public SessionManager newSessionManager()
{
JDBCSessionManager manager = new JDBCSessionManager();
JDBCSessionDataStore ds = manager.getSessionDataStore();
SessionHandler handler = new SessionHandler();
DefaultSessionCache sessionStore = new DefaultSessionCache(handler);
handler.setSessionStore(sessionStore);
JDBCSessionDataStore ds = new JDBCSessionDataStore();
sessionStore.setSessionStore(ds);
ds.setGracePeriodSec(_scavengePeriod);
DatabaseAdaptor da = new DatabaseAdaptor();
da.setDriverInfo(DRIVER_CLASS, (_config==null?DEFAULT_CONNECTION_URL:(String)_config));
@ -134,10 +124,11 @@ public class JdbcTestServer extends AbstractTestServer
sessionTableSchema.setMapColumn(MAP_COL);
sessionTableSchema.setMaxIntervalColumn(MAX_IDLE_COL);
ds.setSessionTableSchema(sessionTableSchema);
return manager;
return handler;
}
public boolean existsInSessionTable(String id, boolean verbose)

View File

@ -21,8 +21,8 @@ package org.eclipse.jetty.nosql.mongodb;
import java.net.UnknownHostException;
import org.eclipse.jetty.server.SessionIdManager;
import org.eclipse.jetty.server.session.SessionManager;
import org.eclipse.jetty.server.session.AbstractTestServer;
import org.eclipse.jetty.server.session.DefaultSessionCache;
import org.eclipse.jetty.server.session.SessionHandler;
import com.mongodb.DBCollection;
@ -80,26 +80,26 @@ public class MongoTestServer extends AbstractTestServer
}
public SessionManager newSessionManager()
public SessionHandler newSessionHandler()
{
MongoSessionManager manager;
SessionHandler handler = new SessionHandler();
try
{
manager = new MongoSessionManager();
((MongoSessionManager)manager).getSessionDataStore().setDBCollection(getCollection());
manager.getSessionDataStore().setGracePeriodSec(_scavengePeriod);
MongoSessionStore ds = new MongoSessionStore();
ds.setDBCollection(getCollection());
ds.setGracePeriodSec(_scavengePeriod);
DefaultSessionCache ss = new DefaultSessionCache(handler);
handler.setSessionStore(ss);
return handler;
}
catch (Exception e)
{
throw new RuntimeException(e);
}
return manager;
}
public SessionHandler newSessionHandler(SessionManager sessionManager)
{
return new SessionHandler(sessionManager);
}
public static void main(String... args) throws Exception

View File

@ -278,9 +278,9 @@ public class SessionExpiryTest extends AbstractSessionExpiryTest
assertNotNull(sessions);
assertNotNull(id);
DBObject o = sessions.findOne(new BasicDBObject(MongoSessionDataStore.__ID,id));
DBObject o = sessions.findOne(new BasicDBObject(MongoSessionStore.__ID,id));
assertNotNull(o);
Long maxIdle = (Long)o.get(MongoSessionDataStore.__MAX_IDLE);
Long maxIdle = (Long)o.get(MongoSessionStore.__MAX_IDLE);
assertNotNull(maxIdle);
assertEquals(val, maxIdle.longValue());
}
@ -290,9 +290,9 @@ public class SessionExpiryTest extends AbstractSessionExpiryTest
assertNotNull(sessions);
assertNotNull(id);
DBObject o = sessions.findOne(new BasicDBObject(MongoSessionDataStore.__ID,id));
DBObject o = sessions.findOne(new BasicDBObject(MongoSessionStore.__ID,id));
assertNotNull(o);
Long expiry = (Long)o.get(MongoSessionDataStore.__EXPIRY);
Long expiry = (Long)o.get(MongoSessionStore.__EXPIRY);
return (expiry == null? null : expiry.longValue());
}
@ -301,9 +301,9 @@ public class SessionExpiryTest extends AbstractSessionExpiryTest
assertNotNull(sessions);
assertNotNull(id);
DBObject o = sessions.findOne(new BasicDBObject(MongoSessionDataStore.__ID,id));
DBObject o = sessions.findOne(new BasicDBObject(MongoSessionStore.__ID,id));
assertNotNull(o);
Long inactiveInterval = (Long)o.get(MongoSessionDataStore.__MAX_IDLE);
Long inactiveInterval = (Long)o.get(MongoSessionStore.__MAX_IDLE);
return (inactiveInterval == null? null : inactiveInterval.longValue());
}
@ -312,9 +312,9 @@ public class SessionExpiryTest extends AbstractSessionExpiryTest
assertNotNull(sessions);
assertNotNull(id);
DBObject o = sessions.findOne(new BasicDBObject(MongoSessionDataStore.__ID,id));
DBObject o = sessions.findOne(new BasicDBObject(MongoSessionStore.__ID,id));
assertNotNull(o);
Long accessed = (Long)o.get(MongoSessionDataStore.__ACCESSED);
Long accessed = (Long)o.get(MongoSessionStore.__ACCESSED);
return (accessed == null? null : accessed.longValue());
}
@ -323,7 +323,7 @@ public class SessionExpiryTest extends AbstractSessionExpiryTest
assertNotNull(sessions);
assertNotNull(id);
DBObject o = sessions.findOne(new BasicDBObject(MongoSessionDataStore.__ID,id));
DBObject o = sessions.findOne(new BasicDBObject(MongoSessionStore.__ID,id));
assertNotNull(o);
System.err.println(o);
}

View File

@ -184,8 +184,8 @@ public abstract class AbstractIdleSessionTest
pause(idlePeriod * 3);
//stop the scavenger
if (_server1.getInspector() != null)
_server1.getInspector().stop();
if (_server1.getHouseKeeper() != null)
_server1.getHouseKeeper().stop();
//check that the session is idle
checkSessionIdled(AbstractTestServer.extractSessionId(sessionCookie));

View File

@ -87,7 +87,7 @@ public abstract class AbstractImmortalSessionTest
resp = response.getContentAsString();
assertEquals(String.valueOf(value),resp.trim());
assertEquals(1, ((org.eclipse.jetty.server.session.SessionManager)context.getSessionHandler().getSessionManager()).getSessionsCreated());
assertEquals(1, context.getSessionHandler().getSessionsCreated());
}
finally
{

View File

@ -73,7 +73,7 @@ public abstract class AbstractLastAccessTimeTest
TestSessionListener listener1 = new TestSessionListener();
context.getSessionHandler().addEventListener(listener1);
context.addServlet(holder1, servletMapping);
SessionManager m1 = (SessionManager)context.getSessionHandler().getSessionManager();
SessionHandler m1 = context.getSessionHandler();
try
@ -83,7 +83,7 @@ public abstract class AbstractLastAccessTimeTest
AbstractTestServer server2 = createServer(0, maxInactivePeriod, scavengePeriod, idlePassivatePeriod);
ServletContextHandler context2 = server2.addContext(contextPath);
context2.addServlet(TestServlet.class, servletMapping);
SessionManager m2 = (SessionManager)context2.getSessionHandler().getSessionManager();
SessionHandler m2 = context2.getSessionHandler();
try
@ -100,9 +100,9 @@ public abstract class AbstractLastAccessTimeTest
assertEquals("test", response1.getContentAsString());
String sessionCookie = response1.getHeaders().get("Set-Cookie");
assertTrue( sessionCookie != null );
assertEquals(1, ((MemorySessionStore)m1.getSessionStore()).getSessions());
assertEquals(1, ((MemorySessionStore)m1.getSessionStore()).getSessionsMax());
assertEquals(1, ((MemorySessionStore)m1.getSessionStore()).getSessionsTotal());
assertEquals(1, ((DefaultSessionCache)m1.getSessionStore()).getSessions());
assertEquals(1, ((DefaultSessionCache)m1.getSessionStore()).getSessionsMax());
assertEquals(1, ((DefaultSessionCache)m1.getSessionStore()).getSessionsTotal());
// Mangle the cookie, replacing Path with $Path, etc.
sessionCookie = sessionCookie.replaceFirst("(\\W)(P|p)ath=", "$1\\$Path=");
@ -152,21 +152,21 @@ public abstract class AbstractLastAccessTimeTest
}
}
public void assertAfterSessionCreated (SessionManager m)
public void assertAfterSessionCreated (SessionHandler m)
{
assertSessionCounts(1, 1, 1, m);
}
public void assertAfterScavenge (SessionManager manager)
public void assertAfterScavenge (SessionHandler manager)
{
assertSessionCounts(1,1,1, manager);
}
public void assertSessionCounts (int current, int max, int total, SessionManager manager)
public void assertSessionCounts (int current, int max, int total, SessionHandler manager)
{
assertEquals(current, ((MemorySessionStore)manager.getSessionStore()).getSessions());
assertEquals(max, ((MemorySessionStore)manager.getSessionStore()).getSessionsMax());
assertEquals(total, ((MemorySessionStore)manager.getSessionStore()).getSessionsTotal());
assertEquals(current, ((DefaultSessionCache)manager.getSessionStore()).getSessions());
assertEquals(max, ((DefaultSessionCache)manager.getSessionStore()).getSessionsMax());
assertEquals(total, ((DefaultSessionCache)manager.getSessionStore()).getSessionsTotal());
}
public static class TestSessionListener implements HttpSessionListener

View File

@ -94,7 +94,7 @@ public abstract class AbstractLocalSessionScavengingTest
assertTrue(sessionCookie != null);
// Mangle the cookie, replacing Path with $Path, etc.
sessionCookie = sessionCookie.replaceFirst("(\\W)(P|p)ath=", "$1\\$Path=");
org.eclipse.jetty.server.session.SessionManager m1 = (org.eclipse.jetty.server.session.SessionManager)context1.getSessionHandler().getSessionManager();
SessionHandler m1 = context1.getSessionHandler();
assertEquals(1, m1.getSessionsCreated());
// Be sure the session is also present in node2
@ -102,7 +102,7 @@ public abstract class AbstractLocalSessionScavengingTest
request.header("Cookie", sessionCookie);
ContentResponse response2 = request.send();
assertEquals(HttpServletResponse.SC_OK,response2.getStatus());
org.eclipse.jetty.server.session.SessionManager m2 = (org.eclipse.jetty.server.session.SessionManager)context2.getSessionHandler().getSessionManager();
SessionHandler m2 = context2.getSessionHandler();
// Wait for the scavenger to run on node1, waiting 2.5 times the scavenger period
pause(scavengePeriod);

View File

@ -62,7 +62,7 @@ public abstract class AbstractRemoveSessionTest
context.addServlet(TestServlet.class, servletMapping);
TestEventListener testListener = new TestEventListener();
context.getSessionHandler().addEventListener(testListener);
SessionManager m = (SessionManager) context.getSessionHandler().getSessionManager();
SessionHandler m = context.getSessionHandler();
try
{
server.start();
@ -81,8 +81,8 @@ public abstract class AbstractRemoveSessionTest
//ensure sessionCreated listener is called
assertTrue (testListener.isCreated());
assertEquals(1, m.getSessionsCreated());
assertEquals(1, ((MemorySessionStore)m.getSessionStore()).getSessionsMax());
assertEquals(1, ((MemorySessionStore)m.getSessionStore()).getSessionsTotal());
assertEquals(1, ((DefaultSessionCache)m.getSessionStore()).getSessionsMax());
assertEquals(1, ((DefaultSessionCache)m.getSessionStore()).getSessionsTotal());
//now delete the session
Request request = client.newRequest("http://localhost:" + port + contextPath + servletMapping + "?action=delete");
@ -91,18 +91,18 @@ public abstract class AbstractRemoveSessionTest
assertEquals(HttpServletResponse.SC_OK,response.getStatus());
//ensure sessionDestroyed listener is called
assertTrue(testListener.isDestroyed());
assertEquals(0, ((MemorySessionStore)m.getSessionStore()).getSessions());
assertEquals(1, ((MemorySessionStore)m.getSessionStore()).getSessionsMax());
assertEquals(1, ((MemorySessionStore)m.getSessionStore()).getSessionsTotal());
assertEquals(0, ((DefaultSessionCache)m.getSessionStore()).getSessions());
assertEquals(1, ((DefaultSessionCache)m.getSessionStore()).getSessionsMax());
assertEquals(1, ((DefaultSessionCache)m.getSessionStore()).getSessionsTotal());
// The session is not there anymore, even if we present an old cookie
request = client.newRequest("http://localhost:" + port + contextPath + servletMapping + "?action=check");
request.header("Cookie", sessionCookie);
response = request.send();
assertEquals(HttpServletResponse.SC_OK,response.getStatus());
assertEquals(0, ((MemorySessionStore)m.getSessionStore()).getSessions());
assertEquals(1, ((MemorySessionStore)m.getSessionStore()).getSessionsMax());
assertEquals(1, ((MemorySessionStore)m.getSessionStore()).getSessionsTotal());
assertEquals(0, ((DefaultSessionCache)m.getSessionStore()).getSessions());
assertEquals(1, ((DefaultSessionCache)m.getSessionStore()).getSessionsMax());
assertEquals(1, ((DefaultSessionCache)m.getSessionStore()).getSessionsTotal());
}
finally
{

View File

@ -159,7 +159,7 @@ public abstract class AbstractSessionRenewTest
assertTrue(beforeSession==afterSession); //same object
assertFalse(beforeSessionId.equals(afterSessionId)); //different id
SessionManager sessionManager = ((Session)afterSession).getSessionManager();
SessionHandler sessionManager = ((Session)afterSession).getSessionHandler();
DefaultSessionIdManager sessionIdManager = (DefaultSessionIdManager)sessionManager.getSessionIdManager();
assertTrue(sessionIdManager.isIdInUse(afterSessionId)); //new session id should be in use

Some files were not shown because too many files have changed in this diff Show More