Search code examples
network-programminggoogle-search-apigoogle-search-appliance

Google Search Appliance Administration API


We are using the GSA for our companies internal search and it has been configured as a secure URL i.e. https_colon_fwdSlash2_Myhostname.net:8443. I am trying to use the google search appliance Administration API to just connect to the GSA. I am using the Java version of the API and writting the programs on a different server within my companies network.

This is the Code I am trying to run

 import java.io.IOException;
 import java.net.MalformedURLException;

 import com.google.enterprise.apis.client.GsaClient;
 import com.google.enterprise.apis.client.GsaEntry;
 import com.google.gdata.util.ServiceException;

 public class GsaFirst {
 public static void main(String args[]) throws MalformedURLException, ServiceException, IOException{

        System.out.println("The program started...");
        GsaClient myClient = new GsaClient("Myhostname.net", 8443, "username", "pwd1234");
        System.out.println("this is the error");
        //String addr = myClient.getAddress();
        //System.out.println(addr);

        GsaEntry myEntry = myClient.getEntry("config", "crawlURLs");
        System.out.println("Start URLs: " + myEntry.getGsaContent("startURLs"));
        System.out.println("Follow URLs: " + myEntry.getGsaContent("followURLs"));
        System.out.println("Do Not Crawl URLs: " + myEntry.getGsaContent("doNotCrawlURLs"));

    }

}

The output I get is The program started... Exception in thread "main" com.google.gdata.util.AuthenticationException: Error authenticating (check service name) at com.google.gdata.client.GoogleAuthTokenFactory.getAuthException(Unknown Source) at com.google.gdata.client.GoogleAuthTokenFactory.getAuthToken(Unknown Source) at com.google.gdata.client.GoogleAuthTokenFactory.setUserCredentials(Unknown Source) at com.google.gdata.client.GoogleService.setUserCredentials(Unknown Source) at com.google.gdata.client.GoogleService.setUserCredentials(Unknown Source) at com.google.gdata.client.GoogleService.setUserCredentials(Unknown Source) at com.google.enterprise.apis.client.GsaClient.(Unknown Source) at com.google.enterprise.apis.client.GsaClient.(Unknown Source) at com.gsa.GsaFirst.main(GsaFirst.java:14)

If someone can help me out or guide me what steps I would have to take to resolve this. Appreciate any help on this.


Solution

  • I was able to solve the issue by adding this small snippet of code wich did the trick.

      import java.io.IOException;
      import java.net.MalformedURLException;
    
      import com.google.enterprise.apis.client.GsaClient;
      import com.google.enterprise.apis.client.GsaEntry;
      import com.google.gdata.util.ServiceException;
    
      public class GsaFirst {
      static {
        //for localhost testing only
        javax.net.ssl.HttpsURLConnection.setDefaultHostnameVerifier(
        new javax.net.ssl.HostnameVerifier(){
    
            public boolean verify(String hostname,
                    javax.net.ssl.SSLSession sslSession) {
                if (hostname.equals("Myhostname.net")) {
                    return true;
                }
                return false;
            }
        });
    }
      public static void main(String args[]) throws MalformedURLException,   ServiceException, IOException{
    
        System.out.println("The program started...");
        GsaClient myClient = new GsaClient("Myhostname.net", 8443, "username", "pwd1234");
        System.out.println("this is the error");
        //String addr = myClient.getAddress();
        //System.out.println(addr);
    
        GsaEntry myEntry = myClient.getEntry("config", "crawlURLs");
        System.out.println("Start URLs: " + myEntry.getGsaContent("startURLs"));
        System.out.println("Follow URLs: " + myEntry.getGsaContent("followURLs"));
        System.out.println("Do Not Crawl URLs: " + myEntry.getGsaContent("doNotCrawlURLs"));
    
    }