1 package org.apache.archiva.redback.struts2.interceptor;
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
12 * http://www.apache.org/licenses/LICENSE-2.0
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
22 import com.opensymphony.xwork2.ActionInvocation;
23 import com.opensymphony.xwork2.interceptor.Interceptor;
24 import org.apache.archiva.redback.system.check.EnvironmentCheck;
25 import org.slf4j.Logger;
26 import org.slf4j.LoggerFactory;
27 import org.springframework.context.annotation.Scope;
28 import org.springframework.stereotype.Controller;
30 import javax.annotation.PostConstruct;
31 import javax.inject.Inject;
32 import java.util.ArrayList;
33 import java.util.List;
36 * EnvironmentCheckInterceptor
38 * @author <a href="mailto:joakim@erdfelt.com">Joakim Erdfelt</a>
41 @Controller( "redbackEnvironmentCheckInterceptor" )
43 public class EnvironmentCheckInterceptor
44 implements Interceptor
46 private static boolean checked = false;
48 private Logger log = LoggerFactory.getLogger( EnvironmentCheckInterceptor.class );
55 private List<EnvironmentCheck> checkers;
66 if ( EnvironmentCheckInterceptor.checked )
68 // No need to check twice.
72 if ( checkers != null )
74 List<String> violations = new ArrayList<String>();
76 for ( EnvironmentCheck check : checkers )
78 check.validateEnvironment( violations );
81 if ( !violations.isEmpty() )
83 StringBuffer msg = new StringBuffer();
84 msg.append( "EnvironmentCheck Failure.\n" );
85 msg.append( "======================================================================\n" );
86 msg.append( " ENVIRONMENT FAILURE !! \n" );
89 for ( String v : violations )
91 msg.append( v ).append( "\n" );
95 msg.append( "======================================================================" );
96 log.error( msg.toString() );
100 EnvironmentCheckInterceptor.checked = true;
103 public String intercept( ActionInvocation invocation )
106 // A no-op here. Work for this intereceptor is done in init().
107 return invocation.invoke();