src/org/ohmage/request/Request.java
protected void respond(
			final HttpServletRequest httpRequest, 
			final HttpServletResponse httpResponse, 
			final JSONObject response) {
				
		// Create a writer for the HTTP response object.
		Writer writer = null;
		String responseText = "";
		
		try {
			writer = 
					new BufferedWriter(
							new OutputStreamWriter(
									getOutputStream(
											httpRequest, 
											httpResponse)));
			
			// Sets the HTTP headers to disable caching.
			expireResponse(httpResponse);
			
			httpResponse.setContentType("application/json");
			
			// If the response hasn't failed yet, attempt to create and write the
			// JSON response.
			if(! failed) {
				try {
					response.put(JSON_KEY_RESULT, RESULT_SUCCESS);
					
					responseText = response.toString();
				}
				catch(JSONException e) {
					// If anything fails, echo it in the logs and set the request
					// as failed.
					LOGGER.error("An error occurred while building the success JSON response.", e);
					failed = true;
				}
			}
			
			// If the request failed, either during the build or while the response
			// was being built, write a failure message.
			if(failed) {
				responseText = getFailureMessage();
			}
			
			writer.write(responseText);
		}
		// SN: commenting as this exception is a subclass of IOException
		// and the exception is tomcat-specific.
		//catch(ClientAbortException e) {
		//	LOGGER.info("The client hung up unexpectedly.", e);
		//}
		catch(IOException e) {
			LOGGER.error("Unable to write response message. Aborting.", e);
		}
		finally {
			if(writer != null) {
				try {
					writer.close();
				}
				catch(IOException e) {
					LOGGER.warn("Unable to close the writer.", e);
				}
			}
		}
	}
/**
	 * Writes the response that is a JSONObject. This is a helper function for
	 * when {@link #respond(HttpServletRequest, HttpServletResponse)} is called
	 * given that most responses are in some sort of JSON format. The response
	 * is modified only add a "success" message and then is sent, unless the
	 * request fails in which case a failure message is sent instead of the
	 * response. This means that the key {@link #JSON_KEY_RESULT} is added to
	 * this JSONObject and any previous value associated with that key is 
	 * removed.
	 *  
	 * @param httpRequest The initial HTTP request that we are processing.
	 * 
	 * @param httpResponse The response for this HTTP request.
	 * 
	 * @param jsonResponse An already-constructed JSONObject that contains the
	 * 					   'data' portion of the object.
	 */
Writes the response that is a JSONObject. This is a helper function for
when  #respond(HttpServletRequest, HttpServletResponse) is called
given that most responses are in some sort of JSON format. The response
is modified only add a "success" message and then is sent, unless the
request fails in which case a failure message is sent instead of the
response. This means that the key  #JSON_KEY_RESULT is added to
this JSONObject and any previous value associated with that key is
removed.

@param httpRequest The initial HTTP request that we are processing.

@param httpResponse The response for this HTTP request.

@param jsonResponse An already-constructed JSONObject that contains the
'data' portion of the object.
Writes the response that is a JSONObject . This is a helper function for when #respond ( HttpServletRequest HttpServletResponse ) is called given that most responses are in some sort of JSON format . The response is modified only add a " success " message and then is sent unless the request fails in which case a failure message is sent instead of the response . This means that the key #JSON_KEY_RESULT is added to this JSONObject and any previous value associated with that key is removed . @param httpRequest The initial HTTP request that we are processing . @param httpResponse The response for this HTTP request . @param jsonResponse An already - constructed JSONObject that contains the ' data ' portion of the object .
protected void respond(
			final HttpServletRequest httpRequest, 
			final HttpServletResponse httpResponse, 
			final JSONObject response) {
		Writer writer = null;
		String responseText = "";
		try {
			writer = 
					new BufferedWriter(
							new OutputStreamWriter(
									getOutputStream(
											httpRequest, 
											httpResponse)));
			expireResponse(httpResponse);
			httpResponse.setContentType("application/json");
			if(! failed) {
				try {
					response.put(JSON_KEY_RESULT, RESULT_SUCCESS);
					responseText = response.toString();
				}
				catch(JSONException e) {
					LOGGER.error("An error occurred while building the success JSON response.", e);
					failed = true;
				}
			}
			if(failed) {
				responseText = getFailureMessage();
			}
			writer.write(responseText);
		}
		catch(IOException e) {
			LOGGER.error("Unable to write response message. Aborting.", e);
		}
		finally {
			if(writer != null) {
				try {
					writer.close();
				}
				catch(IOException e) {
					LOGGER.warn("Unable to close the writer.", e);
				}
			}
		}
	}
protected void respond ( final HttpServletRequest httpRequest , final HttpServletResponse httpResponse , final JSONObject response ) { Writer writer = null ; String responseText = "" ; try { writer = new BufferedWriter ( new OutputStreamWriter ( getOutputStream ( httpRequest , httpResponse ) ) ) ; expireResponse ( httpResponse ) ; httpResponse . setContentType ( "application/json" ) ; if ( ! failed ) { try { response . put ( JSON_KEY_RESULT , RESULT_SUCCESS ) ; responseText = response . toString ( ) ; } catch ( JSONException e ) { LOGGER . error ( "An error occurred while building the success JSON response." , e ) ; failed = true ; } } if ( failed ) { responseText = getFailureMessage ( ) ; } writer . write ( responseText ) ; } catch ( IOException e ) { LOGGER . error ( "Unable to write response message. Aborting." , e ) ; } finally { if ( writer != null ) { try { writer . close ( ) ; } catch ( IOException e ) { LOGGER . warn ( "Unable to close the writer." , e ) ; } } } }
Writes the response that is a JSONObject.
Writes the response that is a JSONObject .
// Create a writer for the HTTP response object. // Sets the HTTP headers to disable caching. // If the response hasn't failed yet, attempt to create and write the // JSON response. // If anything fails, echo it in the logs and set the request // as failed. // If the request failed, either during the build or while the response // was being built, write a failure message. // SN: commenting as this exception is a subclass of IOException // and the exception is tomcat-specific. //catch(ClientAbortException e) { //	LOGGER.info("The client hung up unexpectedly.", e); //}