org.springframework.social.partnercenter.http.client.RestResource Maven / Gradle / Ivy
package org.springframework.social.partnercenter.http.client;
import static java.util.Collections.singletonList;
import java.net.URI;
import java.util.Map;
import org.springframework.core.ParameterizedTypeReference;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpMethod;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.web.client.RestTemplate;
public class RestResource {
private RestTemplate restTemplate;
private String resourceBaseUri;
public HttpRequestBuilder request(){
return new HttpRequestBuilder(this, this.resourceBaseUri);
}
public HttpRequestBuilder request(String msRequestId, String msCorrelationId){
return new HttpRequestBuilder(this, this.resourceBaseUri, msRequestId, msCorrelationId);
}
public HttpRequestBuilder request(MediaType mediaType){
return new HttpRequestBuilder(this, this.resourceBaseUri).header(HttpHeaders.CONTENT_TYPE, singletonList(mediaType.toString()));
}
RestTemplate getRestTemplate() {
return restTemplate;
}
public RestResource(RestTemplate restTemplate, String resourceBaseUri) {
this.restTemplate = restTemplate;
this.resourceBaseUri = resourceBaseUri;
}
ResponseEntity get(URI url, ParameterizedTypeReference responseType) {
return execute(url, HttpMethod.GET, null, responseType);
}
ResponseEntity get(URI url, ParameterizedTypeReference responseType, HttpHeaders headers) {
return execute(url, HttpMethod.GET, new HttpEntity<>(headers), responseType);
}
ResponseEntity get(URI url, Class responseType) {
return execute(url, HttpMethod.GET, null, responseType);
}
ResponseEntity get(URI url, Class responseType, HttpHeaders header) {
return execute(url, HttpMethod.GET, new HttpEntity<>(header), responseType);
}
ResponseEntity post(URI url, ParameterizedTypeReference responseType) {
return execute(url, HttpMethod.POST, HttpEntity.EMPTY, responseType);
}
ResponseEntity post(URI url, ParameterizedTypeReference responseType, HttpHeaders headers) {
return execute(url, HttpMethod.POST, new HttpEntity
© 2015 - 2025 Weber Informatics LLC | Privacy Policy