// 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.core.annotation.Order;
import org.springframework.http.converter.HttpMessageNotReadableException;
import org.springframework.security.access.AccessDeniedException;
import org.springframework.security.authentication.BadCredentialsException;
import org.springframework.security.web.util.matcher.AntPathRequestMatcher;
import org.springframework.stereotype.Component;
import org.springframework.web.HttpMediaTypeNotAcceptableException;
import org.springframework.web.HttpMediaTypeNotSupportedException;
import org.springframework.web.HttpRequestMethodNotSupportedException;
import org.springframework.web.bind.MissingServletRequestParameterException;
import org.springframework.web.bind.ServletRequestBindingException;
import org.springframework.web.client.RestOperations;
import org.springframework.web.filter.OncePerRequestFilter;
import org.springframework.web.method.annotation.MethodArgumentTypeMismatchException;
import org.springframework.web.multipart.support.MissingServletRequestPartException;
import org.springframework.web.servlet.NoHandlerFoundException;
import javax.servlet.FilterChain;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import static java.util.Arrays.asList;
import static java.util.Collections.singletonList;
import static org.springframework.boot.autoconfigure.security.SecurityProperties.DEFAULT_FILTER_ORDER;
import static org.springframework.http.HttpHeaders.ACCEPT;
import static org.springframework.http.HttpHeaders.CONTENT_TYPE;
import static org.springframework.http.MediaType.APPLICATION_JSON;
import static org.springframework.http.MediaType.APPLICATION_XML;
import static org.springframework.http.MediaType.TEXT_HTML;
import static org.springframework.http.MediaType.TEXT_PLAIN;
package com.github.mkopylec.errorest.application;




@Component
@Order(DEFAULT_FILTER_ORDER - 1)
public class ServletFilter extends OncePerRequestFilter {

// 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/ServletFilter.java
import com.github.mkopylec.errorest.client.ErrorestTemplate;
import org.springframework.core.annotation.Order;
import org.springframework.http.converter.HttpMessageNotReadableException;
import org.springframework.security.access.AccessDeniedException;
import org.springframework.security.authentication.BadCredentialsException;
import org.springframework.security.web.util.matcher.AntPathRequestMatcher;
import org.springframework.stereotype.Component;
import org.springframework.web.HttpMediaTypeNotAcceptableException;
import org.springframework.web.HttpMediaTypeNotSupportedException;
import org.springframework.web.HttpRequestMethodNotSupportedException;
import org.springframework.web.bind.MissingServletRequestParameterException;
import org.springframework.web.bind.ServletRequestBindingException;
import org.springframework.web.client.RestOperations;
import org.springframework.web.filter.OncePerRequestFilter;
import org.springframework.web.method.annotation.MethodArgumentTypeMismatchException;
import org.springframework.web.multipart.support.MissingServletRequestPartException;
import org.springframework.web.servlet.NoHandlerFoundException;
import javax.servlet.FilterChain;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import static java.util.Arrays.asList;
import static java.util.Collections.singletonList;
import static org.springframework.boot.autoconfigure.security.SecurityProperties.DEFAULT_FILTER_ORDER;
import static org.springframework.http.HttpHeaders.ACCEPT;
import static org.springframework.http.HttpHeaders.CONTENT_TYPE;
import static org.springframework.http.MediaType.APPLICATION_JSON;
import static org.springframework.http.MediaType.APPLICATION_XML;
import static org.springframework.http.MediaType.TEXT_HTML;
import static org.springframework.http.MediaType.TEXT_PLAIN;

package com.github.mkopylec.errorest.application;




@Component
@Order(DEFAULT_FILTER_ORDER - 1)
public class ServletFilter extends OncePerRequestFilter {

    private final RestOperations rest = new ErrorestTemplate();