0

我们使用 GSA 进行公司内部搜索,它已被配置为安全 URL,即 https_colon_fwdSlash2_Myhostname.net:8443。我正在尝试使用谷歌搜索设备管理 API 来连接到 GSA。我正在使用 API 的 Java 版本,并在我公司网络内的不同服务器上编写程序。

这是我要运行的代码

 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"));

    }

}

我得到的输出是程序已启动...线程“主”com.google.gdata.util.AuthenticationException 中的异常:com.google.gdata.client.GoogleAuthTokenFactory.getAuthException(未知来源)的身份验证错误(检查服务名称)在 com.google.gdata.client.GoogleAuthTokenFactory.getAuthToken(Unknown Source) 在 com.google.gdata.client.GoogleAuthTokenFactory.setUserCredentials(Unknown Source) 在 com.google.gdata.client.GoogleService.setUserCredentials(Unknown Source) 在 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)

如果有人可以帮助我或指导我必须采取哪些步骤来解决这个问题。感谢您对此的任何帮助。

4

1 回答 1

0

我能够通过添加这个小片段的代码来解决这个问题。

  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"));

}
于 2013-12-11T06:09:51.353 回答