View Javadoc

1   /**
2    * Copyright 2004-2012 The Kuali Foundation
3    *
4    * Licensed under the Educational Community License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    * http://www.opensource.org/licenses/ecl2.php
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  package org.kuali.hr.time.web;
17  
18  import java.io.IOException;
19  import java.util.Date;
20  
21  import javax.servlet.ServletException;
22  import javax.servlet.http.HttpServletRequest;
23  import javax.servlet.http.HttpServletResponse;
24  
25  import org.apache.commons.lang.StringUtils;
26  import org.apache.log4j.Logger;
27  import org.kuali.hr.time.util.TKContext;
28  import org.kuali.rice.kns.web.struts.action.KualiRequestProcessor;
29  
30  public class TKRequestProcessor extends KualiRequestProcessor {
31  	
32  	private static final Logger LOG = Logger.getLogger(TKRequestProcessor.class);
33  	private static final String PRIVACY_POLICY_KEY = "P3P";
34  	private static final String PRIVACY_POLICY_VALUE = "CP=\"CAO DSP COR CURa ADMa DEVa CUSo TAIa PSAa PSDa OUR STP ONL UNI COM NAV INT DEM STA PRE\"";
35  	
36  	@Override
37  	public void process(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {
38  
39          // Make sure ThreadLocal context is clean before doing anything else -
40          // Tomcat uses a threadpool, and the ThreadLocals do not automatically die.
41  		
42  		Date startTime = new Date();
43  		
44  		TKContext.clear();
45  		TKContext.setHttpServletRequest(request);
46  		super.process(request, response);
47  
48  		String header = " Browser: " + request.getHeader("User-Agent");
49  		if (StringUtils.isBlank(header)) {
50  			header = "No header found";
51  		}
52  		
53  		response.setHeader(PRIVACY_POLICY_KEY, PRIVACY_POLICY_VALUE);
54  		
55  		long totalTime = System.currentTimeMillis() - startTime.getTime();
56  		
57  		LOG.info(new StringBuffer("Finished processing :: PERFORMANCE :: [[[Total Time: " + totalTime + "ms]]] ").append(request.getRequestURL()).append(header));
58  		
59  	}
60  
61  }