Ensure webapp classloader used to reinflate session from gcloudatastore
This commit is contained in:
parent
dafb354d4b
commit
c70d11c27d
|
@ -778,6 +778,11 @@
|
||||||
<artifactId>jetty-infinispan</artifactId>
|
<artifactId>jetty-infinispan</artifactId>
|
||||||
<version>${project.version}</version>
|
<version>${project.version}</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.eclipse.jetty.gcloud</groupId>
|
||||||
|
<artifactId>gcloud-session-manager</artifactId>
|
||||||
|
<version>${project.version}</version>
|
||||||
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.eclipse.jetty</groupId>
|
<groupId>org.eclipse.jetty</groupId>
|
||||||
<artifactId>jetty-nosql</artifactId>
|
<artifactId>jetty-nosql</artifactId>
|
||||||
|
|
|
@ -9,9 +9,7 @@
|
||||||
<!-- https://www.eclipse.org/jetty/documentation/current/configuring-security-secure-passwords.html -->
|
<!-- https://www.eclipse.org/jetty/documentation/current/configuring-security-secure-passwords.html -->
|
||||||
<!-- ============================================================================================== -->
|
<!-- ============================================================================================== -->
|
||||||
<Call id="gconf" class="org.eclipse.jetty.gcloud.session.GCloudConfiguration" name="fromFile">
|
<Call id="gconf" class="org.eclipse.jetty.gcloud.session.GCloudConfiguration" name="fromFile">
|
||||||
<Args>
|
<Arg><Property name="jetty.base" default="."/>/<Property name="jetty.gcloudSession.configFile" default="etc/gcloud.props"/></Arg>
|
||||||
<Arg><Property name="jetty.base" default="."/>/<Property name="jetty.gcloudSession.configFile" default="etc/gcloud.props"/></Arg>
|
|
||||||
</Args>
|
|
||||||
</Call>
|
</Call>
|
||||||
|
|
||||||
<!-- ============================================================================================== -->
|
<!-- ============================================================================================== -->
|
||||||
|
@ -19,12 +17,14 @@
|
||||||
<!-- Note: passwords can use jetty obfuscation (see -->
|
<!-- Note: passwords can use jetty obfuscation (see -->
|
||||||
<!-- https://www.eclipse.org/jetty/documentation/current/configuring-security-secure-passwords.html -->
|
<!-- https://www.eclipse.org/jetty/documentation/current/configuring-security-secure-passwords.html -->
|
||||||
<!-- ============================================================================================== -->
|
<!-- ============================================================================================== -->
|
||||||
|
<!--
|
||||||
<New id="gconf" class="org.eclipse.jetty.gcloud.session.GCloudConfiguration">
|
<New id="gconf" class="org.eclipse.jetty.gcloud.session.GCloudConfiguration">
|
||||||
<Set name="projectId"><Property name="jetty.gcloudSession.projectId"/></Set>
|
<Set name="projectId"><Property name="jetty.gcloudSession.projectId"/></Set>
|
||||||
<Set name="p12File"><Property name="jetty.gcloudSession.p12File"/></Set>
|
<Set name="p12File"><Property name="jetty.gcloudSession.p12File"/></Set>
|
||||||
<Set name="serviceAccount"><Property name="jetty.gcloudSession.serviceAccount"/></Set>
|
<Set name="serviceAccount"><Property name="jetty.gcloudSession.serviceAccount"/></Set>
|
||||||
<Set name="password"><Property name="jetty.gcloudSession.password"/></Set>
|
<Set name="password"><Property name="jetty.gcloudSession.password"/></Set>
|
||||||
</New>
|
</New>
|
||||||
|
-->
|
||||||
|
|
||||||
|
|
||||||
<!-- ===================================================================== -->
|
<!-- ===================================================================== -->
|
||||||
|
@ -33,10 +33,10 @@
|
||||||
<Set name="sessionIdManager">
|
<Set name="sessionIdManager">
|
||||||
<New id="idMgr" class="org.eclipse.jetty.gcloud.session.GCloudSessionIdManager">
|
<New id="idMgr" class="org.eclipse.jetty.gcloud.session.GCloudSessionIdManager">
|
||||||
<Arg>
|
<Arg>
|
||||||
<Ref refid="Server"/>
|
<Ref id="Server"/>
|
||||||
</Arg>
|
</Arg>
|
||||||
<Set name="workerName"><Property name="jetty.gcloudSession.workerName" default="node1"/></Set>
|
<Set name="workerName"><Property name="jetty.gcloudSession.workerName" default="node1"/></Set>
|
||||||
<Set name="config"><Ref refid="gconf"/></Set>
|
<Set name="config"><Ref id="gconf"/></Set>
|
||||||
</New>
|
</New>
|
||||||
</Set>
|
</Set>
|
||||||
|
|
||||||
|
|
|
@ -32,7 +32,7 @@ maven://javax.transaction/transaction-api/1.1|lib/gcloud/transaction-api-1.1.jar
|
||||||
maven://com.google.http-client/google-http-client-appengine/1.20.0|lib/gcloud/google-http-client-appengine-1.20.0.jar
|
maven://com.google.http-client/google-http-client-appengine/1.20.0|lib/gcloud/google-http-client-appengine-1.20.0.jar
|
||||||
maven://com.google.http-client/google-http-client-jackson/1.20.0|lib/gcloud/google-http-client-jackson-1.20.0.jar
|
maven://com.google.http-client/google-http-client-jackson/1.20.0|lib/gcloud/google-http-client-jackson-1.20.0.jar
|
||||||
maven://org.codehaus.jackson/jackson-core-asl/1.9.11|lib/gcloud/jackson-core-asl-1.9.11.jar
|
maven://org.codehaus.jackson/jackson-core-asl/1.9.11|lib/gcloud/jackson-core-asl-1.9.11.jar
|
||||||
maven://joda-time/joda-time/RELEASE|lib/gcloud/joda-time-RELEASE.jar
|
maven://joda-time/joda-time/2.8.2|lib/gcloud/joda-time-2.8.2.jar
|
||||||
maven://org.json/json/20090211|lib/gcloud/json-20090211.jar
|
maven://org.json/json/20090211|lib/gcloud/json-20090211.jar
|
||||||
maven://com.google.apis/google-api-services-datastore-protobuf/v1beta2-rev1-2.1.2|lib/gcloud/google-api-services-datastore-protobuf-v1beta2-rev1-2.1.2.jar
|
maven://com.google.apis/google-api-services-datastore-protobuf/v1beta2-rev1-2.1.2|lib/gcloud/google-api-services-datastore-protobuf-v1beta2-rev1-2.1.2.jar
|
||||||
maven://com.google.protobuf/protobuf-java/2.5.0|lib/gcloud/protobuf-java-2.5.0.jar
|
maven://com.google.protobuf/protobuf-java/2.5.0|lib/gcloud/protobuf-java-2.5.0.jar
|
||||||
|
|
|
@ -29,6 +29,7 @@ import java.util.Set;
|
||||||
import java.util.concurrent.ConcurrentHashMap;
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
import java.util.concurrent.atomic.AtomicInteger;
|
import java.util.concurrent.atomic.AtomicInteger;
|
||||||
|
import java.util.concurrent.atomic.AtomicReference;
|
||||||
import java.util.concurrent.locks.ReentrantLock;
|
import java.util.concurrent.locks.ReentrantLock;
|
||||||
|
|
||||||
import javax.servlet.http.HttpServletRequest;
|
import javax.servlet.http.HttpServletRequest;
|
||||||
|
@ -178,33 +179,63 @@ public class GCloudSessionManager extends AbstractSessionManager
|
||||||
{
|
{
|
||||||
if (entity == null)
|
if (entity == null)
|
||||||
return null;
|
return null;
|
||||||
|
|
||||||
//turn an entity into a Session
|
final AtomicReference<Session> reference = new AtomicReference<Session>();
|
||||||
String clusterId = entity.getString(CLUSTERID);
|
final AtomicReference<Exception> exception = new AtomicReference<Exception>();
|
||||||
String contextPath = entity.getString(CONTEXTPATH);
|
Runnable load = new Runnable()
|
||||||
String vhost = entity.getString(VHOST);
|
|
||||||
long accessed = entity.getLong(ACCESSED);
|
|
||||||
long lastAccessed = entity.getLong(LASTACCESSED);
|
|
||||||
long createTime = entity.getLong(CREATETIME);
|
|
||||||
long cookieSetTime = entity.getLong(COOKIESETTIME);
|
|
||||||
String lastNode = entity.getString(LASTNODE);
|
|
||||||
long expiry = entity.getLong(EXPIRY);
|
|
||||||
long maxInactive = entity.getLong(MAXINACTIVE);
|
|
||||||
Blob blob = (Blob) entity.getBlob(ATTRIBUTES);
|
|
||||||
|
|
||||||
Session session = new Session (clusterId, createTime, accessed, maxInactive);
|
|
||||||
session.setLastNode(lastNode);
|
|
||||||
session.setContextPath(contextPath);
|
|
||||||
session.setVHost(vhost);
|
|
||||||
session.setCookieSetTime(cookieSetTime);
|
|
||||||
session.setLastAccessedTime(lastAccessed);
|
|
||||||
session.setLastNode(lastNode);
|
|
||||||
try (ClassLoadingObjectInputStream ois = new ClassLoadingObjectInputStream(blob.asInputStream()))
|
|
||||||
{
|
{
|
||||||
Object o = ois.readObject();
|
public void run ()
|
||||||
session.addAttributes((Map<String,Object>)o);
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
//turn an entity into a Session
|
||||||
|
String clusterId = entity.getString(CLUSTERID);
|
||||||
|
String contextPath = entity.getString(CONTEXTPATH);
|
||||||
|
String vhost = entity.getString(VHOST);
|
||||||
|
long accessed = entity.getLong(ACCESSED);
|
||||||
|
long lastAccessed = entity.getLong(LASTACCESSED);
|
||||||
|
long createTime = entity.getLong(CREATETIME);
|
||||||
|
long cookieSetTime = entity.getLong(COOKIESETTIME);
|
||||||
|
String lastNode = entity.getString(LASTNODE);
|
||||||
|
long expiry = entity.getLong(EXPIRY);
|
||||||
|
long maxInactive = entity.getLong(MAXINACTIVE);
|
||||||
|
Blob blob = (Blob) entity.getBlob(ATTRIBUTES);
|
||||||
|
|
||||||
|
Session session = new Session (clusterId, createTime, accessed, maxInactive);
|
||||||
|
session.setLastNode(lastNode);
|
||||||
|
session.setContextPath(contextPath);
|
||||||
|
session.setVHost(vhost);
|
||||||
|
session.setCookieSetTime(cookieSetTime);
|
||||||
|
session.setLastAccessedTime(lastAccessed);
|
||||||
|
session.setLastNode(lastNode);
|
||||||
|
session.setExpiry(expiry);
|
||||||
|
try (ClassLoadingObjectInputStream ois = new ClassLoadingObjectInputStream(blob.asInputStream()))
|
||||||
|
{
|
||||||
|
Object o = ois.readObject();
|
||||||
|
session.addAttributes((Map<String,Object>)o);
|
||||||
|
}
|
||||||
|
reference.set(session);
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
exception.set(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
if (_context==null)
|
||||||
|
load.run();
|
||||||
|
else
|
||||||
|
_context.getContextHandler().handle(null,load);
|
||||||
|
|
||||||
|
|
||||||
|
if (exception.get() != null)
|
||||||
|
{
|
||||||
|
exception.get().printStackTrace();
|
||||||
|
throw exception.get();
|
||||||
}
|
}
|
||||||
return session;
|
|
||||||
|
return reference.get();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -506,6 +537,7 @@ public class GCloudSessionManager extends AbstractSessionManager
|
||||||
@Override
|
@Override
|
||||||
protected void timeout()
|
protected void timeout()
|
||||||
{
|
{
|
||||||
|
if (LOG.isDebugEnabled()) LOG.debug("Timing out session {}", getId());
|
||||||
super.timeout();
|
super.timeout();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -795,11 +827,16 @@ public class GCloudSessionManager extends AbstractSessionManager
|
||||||
//if the session isn't in memory already, put it there so we can do a normal timeout call
|
//if the session isn't in memory already, put it there so we can do a normal timeout call
|
||||||
Session memSession = _sessions.putIfAbsent(session.getId(), session);
|
Session memSession = _sessions.putIfAbsent(session.getId(), session);
|
||||||
if (memSession == null)
|
if (memSession == null)
|
||||||
|
{
|
||||||
memSession = session;
|
memSession = session;
|
||||||
|
}
|
||||||
|
|
||||||
//final check
|
//final check
|
||||||
if (memSession.isExpiredAt(now))
|
if (memSession.isExpiredAt(now))
|
||||||
|
{
|
||||||
|
if (LOG.isDebugEnabled()) LOG.debug("Session {} is definitely expired", memSession.getId());
|
||||||
memSession.timeout();
|
memSession.timeout();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public long getScavengeIntervalSec ()
|
public long getScavengeIntervalSec ()
|
||||||
|
@ -1050,7 +1087,9 @@ public class GCloudSessionManager extends AbstractSessionManager
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
if (session != null)
|
if (session != null)
|
||||||
|
{
|
||||||
delete(session);
|
delete(session);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in New Issue