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.web.client.RestTemplate;
public class RestResource {
private RestTemplate restTemplate;
private String resourceBaseUri;
public HttpRequestBuilder request(){
return new HttpRequestBuilder(this, this.resourceBaseUri);
}
public HttpRequestBuilder request(MediaType mediaType){
return new HttpRequestBuilder(this, this.resourceBaseUri).header(HttpHeaders.CONTENT_TYPE, singletonList(mediaType.toString()));
}
protected RestTemplate getRestTemplate() {
return restTemplate;
}
public RestResource(RestTemplate restTemplate, String resourceBaseUri) {
this.restTemplate = restTemplate;
this.resourceBaseUri = resourceBaseUri;
}
public T get(URI url, ParameterizedTypeReference responseType) {
return execute(url, HttpMethod.GET, null, responseType);
}
public T get(URI url, Class responseType) {
return execute(url, HttpMethod.GET, null, responseType);
}
private T get(URI url, Class responseType, Map header) {
return execute(url, HttpMethod.GET, new HttpEntity<>(header), responseType);
}
public T post(URI url, ParameterizedTypeReference responseType) {
return execute(url, HttpMethod.POST, HttpEntity.EMPTY, responseType);
}
public T post(URI url, ParameterizedTypeReference responseType, Map headers) {
return execute(url, HttpMethod.POST, new HttpEntity
© 2015 - 2025 Weber Informatics LLC | Privacy Policy