Hi, for some feature of the memcached-session-manager (memcached-based session failover, [1]) I want to access/reference webapplication classes (in WEB-INF/lib/) directly from my manager implementation (subclasses o.a.catalina.session.ManagerBase, registered via Context/Manager) when tomcat starts. Alternatively, I would like to do this during request time (in the context of a request). Unfortunately, this doesn't seem to work (the issue is describe later, below).
The strange thing is that basically the memcached-session-manager (msm) already needs to have access to classes from the webapp, as it serialized/deserializes them (in the context of a request). In these cases I use the manager.getContainer().getLoader().getClassLoader(), which reports to be a WebappClassLoader. The exact issue that I have now is that I want to ship msm with custom serializers for certain types that are used when some class is avaible: e.g. if the application uses joda DateTime I want to activate a custom serializer for joda DateTime. The code that tries to load the serializer for joda DateTime looks like this: public class CustomFormatLoader { ... public static XMLFormat<?>[] loadFormats( final ClassLoader classLoader ) { final List<XMLFormat<?>> result = new ArrayList<XMLFormat<?>>(); try { // see if we can load the JodaDateTimeFormat final XMLFormat<?> xmlFormat = (XMLFormat<?>) Class.forName( "de.javakaffee.web.msm.serializer.javolution.JodaDateTimeFormat", true, classLoader ).newInstance(); result.add( xmlFormat ); LOG.info( "Loaded JodaDateTimeFormat." ); } catch ( final Exception e ) { LOG.info( "JodaDateTimeFormat not loaded (joda seems to be not available)." ); } return result.toArray( new XMLFormat<?>[result.size()] ); } } The JodaDateTimeFormat: public class JodaDateTimeFormat extends XMLFormat<DateTime> { private static final DateTimeFormatter FORMAT = ISODateTimeFormat.basicDateTime(); /** * @param cls */ protected JodaDateTimeFormat() { super( DateTime.class ); } ... } When I try to loadFormats in the context of a request, this exception is thrown: Jan 10, 2010 2:57:51 PM org.apache.catalina.connector.CoyoteAdapter service SEVERE: An exception or error occurred in the container during the request processing java.lang.NoClassDefFoundError: org/joda/time/format/ISODateTimeFormat at de.javakaffee.web.msm.serializer.javolution.JodaDateTimeFormat.<clinit>(JodaDateTimeFormat.java:35) at java.lang.Class.forName0(Native Method) at java.lang.Class.forName(Class.java:247) at de.javakaffee.web.msm.serializer.javolution.CustomFormatLoader.loadFormats(CustomFormatLoader.java:46) at de.javakaffee.web.msm.serializer.javolution.ReflectionBinding.getFormat(ReflectionBinding.java:134) at javolution.xml.XMLFormat$OutputElement.add(XMLFormat.java:815) at javolution.xml.XMLObjectWriter.write(XMLObjectWriter.java:242) at de.javakaffee.web.msm.serializer.javolution.JavolutionTranscoder.serialize(JavolutionTranscoder.java:108) at net.spy.memcached.transcoders.SerializingTranscoder.encode(SerializingTranscoder.java:135) at net.spy.memcached.MemcachedClient.asyncStore(MemcachedClient.java:274) at net.spy.memcached.MemcachedClient.set(MemcachedClient.java:631) at de.javakaffee.web.msm.MemcachedBackupSessionManager.storeSessionInMemcached(MemcachedBackupSessionManager.java:721) at de.javakaffee.web.msm.MemcachedBackupSessionManager.backupSession(MemcachedBackupSessionManager.java:495) at de.javakaffee.web.msm.SessionTrackerValve.backupSession(SessionTrackerValve.java:117) at de.javakaffee.web.msm.SessionTrackerValve.invoke(SessionTrackerValve.java:107) at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128) at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102) at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109) at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:286) at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:845) at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:583) at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447) at java.lang.Thread.run(Thread.java:619) Caused by: java.lang.ClassNotFoundException: org.joda.time.format.ISODateTimeFormat at java.net.URLClassLoader$1.run(URLClassLoader.java:200) at java.security.AccessController.doPrivileged(Native Method) at java.net.URLClassLoader.findClass(URLClassLoader.java:188) at java.lang.ClassLoader.loadClass(ClassLoader.java:307) at java.lang.ClassLoader.loadClass(ClassLoader.java:252) at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:320) Though, the ISODateTimeFormat definitively is available in the classpath, as it's used in the application, and also [grot...@mescalin hunter]$ jar tvf webapps/shop/WEB-INF/lib/joda-time-1.6.jar | grep ISODateTimeFormat 14278 Tue Oct 28 00:12:14 CET 2008 org/joda/time/format/ISODateTimeFormat.class shows this. Can someone help with this? Thanx in advance, cheers, Martin [1] http://code.google.com/p/memcached-session-manager/
signature.asc
Description: This is a digitally signed message part