swagger-api / swagger-codegen

swagger-codegen contains a template-driven engine to generate documentation, API clients and server stubs in different languages by parsing your OpenAPI / Swagger definition.
http://swagger.io
Apache License 2.0
16.9k stars 6.03k forks source link

SSL Handshake failure with old version of OkHttp on Latest IBM Liberty Build Pack #6413

Open YathendraPrasad opened 7 years ago

YathendraPrasad commented 7 years ago
Description

With Existing OkHttp Version (2.7.5) , SSL is failing in the IBM Latest Liberty Build Pack .

Swagger-codegen version

2.2.2

Related issues/PRs

https://github.com/watson-developer-cloud/java-sdk/issues/610

Suggest a fix/enhancement

Upgrading to latest version of OkHttp it OkHttp3 (3.7.1) will fix the issue . The changes should be done in the Java Client -> pom.mustache artifact

YathendraPrasad commented 7 years ago

How do i update okhttp version from 2.7.5 to OkHttp3 (3.7.1) .

YathendraPrasad commented 7 years ago

Let me know the quick fix or the workaround

wing328 commented 7 years ago

The pom.mustache for Java okhttp-gson can be found in https://github.com/swagger-api/swagger-codegen/blob/master/modules/swagger-codegen/src/main/resources/Java/libraries/okhttp-gson/pom.mustache

(I think the code also needs to be updated as well after upgrading to OkHttp3)

You can then use the customize template with the -t option.

Of course, we would appreciate if you can contribute back the upgrade to OkHttp3 lib for Java okhttp-gson generator.

YathendraPrasad commented 7 years ago

Thanks for the update wing. Currently we have added the below snippet code as workaround

com.ibm.mfp.adapters.sample.ApiClient apiAuthInstance = new com.ibm.mfp.adapters.sample.ApiClient();
OkHttpClient client =  apiAuthInstance.getHttpClient();
    client.setConnectionSpecs(Arrays.asList(new ConnectionSpec[]{new ConnectionSpec.Builder(ConnectionSpec.MODERN_TLS).allEnabledCipherSuites().build()}));

There exists some differences with respect to api`s in OkHttp and OkHttp3 , therefore code changes will be bit tricky for us atleast which might need thorough understanding.

It would be helpful if you could announce tentative release date for 2.3.0

wing328 commented 7 years ago

It would be helpful if you could announce tentative release date for 2.3.0

Sorry I can't commit a date as we've pending works for Scala and JS clients before we can release 2.3.0

wing328 commented 7 years ago

@YathendraPrasad what about using Java "retrofit2" API client instead?

retrofit2 has a dependency on com.squareup.okhttp3: https://mvnrepository.com/artifact/com.squareup.retrofit2/retrofit/2.1.0

jeanabraham commented 5 years ago

@YathendraPrasad @wing328 were there any resolutions to this issue? We are facing failure with SSL handshake as well on liberty. Thanks!

jeanabraham commented 5 years ago

This is root cause exception that happens for SSL calls only. Any help appreciated.

Caused by: java.io.EOFException
    at okio.RealBufferedSource.require(RealBufferedSource.java:64) ~[okio-1.6.0.jar:?]
    at okio.GzipSource.consumeHeader(GzipSource.java:114) ~[okio-1.6.0.jar:?]
    at okio.GzipSource.read(GzipSource.java:73) ~[okio-1.6.0.jar:?]
    at okio.Buffer.writeAll(Buffer.java:956) ~[okio-1.6.0.jar:?]
    at okio.RealBufferedSource.readByteArray(RealBufferedSource.java:92) ~[okio-1.6.0.jar:?]
    at com.squareup.okhttp.ResponseBody.bytes(ResponseBody.java:57) ~[okhttp-2.7.5.jar:?]
    at com.squareup.okhttp.ResponseBody.string(ResponseBody.java:83) ~[
okhttp-2.7.5.jar:?]
    at ca.acme.bizservice.client.xyzClient.invoker.ApiClient.handleResponse(ApiClient.java:920) ~[xyzClient-1.0-SNAPSHOT.jar:?]
    ... 108 more
wing328 commented 5 years ago

@jeanabraham thanks for tagging me but I'm no longer involved in this project. I hope others will be able to help you out. Good luck.