@Override
	public void handle(HttpExchange exchange) throws IOException {
		System.out.println("In Save Game handler.");
		
		String responseMessage = "";
		
		if(exchange.getRequestMethod().toLowerCase().equals("post")) {
			exchange.getResponseHeaders().set("Content-Type", "appliction/json");
			
			BufferedReader in = new BufferedReader(new InputStreamReader(exchange.getRequestBody()));
			String inputLine;
			StringBuffer requestJson = new StringBuffer();
			while ((inputLine = in.readLine()) != null) {
				requestJson.append(inputLine);
			}
			in.close();
			
			System.out.println(requestJson);
			
			SaveGameRequest request = (SaveGameRequest) translator.translateFrom(requestJson.toString(), SaveGameRequest.class);
			exchange.getRequestBody().close();
			
			if(gamesFacade.validateGameID(request.getId())){
				try{
					gamesFacade.saveGame(request.getId(), request.getName());
					responseMessage = "Successfully wrote game to file: " + request.getId();
					exchange.sendResponseHeaders(HttpURLConnection.HTTP_OK, 0);
				}catch(IOException e){
					System.out.println("Error writing to file.");
					responseMessage = e.getMessage();
					exchange.sendResponseHeaders(HttpURLConnection.HTTP_BAD_REQUEST, 0);
				}
			}
			else{
				System.out.println("Bad game id.");
				responseMessage = "Error: Bad game id";
				exchange.sendResponseHeaders(HttpURLConnection.HTTP_BAD_REQUEST, 0);
			}
		}
		else {
			// unsupported request method
			responseMessage = "Error: \"" + exchange.getRequestMethod() + "\" is not supported!";
			exchange.sendResponseHeaders(HttpURLConnection.HTTP_BAD_REQUEST, 0);
		}
				
				if (!responseMessage.isEmpty()) {
					//send failure response message
					OutputStreamWriter writer = new OutputStreamWriter(
							exchange.getResponseBody());
					writer.write(responseMessage);
					writer.flush();
					writer.close();
				}
				exchange.getResponseBody().close();
	}