Skip to content

Customize RestTemplateBuilder #22896

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Conversation

bedla
Copy link
Contributor

@bedla bedla commented Aug 11, 2020

Hi,
I found that it would be handy to customize RestTemplateBuilder created by auto-configuration. It has some useful method that sometimes I want to call. Currently I have to use bean post processor to customize it - I think that it is ugly and error prone.
What do you think about this proposal?
Thx
Ivos

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Aug 11, 2020
@bedla bedla force-pushed the feature/resttemplatebuildercustomizer branch 2 times, most recently from 49ec4c2 to bfe3bd2 Compare August 12, 2020 06:41
@bedla
Copy link
Contributor Author

bedla commented Aug 12, 2020

there is lots of java.io.IOException: No space left on device errors in build log. could somebody fix CI?

@bedla
Copy link
Contributor Author

bedla commented Aug 13, 2020

@wilkinsona sorry for disturbing but I found that you mentioned at comment #22885 (comment) that CI failures are general problem. Mine PR fails at No space left on device as mentioned above... is it same problem and will be fixed?

@philwebb
Copy link
Member

@bedla Sorry about the CI failures. We had some issues yesterday.

@philwebb philwebb added the for: team-attention An issue we'd like other members of the team to review label Aug 14, 2020
@philwebb
Copy link
Member

Flagging for team attention to see what the rest of the team think about the proposal. I'm a little concerned that the immutable nature of RestTemplateBuilder makes the Customizer slightly unusual. I think most of our existing ones have a void return and expect the customizable thing to be mutable.

Perhaps we need a different name for it. Another option might be have an optional RestTemplateBuilderFactory that's used to create the initial instance.

@bedla out of interest, which RestTemplateBuilder methods do you typically want to customize?

@bedla
Copy link
Contributor Author

bedla commented Aug 16, 2020

Yep, that name is bit unusal as you mentioned, but I cannot imagine something more suitable.

My usecase is that I wan to use all the stuff (otherwise I have to copy-paste it) from auto-configuration (see RestTemplateAutoConfiguration#restTemplateBuilder method) and mainly call methods setBufferRequestBody, setConnectTimeout and setReadTimeout (sometimes defaultHeader).

I am open to any suggestion.

@philwebb philwebb self-assigned this Aug 19, 2020
Allow customization of RestTemplateBuilder when created by RestTemplateAutoConfiguration.
@bedla bedla force-pushed the feature/resttemplatebuildercustomizer branch from bfe3bd2 to ae2c0b1 Compare August 20, 2020 18:24
@philwebb philwebb removed the for: team-attention An issue we'd like other members of the team to review label Aug 24, 2020
@snicoll snicoll self-assigned this Sep 9, 2020
snicoll added a commit to snicoll/spring-boot that referenced this pull request Sep 9, 2020
@snicoll
Copy link
Member

snicoll commented Sep 9, 2020

Thanks for the PR @bedla and the follow-up. I am personally not super keen on the idea of the customizer. We discussed this at our team meeting a couple of weeks ago and I mentioned a similar pattern we use to further tune message listener container factories.

I've pushed some code that mimics that pattern for RestTemplateBuilder, see snicoll@0d06a84

One downside with this approach is that we expose an additional bean for the purpose of customization. I wish we could provide a more efficient option. Anyway, foo for thoughts @philwebb

@snicoll snicoll added the for: team-attention An issue we'd like other members of the team to review label Sep 11, 2020
@bedla
Copy link
Contributor Author

bedla commented Sep 13, 2020

@snicoll no problem, I am happy to help. Anyways I have checked commit you mentioned and maybe I am missing something, but I am still unable to customize that builder, right?
Those setBufferRequestBody, setConnectTimeout and setReadTimeout (sometimes defaultHeader) are interesting for me.

@snicoll
Copy link
Member

snicoll commented Sep 13, 2020

This test showcases that exact use case unless I am missing something: snicoll@0d06a84#diff-cfe5e8d68c724e41762c869df2ddaec6R241

@bedla
Copy link
Contributor Author

bedla commented Sep 13, 2020

ahh, I see. Thx, Ivos

@philwebb philwebb added type: enhancement A general enhancement and removed for: team-attention An issue we'd like other members of the team to review status: waiting-for-triage An issue we've not yet triaged labels Sep 16, 2020
@philwebb philwebb added this to the 2.4.x milestone Sep 16, 2020
@snicoll
Copy link
Member

snicoll commented Sep 17, 2020

@bedla thank you for the suggestion and the PR. We've discussed that at our team meeting and we've decided to give my proposal a go. I am going to close this PR now, please follow-up on #23389

@snicoll snicoll closed this Sep 17, 2020
@snicoll snicoll added the status: declined A suggestion or change that we don't feel we should currently apply label Sep 17, 2020
@snicoll snicoll removed this from the 2.4.x milestone Sep 17, 2020
@snicoll snicoll added the status: superseded An issue that has been superseded by another label Sep 17, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: declined A suggestion or change that we don't feel we should currently apply status: superseded An issue that has been superseded by another type: enhancement A general enhancement
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants