I have to include google recaptcha in my development(Spring app). I had the google key and secret key for validation and everything was working fine.
Now I am moving the recaptcha validation piece over to another rest services based app, so I can use rest services to leverage/change any keys or url and so on. The setup is I have the rest services app in server1(deployed in weblogic, but added the JAVA_OPTS parameter to use sun libraries) and tomcat with my app on server 2. So when I deploy this and access I get the error when validating the response
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
I have all the keys synced between server1 and server2 keystores, but still I see the error.
My piece of code where the error is below:
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);
Am I missing anything here? Thanks.
Note: I can access https://www.google.com/recaptcha/api/siteverify URL via browser.