Skip to content

[Java][okhttp-gson] Use builder api of OkHttpClient to avoid UnsupportedOperationEx#5177

Merged
wing328 merged 5 commits intoOpenAPITools:masterfrom
trohrberg:fix_issue_3432
Feb 13, 2020
Merged

[Java][okhttp-gson] Use builder api of OkHttpClient to avoid UnsupportedOperationEx#5177
wing328 merged 5 commits intoOpenAPITools:masterfrom
trohrberg:fix_issue_3432

Conversation

@trohrberg
Copy link
Copy Markdown
Contributor

Fix Issue #3432

Changed the template for generating the ApiClient.java class for Java with okhttp-gson library so that the GzipRequestInterceptor and the RetryingOauth interceptors are added to the OkHttpClient builder before building it. This avoids modifying the immutable list of interceptors which caused the UnsupportedOperationException before.

@bbdouglas (2017/07) @sreeshas (2017/08) @jfiala (2017/08) @lukoyanov (2017/09) @cbornet (2017/09) @jeff9finger (2018/01) @karismann (2019/03) @Zomzog (2019/04) @lwlee2608 (2019/10) @bkabrda (2020/01)

PR checklist

  • Read the contribution guidelines.
  • If contributing template-only or documentation-only changes which will change sample output, build the project before.
  • Run the shell script(s) under ./bin/ (or Windows batch scripts under.\bin\windows) to update Petstore samples related to your fix. This is important, as CI jobs will verify all generator outputs of your HEAD commit, and these must match the expectations made by your contribution. You only need to run ./bin/{LANG}-petstore.sh, ./bin/openapi3/{LANG}-petstore.sh if updating the code or mustache templates for a language ({LANG}) (e.g. php, ruby, python, etc).
  • File the PR against the correct branch: master, 4.3.x, 5.0.x. Default: master.
  • Copy the technical committee to review the pull request if your PR is targeting a particular programming language.

Timo Rohrberg added 5 commits January 31, 2020 10:21
The reason for the UnsupportedOperationException was an invalid access to the interceptors list of OkHttpClient. That list is unmodifiable as stated by the JavaDoc. Instead accessing the list directly, the interceptors should always be passed when building the client by the builder api.
The reason for the UnsupportedOperationException was an invalid access to the interceptors list of OkHttpClient. That list is unmodifiable as stated by the JavaDoc. Instead accessing the list directly, the interceptors should always be passed when building the client by the builder api.
@trohrberg trohrberg requested a review from wing328 February 2, 2020 18:57
@wing328
Copy link
Copy Markdown
Member

wing328 commented Feb 6, 2020

Thanks for the PR but your commit (as shown in the Commits tab) is not linked to your Github account, which means this PR won't count as your contribution in https://github.com/OpenAPITools/openapi-generator/graphs/contributors.

Let me know if you need help fixing it.

Ref: https://github.com/OpenAPITools/openapi-generator/wiki/FAQ#how-can-i-update-commits-that-are-not-linked-to-my-github-account

// Enable gzip request compression
httpClient.interceptors().add(new GzipRequestInterceptor());
// Enable gzip request compression
builder.addInterceptor(new GzipRequestInterceptor());
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@trohrberg seems like these 2 lines are not indented correctly. I'll file a separate PR to update it after merging this one.

@wing328 wing328 changed the title 3432 Use builder api of OkHttpClient to avoid UnsupportedOperationEx [Java][okhttp-gson] Use builder api of OkHttpClient to avoid UnsupportedOperationEx Feb 13, 2020
@wing328
Copy link
Copy Markdown
Member

wing328 commented Feb 13, 2020

Let's go with your proposed fix. Thanks for the PR.

@wing328 wing328 merged commit f526585 into OpenAPITools:master Feb 13, 2020
MikailBag pushed a commit to MikailBag/openapi-generator that referenced this pull request Mar 23, 2020
…tedOperationEx (OpenAPITools#5177)

* 3432 Use builder api of OkHttpClient to avoid UnsupportedOperationEx

The reason for the UnsupportedOperationException was an invalid access to the interceptors list of OkHttpClient. That list is unmodifiable as stated by the JavaDoc. Instead accessing the list directly, the interceptors should always be passed when building the client by the builder api.

* 3432 Use builder api of OkHttpClient to avoid UnsupportedOperationEx

The reason for the UnsupportedOperationException was an invalid access to the interceptors list of OkHttpClient. That list is unmodifiable as stated by the JavaDoc. Instead accessing the list directly, the interceptors should always be passed when building the client by the builder api.

* 3432 Follow-up fix to make samples compile again

* 3432 Updated sample implementation for okHttp-Gson-ParcelableModel
@wing328
Copy link
Copy Markdown
Member

wing328 commented Mar 27, 2020

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants