Skip to content

Conversation

@nosan
Copy link
Contributor

@nosan nosan commented Jun 4, 2018

this PR provides new methods setConnectTimeout(Duration) and setReadTimeout(Duration) for RestTemplateBuilder .

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Jun 4, 2018
@nosan
Copy link
Contributor Author

nosan commented Jun 4, 2018

	if (!CollectionUtils.isEmpty(this.restTemplateCustomizers)) {
			for (RestTemplateCustomizer customizer : this.restTemplateCustomizers) {
				customizer.customize(restTemplate);
			}
		}
		restTemplate.getInterceptors().addAll(this.interceptors);

Maybe Customizers should be moved in the end of the method in 2.1.0?

@snicoll
Copy link
Member

snicoll commented Jun 4, 2018

@nosan please do not use this issue to discuss something totally unrelated. We're on gitter if you want to chat. Or you can create another issue.

@nosan
Copy link
Contributor Author

nosan commented Jun 4, 2018

@snicoll Got it, sorry about that.

Copy link
Member

@snicoll snicoll left a comment

Choose a reason for hiding this comment

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

Thanks for the PR. I've made a few comments and welcome your thoughts on it.

I really prefer a dedicated PR to focus on the task at hand. We also welcome "polish" PR that improve code structure, fix typo, etc.


private final String rootUri;

private final Duration readTimeout;
Copy link
Member

Choose a reason for hiding this comment

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

That's not what I have in mind, please keep your change to a minimum. I expect two new methods passing a Duration to the existing customizers with the deprecated methods delegating to them.

* {@link ClientHttpRequestFactory}.
* @param connectTimeout the connect timeout in milliseconds
* @return a new builder instance.
* @deprecated Deprecated in favor of {@link #setConnectTimeout(Duration)}
Copy link
Member

Choose a reason for hiding this comment

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

The format we use is @deprecated since 2.1.0 in favour of {@link #setConnectTimeout(Duration)}.

}

/**
* Sets the connection timeout on the underlying {@link ClientHttpRequestFactory}.
Copy link
Member

Choose a reason for hiding this comment

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

I'd put the method taking Duration above the deprecated one, not below.

public class HttpWebServiceMessageSenderBuilder {

private Integer connectionTimeout;
private Duration connectTimeout;
Copy link
Member

Choose a reason for hiding this comment

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

Good catch. I've polished the wrong name in 93396ae please rebase and push force an update.


@Test
@SuppressWarnings("deprecation")
public void nullReadTimeoutShouldNotAppliedIgnorePreviousSettings() {
Copy link
Member

Choose a reason for hiding this comment

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

Those two tests are new right? You could do the same with one that takes a Duration and one that takes null afteR. No need for the deprecation. Besides, I'd appreciate a separate PR for this as they are unrelated.

@snicoll snicoll added the status: waiting-for-feedback We need additional information before we can continue label Jun 4, 2018
@nosan
Copy link
Contributor Author

nosan commented Jun 5, 2018

@snicoll Thank you.
Adding only setReadTimeout(Duration) and setConnectTimeout(Duration) without changing RestTemplateBuilder is not a correct way.
Currently, RestTemplateBuilder uses Set<RestTemplateCustomizer> restTemplateCustomizers> for configuring these timeouts, so every time when a user is trying to set a new timeout, RestTemplateBuilder will add a new Customizer in the Set<RestTemplateCustomizer> restTemplateCustomizers> .
It works perfectly for the current implementation because RestTemplateBuilder has only setReadTimeout(int) and setConnectTimeout(int) and a user is not able to set null timeout.
With the new methods user is able to do this and in that case, it means a user doesn't want to set a timeout on the underlying, thus I've provided new fields for reach this purpose.

P.S. With the current implementation this test doesn't work.

	ClientHttpRequestFactory requestFactory = this.builder
				.requestFactory(SimpleClientHttpRequestFactory.class)
				.setConnectTimeout(Duration.ofSeconds(5))
				.setConnectTimeout(null).build()
				.getRequestFactory();
		assertThat(ReflectionTestUtils.getField(requestFactory, "connectTimeout"))
				.isEqualTo(-1);

@nosan
Copy link
Contributor Author

nosan commented Jun 5, 2018

@snicoll I've updated PR.
I've created a separate PR for HttpWebServiceMessageSenderBuilder. gh-13364

@nosan nosan force-pushed the duration-instead-of-timeout branch from 6bf173d to f1e38fc Compare June 5, 2018 09:53
@nosan nosan force-pushed the duration-instead-of-timeout branch from f1e38fc to a9b8404 Compare June 5, 2018 09:54
@nosan nosan changed the title Duration instead of 'int'. RestTemplateBuilder HttpWebServiceMessageSenderBuilder Duration instead of 'int'. RestTemplateBuilder Jun 5, 2018
@snicoll snicoll changed the title Duration instead of 'int'. RestTemplateBuilder Add duration support for setConnectTimeout and setReadTimeout Jun 5, 2018
@snicoll snicoll added type: enhancement A general enhancement and removed status: waiting-for-feedback We need additional information before we can continue status: waiting-for-triage An issue we've not yet triaged labels Jun 5, 2018
@snicoll snicoll self-assigned this Jun 5, 2018
@snicoll snicoll added this to the 2.1.0.M1 milestone Jun 5, 2018
@snicoll snicoll closed this in e9c3df4 Jun 5, 2018
snicoll added a commit that referenced this pull request Jun 5, 2018
* pr/13355:
  Polish "Add duration support for setConnectTimeout and setReadTimeout"
  Add duration support for setConnectTimeout and setReadTimeout
  Polish "Add duration support for setConnectTimout and setReadTimeout"
@snicoll
Copy link
Member

snicoll commented Jun 5, 2018

@nosan thanks for the PR. I found the changes in RestTemplateBuilder too invasive so I've pre-polished your PR, see 8691d01.

@nosan nosan deleted the duration-instead-of-timeout branch April 23, 2019 11:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

type: enhancement A general enhancement

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants