X-Git-Url: https://juplo.de/gitweb/?a=blobdiff_plain;f=src%2Fmain%2Fjava%2Fde%2Fjuplo%2Fthymeproxy%2FApplication.java;h=9311cf85e2004c8252f2a252ca470a8d72ff714e;hb=d5f095b05c68b3cf143138faf6a084298cf9de36;hp=03b106f600e695f69975d4f1a90c767a8cf516c5;hpb=91aa988e329618f6233b2b2f6394d4948622f4cc;p=maven-thymeleaf-skin diff --git a/src/main/java/de/juplo/thymeproxy/Application.java b/src/main/java/de/juplo/thymeproxy/Application.java index 03b106f..9311cf8 100644 --- a/src/main/java/de/juplo/thymeproxy/Application.java +++ b/src/main/java/de/juplo/thymeproxy/Application.java @@ -2,27 +2,35 @@ package de.juplo.thymeproxy; import de.juplo.thymeleaf.JuploDialect; import java.util.HashMap; -import java.util.Locale; import java.util.Map; +import java.util.Properties; import org.apache.http.impl.client.CloseableHttpClient; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.boot.autoconfigure.web.ErrorAttributes; +import org.springframework.boot.autoconfigure.web.ErrorController; +import org.springframework.boot.autoconfigure.web.ServerProperties; +import org.springframework.context.ApplicationContext; import org.springframework.context.annotation.Bean; import org.springframework.core.Ordered; import org.springframework.core.env.Environment; -import org.springframework.web.servlet.View; import org.springframework.web.servlet.config.annotation.ViewControllerRegistry; import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter; +import org.springframework.web.servlet.handler.SimpleMappingExceptionResolver; import org.springframework.web.servlet.mvc.UrlFilenameViewController; import org.thymeleaf.resourceresolver.IResourceResolver; import org.thymeleaf.resourceresolver.UrlResourceResolver; -import org.thymeleaf.spring4.view.ThymeleafViewResolver; import org.thymeleaf.templateresolver.TemplateResolver; @SpringBootApplication public class Application extends WebMvcConfigurerAdapter { + @Autowired + private ServerProperties properties; + + @Bean public RegexUrlHandlerMapping proxiedHandlerMapping( ProxyHttpRequestHandler proxy, @@ -32,7 +40,6 @@ public class Application extends WebMvcConfigurerAdapter RegexUrlHandlerMapping mapping = new RegexUrlHandlerMapping(); mapping.setOrder(Ordered.HIGHEST_PRECEDENCE); Map mappings = new HashMap<>(); - mappings.put("/thymeleaf/.*\\.html", proxy); mappings.put("/img/.+", proxy); mappings.put("/css/.+", proxy); mappings.put("/js/.+", proxy); @@ -106,9 +113,31 @@ public class Application extends WebMvcConfigurerAdapter } @Bean - public View error(ThymeleafViewResolver resolver) throws Exception + public SimpleMappingExceptionResolver simpleMappingExceptionResolver() + { + SimpleMappingExceptionResolver resolver = + new SimpleMappingExceptionResolver(); + + Properties mappings = new Properties(); + mappings.setProperty("TemplateInputException", "templates/404"); + + resolver.setExceptionMappings(mappings); + resolver.setDefaultErrorView("templates/500"); + resolver.setWarnLogCategory("exception"); + return resolver; + } + + @Bean + public ErrorController errorController( + ApplicationContext context, + ErrorAttributes errorAttributes + ) { - return resolver.resolveViewName("templates/500", Locale.getDefault()); + return new ExceptionResolverErrorController( + context, + errorAttributes, + properties.getError() + ); }