From f41186aa11b4f4d4ada5310682aee7c75c252144 Mon Sep 17 00:00:00 2001 From: Kai Moritz Date: Thu, 16 Jun 2016 16:43:36 +0200 Subject: [PATCH] WIP: thymeproxy --- pom.xml | 3 +- .../java/de/juplo/thymeproxy/Application.java | 47 ++++++++++++++++--- src/main/resources/application.properties | 1 + 3 files changed, 43 insertions(+), 8 deletions(-) diff --git a/pom.xml b/pom.xml index 01ceb99..5d51982 100644 --- a/pom.xml +++ b/pom.xml @@ -25,9 +25,10 @@ ${project.name} - http://localhost:8080/ + http://localhost:8080 8888 300000 + true ERROR diff --git a/src/main/java/de/juplo/thymeproxy/Application.java b/src/main/java/de/juplo/thymeproxy/Application.java index 66557b9..dcc35f8 100644 --- a/src/main/java/de/juplo/thymeproxy/Application.java +++ b/src/main/java/de/juplo/thymeproxy/Application.java @@ -8,6 +8,10 @@ import org.springframework.boot.autoconfigure.SpringBootApplication; 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.thymeleaf.resourceresolver.IResourceResolver; +import org.thymeleaf.resourceresolver.UrlResourceResolver; +import org.thymeleaf.templateresolver.TemplateResolver; @SpringBootApplication @@ -15,23 +19,24 @@ public class Application { @Bean public RegexUrlHandlerMapping proxiedHandlerMapping( - ProxyHttpRequestHandler handler + ProxyHttpRequestHandler proxy, + UrlFilenameViewController views ) { RegexUrlHandlerMapping mapping = new RegexUrlHandlerMapping(); mapping.setOrder(Ordered.HIGHEST_PRECEDENCE); Map mappings = new HashMap<>(); - mappings.put(".*\\.html$", handler); - mappings.put("/css/.+", handler); - mappings.put("/js/.+", handler); - mappings.put("/fonts/.+", handler); - mappings.put("/.+/", handler); + mappings.put("/thymeleaf/.*\\.html", proxy); + mappings.put("/css/.+", proxy); + mappings.put("/js/.+", proxy); + mappings.put("/fonts/.+", proxy); + mappings.put(".*\\.html", views); mapping.setUrlMap(mappings); return mapping; } @Bean - public ProxyHttpRequestHandler proxiedRequestHandler( + public ProxyHttpRequestHandler proxyHttpRequestHandler( CloseableHttpClient client, Environment env ) @@ -43,6 +48,34 @@ public class Application return handler; } + @Bean + public UrlFilenameViewController urlFilenameViewController() + { + return new UrlFilenameViewController(); + } + + @Bean + public TemplateResolver defaultTemplateResolver( + IResourceResolver resources, + Environment env + ) + { + TemplateResolver resolver = new TemplateResolver(); + resolver.setResourceResolver(resources); + resolver.setPrefix("//thymeleaf/"); + resolver.setSuffix(".html"); + resolver.setTemplateMode("HTML5"); + resolver.setCharacterEncoding("UTF-8"); + resolver.setCacheable(Boolean.valueOf(env.getProperty("thymeproxy.cacheable"))); + return resolver; + } + + @Bean + public UrlResourceResolver thymeleafResourceResolver() + { + return new UrlResourceResolver(); + } + public static void main(String[] args) { diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties index 0a4144f..c0d3372 100644 --- a/src/main/resources/application.properties +++ b/src/main/resources/application.properties @@ -3,6 +3,7 @@ thymeproxy.origin=@thymeproxy.origin@ server.port=@thymeproxy.port@ thymeproxy.ttl=@thymeproxy.ttl@ thymeproxy.origins[0].uri=http://localhost:8080/thymeleaf/ +thymeproxy.cacheable=@thymeproxy.cacheable@ logging.level.de.juplo=info logging.level.org.apache.http=@httpclient.logging.level@ -- 2.20.1