From f70d85cd5fcd8db17859b0b8479da32d16dd2bd8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Ferna=CC=81ndez?= Date: Wed, 4 Oct 2017 01:48:32 +0200 Subject: [PATCH 1/3] Added configuration parameters at ThymeleafProperties for "fullModeViewNames" and "chunkedModeViewNames" --- .../thymeleaf/ThymeleafAutoConfiguration.java | 2 ++ .../thymeleaf/ThymeleafProperties.java | 29 +++++++++++++++++++ ...ymeleafReactiveAutoConfigurationTests.java | 16 ++++++++++ 3 files changed, 47 insertions(+) diff --git a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/thymeleaf/ThymeleafAutoConfiguration.java b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/thymeleaf/ThymeleafAutoConfiguration.java index 39e72f6fec5f..82fc1f653856 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/thymeleaf/ThymeleafAutoConfiguration.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/thymeleaf/ThymeleafAutoConfiguration.java @@ -264,6 +264,8 @@ public ThymeleafReactiveViewResolver thymeleafViewResolver( resolver.setResponseMaxChunkSizeBytes( this.properties.getReactive().getMaxChunkSize()); } + resolver.setFullModeViewNames(this.properties.getReactive().getFullModeViewNames()); + resolver.setChunkedModeViewNames(this.properties.getReactive().getChunkedModeViewNames()); // This resolver acts as a fallback resolver (e.g. like a // InternalResourceViewResolver) so it needs to have low precedence resolver.setOrder(Ordered.LOWEST_PRECEDENCE - 5); diff --git a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/thymeleaf/ThymeleafProperties.java b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/thymeleaf/ThymeleafProperties.java index e403f505b6a9..727dc098c289 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/thymeleaf/ThymeleafProperties.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/thymeleaf/ThymeleafProperties.java @@ -227,6 +227,19 @@ public static class Reactive { */ private List mediaTypes; + /** + * Comma-separated list of view names (patterns allowed) that should be executed in FULL mode + * even if a max chunk size is set. + */ + private String[] fullModeViewNames; + + /** + * Comma-separated list of view names (patterns allowed) that should be the only ones executed + * in CHUNKED mode when a max chunk size is set. + */ + private String[] chunkedModeViewNames; + + public List getMediaTypes() { return this.mediaTypes; } @@ -243,6 +256,22 @@ public void setMaxChunkSize(int maxChunkSize) { this.maxChunkSize = maxChunkSize; } + public String[] getFullModeViewNames() { + return this.fullModeViewNames; + } + + public void setFullModeViewNames(String[] fullModeViewNames) { + this.fullModeViewNames = fullModeViewNames; + } + + public String[] getChunkedModeViewNames() { + return this.chunkedModeViewNames; + } + + public void setChunkedModeViewNames(String[] chunkedModeViewNames) { + this.chunkedModeViewNames = chunkedModeViewNames; + } + } } diff --git a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/thymeleaf/ThymeleafReactiveAutoConfigurationTests.java b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/thymeleaf/ThymeleafReactiveAutoConfigurationTests.java index 7ebe9d4dcd0a..c2b5fe75f4e2 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/thymeleaf/ThymeleafReactiveAutoConfigurationTests.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/thymeleaf/ThymeleafReactiveAutoConfigurationTests.java @@ -112,6 +112,22 @@ public void overrideViewNames() throws Exception { assertThat(views.getViewNames()).isEqualTo(new String[] { "foo", "bar" }); } + @Test + public void overrideFullModeViewNames() throws Exception { + load(BaseConfiguration.class, "spring.thymeleaf.reactive.fullModeViewNames:foo,bar"); + ThymeleafReactiveViewResolver views = this.context + .getBean(ThymeleafReactiveViewResolver.class); + assertThat(views.getFullModeViewNames()).isEqualTo(new String[] { "foo", "bar" }); + } + + @Test + public void overrideChunkedModeViewNames() throws Exception { + load(BaseConfiguration.class, "spring.thymeleaf.reactive.chunkedModeViewNames:foo,bar"); + ThymeleafReactiveViewResolver views = this.context + .getBean(ThymeleafReactiveViewResolver.class); + assertThat(views.getChunkedModeViewNames()).isEqualTo(new String[] { "foo", "bar" }); + } + @Test public void templateLocationDoesNotExist() throws Exception { load(BaseConfiguration.class, From aebde10ae63c9c3c43cf7e40988c5dc3bc603d03 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Ferna=CC=81ndez?= Date: Wed, 4 Oct 2017 01:49:03 +0200 Subject: [PATCH 2/3] Added configuration test for spring.thymeleaf.reactive.max-chunk-size --- .../ThymeleafReactiveAutoConfigurationTests.java | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/thymeleaf/ThymeleafReactiveAutoConfigurationTests.java b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/thymeleaf/ThymeleafReactiveAutoConfigurationTests.java index c2b5fe75f4e2..aae0eb35f2d4 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/thymeleaf/ThymeleafReactiveAutoConfigurationTests.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/thymeleaf/ThymeleafReactiveAutoConfigurationTests.java @@ -112,6 +112,14 @@ public void overrideViewNames() throws Exception { assertThat(views.getViewNames()).isEqualTo(new String[] { "foo", "bar" }); } + @Test + public void overrideMaxChunkSize() throws Exception { + load(BaseConfiguration.class, "spring.thymeleaf.reactive.maxChunkSize:8192"); + ThymeleafReactiveViewResolver views = this.context + .getBean(ThymeleafReactiveViewResolver.class); + assertThat(views.getResponseMaxChunkSizeBytes()).isEqualTo(Integer.valueOf(8192)); + } + @Test public void overrideFullModeViewNames() throws Exception { load(BaseConfiguration.class, "spring.thymeleaf.reactive.fullModeViewNames:foo,bar"); From 2f6e062e2e4dfa28a13853f0db8c3f9e417320dc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Ferna=CC=81ndez?= Date: Wed, 4 Oct 2017 01:49:35 +0200 Subject: [PATCH 3/3] Minor documentation improvements at ThymeleafProperties --- .../boot/autoconfigure/thymeleaf/ThymeleafProperties.java | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/thymeleaf/ThymeleafProperties.java b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/thymeleaf/ThymeleafProperties.java index 727dc098c289..b0942b69b415 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/thymeleaf/ThymeleafProperties.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/thymeleaf/ThymeleafProperties.java @@ -84,12 +84,12 @@ public class ThymeleafProperties { private Integer templateResolverOrder; /** - * Comma-separated list of view names that can be resolved. + * Comma-separated list of view names (patterns allowed) that can be resolved. */ private String[] viewNames; /** - * Comma-separated list of view names that should be excluded from resolution. + * Comma-separated list of view names (patterns allowed) that should be excluded from resolution. */ private String[] excludedViewNames; @@ -218,7 +218,8 @@ public void setContentType(MimeType contentType) { public static class Reactive { /** - * Maximum size of data buffers used for writing to the response, in bytes. + * Maximum size of data buffers used for writing to the response, in bytes. Templates will + * execute in CHUNKED mode by default if this is set a value. */ private int maxChunkSize;