View Javadoc

1   /**
2    * Copyright 2004-2014 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.kpme.core;
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.rice.kns.web.struts.action.KualiRequestProcessor;
28  
29  public class KPMERequestProcessor extends KualiRequestProcessor {
30  	
31  	private static final Logger LOG = Logger.getLogger(KPMERequestProcessor.class);
32  	private static final String PRIVACY_POLICY_KEY = "P3P";
33  	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\"";
34  	
35  	@Override
36  	public void process(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {
37  
38          // Make sure ThreadLocal context is clean before doing anything else -
39          // Tomcat uses a threadpool, and the ThreadLocals do not automatically die.
40  		
41  		Date startTime = new Date();
42  		
43  		super.process(request, response);
44  
45  		String header = " Browser: " + request.getHeader("User-Agent");
46  		if (StringUtils.isBlank(header)) {
47  			header = "No header found";
48  		}
49  		
50  		response.setHeader(PRIVACY_POLICY_KEY, PRIVACY_POLICY_VALUE);
51  		
52  		long totalTime = System.currentTimeMillis() - startTime.getTime();
53  		
54  		LOG.info(new StringBuffer("Finished processing :: PERFORMANCE :: [[[Total Time: " + totalTime + "ms]]] ").append(request.getRequestURL()).append(header));
55  		
56  	}
57  
58  }