src/org/ohmage/jee/servlet/RequestServlet.java
@Override
	protected final void service(HttpServletRequest httpRequest, HttpServletResponse httpResponse) throws ServletException, IOException {
		// Get the moment we received the request.
		long receivedTimestamp = System.currentTimeMillis();
		
		// Service the request by calling the appropriate getXXX() method.
		super.service(httpRequest, httpResponse);
		
		// Get the moment we have completed 
		long respondedTimestamp = System.currentTimeMillis();
		
		// Report how long the request took.
		LOGGER.info("Time to process '" + httpRequest.getRequestURI() + "':"+ (respondedTimestamp - receivedTimestamp));
		
		// Retrieve the type of request, GET, POST, etc.
		RequestType requestType;
		try {
			requestType = RequestType.valueOf(httpRequest.getMethod());
		}
		catch(IllegalArgumentException e) {
			requestType = RequestType.UNKNOWN;
		}
		
		// Retrieve the request's URI.
		String uri = httpRequest.getRequestURI();
		
		// Generate an 'extras' Map based on the HTTP headers.
		Map<String, String[]> extras = new HashMap<String, String[]>();
		Enumeration<String> headers = httpRequest.getHeaderNames();
		while(headers.hasMoreElements()) {
			String header = headers.nextElement();
			
			List<String> valueList = new LinkedList<String>();
			Enumeration<String> values = httpRequest.getHeaders(header);
			while(values.hasMoreElements()) {
				valueList.add(values.nextElement());
			}
			
			extras.put(header, valueList.toArray(new String[0]));
		}
		
		// This is the parameter map that will be taken from the request if
		// available; otherwise, it will be taken from the user request.
		Map<String, String[]> parameterMap;
		
		Object requestObject = httpRequest.getAttribute(KEY_ATTRIBUTE);
		Request request = null;
		if(requestObject != null) {
			request = (Request) requestObject;
			
			parameterMap = new HashMap<String, String[]>(request.getParameterMap());
		}
		else {
			// Retrieve the request's parameter map. We must make a copy 
			// because as soon as this function exists Tomcat will begin 
			// destroying the original parameter map.
			parameterMap = new HashMap<String, String[]>(httpRequest.getParameterMap());
		}

		// Create a separate thread with the parameters and start that thread.
		AuditThread auditThread =
			new AuditThread(
				request,
				requestType,
				uri,
				(String) httpRequest.getAttribute(Log4jNdcFilter.ATTRIBUTE_REQUEST_ID),
				parameterMap,
				extras,
				receivedTimestamp,
				respondedTimestamp);
		auditThread.start();
	}
/**
	 * This injects itself between Tomcat and our request servicing components,
	 * so that we can audit all incoming requests.
	 */
This injects itself between Tomcat and our request servicing components,
so that we can audit all incoming requests.
This injects itself between Tomcat and our request servicing components so that we can audit all incoming requests .
@Override
	protected final void service(HttpServletRequest httpRequest, HttpServletResponse httpResponse) throws ServletException, IOException {
		long receivedTimestamp = System.currentTimeMillis();
		super.service(httpRequest, httpResponse);
		long respondedTimestamp = System.currentTimeMillis();
		LOGGER.info("Time to process '" + httpRequest.getRequestURI() + "':"+ (respondedTimestamp - receivedTimestamp));
		RequestType requestType;
		try {
			requestType = RequestType.valueOf(httpRequest.getMethod());
		}
		catch(IllegalArgumentException e) {
			requestType = RequestType.UNKNOWN;
		}
		String uri = httpRequest.getRequestURI();
		Map<String, String[]> extras = new HashMap<String, String[]>();
		Enumeration<String> headers = httpRequest.getHeaderNames();
		while(headers.hasMoreElements()) {
			String header = headers.nextElement();
			List<String> valueList = new LinkedList<String>();
			Enumeration<String> values = httpRequest.getHeaders(header);
			while(values.hasMoreElements()) {
				valueList.add(values.nextElement());
			}
			extras.put(header, valueList.toArray(new String[0]));
		}
		Map<String, String[]> parameterMap;
		Object requestObject = httpRequest.getAttribute(KEY_ATTRIBUTE);
		Request request = null;
		if(requestObject != null) {
			request = (Request) requestObject;
			parameterMap = new HashMap<String, String[]>(request.getParameterMap());
		}
		else {
			parameterMap = new HashMap<String, String[]>(httpRequest.getParameterMap());
		}
		AuditThread auditThread =
			new AuditThread(
				request,
				requestType,
				uri,
				(String) httpRequest.getAttribute(Log4jNdcFilter.ATTRIBUTE_REQUEST_ID),
				parameterMap,
				extras,
				receivedTimestamp,
				respondedTimestamp);
		auditThread.start();
	}
@ Override protected final void service ( HttpServletRequest httpRequest , HttpServletResponse httpResponse ) throws ServletException , IOException { long receivedTimestamp = System . currentTimeMillis ( ) ; super . service ( httpRequest , httpResponse ) ; long respondedTimestamp = System . currentTimeMillis ( ) ; LOGGER . info ( "Time to process '" + httpRequest . getRequestURI ( ) + "':" + ( respondedTimestamp - receivedTimestamp ) ) ; RequestType requestType ; try { requestType = RequestType . valueOf ( httpRequest . getMethod ( ) ) ; } catch ( IllegalArgumentException e ) { requestType = RequestType . UNKNOWN ; } String uri = httpRequest . getRequestURI ( ) ; Map < String , String [ ] > extras = new HashMap < String , String [ ] > ( ) ; Enumeration < String > headers = httpRequest . getHeaderNames ( ) ; while ( headers . hasMoreElements ( ) ) { String header = headers . nextElement ( ) ; List < String > valueList = new LinkedList < String > ( ) ; Enumeration < String > values = httpRequest . getHeaders ( header ) ; while ( values . hasMoreElements ( ) ) { valueList . add ( values . nextElement ( ) ) ; } extras . put ( header , valueList . toArray ( new String [ 0 ] ) ) ; } Map < String , String [ ] > parameterMap ; Object requestObject = httpRequest . getAttribute ( KEY_ATTRIBUTE ) ; Request request = null ; if ( requestObject != null ) { request = ( Request ) requestObject ; parameterMap = new HashMap < String , String [ ] > ( request . getParameterMap ( ) ) ; } else { parameterMap = new HashMap < String , String [ ] > ( httpRequest . getParameterMap ( ) ) ; } AuditThread auditThread = new AuditThread ( request , requestType , uri , ( String ) httpRequest . getAttribute ( Log4jNdcFilter . ATTRIBUTE_REQUEST_ID ) , parameterMap , extras , receivedTimestamp , respondedTimestamp ) ; auditThread . start ( ) ; }
This injects itself between Tomcat and our request servicing components,
 so that we can audit all incoming requests.
This injects itself between Tomcat and our request servicing components so that we can audit all incoming requests .
// Get the moment we received the request. // Service the request by calling the appropriate getXXX() method. // Get the moment we have completed  // Report how long the request took. // Retrieve the type of request, GET, POST, etc. // Retrieve the request's URI. // Generate an 'extras' Map based on the HTTP headers. // This is the parameter map that will be taken from the request if // available; otherwise, it will be taken from the user request. // Retrieve the request's parameter map. We must make a copy  // because as soon as this function exists Tomcat will begin  // destroying the original parameter map. // Create a separate thread with the parameters and start that thread.