Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/373.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ssl/3.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
javax.net.ssl.SSLHandshakeException:sun.security.validator.ValidatorException:PKIX路径构建失败google recaptcha_Java_Ssl_Key_Recaptcha_Sslhandshakeexception - Fatal编程技术网

javax.net.ssl.SSLHandshakeException:sun.security.validator.ValidatorException:PKIX路径构建失败google recaptcha

javax.net.ssl.SSLHandshakeException:sun.security.validator.ValidatorException:PKIX路径构建失败google recaptcha,java,ssl,key,recaptcha,sslhandshakeexception,Java,Ssl,Key,Recaptcha,Sslhandshakeexception,我必须在我的开发(Spring应用程序)中包括google recaptcha。我有谷歌密钥和秘密密钥进行验证,一切正常 现在,我将recaptcha验证部分转移到另一个基于rest服务的应用程序上,这样我就可以使用rest服务来利用/更改任何键或url等等。设置是我在server1中有rest服务应用程序(部署在weblogic中,但添加了JAVA_OPTS参数以使用sun库),在Server2上有tomcat和我的应用程序。因此,当我部署这个并访问时,在验证响应时会出现错误 javax.ne

我必须在我的开发(Spring应用程序)中包括google recaptcha。我有谷歌密钥和秘密密钥进行验证,一切正常

现在,我将recaptcha验证部分转移到另一个基于rest服务的应用程序上,这样我就可以使用rest服务来利用/更改任何键或url等等。设置是我在server1中有rest服务应用程序(部署在weblogic中,但添加了JAVA_OPTS参数以使用sun库),在Server2上有tomcat和我的应用程序。因此,当我部署这个并访问时,在验证响应时会出现错误

javax.net.ssl.SSLHandshakeException: sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target
我已经在server1和server2密钥库之间同步了所有密钥,但仍然看到了错误

我的一段代码,错误如下:

public static final String url = "https://www.google.com/recaptcha/api/siteverify";
    public static final String secret = "";
    private final static String USER_AGENT = "";

    public static boolean verify(String gRecaptchaResponse) throws IOException {
        if (gRecaptchaResponse == null || "".equals(gRecaptchaResponse)) {
            return false;
        }

        try{
        URL obj = new URL(url);
        HttpsURLConnection con = (HttpsURLConnection) obj.openConnection();

        con.setRequestMethod("POST");
        String postParams = "secret=" + secret + "&response="
                + gRecaptchaResponse;
        con.setDoOutput(true);
        DataOutputStream wr = new DataOutputStream(con.getOutputStream()); --------------------------->**This is where the I get the exception**
        wr.writeBytes(postParams);
我有什么遗漏吗?谢谢


注意:我可以通过浏览器访问URL。

您确定您有正确的证书路径吗?当您移动recaptcha片段时,它应该构建在另一台具有不同证书路径的服务器(server1?)上。这个错误就是这样。检查(或添加)JAVA中的证书路径,选择在server1上构建。 此错误仅与无法在定义的路径中找到证书有关。检查路径或权限。 或者,您可以通过硬设置来设置证书路径:)用于运行应用程序服务器:

-Djavax.net.ssl.keyStore=path/to/keystore.jks
还是用Java

System.setProperty("javax.net.ssl.trustStore",path_to_your_cacerts_file);

我能解决这个问题。这个网站帮助了我

我必须在我的weblogic密钥库中添加google证书。默认情况下,它存在于cacerts中,但不存在于democrust.jks中


再次感谢赫拉博什。

谢谢。我在本地EclipseMaven中构建了这两个应用程序文件,并将它们部署在适当的服务器上。有没有办法找到它正在寻找的路径?默认证书存储cacerts位于两台服务器中的同一位置。除了他们提供的密钥外,我还需要添加任何与谷歌相关的密钥吗?我不记得在我的本地tomcat中添加了任何其他内容,直到现在。谢谢,问题还在。还有什么我可以看的吗?再次感谢。并尝试检查证书是否真的在您的密钥库中!抱歉,我没能试一下。我会尽力让你知道的。再次感谢。