diff --git a/core/src/main/java/de/javakaffee/web/msm/RequestTrackingHostValve.java b/core/src/main/java/de/javakaffee/web/msm/RequestTrackingHostValve.java index 3eb5c5ab..7fcf99a1 100644 --- a/core/src/main/java/de/javakaffee/web/msm/RequestTrackingHostValve.java +++ b/core/src/main/java/de/javakaffee/web/msm/RequestTrackingHostValve.java @@ -158,7 +158,25 @@ public void invoke( final Request request, final Response response ) throws IOEx getNext().invoke( request, response ); } finally { final Boolean sessionIdChanged = (Boolean) request.getNote(SESSION_ID_CHANGED); - backupSession( request, response, sessionIdChanged == null ? false : sessionIdChanged.booleanValue() ); + + ClassLoader old = Thread.currentThread().getContextClassLoader(); + //From org.apache.catalina.core.StandardHostValve.invoke(Request, Response) + // Bind the context CL to the current thread + if( _msmContext.getLoader() != null ) { + // Not started - it should check for availability first + // This should eventually move to Engine, it's generic. + Thread.currentThread().setContextClassLoader + (_msmContext.getLoader().getClassLoader()); + } + try { + backupSession( request, response, sessionIdChanged == null ? false : sessionIdChanged.booleanValue() ); + }finally { + // Restore the context classloader + if(old!=null) { + Thread.currentThread().setContextClassLoader(old); + } + } + resetRequestThreadLocal(); } diff --git a/core/src/main/java/de/javakaffee/web/msm/TranscoderService.java b/core/src/main/java/de/javakaffee/web/msm/TranscoderService.java index b0db00e4..e09a3f7f 100644 --- a/core/src/main/java/de/javakaffee/web/msm/TranscoderService.java +++ b/core/src/main/java/de/javakaffee/web/msm/TranscoderService.java @@ -148,6 +148,9 @@ public MemcachedBackupSession deserialize( final byte[] data, final SessionManag * @see de.javakaffee.web.msm.SessionAttributesTranscoder#serializeAttributes(MemcachedBackupSession, ConcurrentMap) */ public byte[] serializeAttributes( final MemcachedBackupSession session, final ConcurrentMap attributes ) { + if(LOG.isTraceEnabled()) { + LOG.trace("Context Classloader - serialize: " + Thread.currentThread().getContextClassLoader()); + } return _attributesTranscoder.serializeAttributes( session, attributes ); } @@ -164,6 +167,9 @@ public byte[] serializeAttributes( final MemcachedBackupSession session, final C * @see de.javakaffee.web.msm.SessionAttributesTranscoder#deserializeAttributes(byte[]) */ public ConcurrentMap deserializeAttributes(final byte[] data ) { + if(LOG.isTraceEnabled()) { + LOG.trace("Context Classloader - deserialize: " + Thread.currentThread().getContextClassLoader()); + } return _attributesTranscoder.deserializeAttributes( data ); }