Thibaud Lepretre opened SPR-15754 and commented

I would propose a new feature for RestTemplate that allow us to describe a kind of retry strategy regarding the HTTP response sent back by the targeted server.

This feature is very close to what Apache HTTP Client can offer with https://hc.apache.org/httpcomponents-client-ga/httpclient/apidocs/org/apache/http/client/ServiceUnavailableRetryStrategy.html

Use case can be apply to existing Oauth2RestTemplate https://github.com/spring-projects/spring-security-oauth/blob/master/spring-security-oauth2/src/main/java/org/springframework/security/oauth2/client/OAuth2RestTemplate.java#L140

Indeed Oauth2RestTemplate provides a way to retry request if access token is too old.

Flag to determine whether a request that has an existing access token, and which then leads to an AccessTokenRequiredException should be retried (immediately, once). Useful if the remote server doesn't recognize an old token which is stored in the client, but is happy to re-grant it.

I have similar needs since I'm developing a Spring security CAS starter from Spring boot https://github.com/kakawait/cas-security-spring-boot-starter and I would offer a pre-configured RestTemplate with that starter that allow client to execute request with a pre-filled proxy ticket (similar to access token in OAuth2 vocabulary).

In addition CAS proxy ticket unlike OAuth2 access token is one time use, so to do not call each time CAS server to get a proxy ticket you can define a stateful strategy (like http://docs.spring.io/spring-security/site/docs/current/reference/html/cas.html#cas-pt) but I can't determine how many time proxy ticket is valid. Only way is to try the request!

Thus I would be a great to get something to be able to retry RestTemplate request with new proxy ticket.

Today if I have to implement such thing I have only 1 solution: extends RestTemplate like Dave Syer did for Oauth2RestTemplate...


Affects: 4.3.9

1 votes, 1 watchers

Comment From: bclozel

RestTemplate is now in maintenance mode, so we won't be adding new features to it. Also, extending RestTemplate proved to be a brittle approach in the past.

Using spring-retry and a RetryTemplate works in most setups.