Coverage Report - org.apache.maven.wagon.tck.http.fixture.RedirectionServlet
 
Classes in this File Line Coverage Branch Coverage Complexity
RedirectionServlet
0 %
0/27
0 %
0/6
1,75
 
 1  
 package org.apache.maven.wagon.tck.http.fixture;
 2  
 
 3  
 /*
 4  
  * Licensed to the Apache Software Foundation (ASF) under one
 5  
  * or more contributor license agreements.  See the NOTICE file
 6  
  * distributed with this work for additional information
 7  
  * regarding copyright ownership.  The ASF licenses this file
 8  
  * to you under the Apache License, Version 2.0 (the
 9  
  * "License"); you may not use this file except in compliance
 10  
  * with the License.  You may obtain a copy of the License at
 11  
  *
 12  
  *   http://www.apache.org/licenses/LICENSE-2.0
 13  
  *
 14  
  * Unless required by applicable law or agreed to in writing,
 15  
  * software distributed under the License is distributed on an
 16  
  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 17  
  * KIND, either express or implied.  See the License for the
 18  
  * specific language governing permissions and limitations
 19  
  * under the License.
 20  
  */
 21  
 
 22  
 import javax.servlet.ServletException;
 23  
 import javax.servlet.http.HttpServlet;
 24  
 import javax.servlet.http.HttpServletRequest;
 25  
 import javax.servlet.http.HttpServletResponse;
 26  
 import java.io.IOException;
 27  
 
 28  
 public class RedirectionServlet
 29  
     extends HttpServlet
 30  
 {
 31  
 
 32  
     private static final long serialVersionUID = 1L;
 33  
 
 34  
     private final String targetPath;
 35  
 
 36  
     private final int code;
 37  
 
 38  
     private final int maxRedirects;
 39  
 
 40  0
     private int redirectCount = 0;
 41  
 
 42  
     private final String myPath;
 43  
 
 44  
     public RedirectionServlet( final int code, final String targetPath )
 45  0
     {
 46  0
         this.code = code;
 47  0
         this.targetPath = targetPath;
 48  0
         this.maxRedirects = 1;
 49  0
         this.myPath = null;
 50  0
     }
 51  
 
 52  
     public RedirectionServlet( final int code, final String myPath, final String targetPath, final int maxRedirects )
 53  0
     {
 54  0
         this.code = code;
 55  0
         this.myPath = myPath;
 56  0
         this.targetPath = targetPath;
 57  0
         this.maxRedirects = maxRedirects;
 58  0
     }
 59  
 
 60  
     public int getRedirectCount()
 61  
     {
 62  0
         return redirectCount;
 63  
     }
 64  
 
 65  
     @Override
 66  
     protected void service( final HttpServletRequest req, final HttpServletResponse resp )
 67  
         throws ServletException, IOException
 68  
     {
 69  0
         redirectCount++;
 70  
 
 71  0
         if ( myPath == null )
 72  
         {
 73  0
             resp.setStatus( code );
 74  0
             resp.setHeader( "Location", targetPath );
 75  
         }
 76  0
         else if ( maxRedirects < 0 )
 77  
         {
 78  0
             resp.setStatus( code );
 79  0
             resp.setHeader( "Location", myPath );
 80  
         }
 81  0
         else if ( redirectCount <= maxRedirects )
 82  
         {
 83  0
             resp.setStatus( code );
 84  0
             resp.setHeader( "Location", myPath + "/" + redirectCount );
 85  
         }
 86  
         else
 87  
         {
 88  0
             resp.setStatus( code );
 89  0
             resp.setHeader( "Location", targetPath );
 90  
         }
 91  0
     }
 92  
 
 93  
 }