fhanik 2005/02/08 15:15:06 Modified: modules/cluster/src/share/org/apache/catalina/cluster/session DeltaManager.java Log: Set the context class loader while doing a state transfer, otherwise static struts classes fail loading Revision Changes Path 1.38 +70 -60 jakarta-tomcat-catalina/modules/cluster/src/share/org/apache/catalina/cluster/session/DeltaManager.java Index: DeltaManager.java =================================================================== RCS file: /home/cvs/jakarta-tomcat-catalina/modules/cluster/src/share/org/apache/catalina/cluster/session/DeltaManager.java,v retrieving revision 1.37 retrieving revision 1.38 diff -u -r1.37 -r1.38 --- DeltaManager.java 7 Feb 2005 21:56:32 -0000 1.37 +++ DeltaManager.java 8 Feb 2005 23:15:06 -0000 1.38 @@ -357,52 +357,28 @@ ObjectInputStream ois = null; Loader loader = null; ClassLoader classLoader = null; + ClassLoader originalLoader = Thread.currentThread().getContextClassLoader(); try { - fis = new ByteArrayInputStream(data); - BufferedInputStream bis = new BufferedInputStream(fis); - if (container != null) - loader = container.getLoader(); - if (loader != null) - classLoader = loader.getClassLoader(); - if (classLoader != null) { - ois = new CustomObjectInputStream(bis, classLoader); - } else { - ois = new ObjectInputStream(bis); - } - } catch (IOException e) { - log.error(sm.getString("standardManager.loading.ioe", e), e); - if (ois != null) { - try { - ois.close(); - } catch (IOException f) { - ; - } - ois = null; - } - throw e; - } - - // Load the previously unloaded active sessions - synchronized (sessions) { + try { - Integer count = (Integer) ois.readObject(); - int n = count.intValue(); - for (int i = 0; i < n; i++) { - DeltaSession session = getNewDeltaSession(); - session.readObjectData(ois); - session.setManager(this); - session.setValid(true); - session.setPrimarySession(false); - //in case the nodes in the cluster are out of - //time synch, this will make sure that we have the - //correct timestamp, isValid returns true, cause accessCount=1 - session.access(); - //make sure that the session gets ready to expire if needed - session.setAccessCount(0); - sessions.put(session.getId(), session); + fis = new ByteArrayInputStream(data); + BufferedInputStream bis = new BufferedInputStream(fis); + if (container != null) + loader = container.getLoader(); + if (loader != null) + classLoader = loader.getClassLoader(); + if (classLoader != null) { + log.debug( + "\n\n\n[CLUSTER] Loading the object data with a class loader.\n\n\n"); + ois = new CustomObjectInputStream(bis, classLoader); + Thread.currentThread().setContextClassLoader(classLoader); + } else { + log.debug( + "\n\n\n[CLUSTER] Loading the object data without a class loader.\n\n\n"); + ois = new ObjectInputStream(bis); } - } catch (ClassNotFoundException e) { - log.error(sm.getString("standardManager.loading.cnfe", e), e); + } catch (IOException e) { + log.error(sm.getString("standardManager.loading.ioe", e), e); if (ois != null) { try { ois.close(); @@ -412,27 +388,61 @@ ois = null; } throw e; - } catch (IOException e) { - log.error(sm.getString("standardManager.loading.ioe", e), e); - if (ois != null) { + } + // Load the previously unloaded active sessions + synchronized (sessions) { + try { + Integer count = (Integer) ois.readObject(); + int n = count.intValue(); + for (int i = 0; i < n; i++) { + DeltaSession session = getNewDeltaSession(); + session.readObjectData(ois); + session.setManager(this); + session.setValid(true); + session.setPrimarySession(false); + //in case the nodes in the cluster are out of + //time synch, this will make sure that we have the + //correct timestamp, isValid returns true, cause accessCount=1 + session.access(); + //make sure that the session gets ready to expire if needed + session.setAccessCount(0); + sessions.put(session.getId(), session); + } + } catch (ClassNotFoundException e) { + log.error(sm.getString("standardManager.loading.cnfe", e), + e); + if (ois != null) { + try { + ois.close(); + } catch (IOException f) { + ; + } + ois = null; + } + throw e; + } catch (IOException e) { + log.error(sm.getString("standardManager.loading.ioe", e), e); + if (ois != null) { + try { + ois.close(); + } catch (IOException f) { + ; + } + ois = null; + } + throw e; + } finally { + // Close the input stream try { - ois.close(); + if (ois != null) + ois.close(); } catch (IOException f) { - ; + // ignored } - ois = null; } - throw e; - } finally { - // Close the input stream - try { - if (ois != null) - ois.close(); - } catch (IOException f) { - // ignored - } - } + } finally { + if ( originalLoader != null ) Thread.currentThread().setContextClassLoader(originalLoader); } }
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]