I'm using the following setup InteliiJ + java 8 + Webservice + OkHTTP(3.12.12) + Glassfish (4.1.1)to call a REST Api but facing some issue when connecting to it
java.net.UnknownServiceException: Unable to find acceptable protocols. isFallback=false, modes=[ConnectionSpec(cipherSuites=[TLS_AES_128_GCM_SHA256, TLS_AES_256_GCM_SHA384, TLS_CHACHA20_POLY1305_SHA256, TLS_AES_128_CCM_SHA256, TLS_AES_256_CCM_8_SHA256, TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256, TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256, TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384, TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384, TLS_ECDHE_ECDSA_WITH_CHACHA20_POLY1305_SHA256, TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256, TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA, TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA, TLS_RSA_WITH_AES_128_GCM_SHA256, TLS_RSA_WITH_AES_256_GCM_SHA384, TLS_RSA_WITH_AES_128_CBC_SHA, TLS_RSA_WITH_AES_256_CBC_SHA, SSL_RSA_WITH_3DES_EDE_CBC_SHA], tlsVersions=[TLS_1_3, TLS_1_2, TLS_1_1, TLS_1_0], supportsTlsExtensions=true), ConnectionSpec()], supported protocols=[TLSv1.2, TLSv1.1, TLSv1]
My suspect for this would be the TLS version issue i.e. I'm calling via OkHTTP with a lower TLS.But JDK 8 is using TLS 1.2 by default. I've also set the TLS to be set at TLS 1.2 on code still no result.Now I'm wondering what other setting would cause this issue.I'm sorry this is my first time building a webservice using java.If there's other setting that I need to do please let me know.
My code below
ConnectionSpec requireTLS12 = new ConnectionSpec.Builder(ConnectionSpec.MODERN_TLS)
.tlsVersions(TlsVersion.TLS_1_2)
.build();
OkHttpClient client = new OkHttpClient.Builder()
.connectionSpecs(Arrays.asList(requireTLS12))
.build();
Request request = new Request.Builder()
.url("https://restcountries-v1.p.rapidapi.com/all")
.get()
.addHeader("x-rapidapi-host", "restcountries-v1.p.rapidapi.com")
.addHeader("x-rapidapi-key", "key_key_key")
.build();
try (Response response = client.newCall(request).execute()) {
ResponseLah = response.body().string();
// ... do something with response
return ResponseLah;
} catch (IOException e) {
e.printStackTrace();
}