@@ -0,0 +1,2903 @@
+/**Copyright 2019 Google LLC%0A%0ALicensed under the Apache License, Version 2.0 (the %22License%22);%0Ayou may not use this file except in compliance with the License.%0AYou may obtain a copy of the License at%0A%0A    https://www.apache.org/licenses/LICENSE-2.0%0A%0AUnless required by applicable law or agreed to in writing, software%0Adistributed under the License is distributed on an %22AS IS%22 BASIS,%0AWITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.%0ASee the License for the specific language governing permissions and%0Alimitations under the License.*/%0Apackage com.google.sps.data;%0A%0Aimport com.google.gson.Gson;%0Aimport java.util.*;%0Aimport java.lang.*;%0Aimport com.google.sps.data.SearchErrors;%0Aimport java.io.IOException;%0Aimport javax.servlet.annotation.WebServlet;%0Aimport javax.servlet.http.HttpServlet;%0Aimport javax.servlet.http.HttpServletRequest;%0Aimport javax.servlet.http.HttpServletResponse;%0A%0Aimport java.security.GeneralSecurityException;%0A%0Aimport java.util.*;%0Aimport java.net.*;%0Aimport java.io.*;%0Aimport com.google.api.services.customsearch.Customsearch;%0Aimport com.google.api.services.customsearch.Customsearch.Cse;%0Aimport com.google.api.services.customsearch.CustomsearchRequestInitializer;%0Aimport com.google.api.client.googleapis.javanet.GoogleNetHttpTransport;%0Aimport com.google.api.client.json.jackson2.JacksonFactory;%0Aimport com.google.api.services.customsearch.Customsearch.Cse.List;%0Aimport com.google.api.services.customsearch.model.Result;%0Aimport com.google.api.services.customsearch.model.Search;%0A%0A@WebServlet(%22/fix%22)%0Apublic class ErrorFixes extends HttpServlet  %7B%0A    // public static String findFixes(String searchQuery) throws GeneralSecurityException, IOException %7B%0A     @Override%0A    public void doPost(HttpServletRequest request, HttpServletResponse response) throws IOException %7B%0A        try%7B%0A    String searchQuery=request.getParameter(%22fix%22);%0A    String searchEngine = %22cx%22; //Your search engine%0A%0A    //Instance Customsearch%0A    Customsearch customeSearch = new Customsearch.Builder(GoogleNetHttpTransport.newTrustedTransport(), JacksonFactory.getDefaultInstance(), null) %0A                   .setApplicationName(%22errorFixes%22) %0A                   .setGoogleClientRequestInitializer(new CustomsearchRequestInitializer(%22your_api_key%22)) %0A                   .build();%0A%0A    //Set search parameter%0A    Customsearch.Cse.List list = customeSearch.cse().list(searchQuery).setCx(searchEngine); %0A    response.setContentType(%22text/html%22);%0A    //  response.getWriter().println(%22hi%22);%0A    //Execute search%0A    Search result = list.execute();%0A    if (result.getItems()!=null)%7B%0A        for (Result ri : result.getItems()) %7B%0A            //Get title, link, body etc. from search%0A            response.getWriter().println(ri.getTitle() + %22, %22 + ri.getLink());%0A        %7D%0A    %7Delse%7B%0A        return new String();%0A    %7D%0A    %7Dcatch(GeneralSecurityException e)%7B%0A        return new String();%0A    %7D%0A%0A%7D%0A%7D

add custom search