I have a webservice client developed in Java 8. I've verified the host I'm connecting to is using TLSv1.2 via this site. https://www.ssllabs.com/ssltest/
I am getting the error below when sending executing the post request:
javax.net.ssl.SSLException: Received fatal alert: protocol_version
I have added this line at the start of my code. No luck.
System.setProperty("https.protocols", "TLSv1.2");
I have also added a JVM argument in my WebSphere server application.
-Dhttps.protocols=TLSv1.2
Still, the error is there.
I have read similar questions, and I think using Java 8 defaults to TLSv1.2. The error keeps coming up so I still added those properties. So I'm not sure why this is coming up.
Here's my code.
Loggers.general().debug(LOG, "### getOKTAToken()...");
String OKTAresponse = "";
OKTAResponse oktaReply = new OKTAResponse();
HttpClient httpClient = HttpClientBuilder.create().build();
Loggers.general().debug(LOG, "### ipsum");
//pass webservice URL
Loggers.general().debug(LOG, "URL:{}",Constants.URL);
HttpPost httpPost = new HttpPost(Constants.URL);
ArrayList<NameValuePair> postParameters;
//required keys for OKTA call
Loggers.general().debug(LOG, "Setting Body");
postParameters = new ArrayList<NameValuePair>();
postParameters.add(new BasicNameValuePair("client_id",
Constants.clientID));
postParameters.add(new BasicNameValuePair("client_secret",
Constants.clientSecret));
postParameters.add(new BasicNameValuePair("grant_type",
Constants.grantType));
try
{
Loggers.general().debug(LOG, "Setting entity...");
httpPost.setEntity(new UrlEncodedFormEntity(postParameters,"UTF-8"));
HttpResponse response = httpClient.execute(httpPost);
The error points to the last line. HttpResponse response = httpClient.execute(httpPost); Does anyone have an idea why this error keep coming up? Need reinforcements.
Environment:
- Java 8
- WebSphere 8.5.5
- Windows 10