##### Coverage Report - org.apache.turbine.pipeline.DetermineRedirectRequestedValve

Classes in this File | Line Coverage | Branch Coverage | Complexity
DetermineRedirectRequestedValve |
23% | 3/13
0% | 0/4
| 1.6666666666666667;1,667

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.lang.StringUtils;
27 |  |
     import org.apache.commons.logging.Log;
28 |  |
     import org.apache.commons.logging.LogFactory;
29 |  |
     import org.apache.turbine.util.RunData;
30 |  |
     import org.apache.turbine.util.TurbineException;
31 |  |
32 |  |
     /**
33 |  |
      * Implements the Redirect Requested portion of the "Turbine classic"
34 |  |
      * processing pipeline (from the Turbine 2.x series).
35 |  |
      *
36 |  |
      * @author <a href="mailto:epugh@opensourceConnections.com">Eric Pugh</a>
37 |  |
      * @author <a href="mailto:peter@courcoux.biz">Peter Courcoux</a>
38 |  |
      * @version $Id: DetermineRedirectRequestedValve.java 1773378 2016-12-09 13:19:59Z tv $
39 |  |
      */
40 |  |
     public class DetermineRedirectRequestedValve
41 |  |
         extends AbstractValve
42 |  |
     {
43 | 33 |
         private static final Log log = LogFactory.getLog(DetermineRedirectRequestedValve.class);
44 |  |
45 |  |
         /**
46 |  |
          * Creates a new instance.
47 |  |
          */
48 |  |
         public DetermineRedirectRequestedValve()
49 | 43 |
         {
50 |  |
             // empty constructor
51 | 43 |
         }
52 |  |
53 |  |
         /**
54 |  |
          * @see org.apache.turbine.pipeline.Valve#invoke(PipelineData, ValveContext)
55 |  |
          */
56 |  |
         @Override
57 |  |
         public void invoke(PipelineData pipelineData, ValveContext context)
58 |  |
             throws IOException, TurbineException
59 |  |
         {
60 | 0 |
             redirectRequested(pipelineData);
61 |  |
62 |  |
             // Pass control to the next Valve in the Pipeline
63 | 0 |
             context.invokeNext(pipelineData);
64 | 0 |
         }
65 |  |
66 |  |
         /**
67 |  |
          * Perform clean up after processing the request.
68 |  |
          *
69 |  |
          * @param pipelineData The run-time data.
70 |  |
          *
71 |  |
          * @throws IOException if sending the redirect fails
72 |  |
          */
73 |  |
         protected void redirectRequested(PipelineData pipelineData)
74 |  |
             throws IOException
75 |  |
         {
76 | 0 |
             RunData data = getRunData(pipelineData);
77 |  |
             // handle a redirect request
78 | 0 |
             boolean requestRedirected = StringUtils.isNotEmpty(data.getRedirectURI());
79 | 0 |
             if (requestRedirected)
80 |  |
             {
81 | 0 |
                 if (data.getResponse().isCommitted())
82 |  |
                 {
83 | 0 |
                     log.warn("redirect requested, response already committed: " + data.getRedirectURI());
84 |  |
                 }
85 |  |
                 else
86 |  |
                 {
87 | 0 |
                     data.getResponse().sendRedirect(data.getRedirectURI());
88 |  |
                 }
89 |  |
             }
90 | 0 |
         }
91 |  |
     }