question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

OkHTTP connection to PayPal gives an SSLHandshakeException

See original GitHub issue

I’m using Java 1.8 and

    <dependency>
        <groupId>com.squareup.okhttp</groupId>
        <artifactId>okhttp</artifactId>
        <version>2.7.5</version>
    </dependency>

To connect to Paypal via this code…

    String httpUrl = "https://api.sandbox.paypal.com/retail/merchant/v1/invoices/";
    String jsonContent = "{'test':'test'}";

    RequestBody requestBody = RequestBody.create(MediaType.parse("application/json; charset=utf-8"), jsonContent);
    Request request =  new Request.Builder().url(httpUrl).post(requestBody).build();
    Response response = new OkHttpClient().newCall(request).execute();

    System.out.println(response.body());

I get the error response of…

main, READ: TLSv1 Alert, length = 2 main, RECV TLSv1 ALERT: fatal, handshake_failure main, called closeSocket() main, handling exception: javax.net.ssl.SSLHandshakeException: Received fatal alert: handshake_failure main, called close() main, called closeInternal(true) Exception in thread “main” javax.net.ssl.SSLHandshakeException: Received fatal alert: handshake_failure at sun.security.ssl.Alerts.getSSLException(Alerts.java:192) at sun.security.ssl.Alerts.getSSLException(Alerts.java:154) at sun.security.ssl.SSLSocketImpl.recvAlert(SSLSocketImpl.java:1979) at sun.security.ssl.SSLSocketImpl.readRecord(SSLSocketImpl.java:1086) at sun.security.ssl.SSLSocketImpl.performInitialHandshake(SSLSocketImpl.java:1332) at sun.security.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:1359) at sun.security.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:1343) at com.squareup.okhttp.internal.io.RealConnection.connectTls(RealConnection.java:192)

Can anyone help me out please.

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:7

github_iconTop GitHub Comments

1reaction
hharsunencommented, Oct 31, 2016

try changing ConnectionSpec spec = new ConnectionSpec.Builder(ConnectionSpec.COMPATIBLE_TLS) to ConnectionSpec spec = new ConnectionSpec.Builder(ConnectionSpec.MODERN_TLS)

0reactions
jeffreyportercommented, Nov 1, 2016

(ConnectionSpec.MODERN_TLS) This works! THANK YOU!

Read more comments on GitHub >

github_iconTop Results From Across the Web

java - OkHTTP connection to PayPal gives an ...
I can see that it says 'Ignoring unavailable cipher suite: TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA', but I've listed that in the cipher suite. Can ...
Read more >
OkHTTP connection to PayPal gives an SSLHandshakeException
I'm using Java 1.8 and <dependency> <groupId>com.squareup.okhttp</groupId> <artifactId>okhttp</artifactId> <version>2.7.5</version> </dependency>.
Read more >
okHttp - javax.net.ssl.SSLProtocolException SHA-256
Hi all. Time ago i write time ago one library Paypal credit card, now seem that this library have a few problems with...
Read more >
How to Fix javax.net.ssl.SSLHandshakeException: sun. ...
The reason of this error is simple, certificates returned by the Server during SSL handshake are not signed by any trusted Certification Authority(CA)...
Read more >
[Solved]-spring3 annotation with main method-Java
Reliable web application GUI testing · OkHTTP connection to PayPal gives an SSLHandshakeException · Missing closing bracket · How to resume a thread ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found