[Java][okhttp-gson] Fix incorrect use of OkHttp interceptors #8053
[Java][okhttp-gson] Fix incorrect use of OkHttp interceptors #8053ngaya-ll wants to merge 6 commits intoswagger-api:masterfrom
Conversation
| result.put("pet", pet); | ||
| } | ||
| @Test | ||
| public void testCreateAndGetMultiplePetsAsync() throws Exception { |
There was a problem hiding this comment.
This is the new test mentioned in the description. I also modified the preceding async test.
| } | ||
|
|
||
| @Test | ||
| @Ignore |
There was a problem hiding this comment.
This endpoint is deprecated on petstore.swagger.io and was returning a 500 status.
| */ | ||
| public ApiClient setHttpClient(OkHttpClient httpClient) { | ||
| this.httpClient = httpClient; | ||
| addProgressInterceptor(); |
There was a problem hiding this comment.
Note that if multiple ApiClients are created with the same underlying OkHttpClient this will create duplicate progress updates for each request. However, from reading the rest of the class (e.g. the setDebugging() method) I concluded that this is not a supported use case.
|
@bbdouglas @JFCote @sreeshas @jfiala @lukoyanov @cbornet @jeff9finger Any update on this? This fixes a critical bug for users making async calls using okhttp-gson generated clients. |
|
It would be lovely to have this merged to fix #7876 as the current state renders it impossible to use any of the generated "async" methods in any sort of long-lived production server. |
+1 |
PR checklist
./bin/to update Petstore sample so that CIs can verify the change. (For instance, only need to run./bin/{LANG}-petstore.shand./bin/security/{LANG}-petstore.shif updating the {LANG} (e.g. php, ruby, python, etc) code generator or {LANG} client's mustache templates). Windows batch files can be found in.\bin\windows\.3.0.0branch for changes related to OpenAPI spec 3.0. Default:master.Description of the PR
Currently, the generated Java okhttp-gson client adds an interceptor to the underlying
OkHttpClientfor each async call. The purpose of the interceptor is to wrap the response body to track download progress. This implementation doesn't work correctly, for multiple reasons:StackOverflowError.With this code change, the client uses a single interceptor to decorate all async requests and send updates to the relevant listener only.
I also added a test case to demonstrate the issue, which fails on the current master and passes on this branch.
Fixes #7876, #8915