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.ActionContext;
23 import com.opensymphony.xwork2.ActionInvocation;
24 import com.opensymphony.xwork2.interceptor.AbstractInterceptor;
25 import org.apache.struts2.StrutsException;
26 import org.slf4j.Logger;
27 import org.slf4j.LoggerFactory;
28 import org.springframework.context.ApplicationContext;
29 import org.springframework.web.context.WebApplicationContext;
33 public abstract class AbstractHttpRequestTrackerInterceptor
34 extends AbstractInterceptor
36 public static final String TRACKER_NAME = ActionInvocationTracker.class.getName( )+ ":name";
38 protected Logger logger = LoggerFactory.getLogger( getClass() );
40 protected abstract String getTrackerName();
46 logger.info( "{} initialized!", this.getClass().getName() );
49 @SuppressWarnings( "unchecked" )
50 protected synchronized ActionInvocationTracker addActionInvocation( ActionInvocation invocation )
52 Map<String, Object> sessionMap = invocation.getInvocationContext().getSession();
54 ApplicationContext applicationContext = (ApplicationContext) ActionContext.getContext().getApplication().get(
55 WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE );
56 if ( applicationContext == null )
58 throw new StrutsException( "Could not locate ApplicationContext" );
61 ActionInvocationTracker tracker = (ActionInvocationTracker) sessionMap.get( ActionInvocationTracker.class.getName() );
63 if ( tracker == null )
65 //noinspection deprecation
66 tracker = applicationContext.getBean( getTrackerName(), ActionInvocationTracker.class );
67 sessionMap.put( ActionInvocationTracker.class.getName(), tracker );
70 tracker.addActionInvocation( invocation );