Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/385.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java GSA API-无法获取身份验证令牌_Java_Acl_Google Search_Google Search Appliance - Fatal编程技术网

Java GSA API-无法获取身份验证令牌

Java GSA API-无法获取身份验证令牌,java,acl,google-search,google-search-appliance,Java,Acl,Google Search,Google Search Appliance,我一直在尝试获取一个用于管理Google搜索设备的身份验证密钥,并修改其访问控制列表(ACL) 这是我的代码: SocketAddress proxyAddress = new InetSocketAddress(PROXY_HOST,PROXY_PORT); Proxy proxy = new Proxy(Proxy.Type.HTTP, proxyAddress); URL clientLoginUrl = new URL("https://my.server.com

我一直在尝试获取一个用于管理Google搜索设备的身份验证密钥,并修改其访问控制列表(ACL)

这是我的代码:

    SocketAddress proxyAddress = new InetSocketAddress(PROXY_HOST,PROXY_PORT);
    Proxy proxy = new Proxy(Proxy.Type.HTTP, proxyAddress);
    URL clientLoginUrl = new URL("https://my.server.com:8443/accounts/ClientLogin");
    HttpURLConnection clientLoginSecureConnection = 
        (HttpURLConnection)clientLoginUrl.openConnection(proxy);
    clientLoginSecureConnection.setDoInput(true);
    clientLoginSecureConnection.setDoOutput(true);
    clientLoginSecureConnection.setUseCaches(false);
    clientLoginSecureConnection.setRequestProperty("Content-Type",          
        "application/x-www-form-urlencoded");
    StringBuilder content = new StringBuilder();
    content.append("Email=").append(
    URLEncoder.encode(Constants.GSA_AUTH_USER, "UTF-8"));
    content.append("&Passwd=").append(
    URLEncoder.encode(Constants.GSA_AUTH_PASSWORD, "UTF-8"));
    OutputStream outputStream = clientLoginSecureConnection.getOutputStream();
    outputStream.write(content.toString().getBytes("UTF-8"));
    outputStream.close();
    // Retrieve the output
    int responseCode = clientLoginSecureConnection.getResponseCode();
    System.out.println("Response code: " + responseCode);
    InputStream inputStream;
    if (responseCode == HttpURLConnection.HTTP_OK) {
        inputStream = clientLoginSecureConnection.getInputStream();
    } else {
        inputStream = clientLoginSecureConnection.getErrorStream();
    }
    String postOutput = toString(inputStream);
    StringTokenizer tokenizer = new StringTokenizer(postOutput, "=\n ");
    String key = null;
    while (tokenizer.hasMoreElements()) {
        if (tokenizer.nextToken().equalsIgnoreCase("Auth")) {
            if (tokenizer.hasMoreElements()) {
                key = tokenizer.nextToken();
            }
            break;
        }
    }
    if (key == null) {
    System.out.println("Error response from server:\n" + postOutput);
    } else {
        System.out.println("Key found: " + key);
}
我已按照说明进行操作,但我总是遇到以下例外情况:

javax.net.ssl.SSLHandshakeException:远程主机关闭连接 在握手时 com.sun.net.ssl.internal.ssl.SSLSocketImpl.readRecord(SSLSocketImpl.java:808) 在 com.sun.net.ssl.internal.ssl.SSLSocketImpl.performInitialHandshake(SSLSocketImpl.java:1120) 在 com.sun.net.ssl.internal.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:1147) 在 com.sun.net.ssl.internal.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:1131) 在 net.www.protocol.https.HttpsClient.afterConnect(HttpsClient.java:434) 在 net.www.protocol.https.AbstractDelegateHttpsURLConnection.connect(AbstractDelegateHttpsURLConnection.java:166) 在 net.www.protocol.http.HttpURLConnection.getOutputStream(HttpURLConnection.java:904) 在 net.www.protocol.https.HttpsURLConnectionImpl.getOutputStream(HttpsURLConnectionImpl.java:230) 在 GetKeysTestCase.testGetAccessControlListKeys(GetKeysTestCase.java:90) 位于的sun.reflect.NativeMethodAccessorImpl.invoke0(本机方法) invoke(NativeMethodAccessorImpl.java:39) 在 reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) 位于java.lang.reflect.Method.invoke(Method.java:597) runTest(TestCase.java:168)位于 runBare(TestCase.java:134)位于 TestResult$1.protect(TestResult.java:110)位于 junit.framework.TestResult.runProtected(TestResult.java:128)位于 运行(TestResult.java:113) 运行(TestCase.java:124) runTest(TestSuite.java:243)位于 运行(TestSuite.java:238) org.junit.internal.runners.JUnit38ClassRunner.run(JUnit38ClassRunner.java:83) 在 org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50) 在 org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38) 在 org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467) 在 org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683) 在 org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390) 在 org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197) 原因:java.io.EOFException:SSL对等机在错误地关闭 com.sun.net.ssl.internal.ssl.InputRecord.read(InputRecord.java:333) 在 com.sun.net.ssl.internal.ssl.SSLSocketImpl.readRecord(SSLSocketImpl.java:789) ... 还有27个

有什么想法吗?

找到了

我只是按照里面的说明做的。 我所做的是使用浏览器(Chrome)下载站点证书(.cer),并通过运行以下命令将其导入默认密钥库:

#keytool -import -alias GSAAPI -file ./GSA.cer