Search in sources :

Example 1 with RestTemplateResponseErrorHandler

use of edu.hawaii.its.api.controller.RestTemplateResponseErrorHandler in project uhgroupings by uhawaii-system-its-ti-iam.

the class HttpRequestServiceImpl method makeApiRequest.

/*
     * Make an http request to the API with path variables.
     */
@SuppressWarnings("lgtm[java/xss]")
@Override
public ResponseEntity<String> makeApiRequest(String currentUser, String uri, HttpMethod method) {
    HttpHeaders httpHeaders = new HttpHeaders();
    httpHeaders.set(CURRENT_USER, currentUser);
    HttpEntity<String> httpEntity = new HttpEntity<>(httpHeaders);
    RestTemplate restTemplate = new RestTemplateBuilder().errorHandler(new RestTemplateResponseErrorHandler()).build();
    return restTemplate.exchange(uri, method, httpEntity, String.class);
}
Also used : HttpHeaders(org.springframework.http.HttpHeaders) RestTemplateBuilder(org.springframework.boot.web.client.RestTemplateBuilder) HttpEntity(org.springframework.http.HttpEntity) RestTemplateResponseErrorHandler(edu.hawaii.its.api.controller.RestTemplateResponseErrorHandler) RestTemplate(org.springframework.web.client.RestTemplate)

Example 2 with RestTemplateResponseErrorHandler

use of edu.hawaii.its.api.controller.RestTemplateResponseErrorHandler in project uhgroupings by uhawaii-system-its-ti-iam.

the class HttpRequestServiceImpl method makeApiRequestWithBody.

/*
     * Make an http request to the API with path variables and description in the body.
     */
@SuppressWarnings("lgtm[java/xss]")
@Override
public ResponseEntity<String> makeApiRequestWithBody(String currentUser, String uri, String data, HttpMethod method) {
    HttpHeaders httpHeaders = new HttpHeaders();
    httpHeaders.set(CURRENT_USER, currentUser);
    HttpEntity<String> httpEntity = new HttpEntity<>(data, httpHeaders);
    RestTemplate restTemplate = new RestTemplateBuilder().errorHandler(new RestTemplateResponseErrorHandler()).build();
    return restTemplate.exchange(uri, method, httpEntity, String.class);
}
Also used : HttpHeaders(org.springframework.http.HttpHeaders) RestTemplateBuilder(org.springframework.boot.web.client.RestTemplateBuilder) HttpEntity(org.springframework.http.HttpEntity) RestTemplateResponseErrorHandler(edu.hawaii.its.api.controller.RestTemplateResponseErrorHandler) RestTemplate(org.springframework.web.client.RestTemplate)

Aggregations

RestTemplateResponseErrorHandler (edu.hawaii.its.api.controller.RestTemplateResponseErrorHandler)2 RestTemplateBuilder (org.springframework.boot.web.client.RestTemplateBuilder)2 HttpEntity (org.springframework.http.HttpEntity)2 HttpHeaders (org.springframework.http.HttpHeaders)2 RestTemplate (org.springframework.web.client.RestTemplate)2