001 /**
002 * Copyright 2004-2013 The Kuali Foundation
003 *
004 * Licensed under the Educational Community License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 * http://www.opensource.org/licenses/ecl2.php
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 */
016 package org.kuali.hr.time.web;
017
018 import java.io.IOException;
019 import java.util.Date;
020
021 import javax.servlet.ServletException;
022 import javax.servlet.http.HttpServletRequest;
023 import javax.servlet.http.HttpServletResponse;
024
025 import org.apache.commons.lang.StringUtils;
026 import org.apache.log4j.Logger;
027 import org.kuali.hr.time.util.TKContext;
028 import org.kuali.rice.kns.web.struts.action.KualiRequestProcessor;
029
030 public class TKRequestProcessor extends KualiRequestProcessor {
031
032 private static final Logger LOG = Logger.getLogger(TKRequestProcessor.class);
033 private static final String PRIVACY_POLICY_KEY = "P3P";
034 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\"";
035
036 @Override
037 public void process(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {
038
039 // Make sure ThreadLocal context is clean before doing anything else -
040 // Tomcat uses a threadpool, and the ThreadLocals do not automatically die.
041
042 Date startTime = new Date();
043
044 TKContext.clear();
045 TKContext.setHttpServletRequest(request);
046 super.process(request, response);
047
048 String header = " Browser: " + request.getHeader("User-Agent");
049 if (StringUtils.isBlank(header)) {
050 header = "No header found";
051 }
052
053 response.setHeader(PRIVACY_POLICY_KEY, PRIVACY_POLICY_VALUE);
054
055 long totalTime = System.currentTimeMillis() - startTime.getTime();
056
057 LOG.info(new StringBuffer("Finished processing :: PERFORMANCE :: [[[Total Time: " + totalTime + "ms]]] ").append(request.getRequestURL()).append(header));
058
059 }
060
061 }