src/org/ohmage/request/visualization/VisualizationRequest.java
@Override
	public void respond(HttpServletRequest httpRequest, HttpServletResponse httpResponse) {
		LOGGER.info("Writing the visualization response.");
		
		// Creates the writer that will write the response, success or fail.
		Writer writer;
		OutputStream os;
		try {
			os = getOutputStream(httpRequest, httpResponse);
			writer = new BufferedWriter(new OutputStreamWriter(os));
		}
		catch(IOException e) {
			LOGGER.error("Unable to create writer object. Aborting.", e);
			return;
		}
		
		// Sets the HTTP headers to disable caching
		expireResponse(httpResponse);
		
		// If the request hasn't failed, attempt to write the file to the
		// output stream. 
		if(! isFailed() && (result != null)) {
			try {
				// Setup the response headers.
				httpResponse.setContentType("image/png");
				
				// If available, set the token.
				if(getUser() != null) {
					final String token = getUser().getToken(); 
					if(token != null) {
						CookieUtils.setCookieValue(httpResponse, InputKeys.AUTH_TOKEN, token);
					}
				}
				
				os.write(result);
				os.flush();
				os.close();
			}
			catch(IOException e) {
				LOGGER.error("There was an error writing the image to the output stream.", e);
				return;
			}
		}
		
		// If the request ever failed, write an error message.
		if(isFailed()) {
			httpResponse.setContentType("text/html");
			
			// Write the error response.
			try {
				writer.write(getFailureMessage()); 
			}
			catch(IOException e) {
				LOGGER.warn("Unable to write failed response message. Aborting.", e);
			}
			
			// Close it.
			try {
				writer.close();
			}
			catch(IOException e) {
				LOGGER.warn("Unable to close the writer.", e);
			}
		}
	}
/**
	 * Writes the resulting image to the response's output stream.
	 */
Writes the resulting image to the response's output stream.
Writes the resulting image to the response ' s output stream .
@Override
	public void respond(HttpServletRequest httpRequest, HttpServletResponse httpResponse) {
		LOGGER.info("Writing the visualization response.");
		Writer writer;
		OutputStream os;
		try {
			os = getOutputStream(httpRequest, httpResponse);
			writer = new BufferedWriter(new OutputStreamWriter(os));
		}
		catch(IOException e) {
			LOGGER.error("Unable to create writer object. Aborting.", e);
			return;
		}
		expireResponse(httpResponse);
		if(! isFailed() && (result != null)) {
			try {
				httpResponse.setContentType("image/png");
				if(getUser() != null) {
					final String token = getUser().getToken(); 
					if(token != null) {
						CookieUtils.setCookieValue(httpResponse, InputKeys.AUTH_TOKEN, token);
					}
				}
				os.write(result);
				os.flush();
				os.close();
			}
			catch(IOException e) {
				LOGGER.error("There was an error writing the image to the output stream.", e);
				return;
			}
		}
		if(isFailed()) {
			httpResponse.setContentType("text/html");
			try {
				writer.write(getFailureMessage()); 
			}
			catch(IOException e) {
				LOGGER.warn("Unable to write failed response message. Aborting.", e);
			}
			try {
				writer.close();
			}
			catch(IOException e) {
				LOGGER.warn("Unable to close the writer.", e);
			}
		}
	}
@ Override public void respond ( HttpServletRequest httpRequest , HttpServletResponse httpResponse ) { LOGGER . info ( "Writing the visualization response." ) ; Writer writer ; OutputStream os ; try { os = getOutputStream ( httpRequest , httpResponse ) ; writer = new BufferedWriter ( new OutputStreamWriter ( os ) ) ; } catch ( IOException e ) { LOGGER . error ( "Unable to create writer object. Aborting." , e ) ; return ; } expireResponse ( httpResponse ) ; if ( ! isFailed ( ) && ( result != null ) ) { try { httpResponse . setContentType ( "image/png" ) ; if ( getUser ( ) != null ) { final String token = getUser ( ) . getToken ( ) ; if ( token != null ) { CookieUtils . setCookieValue ( httpResponse , InputKeys . AUTH_TOKEN , token ) ; } } os . write ( result ) ; os . flush ( ) ; os . close ( ) ; } catch ( IOException e ) { LOGGER . error ( "There was an error writing the image to the output stream." , e ) ; return ; } } if ( isFailed ( ) ) { httpResponse . setContentType ( "text/html" ) ; try { writer . write ( getFailureMessage ( ) ) ; } catch ( IOException e ) { LOGGER . warn ( "Unable to write failed response message. Aborting." , e ) ; } try { writer . close ( ) ; } catch ( IOException e ) { LOGGER . warn ( "Unable to close the writer." , e ) ; } } }
Writes the resulting image to the response's output stream.
Writes the resulting image to the response ' s output stream .
// Creates the writer that will write the response, success or fail. // Sets the HTTP headers to disable caching // If the request hasn't failed, attempt to write the file to the // output stream.  // Setup the response headers. // If available, set the token. // If the request ever failed, write an error message. // Write the error response. // Close it.