Ensure webapp classloader used to reinflate session from gcloudatastore

This commit is contained in:
Jan Bartel 2015-10-02 10:32:41 +10:00
parent dafb354d4b
commit c70d11c27d
4 changed files with 75 additions and 31 deletions

View File

@ -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>

View File

@ -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>
<Arg><Property name="jetty.base" default="."/>/<Property name="jetty.gcloudSession.configFile" default="etc/gcloud.props"/></Arg>
</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>

View File

@ -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

View File

@ -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;
@ -178,33 +179,63 @@ public class GCloudSessionManager extends AbstractSessionManager
{
if (entity == null)
return null;
//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);
try (ClassLoadingObjectInputStream ois = new ClassLoadingObjectInputStream(blob.asInputStream()))
final AtomicReference<Session> reference = new AtomicReference<Session>();
final AtomicReference<Exception> exception = new AtomicReference<Exception>();
Runnable load = new Runnable()
{
Object o = ois.readObject();
session.addAttributes((Map<String,Object>)o);
public void run ()
{
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
protected void timeout()
{
if (LOG.isDebugEnabled()) LOG.debug("Timing out session {}", getId());
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
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,7 +1087,9 @@ public class GCloudSessionManager extends AbstractSessionManager
try
{
if (session != null)
{
delete(session);
}
}
catch (Exception e)
{