001    package org.apache.turbine.pipeline;
002    
003    
004    /*
005     * Licensed to the Apache Software Foundation (ASF) under one
006     * or more contributor license agreements.  See the NOTICE file
007     * distributed with this work for additional information
008     * regarding copyright ownership.  The ASF licenses this file
009     * to you under the Apache License, Version 2.0 (the
010     * "License"); you may not use this file except in compliance
011     * with the License.  You may obtain a copy of the License at
012     *
013     *   http://www.apache.org/licenses/LICENSE-2.0
014     *
015     * Unless required by applicable law or agreed to in writing,
016     * software distributed under the License is distributed on an
017     * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
018     * KIND, either express or implied.  See the License for the
019     * specific language governing permissions and limitations
020     * under the License.
021     */
022    
023    
024    import java.io.IOException;
025    
026    import org.apache.commons.configuration.Configuration;
027    import org.apache.turbine.Turbine;
028    import org.apache.turbine.TurbineConstants;
029    import org.apache.turbine.util.RunData;
030    import org.apache.turbine.util.TurbineException;
031    
032    /**
033     * Implements the action portion of the "Turbine classic" processing
034     * pipeline (from the Turbine 2.x series).
035     *
036     * @author <a href="mailto:jvanzyl@apache.org">Jason van Zyl</a>
037     * @author <a href="mailto:mpoeschl@marmot.at">Martin Poeschl</a>
038     * @author <a href="mailto:peter@courcoux.biz">Peter Courcoux</a>
039     * @version $Id: DefaultSessionTimeoutValve.java 757213 2009-03-22 16:43:31Z tv $
040     */
041    public class DefaultSessionTimeoutValve
042        extends AbstractValve
043    {
044        protected int timeout;
045    
046        /**
047         * Here we can setup objects that are thread safe and can be
048         * reused, so we get the timeout from the configuration..
049         */
050        public DefaultSessionTimeoutValve()
051            throws Exception
052        {
053            Configuration cfg = Turbine.getConfiguration();
054    
055            // Get the session timeout.
056    
057            timeout = cfg.getInt(TurbineConstants.SESSION_TIMEOUT_KEY,
058                    TurbineConstants.SESSION_TIMEOUT_DEFAULT);
059    
060        }
061    
062        /**
063         * @see org.apache.turbine.Valve#invoke(RunData, ValveContext)
064         */
065        public void invoke(PipelineData pipelineData, ValveContext context)
066            throws IOException, TurbineException
067        {
068            RunData runData = getRunData(pipelineData);
069            // If the session is new take this opportunity to
070            // set the session timeout if specified in TR.properties
071            if (runData.getSession().isNew() && timeout != TurbineConstants.SESSION_TIMEOUT_DEFAULT)
072            {
073                runData.getSession().setMaxInactiveInterval(timeout);
074            }
075    
076            // Pass control to the next Valve in the Pipeline
077            context.invokeNext(pipelineData);
078        }
079    }