<commit_before>package com.google.sps.servlets;

import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.FileNotFoundException;
import java.util.Map;
import java.util.HashMap;
import java.lang.reflect.Type;
import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
import com.google.sps.data.UrlRequest;

/** Servlet that gets civic information. */
@WebServlet("/civic")
public class CivicServlet extends HttpServlet {

  private static final String API_KEY = "API_KEY";  // Insert the API_KEY here for testing.
  private static final String API_PATH = "https://www.googleapis.com/civicinfo/v2/representatives";

  @Override
  public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException {
    String latitude = request.getParameter("lat");
    String longitude = request.getParameter("lng");
    Map<String, String> locationQueryParams = new HashMap<>();
    locationQueryParams.put("lat", latitude);
    locationQueryParams.put("lng", longitude);
    String locationUrl = String.format("%s://%s:%s/location",
        request.getScheme(), 
        request.getServerName(), 
        request.getServerPort());
    String address = "";
    try {
      // Location URL doesn't work on devserver, so instead use hardcoded string.
      String locationJsonResult = UrlRequest.urlQuery(locationUrl, locationQueryParams);
      Gson gson = new Gson();
      Type mapType = new TypeToken<Map<String, String>>() {}.getType();
      Map<String, String> locationMap = gson.fromJson(locationJsonResult, mapType);
      address = String.format("%s %s, %s, %s %s", 
          locationMap.get("Street Number"),
          locationMap.get("Street Name"),
          locationMap.get("City"),
          locationMap.get("State"),
          locationMap.get("Zip Code"));
    } catch (FileNotFoundException fnfe) {
      System.out.println(fnfe.printStackTrace());
      address = "1 LMU Dr, Los Angeles, California";
    } finally {
      Map<String, String> apiQueryParams = new HashMap<>();
      apiQueryParams.put("key", API_KEY);
      apiQueryParams.put("address", address);
      String jsonResult = UrlRequest.urlQuery(API_PATH, apiQueryParams);
      response.setContentType("application/json;");
      response.getWriter().println(jsonResult);
    }
  }
}<commit_msg>Update CivicServlet.java<commit_after>package com.google.sps.servlets;

import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.FileNotFoundException;
import java.util.Map;
import java.util.HashMap;
import java.lang.reflect.Type;
import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
import com.google.sps.data.UrlRequest;

/** Servlet that gets civic information. */
@WebServlet("/civic")
public class CivicServlet extends HttpServlet {

  private static final String API_KEY = "API_KEY";  // Insert the API_KEY here for testing.
  private static final String API_PATH = "https://www.googleapis.com/civicinfo/v2/representatives";

  @Override
  public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException {
    String latitude = request.getParameter("lat");
    String longitude = request.getParameter("lng");
    Map<String, String> locationQueryParams = new HashMap<>();
    locationQueryParams.put("lat", latitude);
    locationQueryParams.put("lng", longitude);
    String locationUrl = String.format("%s://%s:%s/location",
        request.getScheme(), 
        request.getServerName(), 
        request.getServerPort());
    String address = "";
    try {
      // Location URL doesn't work on devserver, so instead use hardcoded string.
      String locationJsonResult = UrlRequest.urlQuery(locationUrl, locationQueryParams);
      Gson gson = new Gson();
      Type mapType = new TypeToken<Map<String, String>>() {}.getType();
      Map<String, String> locationMap = gson.fromJson(locationJsonResult, mapType);
      address = String.format("%s %s, %s, %s %s", 
          locationMap.get("Street Number"),
          locationMap.get("Street Name"),
          locationMap.get("City"),
          locationMap.get("State"),
          locationMap.get("Zip Code"));
    } catch (FileNotFoundException fnfe) {
      fnfe.printStackTrace();
      address = "1 LMU Dr, Los Angeles, California";
    } finally {
      Map<String, String> apiQueryParams = new HashMap<>();
      apiQueryParams.put("key", API_KEY);
      apiQueryParams.put("address", address);
      String jsonResult = UrlRequest.urlQuery(API_PATH, apiQueryParams);
      response.setContentType("application/json;");
      response.getWriter().println(jsonResult);
    }
  }
}
{'fraction_non_alphanumeric': 0.12456817719975614, 'fraction_numerical': 0.000812842918106076, 'mean_word_length': 3.996954314720812, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 17, 'https://': 2, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1689171', 'n_tokens_mistral': 1397, 'n_tokens_neox': 1364, 'n_words': 319}