@@ -0,0 +1,2505 @@
+package com.google.sps.servlets;%0A%0Aimport javax.servlet.annotation.WebServlet;%0Aimport javax.servlet.http.HttpServlet;%0Aimport javax.servlet.http.HttpServletRequest;%0Aimport javax.servlet.http.HttpServletResponse;%0Aimport java.io.IOException;%0Aimport java.io.FileNotFoundException;%0A// import java.util.List;%0A// import java.util.ArrayList;%0A// import java.util.Arrays;%0Aimport java.util.Map;%0Aimport java.util.HashMap;%0Aimport java.lang.reflect.Type;%0Aimport com.google.gson.Gson;%0Aimport com.google.gson.reflect.TypeToken;%0Aimport com.google.sps.data.UrlRequest;%0A%0A/** Servlet that gets civic information. */%0A@WebServlet(%22/civic%22)%0Apublic class CivicServlet extends HttpServlet %7B%0A%0A  private static final String API_KEY = %22API_KEY%22;  // Insert the API_KEY here for testing.%0A  private static final String API_PATH = %22https://www.googleapis.com/civicinfo/v2/representatives%22;%0A%0A  @Override%0A  public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException %7B%0A    String latitude = request.getParameter(%22lat%22);%0A    String longitude = request.getParameter(%22lng%22);%0A    Map%3CString, String%3E locationQueryParams = new HashMap%3C%3E();%0A    locationQueryParams.put(%22lat%22, latitude);%0A    locationQueryParams.put(%22lng%22, longitude);%0A    String locationUrl = String.format(%22%25s://%25s:%25s/location%22,%0A        request.getScheme(), %0A        request.getServerName(), %0A        request.getServerPort());%0A    String address = %22%22;%0A    try %7B%0A      // Location URL doesn't work on devserver, so isntead use hardcoded string.%0A      String locationJsonResult = UrlRequest.urlQuery(locationUrl, locationQueryParams);%0A      Gson gson = new Gson();%0A      Type mapType = new TypeToken%3CMap%3CString, String%3E%3E() %7B%7D.getType();%0A      Map%3CString, String%3E locationMap = gson.fromJson(locationJsonResult, mapType);%0A      address = String.format(%22%25s %25s, %25s, %25s %25s%22, %0A          locationMap.get(%22Street Number%22),%0A          locationMap.get(%22Street Name%22),%0A          locationMap.get(%22City%22),%0A          locationMap.get(%22State%22),%0A          locationMap.get(%22Zip Code%22));%0A    %7D catch (FileNotFoundException fnfe) %7B%0A      System.out.println(fnfe);%0A      address = %221 LMU Dr, Los Angeles, California%22;%0A    %7D finally %7B%0A      Map%3CString, String%3E apiQueryParams = new HashMap%3C%3E();%0A      apiQueryParams.put(%22key%22, API_KEY);%0A      apiQueryParams.put(%22address%22, address);%0A      String jsonResult = UrlRequest.urlQuery(API_PATH, apiQueryParams);%0A      response.setContentType(%22application/json;%22);%0A      response.getWriter().println(jsonResult);%0A    %7D%0A  %7D%0A%7D

Add civic servlet