X-Git-Url: https://juplo.de/gitweb/?a=blobdiff_plain;f=src%2Fmain%2Fjava%2Fde%2Fjuplo%2Fthymeproxy%2FApplication.java;h=0840e957814c8b7ab12d6f126bb848e927187a2e;hb=551b78259633a9d1c42d8ed1c8e081ba5432fc06;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..0840e95 100644 --- a/src/main/java/de/juplo/thymeproxy/Application.java +++ b/src/main/java/de/juplo/thymeproxy/Application.java @@ -3,12 +3,24 @@ package de.juplo.thymeproxy; import de.juplo.thymeleaf.JuploDialect; import java.util.HashMap; import java.util.Map; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; 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.BasicErrorController; +import org.springframework.boot.autoconfigure.web.ErrorAttributes; +import org.springframework.boot.autoconfigure.web.ErrorController; +import org.springframework.boot.autoconfigure.web.ErrorProperties; +import org.springframework.boot.autoconfigure.web.ServerProperties; import org.springframework.context.annotation.Bean; import org.springframework.core.Ordered; import org.springframework.core.env.Environment; +import org.springframework.http.MediaType; +import org.springframework.web.servlet.ModelAndView; +import org.springframework.web.servlet.config.annotation.ViewControllerRegistry; +import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter; import org.springframework.web.servlet.mvc.UrlFilenameViewController; import org.thymeleaf.resourceresolver.IResourceResolver; import org.thymeleaf.resourceresolver.UrlResourceResolver; @@ -16,8 +28,12 @@ import org.thymeleaf.templateresolver.TemplateResolver; @SpringBootApplication -public class Application +public class Application extends WebMvcConfigurerAdapter { + @Autowired + private ServerProperties properties; + + @Bean public RegexUrlHandlerMapping proxiedHandlerMapping( ProxyHttpRequestHandler proxy, @@ -100,9 +116,47 @@ public class Application return new JuploDialect(); } + @Bean + public ErrorController errorController(ErrorAttributes errorAttributes) + { + return new CustomErrorController(errorAttributes, properties.getError()); + } + + + @Override + public void addViewControllers(ViewControllerRegistry registry) + { + registry.addViewController("/").setViewName("forward:index.html"); + } + public static void main(String[] args) { SpringApplication.run(Application.class, args); } + + + static class CustomErrorController extends BasicErrorController + { + CustomErrorController( + ErrorAttributes errorAttributes, + ErrorProperties errorProperties + ) + { + super(errorAttributes, errorProperties); + } + + + @Override + public ModelAndView errorHtml(HttpServletRequest request, HttpServletResponse response) + { + response.setStatus(getStatus(request).value()); + Map model = + getErrorAttributes( + request, + isIncludeStackTrace(request, MediaType.TEXT_HTML) + ); + return new ModelAndView("templates/error", model); + } + } } \ No newline at end of file