Skip to content

Improvements on Thymeleaf reactive configuration #10507

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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;

Expand All @@ -227,6 +228,19 @@ public static class Reactive {
*/
private List<MediaType> 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<MediaType> getMediaTypes() {
return this.mediaTypes;
}
Expand All @@ -243,6 +257,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;
}

}

}
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,30 @@ 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");
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,
Expand Down