I have completed configuring SSL in my local Tomcat.
And the exception was thrown when I call getOutputStream()
public static InputStream send( String uri, Map<String, String> queryString,
Map<String, String> headers, String method, String reqBody) throws IOException
{
String body = (reqBody != null ? reqBody : "");
//URL myURL = new URL(addUrlParam(uri, queryString));
URL myURL = new URL(uri);
HttpURLConnection httpConn = (HttpURLConnection)myURL.openConnection();
httpConn.setRequestMethod(method);
httpConn.setRequestProperty("Content-Length", String.valueOf(body.toString().getBytes().length));
if ( headers != null ) {
for ( String key : headers.keySet() ) {
httpConn.setRequestProperty(key, headers.get(key));
}
}
httpConn.setDoInput(true);
//POST
if (!HTTP_GET.equals(method) || body.length() > 0) {
httpConn.setDoOutput(true);
httpConn.setUseCaches(false); //POST do not use user caches
***httpConn.getOutputStream().write(body.toString().getBytes());***
httpConn.getOutputStream().flush();
}
return httpConn.getInputStream();
}
How can I fix the issue?
Thanks in advance!!
Java requires a valid certification path to a known root CA. If you are trying to access a site with a self-signed certificate you will need to add the CA key for the self-signed cert to your keystore as a CA key. Assuming your CA certificate is in a file
cacert.pem, usekeytoolas follows: