| Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
| DefaultSessionTimeoutValve |
|
| 2.0;2 |
| 1 | package org.apache.turbine.pipeline; | |
| 2 | ||
| 3 | ||
| 4 | /* | |
| 5 | * Licensed to the Apache Software Foundation (ASF) under one | |
| 6 | * or more contributor license agreements. See the NOTICE file | |
| 7 | * distributed with this work for additional information | |
| 8 | * regarding copyright ownership. The ASF licenses this file | |
| 9 | * to you under the Apache License, Version 2.0 (the | |
| 10 | * "License"); you may not use this file except in compliance | |
| 11 | * with the License. You may obtain a copy of the License at | |
| 12 | * | |
| 13 | * http://www.apache.org/licenses/LICENSE-2.0 | |
| 14 | * | |
| 15 | * Unless required by applicable law or agreed to in writing, | |
| 16 | * software distributed under the License is distributed on an | |
| 17 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | |
| 18 | * KIND, either express or implied. See the License for the | |
| 19 | * specific language governing permissions and limitations | |
| 20 | * under the License. | |
| 21 | */ | |
| 22 | ||
| 23 | ||
| 24 | import java.io.IOException; | |
| 25 | ||
| 26 | import org.apache.commons.configuration.Configuration; | |
| 27 | import org.apache.turbine.Turbine; | |
| 28 | import org.apache.turbine.TurbineConstants; | |
| 29 | import org.apache.turbine.util.RunData; | |
| 30 | import org.apache.turbine.util.TurbineException; | |
| 31 | ||
| 32 | /** | |
| 33 | * Implements the action portion of the "Turbine classic" processing | |
| 34 | * pipeline (from the Turbine 2.x series). | |
| 35 | * | |
| 36 | * @author <a href="mailto:jvanzyl@apache.org">Jason van Zyl</a> | |
| 37 | * @author <a href="mailto:mpoeschl@marmot.at">Martin Poeschl</a> | |
| 38 | * @author <a href="mailto:peter@courcoux.biz">Peter Courcoux</a> | |
| 39 | * @version $Id: DefaultSessionTimeoutValve.java 757213 2009-03-22 16:43:31Z tv $ | |
| 40 | */ | |
| 41 | public class DefaultSessionTimeoutValve | |
| 42 | extends AbstractValve | |
| 43 | { | |
| 44 | protected int timeout; | |
| 45 | ||
| 46 | /** | |
| 47 | * Here we can setup objects that are thread safe and can be | |
| 48 | * reused, so we get the timeout from the configuration.. | |
| 49 | */ | |
| 50 | public DefaultSessionTimeoutValve() | |
| 51 | throws Exception | |
| 52 | 4 | { |
| 53 | 4 | Configuration cfg = Turbine.getConfiguration(); |
| 54 | ||
| 55 | // Get the session timeout. | |
| 56 | ||
| 57 | 4 | timeout = cfg.getInt(TurbineConstants.SESSION_TIMEOUT_KEY, |
| 58 | TurbineConstants.SESSION_TIMEOUT_DEFAULT); | |
| 59 | ||
| 60 | 4 | } |
| 61 | ||
| 62 | /** | |
| 63 | * @see org.apache.turbine.Valve#invoke(RunData, ValveContext) | |
| 64 | */ | |
| 65 | public void invoke(PipelineData pipelineData, ValveContext context) | |
| 66 | throws IOException, TurbineException | |
| 67 | { | |
| 68 | 6 | RunData runData = getRunData(pipelineData); |
| 69 | // If the session is new take this opportunity to | |
| 70 | // set the session timeout if specified in TR.properties | |
| 71 | 6 | if (runData.getSession().isNew() && timeout != TurbineConstants.SESSION_TIMEOUT_DEFAULT) |
| 72 | { | |
| 73 | 4 | runData.getSession().setMaxInactiveInterval(timeout); |
| 74 | } | |
| 75 | ||
| 76 | // Pass control to the next Valve in the Pipeline | |
| 77 | 6 | context.invokeNext(pipelineData); |
| 78 | 4 | } |
| 79 | } |