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>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.eclipse.jetty.gcloud</groupId>
|
||||
<artifactId>gcloud-session-manager</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.eclipse.jetty</groupId>
|
||||
<artifactId>jetty-nosql</artifactId>
|
||||
|
|
|
@ -9,9 +9,7 @@
|
|||
<!-- https://www.eclipse.org/jetty/documentation/current/configuring-security-secure-passwords.html -->
|
||||
<!-- ============================================================================================== -->
|
||||
<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>
|
||||
</Args>
|
||||
</Call>
|
||||
|
||||
<!-- ============================================================================================== -->
|
||||
|
@ -19,12 +17,14 @@
|
|||
<!-- Note: passwords can use jetty obfuscation (see -->
|
||||
<!-- https://www.eclipse.org/jetty/documentation/current/configuring-security-secure-passwords.html -->
|
||||
<!-- ============================================================================================== -->
|
||||
<!--
|
||||
<New id="gconf" class="org.eclipse.jetty.gcloud.session.GCloudConfiguration">
|
||||
<Set name="projectId"><Property name="jetty.gcloudSession.projectId"/></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>
|
||||
-->
|
||||
|
||||
|
||||
<!-- ===================================================================== -->
|
||||
|
@ -33,10 +33,10 @@
|
|||
<Set name="sessionIdManager">
|
||||
<New id="idMgr" class="org.eclipse.jetty.gcloud.session.GCloudSessionIdManager">
|
||||
<Arg>
|
||||
<Ref refid="Server"/>
|
||||
<Ref id="Server"/>
|
||||
</Arg>
|
||||
<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>
|
||||
</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-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://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://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
|
||||
|
|
|
@ -29,6 +29,7 @@ import java.util.Set;
|
|||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
import java.util.concurrent.atomic.AtomicReference;
|
||||
import java.util.concurrent.locks.ReentrantLock;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
|
@ -179,6 +180,14 @@ public class GCloudSessionManager extends AbstractSessionManager
|
|||
if (entity == null)
|
||||
return null;
|
||||
|
||||
final AtomicReference<Session> reference = new AtomicReference<Session>();
|
||||
final AtomicReference<Exception> exception = new AtomicReference<Exception>();
|
||||
Runnable load = new Runnable()
|
||||
{
|
||||
public void run ()
|
||||
{
|
||||
try
|
||||
{
|
||||
//turn an entity into a Session
|
||||
String clusterId = entity.getString(CLUSTERID);
|
||||
String contextPath = entity.getString(CONTEXTPATH);
|
||||
|
@ -199,12 +208,34 @@ public class GCloudSessionManager extends AbstractSessionManager
|
|||
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);
|
||||
}
|
||||
return session;
|
||||
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 reference.get();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -506,6 +537,7 @@ public class GCloudSessionManager extends AbstractSessionManager
|
|||
@Override
|
||||
protected void timeout()
|
||||
{
|
||||
if (LOG.isDebugEnabled()) LOG.debug("Timing out session {}", getId());
|
||||
super.timeout();
|
||||
}
|
||||
|
||||
|
@ -795,12 +827,17 @@ public class GCloudSessionManager extends AbstractSessionManager
|
|||
//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);
|
||||
if (memSession == null)
|
||||
{
|
||||
memSession = session;
|
||||
}
|
||||
|
||||
//final check
|
||||
if (memSession.isExpiredAt(now))
|
||||
{
|
||||
if (LOG.isDebugEnabled()) LOG.debug("Session {} is definitely expired", memSession.getId());
|
||||
memSession.timeout();
|
||||
}
|
||||
}
|
||||
|
||||
public long getScavengeIntervalSec ()
|
||||
{
|
||||
|
@ -1050,8 +1087,10 @@ public class GCloudSessionManager extends AbstractSessionManager
|
|||
try
|
||||
{
|
||||
if (session != null)
|
||||
{
|
||||
delete(session);
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
LOG.warn("Problem deleting session id="+idInCluster, e);
|
||||
|
|
Loading…
Reference in New Issue