org.springframework.social.partnercenter.http.client.RetryRestResource Maven / Gradle / Ivy
package org.springframework.social.partnercenter.http.client;
import java.net.URI;
import org.springframework.core.ParameterizedTypeReference;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpMethod;
import org.springframework.http.ResponseEntity;
import org.springframework.social.partnercenter.http.client.retry.RetryService;
import org.springframework.web.client.RestTemplate;
public class RetryRestResource extends RestResource {
private final RetryService retryService;
public RetryRestResource(RestTemplate restTemplate, String resourceBaseUri, RetryService retryService) {
super(restTemplate, resourceBaseUri);
this.retryService = retryService;
}
@Override
public ResponseEntity execute(URI uri, HttpMethod httpMethod, HttpEntity entity, Class responseType) {
return retryService.doWithRetry(() -> {
System.out.println("retry");
return getRestTemplate().exchange(
uri,
httpMethod,
entity,
responseType
);
}
);
}
@Override
public ResponseEntity execute(URI uri, HttpMethod httpMethod, HttpEntity entity, ParameterizedTypeReference responseType) {
return retryService.doWithRetry(() -> {
System.out.println("retry");
return getRestTemplate().exchange(
uri,
httpMethod,
entity,
responseType
);
}
);
}
@Override
public ResponseEntity delete(URI uri, HttpHeaders headers) {
return retryService.doWithRetry(() -> getRestTemplate().exchange(uri, HttpMethod.DELETE, new HttpEntity<>(headers), String.class));
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy