// Path: src/main/java/com/github/mkopylec/errorest/client/ErrorestTemplate.java
// public class ErrorestTemplate extends RestTemplate {
// 
//     protected ObjectMapper jsonMapper = json().build();
//     protected XmlMapper xmlMapper = xml().build();
// 
//     public ErrorestTemplate() {
//         super();
//     }
// 
//     public ErrorestTemplate(ClientHttpRequestFactory requestFactory) {
//         super(requestFactory);
//     }
// 
//     public ErrorestTemplate(List<HttpMessageConverter<?>> messageConverters) {
//         super(messageConverters);
//     }
// 
//     public void setJsonMapper(ObjectMapper jsonMapper) {
//         this.jsonMapper = jsonMapper;
//     }
// 
//     public void setXmlMapper(XmlMapper xmlMapper) {
//         this.xmlMapper = xmlMapper;
//     }
// 
//     @Override
//     protected <T> T doExecute(URI url, HttpMethod method, RequestCallback requestCallback, ResponseExtractor<T> responseExtractor) throws RestClientException {
//         try {
//             return super.doExecute(url, method, requestCallback, responseExtractor);
//         } catch (HttpStatusCodeException ex) {
//             throw createExternalHttpRequestException(method, url, ex);
//         }
//     }
// 
//     protected ExternalHttpRequestException createExternalHttpRequestException(HttpMethod method, URI url, HttpStatusCodeException ex) {
//         return new ExternalHttpRequestException(method, url.toString(), ex.getStatusCode(), ex.getStatusText(), ex.getResponseHeaders(), ex.getResponseBodyAsByteArray(), getCharset(ex), jsonMapper, xmlMapper);
//     }
// 
//     protected Charset getCharset(HttpStatusCodeException ex) {
//         MediaType contentType = ex.getResponseHeaders().getContentType();
//         return contentType != null ? contentType.getCharset() : null;
//     }
// }


import com.github.mkopylec.errorest.client.ErrorestTemplate;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RequestPart;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestOperations;
import javax.validation.Valid;
import java.util.Map;
import static org.springframework.http.MediaType.APPLICATION_JSON_VALUE;
import static org.springframework.http.MediaType.APPLICATION_XML_VALUE;
import static org.springframework.http.MediaType.TEXT_PLAIN_VALUE;
package com.github.mkopylec.errorest.application;




@RestController
@RequestMapping("/controller")
public class Controller {

// Path: src/main/java/com/github/mkopylec/errorest/client/ErrorestTemplate.java
// public class ErrorestTemplate extends RestTemplate {
// 
//     protected ObjectMapper jsonMapper = json().build();
//     protected XmlMapper xmlMapper = xml().build();
// 
//     public ErrorestTemplate() {
//         super();
//     }
// 
//     public ErrorestTemplate(ClientHttpRequestFactory requestFactory) {
//         super(requestFactory);
//     }
// 
//     public ErrorestTemplate(List<HttpMessageConverter<?>> messageConverters) {
//         super(messageConverters);
//     }
// 
//     public void setJsonMapper(ObjectMapper jsonMapper) {
//         this.jsonMapper = jsonMapper;
//     }
// 
//     public void setXmlMapper(XmlMapper xmlMapper) {
//         this.xmlMapper = xmlMapper;
//     }
// 
//     @Override
//     protected <T> T doExecute(URI url, HttpMethod method, RequestCallback requestCallback, ResponseExtractor<T> responseExtractor) throws RestClientException {
//         try {
//             return super.doExecute(url, method, requestCallback, responseExtractor);
//         } catch (HttpStatusCodeException ex) {
//             throw createExternalHttpRequestException(method, url, ex);
//         }
//     }
// 
//     protected ExternalHttpRequestException createExternalHttpRequestException(HttpMethod method, URI url, HttpStatusCodeException ex) {
//         return new ExternalHttpRequestException(method, url.toString(), ex.getStatusCode(), ex.getStatusText(), ex.getResponseHeaders(), ex.getResponseBodyAsByteArray(), getCharset(ex), jsonMapper, xmlMapper);
//     }
// 
//     protected Charset getCharset(HttpStatusCodeException ex) {
//         MediaType contentType = ex.getResponseHeaders().getContentType();
//         return contentType != null ? contentType.getCharset() : null;
//     }
// }


// Path: src/test/java/com/github/mkopylec/errorest/application/Controller.java
import com.github.mkopylec.errorest.client.ErrorestTemplate;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RequestPart;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestOperations;
import javax.validation.Valid;
import java.util.Map;
import static org.springframework.http.MediaType.APPLICATION_JSON_VALUE;
import static org.springframework.http.MediaType.APPLICATION_XML_VALUE;
import static org.springframework.http.MediaType.TEXT_PLAIN_VALUE;

package com.github.mkopylec.errorest.application;




@RestController
@RequestMapping("/controller")
public class Controller {

    private final RestOperations rest = new ErrorestTemplate();