X-Git-Url: https://juplo.de/gitweb/?a=blobdiff_plain;f=src%2Fmain%2Fjava%2Fde%2Fjuplo%2Fthymeproxy%2FApplication.java;h=6b0ad09edf6a5a75287a01b99fbf94d57af86195;hb=47ba6f9913adb987a0fda0e25e101ae34297d725;hp=eb2ddbb4f55d1f130fe50dac960c3c8442ba3e3a;hpb=bdb1a080e3a4c02849ff5d0ce9e78ab376393afe;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 eb2ddbb..6b0ad09 100644 --- a/src/main/java/de/juplo/thymeproxy/Application.java +++ b/src/main/java/de/juplo/thymeproxy/Application.java @@ -3,31 +3,43 @@ package de.juplo.thymeproxy; import de.juplo.thymeleaf.JuploDialect; import java.util.HashMap; 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.mvc.UrlFilenameViewController; +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.thymeleaf.TemplateEngine; import org.thymeleaf.resourceresolver.IResourceResolver; import org.thymeleaf.resourceresolver.UrlResourceResolver; import org.thymeleaf.templateresolver.TemplateResolver; @SpringBootApplication -public class Application +public class Application extends WebMvcConfigurerAdapter { + @Autowired + private ServerProperties properties; + + @Bean public RegexUrlHandlerMapping proxiedHandlerMapping( ProxyHttpRequestHandler proxy, - UrlFilenameViewController views + UrlThymeleafViewController views ) { 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); @@ -51,9 +63,11 @@ public class Application } @Bean - public UrlFilenameViewController urlFilenameViewController() + public UrlThymeleafViewController urlThymeleafViewController( + TemplateEngine engine + ) { - return new UrlFilenameViewController(); + return new UrlThymeleafViewController(engine); } @Bean @@ -100,6 +114,41 @@ public class Application return new JuploDialect(); } + @Bean + 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 new ExceptionResolverErrorController( + context, + errorAttributes, + properties.getError() + ); + } + + + @Override + public void addViewControllers(ViewControllerRegistry registry) + { + registry.addViewController("/").setViewName("forward:index.html"); + } + public static void main(String[] args) {