com.gitee.maskit.web.ExceptionResolver Maven / Gradle / Ivy
package com.gitee.maskit.web;
import com.gitee.maskit.utils.Response;
import com.gitee.maskit.utils.ResponseAdapter;
import com.google.common.cache.CacheBuilder;
import com.google.common.cache.CacheLoader;
import com.google.common.cache.LoadingCache;
import org.springframework.context.MessageSource;
import org.springframework.core.Ordered;
import org.springframework.core.annotation.Order;
import org.springframework.http.MediaType;
import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter;
import org.springframework.http.server.ServletServerHttpResponse;
import org.springframework.web.method.HandlerMethod;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.method.annotation.ExceptionHandlerExceptionResolver;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.*;
import java.util.concurrent.TimeUnit;
/**
* @author z0228
*/
@Order(Ordered.HIGHEST_PRECEDENCE)
public class ExceptionResolver extends ExceptionHandlerExceptionResolver {
private static final ModelAndView HANDLED = new ModelAndView();
private static final LoadingCache> STATUS =
CacheBuilder.newBuilder().expireAfterWrite(3, TimeUnit.MINUTES)
.build(new CacheLoader>() {
@Override
public Map load(MaskitWebProperties properties) throws Exception {
final Map statuses = new HashMap<>();
if (null != properties.getException().getStatuses()) {
properties.getException().getStatuses().forEach((status, classes) -> {
if (null != classes) {
classes.forEach(c -> statuses.put(c, status));
}
});
}
return statuses;
}
});
private static final LoadingCache> IGNORE_CAUSE =
CacheBuilder.newBuilder().expireAfterWrite(3, TimeUnit.MINUTES)
.build(new CacheLoader>() {
@Override
public Set load(MaskitWebProperties properties) throws Exception {
if (null != properties.getException().getIgnoreCauses()) {
return new HashSet<>(properties.getException().getIgnoreCauses());
} else {
return Collections.emptySet();
}
}
});
private static final Map BUILDERS = new HashMap<>();
private final boolean forceHandle;
private final ResponseAdapter
© 2015 - 2025 Weber Informatics LLC | Privacy Policy