Added: 
tomcat/sandbox/tomcat-lite/java/org/apache/tomcat/servlets/session/SessionManagerServlet.java
URL: 
http://svn.apache.org/viewvc/tomcat/sandbox/tomcat-lite/java/org/apache/tomcat/servlets/session/SessionManagerServlet.java?rev=433260&view=auto
==============================================================================
--- 
tomcat/sandbox/tomcat-lite/java/org/apache/tomcat/servlets/session/SessionManagerServlet.java
 (added)
+++ 
tomcat/sandbox/tomcat-lite/java/org/apache/tomcat/servlets/session/SessionManagerServlet.java
 Mon Aug 21 08:20:40 2006
@@ -0,0 +1,575 @@
+/*
+ * Copyright 1999,2004 The Apache Software Foundation.
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+
+package org.apache.tomcat.servlets.session;
+
+
+import java.io.IOException;
+import java.util.Date;
+import java.util.EventListener;
+import java.util.HashMap;
+import java.util.LinkedHashMap;
+import java.util.List;
+import java.util.Map;
+
+import javax.servlet.ServletContext;
+import javax.servlet.http.Cookie;
+import javax.servlet.http.HttpServlet;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpSession;
+
+import org.apache.catalina.Globals;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.tomcat.servlets.util.RandomGenerator;
+
+// TODO: move 'expiring objects' to a separate utility class
+// TODO: hook the background thread
+
+// Must be implemented as load-on-startup
+
+
+/**
+ * Minimal implementation of the <b>Manager</b> interface that supports
+ * no session persistence or distributable capabilities.  This class may
+ * be subclassed to create more sophisticated Manager implementations.
+ *
+ * @author Costin Manolache
+ * @author Craig R. McClanahan
+ */
+public class SessionManagerServlet extends HttpServlet {
+    protected static Log log = LogFactory.getLog(SessionManagerServlet.class);
+
+    protected RandomGenerator randomG = new RandomGenerator();
+    
+    protected ServletContext context;
+
+    static class ExpiringMap {
+        
+        
+    }
+    
+
+    /**
+     * The distributable flag for Sessions created by this Manager.  If this
+     * flag is set to <code>true</code>, any user attributes added to a
+     * session controlled by this Manager must be Serializable. 
+     * 
+     * This is for compliance with the spec - tomcat-lite is not intended for
+     * session replication ( use a full version for that )
+     */
+    protected boolean distributable;
+
+    /**
+     * The default maximum inactive interval for Sessions created by
+     * this Manager.
+     */
+    protected int maxInactiveInterval = 60;
+
+    /**
+     * The longest time (in seconds) that an expired session had been alive.
+     */
+    protected int sessionMaxAliveTime;
+
+
+    /**
+     * Average time (in seconds) that expired sessions had been alive.
+     */
+    protected int sessionAverageAliveTime;
+
+
+    /**
+     * Number of sessions that have expired.
+     */
+    protected int expiredSessions = 0;
+
+    static class SessionLRU extends LinkedHashMap {
+        protected boolean removeEldestEntry(Map.Entry eldest) {
+            HttpSessionImpl s = (HttpSessionImpl)eldest.getValue();
+            int size = this.size();
+            
+            // TODO: check if eldest is expired or if we're above the limit.
+            // if eldest is expired, turn a flag to check for more.
+            
+            // Note: this doesn't work well for sessions that set shorter
+            // expiry time, or longer expiry times. 
+            return false;
+        }
+
+    }
+
+    /**
+     * The set of currently active Sessions for this Manager, keyed by
+     * session identifier.
+     */
+    protected LinkedHashMap sessions = new SessionLRU();
+        
+    // Number of sessions created by this manager
+    protected int sessionCounter=0;
+
+    protected int maxActive=0;
+
+    // number of duplicated session ids - anything >0 means we have problems
+    protected int duplicates=0;
+
+    protected boolean initialized=false;
+    
+    /**
+     * Processing time during session expiration.
+     */
+    protected long processingTime = 0;
+
+    /**
+     * Iteration count for background processing.
+     */
+    private int count = 0;
+
+
+    /**
+     * Frequency of the session expiration, and related manager operations.
+     * Manager operations will be done once for the specified amount of
+     * backgrondProcess calls (ie, the lower the amount, the most often the
+     * checks will occur).
+     */
+    protected int processExpiresFrequency = 6;
+    
+    public static final String INTERNAL_PREFIX = "_SERVLET_IMPL_";
+
+
+    public List getEventListeners() {
+        return (List)context.getAttribute(INTERNAL_PREFIX + ".EventListeners");
+    }
+    
+    public void addEventListener(EventListener l) {
+        
+    }
+
+    public static SessionManagerServlet getSessionManager(ServletContext ctx) {
+        SessionManagerServlet result = 
+            (SessionManagerServlet)ctx.getAttribute(INTERNAL_PREFIX + 
".SessionManager");
+        if (result == null) {
+            result = new SessionManagerServlet();
+            result.setContext(ctx);
+            ctx.setAttribute(INTERNAL_PREFIX + ".SessionManager", result);
+        }
+        return result;
+    }
+    
+    public void setSessionCounter(int sessionCounter) {
+        this.sessionCounter = sessionCounter;
+    }
+
+
+    /** 
+     * Total sessions created by this manager.
+     *
+     * @return sessions created
+     */
+    public int getSessionCounter() {
+        return sessionCounter;
+    }
+
+
+    /** 
+     * Number of duplicated session IDs generated by the random source.
+     * Anything bigger than 0 means problems.
+     *
+     * @return The count of duplicates
+     */
+    public int getDuplicates() {
+        return duplicates;
+    }
+
+
+    public void setDuplicates(int duplicates) {
+        this.duplicates = duplicates;
+    }
+
+
+    /** 
+     * Returns the number of active sessions
+     *
+     * @return number of sessions active
+     */
+    public int getActiveSessions() {
+        return sessions.size();
+    }
+
+
+    /**
+     * Max number of concurrent active sessions
+     *
+     * @return The highest number of concurrent active sessions
+     */
+    public int getMaxActive() {
+        return maxActive;
+    }
+
+
+    public void setMaxActive(int maxActive) {
+        this.maxActive = maxActive;
+    }
+
+
+    /**
+     * Gets the longest time (in seconds) that an expired session had been
+     * alive.
+     *
+     * @return Longest time (in seconds) that an expired session had been
+     * alive.
+     */
+    public int getSessionMaxAliveTime() {
+        return sessionMaxAliveTime;
+    }
+
+    /**
+     * Gets the average time (in seconds) that expired sessions had been
+     * alive.
+     *
+     * @return Average time (in seconds) that expired sessions had been
+     * alive.
+     */
+    public int getSessionAverageAliveTime() {
+        return sessionAverageAliveTime;
+    }
+
+    /**
+     * Return the Container with which this Manager is associated.
+     */
+    public ServletContext getContext() {
+        return (this.context);
+    }
+
+
+    /**
+     * Set the Container with which this Manager is associated.
+     *
+     * @param container The newly associated Container
+     */
+    public void setContext(ServletContext container) {
+        this.context = container;
+    }
+
+    /**
+     * Return the distributable flag for the sessions supported by
+     * this Manager.
+     */
+    public boolean getDistributable() {
+        return (this.distributable);
+    }
+
+    /**
+     * Set the distributable flag for the sessions supported by this
+     * Manager.  If this flag is set, all user data objects added to
+     * sessions associated with this manager must implement Serializable.
+     *
+     * @param distributable The new distributable flag
+     */
+    public void setDistributable(boolean distributable) {
+        this.distributable = distributable;
+    }
+
+    /**
+     * Return the default maximum inactive interval (in seconds)
+     * for Sessions created by this Manager.
+     */
+    public int getSessionTimeout() {
+        return (this.maxInactiveInterval);
+    }
+
+    public void setSessionTimeout(int stout) {
+        maxInactiveInterval = stout;
+    }
+
+    /**
+     * Gets the number of sessions that have expired.
+     *
+     * @return Number of sessions that have expired
+     */
+    public int getExpiredSessions() {
+        return expiredSessions;
+    }
+
+    /**
+     * Called when a session is expired, add the time to statistics
+     */
+    public void addExpiredSession(int timeAlive) {
+        synchronized (this) {
+            this.expiredSessions++; // should be atomic
+            // not sure it's the best solution
+            sessionAverageAliveTime = 
+                ((sessionAverageAliveTime * (expiredSessions-1)) + 
+                        timeAlive)/expiredSessions;
+            if (timeAlive > sessionMaxAliveTime) {
+                sessionMaxAliveTime = timeAlive;
+            }
+        }
+    }
+
+    public long getProcessingTime() {
+        return processingTime;
+    }
+
+    
+    /**
+     * Return the frequency of manager checks.
+     */
+    public int getProcessExpiresFrequency() {
+        return (this.processExpiresFrequency);
+    }
+
+    /**
+     * Set the manager checks frequency.
+     *
+     * @param processExpiresFrequency the new manager checks frequency
+     */
+    public void setProcessExpiresFrequency(int processExpiresFrequency) {
+        if (processExpiresFrequency <= 0) {
+            return;
+        }
+        this.processExpiresFrequency = processExpiresFrequency;
+    }
+
+    public void backgroundProcess() {
+        count = (count + 1) % processExpiresFrequency;
+        if (count == 0)
+            processExpires();
+    }
+
+    /**
+     * Invalidate all sessions that have expired.
+     */
+    public void processExpires() {
+
+        long timeNow = System.currentTimeMillis();
+        HttpSessionImpl sessions[] = findSessions();
+        int expireHere = 0 ;
+        
+        if(log.isDebugEnabled())
+            log.debug("Start expire sessions "  + " at " + timeNow + " 
sessioncount " + sessions.length);
+        for (int i = 0; i < sessions.length; i++) {
+            if (!sessions[i].isValid()) {
+                expiredSessions++;
+                expireHere++;
+            }
+        }
+        long timeEnd = System.currentTimeMillis();
+        if(log.isDebugEnabled())
+             log.debug("End expire sessions " + " processingTime " + 
+                       (timeEnd - timeNow) + " expired sessions: " + 
expireHere);
+        processingTime += ( timeEnd - timeNow );
+
+    }
+
+    public void destroy() {
+        initialized=false;
+    }
+    
+    public void init() {
+        getServletContext().setAttribute(INTERNAL_PREFIX + ".SessionManager",
+                                         this);
+        randomG.init();
+        
+        // TODO: process init params to configure randomG and the manager
+    }
+
+    /**
+     * Add this Session to the set of active Sessions for this Manager.
+     *
+     * @param session Session to be added
+     */
+    public void add(HttpSessionImpl session) {
+        synchronized (sessions) {
+            sessions.put(session.getId(), session);
+            if( sessions.size() > maxActive ) {
+                maxActive=sessions.size();
+            }
+        }
+    }
+
+    
+    /**
+     * Construct and return a new session object, based on the default
+     * settings specified by this Manager's properties.  The session
+     * id specified will be used as the session id.  
+     * If a new session cannot be created for any reason, return 
+     * <code>null</code>.
+     * 
+     * @param sessionId The session id which should be used to create the
+     *  new session; if <code>null</code>, a new session id will be
+     *  generated
+     * @exception IllegalStateException if a new session cannot be
+     *  instantiated for any reason
+     */
+    public HttpSessionImpl createSession(String sessionId) {
+        
+        // Recycle or create a Session instance
+        HttpSessionImpl session = createEmptySession();
+
+        // Initialize the properties of the new session and return it
+        session.setNew(true);
+        session.setValid(true);
+        session.setCreationTime(System.currentTimeMillis());
+        session.setMaxInactiveInterval(this.maxInactiveInterval);
+        if (sessionId == null ) {
+            while (sessionId == null) {
+                sessionId = randomG.generateSessionId();
+                if (sessions.get(sessionId) != null) {
+                    duplicates++;
+                    sessionId = null;    
+                }
+            }
+        }
+/*        } else {
+        // FIXME: Code to be used in case route replacement is needed
+            String jvmRoute = randomG.jvmRoute;
+            if (jvmRoute != null) {
+                String requestJvmRoute = null;
+                int index = sessionId.indexOf(".");
+                if (index > 0) {
+                    requestJvmRoute = sessionId
+                            .substring(index + 1, sessionId.length());
+                }
+                if (requestJvmRoute != null && 
!requestJvmRoute.equals(jvmRoute)) {
+                    sessionId = sessionId.substring(0, index) + "." + jvmRoute;
+                }
+            }
+*/
+        session.setId(sessionId);
+        sessionCounter++;
+        return (session);
+    }
+    
+    
+    /**
+     * Get a session from the recycled ones or create a new empty one.
+     * The PersistentManager manager does not need to create session data
+     * because it reads it from the Store.
+     */
+    public HttpSessionImpl createEmptySession() {
+        return new HttpSessionImpl(this);
+    }
+
+
+    /**
+     * Return the active Session, associated with this Manager, with the
+     * specified session id (if any); otherwise return <code>null</code>.
+     *
+     * @param id The session id for the session to be returned
+     *
+     * @exception IllegalStateException if a new session cannot be
+     *  instantiated for any reason
+     * @exception IOException if an input/output error occurs while
+     *  processing this request
+     */
+    public HttpSessionImpl findSession(String id) throws IOException {
+
+        if (id == null)
+            return (null);
+        synchronized (sessions) {
+            HttpSessionImpl session = (HttpSessionImpl) sessions.get(id);
+            return (session);
+        }
+
+    }
+
+
+    /**
+     * Return the set of active Sessions associated with this Manager.
+     * If this Manager has no active Sessions, a zero-length array is returned.
+     */
+    public HttpSessionImpl[] findSessions() {
+
+        HttpSessionImpl results[] = null;
+        synchronized (sessions) {
+            results = new HttpSessionImpl[sessions.size()];
+            results = (HttpSessionImpl[]) sessions.values().toArray(results);
+        }
+        return (results);
+
+    }
+
+
+    /**
+     * Remove this Session from the active Sessions for this Manager.
+     *
+     * @param session Session to be removed
+     */
+    public void remove(HttpSessionImpl session) {
+
+        synchronized (sessions) {
+            sessions.remove(session.getId());
+        }
+
+    }
+
+    // ------------------------------------------------------ Protected Methods
+
+    /** JMX and debugging
+     */
+    public void expireSession( String sessionId ) {
+        HttpSessionImpl s=(HttpSessionImpl)sessions.get(sessionId);
+        if( s==null ) {
+            return;
+        }
+        s.expire();
+    }
+
+
+    /** JMX method or debugging
+     */
+    public String getLastAccessedTime( String sessionId ) {
+        HttpSessionImpl s=(HttpSessionImpl)sessions.get(sessionId);
+        if( s==null ) {
+            return "";
+        }
+        return new Date(s.getLastAccessedTime()).toString();
+    }
+
+    ThreadLocal httpSession;
+    
+    /** Parse the cookies. Since multiple session cookies could be set ( 
+     * different paths for example ), we need to lookup and find a valid one
+     * for our context. 
+     * 
+     * If none is found - the last (bad) session id is returned.
+     * 
+     * As side effect, an attribute is set on the req with the session ( we 
+     * already looked it up while searching ).
+     */
+    public HttpSession getRequestedSessionId(HttpServletRequest req) {
+        Cookie[] cookies = req.getCookies();
+        String cn = getSessionCookieName();
+        for (int i=0; i<cookies.length; i++) {
+            if (cn.equals(cookies[i].getName())) {
+                String id = cookies[i].getValue();
+                // TODO: mark session from cookie, check validity
+            }
+        }
+        return null;
+    }
+    
+    public String getSessionIdFromUrl(HttpServletRequest req) {
+        
+        return null;
+    }
+    
+    
+    public String getSessionCookieName() {
+        return "JSESSIONID";
+    }
+}

Added: 
tomcat/sandbox/tomcat-lite/java/org/apache/tomcat/servlets/util/RandomGenerator.java
URL: 
http://svn.apache.org/viewvc/tomcat/sandbox/tomcat-lite/java/org/apache/tomcat/servlets/util/RandomGenerator.java?rev=433260&view=auto
==============================================================================
--- 
tomcat/sandbox/tomcat-lite/java/org/apache/tomcat/servlets/util/RandomGenerator.java
 (added)
+++ 
tomcat/sandbox/tomcat-lite/java/org/apache/tomcat/servlets/util/RandomGenerator.java
 Mon Aug 21 08:20:40 2006
@@ -0,0 +1,352 @@
+package org.apache.tomcat.servlets.util;
+
+import java.io.DataInputStream;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.IOException;
+import java.lang.reflect.Method;
+import java.security.MessageDigest;
+import java.security.NoSuchAlgorithmException;
+import java.util.Random;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+/**
+ *  Generates random IDs, useable as cookies.
+ * 
+ *  Based on code from tomcat session manager - but general purpose.
+ *  Can use /dev/urandom or similar file.
+ *  
+ * 
+ */
+public class RandomGenerator {
+    protected DataInputStream randomIS=null;
+    protected String devRandomSource="/dev/urandom";
+
+    protected static Log log = LogFactory.getLog(RandomGenerator.class);
+
+    /**
+     * The message digest algorithm to be used when generating session
+     * identifiers.  This must be an algorithm supported by the
+     * <code>java.security.MessageDigest</code> class on your platform.
+     */
+    protected String algorithm = "MD5";
+
+    /**
+     * The session id length of Sessions created by this Manager.
+     */
+    protected int sessionIdLength = 16;
+
+    
+    /**
+     * Return the MessageDigest implementation to be used when
+     * creating session identifiers.
+     */
+    protected MessageDigest digest = null;
+
+    public String jvmRoute;
+
+    /**
+     * A String initialization parameter used to increase the entropy of
+     * the initialization of our random number generator.
+     */
+    protected String entropy = null;
+
+    /**
+     * A random number generator to use when generating session identifiers.
+     */
+    protected Random random = null;
+
+    /**
+     * Return the message digest algorithm for this Manager.
+     */
+    public String getAlgorithm() {
+        return (this.algorithm);
+    }
+    
+    public void init() {
+        // Initialize random number generation
+        getRandomBytes(new byte[16]);
+    }
+
+
+    /**
+     * Set the message digest algorithm for this Manager.
+     *
+     * @param algorithm The new message digest algorithm
+     */
+    public void setAlgorithm(String algorithm) {
+        this.algorithm = algorithm;
+    }
+    
+    /**
+     * Return the MessageDigest object to be used for calculating
+     * session identifiers.  If none has been created yet, initialize
+     * one the first time this method is called.
+     */
+    public synchronized MessageDigest getDigest() {
+
+        if (this.digest == null) {
+            long t1=System.currentTimeMillis();
+            try {
+                this.digest = MessageDigest.getInstance(algorithm);
+            } catch (NoSuchAlgorithmException e) {
+                log.error("Algorithm not found", e);
+                try {
+                    this.digest = MessageDigest.getInstance("MD5");
+                } catch (NoSuchAlgorithmException f) {
+                    log.error("No message digest available", f);
+                    this.digest = null;
+                }
+            }
+            long t2=System.currentTimeMillis();
+            if( log.isDebugEnabled() )
+                log.debug("getDigest() " + (t2-t1));
+        }
+
+        return (this.digest);
+
+    }
+    
+    /**
+     * Generate and return a new session identifier.
+     */
+    public synchronized String generateSessionId() {
+
+        byte random[] = new byte[16];
+        String result = null;
+
+        // Render the result as a String of hexadecimal digits
+        StringBuffer buffer = new StringBuffer();
+        int resultLenBytes = 0;
+
+        while (resultLenBytes < this.sessionIdLength) {
+            getRandomBytes(random);
+            random = getDigest().digest(random);
+            for (int j = 0;
+            j < random.length && resultLenBytes < this.sessionIdLength;
+            j++) {
+                byte b1 = (byte) ((random[j] & 0xf0) >> 4);
+                byte b2 = (byte) (random[j] & 0x0f);
+                if (b1 < 10)
+                    buffer.append((char) ('0' + b1));
+                else
+                    buffer.append((char) ('A' + (b1 - 10)));
+                if (b2 < 10)
+                    buffer.append((char) ('0' + b2));
+                else
+                    buffer.append((char) ('A' + (b2 - 10)));
+                resultLenBytes++;
+            }
+        }
+        if (jvmRoute != null) {
+            buffer.append('.').append(jvmRoute);
+        }
+        result = buffer.toString();
+        return (result);
+
+    }
+    
+    protected void getRandomBytes(byte bytes[]) {
+        // Generate a byte array containing a session identifier
+        if (devRandomSource != null && randomIS == null) {
+            setRandomFile(devRandomSource);
+        }
+        if (randomIS != null) {
+            try {
+                int len = randomIS.read(bytes);
+                if (len == bytes.length) {
+                    return;
+                }
+                if(log.isDebugEnabled())
+                    log.debug("Got " + len + " " + bytes.length );
+            } catch (Exception ex) {
+                // Ignore
+            }
+            devRandomSource = null;
+            
+            try {
+                randomIS.close();
+            } catch (Exception e) {
+                log.warn("Failed to close randomIS.");
+            }
+            
+            randomIS = null;
+        }
+        getRandom().nextBytes(bytes);
+    }
+
+    /**
+     * Return the random number generator instance we should use for
+     * generating session identifiers.  If there is no such generator
+     * currently defined, construct and seed a new one.
+     */
+    public Random getRandom() {
+        if (this.random == null) {
+            // Calculate the new random number generator seed
+            long seed = System.currentTimeMillis();
+            long t1 = seed;
+            char entropy[] = getEntropy().toCharArray();
+            for (int i = 0; i < entropy.length; i++) {
+                long update = ((byte) entropy[i]) << ((i % 8) * 8);
+                seed ^= update;
+            }
+            try {
+                // Construct and seed a new random number generator
+                Class clazz = Class.forName(randomClass);
+                this.random = (Random) clazz.newInstance();
+                this.random.setSeed(seed);
+            } catch (Exception e) {
+                // Fall back to the simple case
+                log.error("Failed to create random " + randomClass, e);
+                this.random = new java.util.Random();
+                this.random.setSeed(seed);
+            }
+            if(log.isDebugEnabled()) {
+                long t2=System.currentTimeMillis();
+                if( (t2-t1) > 100 )
+                    log.debug("Init random: " + " " + (t2-t1));
+            }
+        }
+        
+        return (this.random);
+
+    }
+    
+    /**
+     * Return the entropy increaser value, or compute a semi-useful value
+     * if this String has not yet been set.
+     */
+    public String getEntropy() {
+
+        // Calculate a semi-useful value if this has not been set
+        if (this.entropy == null) {
+            // Use APR to get a crypto secure entropy value
+            byte[] result = new byte[32];
+            boolean apr = false;
+            try {
+                String methodName = "random";
+                Class paramTypes[] = new Class[2];
+                paramTypes[0] = result.getClass();
+                paramTypes[1] = int.class;
+                Object paramValues[] = new Object[2];
+                paramValues[0] = result;
+                paramValues[1] = new Integer(32);
+                Method method = Class.forName("org.apache.tomcat.jni.OS")
+                    .getMethod(methodName, paramTypes);
+                method.invoke(null, paramValues);
+                apr = true;
+            } catch (Throwable t) {
+                // Ignore
+            }
+            if (apr) {
+                setEntropy(new String(result));
+            } else {
+                setEntropy(this.toString());
+            }
+        }
+
+        return (this.entropy);
+
+    }
+
+
+    /**
+     * Set the entropy increaser value.
+     *
+     * @param entropy The new entropy increaser value
+     */
+    public void setEntropy(String entropy) {
+        this.entropy = entropy;
+    }
+
+
+    /**
+     * Return the random number generator class name.
+     */
+    public String getRandomClass() {
+
+        return (this.randomClass);
+
+    }
+
+
+    /**
+     * Set the random number generator class name.
+     *
+     * @param randomClass The new random number generator class name
+     */
+    public void setRandomClass(String randomClass) {
+        this.randomClass = randomClass;
+    }
+    
+    /**
+     * The Java class name of the random number generator class to be used
+     * when generating session identifiers.
+     */
+    protected String randomClass = "java.security.SecureRandom";
+    /** 
+     * Use /dev/random-type special device. This is new code, but may reduce
+     * the big delay in generating the random.
+     *
+     *  You must specify a path to a random generator file. Use /dev/urandom
+     *  for linux ( or similar ) systems. Use /dev/random for maximum security
+     *  ( it may block if not enough "random" exist ). You can also use
+     *  a pipe that generates random.
+     *
+     *  The code will check if the file exists, and default to java Random
+     *  if not found. There is a significant performance difference, very
+     *  visible on the first call to getSession ( like in the first JSP )
+     *  - so use it if available.
+     */
+    public void setRandomFile( String s ) {
+        // as a hack, you can use a static file - and genarate the same
+        // session ids ( good for strange debugging )
+        try{
+            devRandomSource=s;
+            File f=new File( devRandomSource );
+            if( ! f.exists() ) return;
+            randomIS= new DataInputStream( new FileInputStream(f));
+            randomIS.readLong();
+            if( log.isDebugEnabled() )
+                log.debug( "Opening " + devRandomSource );
+        } catch( IOException ex ) {
+            try {
+                randomIS.close();
+            } catch (Exception e) {
+                log.warn("Failed to close randomIS.");
+            }
+            
+            randomIS=null;
+        }
+    }
+
+    public String getRandomFile() {
+        return devRandomSource;
+    }
+
+
+    /**
+     * Gets the session id length (in bytes) of Sessions created by
+     * this Manager.
+     *
+     * @return The session id length
+     */
+    public int getSessionIdLength() {
+
+        return (this.sessionIdLength);
+
+    }
+
+
+    /**
+     * Sets the session id length (in bytes) for Sessions created by this
+     * Manager.
+     *
+     * @param idLength The session id length
+     */
+    public void setSessionIdLength(int idLength) {
+        this.sessionIdLength = idLength;
+    }
+}
\ No newline at end of file

Modified: 
tomcat/sandbox/tomcat-lite/java/org/apache/tomcat/util/net/http11/Http11Processor.java
URL: 
http://svn.apache.org/viewvc/tomcat/sandbox/tomcat-lite/java/org/apache/tomcat/util/net/http11/Http11Processor.java?rev=433260&r1=433259&r2=433260&view=diff
==============================================================================
--- 
tomcat/sandbox/tomcat-lite/java/org/apache/tomcat/util/net/http11/Http11Processor.java
 (original)
+++ 
tomcat/sandbox/tomcat-lite/java/org/apache/tomcat/util/net/http11/Http11Processor.java
 Mon Aug 21 08:20:40 2006
@@ -792,6 +792,7 @@
                 }
                 inputBuffer.parseHeaders();
             } catch (IOException e) {
+                e.printStackTrace();
                 error = true;
                 break;
             } catch (Throwable t) {

Modified: 
tomcat/sandbox/tomcat-lite/java/org/apache/tomcat/util/net/nio/NioEndpoint.java
URL: 
http://svn.apache.org/viewvc/tomcat/sandbox/tomcat-lite/java/org/apache/tomcat/util/net/nio/NioEndpoint.java?rev=433260&r1=433259&r2=433260&view=diff
==============================================================================
--- 
tomcat/sandbox/tomcat-lite/java/org/apache/tomcat/util/net/nio/NioEndpoint.java 
(original)
+++ 
tomcat/sandbox/tomcat-lite/java/org/apache/tomcat/util/net/nio/NioEndpoint.java 
Mon Aug 21 08:20:40 2006
@@ -233,7 +233,7 @@
                             ServerSocketChannel ssc=(ServerSocketChannel)sc;
                             
                             SocketChannel sockC = ssc.accept();
-                            
+                            if (sockC == null) continue;
                             // continue polling on a different thread
                             // Side effect: if pool is full, accept will be 
                             // blocked. 
@@ -260,7 +260,8 @@
                     }
                     
                 } catch (IOException e) {
-                    e.printStackTrace();
+                    //e.printStackTrace();
+                    System.err.println("Ignoring IOE" + e.toString());
                 }
             }
         }

Added: tomcat/sandbox/tomcat-lite/resources/tomcat-lite.MF
URL: 
http://svn.apache.org/viewvc/tomcat/sandbox/tomcat-lite/resources/tomcat-lite.MF?rev=433260&view=auto
==============================================================================
--- tomcat/sandbox/tomcat-lite/resources/tomcat-lite.MF (added)
+++ tomcat/sandbox/tomcat-lite/resources/tomcat-lite.MF Mon Aug 21 08:20:40 2006
@@ -0,0 +1,2 @@
+Manifest-version: 1.0
+Main-Class: org.apache.tomcat.lite.TomcatLite

Propchange: tomcat/sandbox/tomcat-lite/resources/tomcat-lite.MF
------------------------------------------------------------------------------
    svn:executable = *

Added: tomcat/sandbox/tomcat-lite/webapps/ROOT/WEB-INF/classes
URL: 
http://svn.apache.org/viewvc/tomcat/sandbox/tomcat-lite/webapps/ROOT/WEB-INF/classes?rev=433260&view=auto
==============================================================================
--- tomcat/sandbox/tomcat-lite/webapps/ROOT/WEB-INF/classes (added)
+++ tomcat/sandbox/tomcat-lite/webapps/ROOT/WEB-INF/classes Mon Aug 21 08:20:40 
2006
@@ -0,0 +1 @@
+link /ws/webinv/classes
\ No newline at end of file

Propchange: tomcat/sandbox/tomcat-lite/webapps/ROOT/WEB-INF/classes
------------------------------------------------------------------------------
    svn:special = *

Added: tomcat/sandbox/tomcat-lite/webapps/ROOT/WEB-INF/lib/moneydance.jar
URL: 
http://svn.apache.org/viewvc/tomcat/sandbox/tomcat-lite/webapps/ROOT/WEB-INF/lib/moneydance.jar?rev=433260&view=auto
==============================================================================
--- tomcat/sandbox/tomcat-lite/webapps/ROOT/WEB-INF/lib/moneydance.jar (added)
+++ tomcat/sandbox/tomcat-lite/webapps/ROOT/WEB-INF/lib/moneydance.jar Mon Aug 
21 08:20:40 2006
@@ -0,0 +1 @@
+link /opt/moneydance2006/moneydance.jar
\ No newline at end of file

Propchange: tomcat/sandbox/tomcat-lite/webapps/ROOT/WEB-INF/lib/moneydance.jar
------------------------------------------------------------------------------
    svn:special = *

Added: tomcat/sandbox/tomcat-lite/webapps/ROOT/index.html
URL: 
http://svn.apache.org/viewvc/tomcat/sandbox/tomcat-lite/webapps/ROOT/index.html?rev=433260&view=auto
==============================================================================
--- tomcat/sandbox/tomcat-lite/webapps/ROOT/index.html (added)
+++ tomcat/sandbox/tomcat-lite/webapps/ROOT/index.html Mon Aug 21 08:20:40 2006
@@ -0,0 +1 @@
+Hi world

Added: tomcat/sandbox/tomcat-lite/webapps/__x_deploy/WEB-INF/web.xml
URL: 
http://svn.apache.org/viewvc/tomcat/sandbox/tomcat-lite/webapps/__x_deploy/WEB-INF/web.xml?rev=433260&view=auto
==============================================================================
--- tomcat/sandbox/tomcat-lite/webapps/__x_deploy/WEB-INF/web.xml (added)
+++ tomcat/sandbox/tomcat-lite/webapps/__x_deploy/WEB-INF/web.xml Mon Aug 21 
08:20:40 2006
@@ -0,0 +1,13 @@
+<web-app>
+
+   
<filter><filter-name>simpleIP</filter-name><filter-class>org.apache.tomcat.servlets.sec.SimpleIPFilter</filter-class></filter>
+   
<filter><filter-name>_tc_auth</filter-name><filter-class>org.apache.tomcat.servlets.sec.AccessFilter</filter-class></filter>
+    
+   
<filter-mapping><filter-name>simpleIP</filter-name><url-pattern>/*</url-pattern></filter-mapping>
    
+  
+   
<servlet><servlet-name>__x_deploy_webxml</servlet-name><servlet-class>org.apache.tomcat.servlets.deploy.WebXml</servlet-class>
+     
<init-param><param-name>u.test</param-name><param-value>pass</param-value></init-param>
+   </servlet>
+ 
+   
<servlet-mapping><servlet-name>__x_deploy_webxml</servlet-name><url-pattern>/*</url-pattern></servlet-mapping>
+</web-app>
\ No newline at end of file

Added: tomcat/sandbox/tomcat-lite/webapps/__x_engine/WEB-INF/web.xml
URL: 
http://svn.apache.org/viewvc/tomcat/sandbox/tomcat-lite/webapps/__x_engine/WEB-INF/web.xml?rev=433260&view=auto
==============================================================================
--- tomcat/sandbox/tomcat-lite/webapps/__x_engine/WEB-INF/web.xml (added)
+++ tomcat/sandbox/tomcat-lite/webapps/__x_engine/WEB-INF/web.xml Mon Aug 21 
08:20:40 2006
@@ -0,0 +1,14 @@
+<web-app>
+
+   
<filter><filter-name>simpleIP</filter-name><filter-class>org.apache.tomcat.servlets.sec.SimpleIPFilter</filter-class></filter>
+   
<filter><filter-name>_tc_auth</filter-name><filter-class>org.apache.tomcat.servlets.sec.AccessFilter</filter-class></filter>
+    
+   
<filter-mapping><filter-name>simpleIP</filter-name><url-pattern>/*</url-pattern></filter-mapping>
    
+  
+<!--   
<servlet><servlet-name>_tc_users</servlet-name><servlet-class>org.apache.tomcat.servlets.sec.DigestAuthenticator</servlet-class>
+     
<init-param><param-name>u.test</param-name><param-value>pass</param-value></init-param>
+   </servlet>
+ 
+   
<servlet-mapping><servlet-name>dav</servlet-name><url-pattern>/dav/*</url-pattern></servlet-mapping>
+-->
+</web-app>
\ No newline at end of file

Added: tomcat/sandbox/tomcat-lite/webapps/__x_protocol/WEB-INF/web.xml
URL: 
http://svn.apache.org/viewvc/tomcat/sandbox/tomcat-lite/webapps/__x_protocol/WEB-INF/web.xml?rev=433260&view=auto
==============================================================================
--- tomcat/sandbox/tomcat-lite/webapps/__x_protocol/WEB-INF/web.xml (added)
+++ tomcat/sandbox/tomcat-lite/webapps/__x_protocol/WEB-INF/web.xml Mon Aug 21 
08:20:40 2006
@@ -0,0 +1,15 @@
+<web-app>
+
+   
<filter><filter-name>simpleIP</filter-name><filter-class>org.apache.tomcat.servlets.sec.SimpleIPFilter</filter-class></filter>
+   
<filter><filter-name>_tc_auth</filter-name><filter-class>org.apache.tomcat.servlets.sec.AccessFilter</filter-class></filter>
+    
+   
<filter-mapping><filter-name>simpleIP</filter-name><url-pattern>/*</url-pattern></filter-mapping>
    
+   
<filter-mapping><filter-name>_tc_auth</filter-name><url-pattern>/xxx/*</url-pattern></filter-mapping>
    
+  
+   
<servlet><servlet-name>__x_connector</servlet-name><servlet-class>org.apache.tomcat.lite.http.CoyoteAdapter</servlet-class>
+     
<init-param><param-name>port</param-name><param-value>8800</param-value></init-param>
+     <load-on-startup>1</load-on-startup>
+   </servlet>
+ 
+   
<servlet-mapping><servlet-name>__x_connector</servlet-name><url-pattern>/*</url-pattern></servlet-mapping>
+</web-app>
\ No newline at end of file



---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to