01: /*
02: * Copyright 2005-2006 the original author or authors.
03: *
04: * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
05: * in compliance with the License. You may obtain a copy of the License at
06: *
07: * http://www.apache.org/licenses/LICENSE-2.0
08: *
09: * Unless required by applicable law or agreed to in writing, software distributed under the License
10: * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
11: * or implied. See the License for the specific language governing permissions and limitations under
12: * the License.
13: */
14:
15: package org.strecks.interceptor;
16:
17: import java.util.ArrayList;
18: import java.util.List;
19:
20: import javax.servlet.http.HttpServletRequest;
21: import javax.servlet.http.HttpSession;
22:
23: import org.strecks.constants.InfrastructureKeys;
24: import org.strecks.context.ActionContext;
25:
26: /**
27: * Action interceptor used to track list of URLs for HTTP GET method requests
28: * @author Phil Zoio
29: */
30: public class HistoryRecorder implements AfterInterceptor {
31:
32: public void afterExecute(Object actionBean, ActionContext context,
33: Exception e) {
34:
35: HttpServletRequest request = context.getRequest();
36:
37: if (request.getMethod().equalsIgnoreCase("GET")) {
38: HttpSession session = request.getSession();
39:
40: @SuppressWarnings("unchecked")
41: List<String> goodURLs = (List<String>) session
42: .getAttribute(InfrastructureKeys.GOOD_URL_HISTORY);
43:
44: if (goodURLs == null) {
45: goodURLs = new ArrayList<String>();
46: }
47:
48: goodURLs.add(buildURL(request));
49: session.setAttribute(InfrastructureKeys.GOOD_URL_HISTORY,
50: goodURLs);
51: }
52: }
53:
54: String buildURL(HttpServletRequest request) {
55: String servletPath = request.getServletPath();
56:
57: String queryString = request.getQueryString();
58: if (queryString != null) {
59: servletPath += "?" + queryString;
60: }
61: return servletPath;
62: }
63: }
|