带有SNI的OkHttp:Java 7上的连接重置

时间:2016-04-07 15:09:15

标签: java java-7 okhttp retrofit2 sni

只要在nginx服务器上只启用了一个tls证书,以下代码段就能正常运行。

OkHttpClient client = new OkHttpClient();
Request request = new Request.Builder()
    .url("ENDPOINT").build();
Response response = client.newCall(request).execute();
System.out.println(response.body().string());

激活具有不同证书的站点会导致nginx启用SNI。这显然打破了Oracle Java 7和OpenJDK 7。

Exception in thread "main" java.net.SocketException: Connection reset
    at java.net.SocketInputStream.read(SocketInputStream.java:196)
    at java.net.SocketInputStream.read(SocketInputStream.java:122)
    at sun.security.ssl.InputRecord.readFully(InputRecord.java:442)
    at sun.security.ssl.InputRecord.read(InputRecord.java:480)
    at sun.security.ssl.SSLSocketImpl.readRecord(SSLSocketImpl.java:934)
    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 okhttp3.internal.io.RealConnection.connectTls(RealConnection.java:195)
    at okhttp3.internal.io.RealConnection.connectSocket(RealConnection.java:148)
    at okhttp3.internal.io.RealConnection.connect(RealConnection.java:111)
    at okhttp3.internal.http.StreamAllocation.findConnection(StreamAllocation.java:188)
    at okhttp3.internal.http.StreamAllocation.findHealthyConnection(StreamAllocation.java:127)
    at okhttp3.internal.http.StreamAllocation.newStream(StreamAllocation.java:97)
    at okhttp3.internal.http.HttpEngine.connect(HttpEngine.java:289)
    at okhttp3.internal.http.HttpEngine.sendRequest(HttpEngine.java:241)
    at okhttp3.RealCall.getResponse(RealCall.java:240)
    at okhttp3.RealCall$ApplicationInterceptorChain.proceed(RealCall.java:198)
    at okhttp3.RealCall.getResponseWithInterceptorChain(RealCall.java:160)
    at okhttp3.RealCall.execute(RealCall.java:57)
    at Main.main(Main.java:20)

0 个答案:

没有答案