Coverage Report - net.admin4j.ui.filters.Admin4JStandardFilter
 
Classes in this File Line Coverage Branch Coverage Complexity
Admin4JStandardFilter
84%
32/38
61%
11/18
3.4
 
 1  
 /*
 2  
  * This software is licensed under the Apache License, Version 2.0
 3  
  * (the "License") agreement; you may not use this file except in compliance with
 4  
  * the License.  You may obtain a copy of the License at
 5  
  * 
 6  
  *      http://www.apache.org/licenses/LICENSE-2.0
 7  
  * 
 8  
  * Unless required by applicable law or agreed to in writing, software
 9  
  * distributed under the License is distributed on an "AS IS" BASIS,
 10  
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 11  
  * See the License for the specific language governing permissions and
 12  
  * limitations under the License.
 13  
  */
 14  
 package net.admin4j.ui.filters;
 15  
 
 16  
 import java.io.IOException;
 17  
 import java.util.ArrayList;
 18  
 import java.util.List;
 19  
 
 20  
 import javax.servlet.Filter;
 21  
 import javax.servlet.FilterChain;
 22  
 import javax.servlet.FilterConfig;
 23  
 import javax.servlet.ServletException;
 24  
 import javax.servlet.ServletRequest;
 25  
 import javax.servlet.ServletResponse;
 26  
 
 27  
 import net.admin4j.deps.commons.lang3.StringUtils;
 28  
 
 29  
 /**
 30  
  * Standard filter that conveniently invokes all other Admin4J filters in a standard configuration.
 31  
  * this exists to make Admin4J easier to configure.
 32  
  * 
 33  
  * <p>Init parameters for this filter are as follows:</p>
 34  
  * <li>include.serverside.timestamp -- Optional.  Default false.  If true, includes a server-side timestamp in all returned html.
 35  
  *    Useful if debugging possible performance issues reported only by people in some remote places of the world.</li>
 36  
  * @author D. Ashmore
 37  
  *
 38  
  */
 39  6
 public class Admin4JStandardFilter extends BaseFilter {
 40  
     
 41  
     private List<String> filterKeyList;
 42  
     
 43  
     public void destroy() {
 44  
         // No Op
 45  
 
 46  0
     }
 47  
 
 48  
     public void doFilter(ServletRequest request, ServletResponse response,
 49  
             FilterChain chain) throws IOException, ServletException {
 50  3
         Admin4JStandardFilterChain localChain = new Admin4JStandardFilterChain(this.findfilterKeyList(), chain);
 51  3
         localChain.doFilter(request, response);
 52  3
     }
 53  
     
 54  
     private synchronized List<String> findfilterKeyList() {
 55  3
         if (filterKeyList != null) {
 56  0
             return filterKeyList;
 57  
         }
 58  
         
 59  3
         List<String> list = new ArrayList<String>();
 60  3
         if (Admin4JStandardFilterChain.isRegistered(PerformanceMonitoringFilter.class.getName())) {
 61  3
             list.add(PerformanceMonitoringFilter.class.getName());
 62  
         }
 63  3
         if (Admin4JStandardFilterChain.isRegistered(PerformanceTimeStampingFilter.class.getName())) {
 64  3
             list.add(PerformanceTimeStampingFilter.class.getName());
 65  
         }
 66  3
         if (Admin4JStandardFilterChain.isRegistered(ConcurrentUsageFilter.class.getName())) {
 67  3
             list.add(ConcurrentUsageFilter.class.getName());
 68  
         }
 69  3
         if (Admin4JStandardFilterChain.isRegistered(RequestTrackingFilter.class.getName())) {
 70  3
             list.add(RequestTrackingFilter.class.getName());
 71  
         }
 72  
         
 73  3
         if (Admin4JStandardFilterChain.isRegistered(ErrorNotificationFilter.class.getName())) {
 74  3
             list.add(ErrorNotificationFilter.class.getName());
 75  
         }
 76  
         else {
 77  0
             list.add(ErrorLoggingFilter.class.getName());
 78  
         }
 79  
         
 80  3
         filterKeyList = list;
 81  3
         return list;
 82  
     }
 83  
 
 84  
     public void init(FilterConfig config) throws ServletException {
 85  6
         this.configureFilter(new ErrorLoggingFilter(), config);
 86  6
         this.configureFilter(new ErrorNotificationFilter(), config);
 87  6
         this.configureFilter(new PerformanceMonitoringFilter(), config);
 88  6
         this.configureFilter(new ConcurrentUsageFilter(), config);
 89  6
         this.configureFilter(new RequestTrackingFilter(), config);
 90  
         
 91  6
         String includeTimestampingStr = config.getInitParameter("include.serverside.timestamp");
 92  0
         if ( !StringUtils.isEmpty(includeTimestampingStr) && "true".equalsIgnoreCase(includeTimestampingStr)) {
 93  3
             this.configureFilter(new PerformanceTimeStampingFilter(), config);
 94  
         }
 95  
                 
 96  6
     }
 97  
     
 98  
     private void configureFilter(Filter filter, FilterConfig config) {
 99  33
         if (Admin4JStandardFilterChain.isRegistered(filter.getClass().getName())) {
 100  15
             return;
 101  
         }
 102  
         
 103  
         try {
 104  18
             filter.init(config);
 105  18
             Admin4JStandardFilterChain.registerFilter(filter, true);
 106  
         }
 107  0
         catch (Throwable t) {
 108  0
             logger.warn("Error configuring Filter", t);
 109  18
         }
 110  18
     }
 111  
 
 112  
 }