001package 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 024import java.io.IOException; 025 026import org.apache.commons.configuration.Configuration; 027import org.apache.turbine.Turbine; 028import org.apache.turbine.TurbineConstants; 029import org.apache.turbine.util.RunData; 030import 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 1706239 2015-10-01 13:18:35Z tv $ 040 */ 041public 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 { 052 Configuration cfg = Turbine.getConfiguration(); 053 054 // Get the session timeout. 055 timeout = cfg.getInt(TurbineConstants.SESSION_TIMEOUT_KEY, 056 TurbineConstants.SESSION_TIMEOUT_DEFAULT); 057 } 058 059 /** 060 * @see org.apache.turbine.pipeline.Valve#invoke(PipelineData, ValveContext) 061 */ 062 @Override 063 public void invoke(PipelineData pipelineData, ValveContext context) 064 throws IOException, TurbineException 065 { 066 RunData runData = getRunData(pipelineData); 067 // If the session is new take this opportunity to 068 // set the session timeout if specified in TR.properties 069 if (runData.getSession().isNew() && timeout != TurbineConstants.SESSION_TIMEOUT_DEFAULT) 070 { 071 runData.getSession().setMaxInactiveInterval(timeout); 072 } 073 074 // Pass control to the next Valve in the Pipeline 075 context.invokeNext(pipelineData); 076 } 077}