I'm having a problem using truststore/keystore in java. My code goes like this. I have tried also all the suggestion I searched here Error - trustAnchors parameter must be non-empty , the cacerts exists in the specified path, I have permission to cacerts and it's also not expired but there still appears to have an error.
URL obj = null;
try {
obj = new URL(url);
} catch (MalformedURLException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
return InternalError();
}
System.setProperty("javax.net.ssl.trustStore", "path/to/trustStore");
System.setProperty("javax.net.ssl.trustStorePassword","changeit");
HttpsURLConnection conn = null;
try {
conn = (HttpsURLConnection) obj.openConnection();
conn.setDoOutput(true);
conn.setDoInput(true);
conn.setRequestProperty("Content-Type", "application/json");
conn.setRequestProperty("X-Gateway-Auth", "gatewayAuth");
conn.setRequestMethod("POST");
} catch (IOException e3) {
// TODO Auto-generated catch block
e3.printStackTrace();
return InternalError();
}
String data = "{\"mobile_number\":" +mobileNumber+ ",\"pin\":" +pin+ "}";
OutputStreamWriter out = null;
try {
out = new OutputStreamWriter(conn.getOutputStream());
out.write(data);
out.flush();
} catch (IOException e2) {
// TODO Auto-generated catch block
e2.printStackTrace();
return InternalError();
}
I always get the "the trustAnchors parameter must be non-empty" error specifically on line out = new OutputStreamWriter(conn.getOutputStream());
javax.net.ssl.SSLException: java.lang.RuntimeException: Unexpected error: java.security.InvalidAlgorithmParameterException: the trustAnchors parameter must be non-empty