From 236c64c04cc05a8fa6f222753d27dc758736ef35 Mon Sep 17 00:00:00 2001 From: Scott Murphy Heiberg Date: Fri, 15 Nov 2024 22:47:40 -0800 Subject: [PATCH 1/9] AutoConfiguration for Url Mappings Plugin --- .../mapping/UrlMappingsAutoConfiguration.java | 90 +++++++++++++++++++ .../mapping/UrlMappingsGrailsPlugin.groovy | 29 +----- ...ot.autoconfigure.AutoConfiguration.imports | 1 + 3 files changed, 92 insertions(+), 28 deletions(-) create mode 100644 grails-plugin-url-mappings/src/main/groovy/org/grails/plugins/web/mapping/UrlMappingsAutoConfiguration.java create mode 100644 grails-plugin-url-mappings/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports diff --git a/grails-plugin-url-mappings/src/main/groovy/org/grails/plugins/web/mapping/UrlMappingsAutoConfiguration.java b/grails-plugin-url-mappings/src/main/groovy/org/grails/plugins/web/mapping/UrlMappingsAutoConfiguration.java new file mode 100644 index 00000000000..0eb6f391378 --- /dev/null +++ b/grails-plugin-url-mappings/src/main/groovy/org/grails/plugins/web/mapping/UrlMappingsAutoConfiguration.java @@ -0,0 +1,90 @@ +package org.grails.plugins.web.mapping; + +import grails.config.Settings; +import grails.util.Environment; +import grails.web.CamelCaseUrlConverter; +import grails.web.HyphenatedUrlConverter; +import grails.web.UrlConverter; +import grails.web.mapping.LinkGenerator; +import grails.web.mapping.UrlMappings; +import grails.web.mapping.cors.GrailsCorsConfiguration; +import grails.web.mapping.cors.GrailsCorsFilter; +import org.grails.web.mapping.CachingLinkGenerator; +import org.grails.web.mapping.DefaultLinkGenerator; +import org.grails.web.mapping.UrlMappingsHolderFactoryBean; +import org.grails.web.mapping.mvc.UrlMappingsInfoHandlerAdapter; +import org.grails.web.mapping.servlet.UrlMappingsErrorPageCustomizer; +import org.springframework.beans.factory.ObjectProvider; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.boot.autoconfigure.AutoConfiguration; +import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; +import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; +import org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication; +import org.springframework.boot.context.properties.EnableConfigurationProperties; +import org.springframework.context.annotation.*; +import org.springframework.core.type.AnnotatedTypeMetadata; + +@AutoConfiguration +@ConditionalOnWebApplication(type = ConditionalOnWebApplication.Type.SERVLET) +@EnableConfigurationProperties({ GrailsCorsConfiguration.class }) +public class UrlMappingsAutoConfiguration { + @Value("${" + Settings.WEB_LINK_GENERATOR_USE_CACHE + ":#{null}}") + private Boolean cacheUrls; + + @Value("${" + Settings.SERVER_URL + ":#{null}}") + private String serverURL; + + @Bean(UrlConverter.BEAN_NAME) + @ConditionalOnMissingBean(name = UrlConverter.BEAN_NAME) + @ConditionalOnProperty(name = Settings.WEB_URL_CONVERTER, havingValue = "camelCase", matchIfMissing = true) + public UrlConverter camelCaseUrlConverter() { + return new CamelCaseUrlConverter(); + } + + @Bean(UrlConverter.BEAN_NAME) + @ConditionalOnMissingBean(name = UrlConverter.BEAN_NAME) + @ConditionalOnProperty(name = Settings.WEB_URL_CONVERTER, havingValue = "hyphenated") + public UrlConverter hyphenatedUrlConverter() { + return new HyphenatedUrlConverter(); + } + + @Bean + public LinkGenerator grailsLinkGenerator() { + boolean isReloadEnabled = Environment.isDevelopmentMode() || Environment.getCurrent().isReloadEnabled(); + if (cacheUrls == null) { + cacheUrls = !isReloadEnabled; + } + return cacheUrls? new CachingLinkGenerator(serverURL) : new DefaultLinkGenerator(serverURL); + } + + @Bean + @ConditionalOnProperty(name = Settings.SETTING_CORS_FILTER, havingValue = "true", matchIfMissing = true) + public GrailsCorsFilter grailsCorsFilter(GrailsCorsConfiguration grailsCorsConfiguration) { + return new GrailsCorsFilter(grailsCorsConfiguration); + } + + @Bean("grailsUrlMappingsHolder") + @Conditional(NonLiveReloadEnabledCondition.class) + public UrlMappingsHolderFactoryBean grailsUrlMappingsHolderNonLiveReload() { + return new UrlMappingsHolderFactoryBean(); + } + + @Bean + public UrlMappingsErrorPageCustomizer urlMappingsErrorPageCustomizer(ObjectProvider urlMappingsProvider) { + UrlMappingsErrorPageCustomizer errorPageCustomizer = new UrlMappingsErrorPageCustomizer(); + errorPageCustomizer.setUrlMappings(urlMappingsProvider.getIfAvailable()); + return errorPageCustomizer; + } + + @Bean + public UrlMappingsInfoHandlerAdapter urlMappingsInfoHandlerAdapter() { + return new UrlMappingsInfoHandlerAdapter(); + } + + public static class NonLiveReloadEnabledCondition implements Condition { + @Override + public boolean matches(ConditionContext context, AnnotatedTypeMetadata metadata) { + return !(Environment.isDevelopmentMode() || Environment.getCurrent().isReloadEnabled()); + } + } +} diff --git a/grails-plugin-url-mappings/src/main/groovy/org/grails/plugins/web/mapping/UrlMappingsGrailsPlugin.groovy b/grails-plugin-url-mappings/src/main/groovy/org/grails/plugins/web/mapping/UrlMappingsGrailsPlugin.groovy index 9b0afee2301..940be4ced3a 100644 --- a/grails-plugin-url-mappings/src/main/groovy/org/grails/plugins/web/mapping/UrlMappingsGrailsPlugin.groovy +++ b/grails-plugin-url-mappings/src/main/groovy/org/grails/plugins/web/mapping/UrlMappingsGrailsPlugin.groovy @@ -19,23 +19,16 @@ import grails.config.Settings import grails.plugins.Plugin import grails.util.Environment import grails.util.GrailsUtil -import grails.web.CamelCaseUrlConverter -import grails.web.HyphenatedUrlConverter -import grails.web.mapping.cors.GrailsCorsFilter import groovy.transform.CompileDynamic import groovy.transform.CompileStatic import org.grails.core.artefact.UrlMappingsArtefactHandler -import grails.web.mapping.cors.GrailsCorsConfiguration import org.grails.spring.beans.factory.HotSwappableTargetSourceFactoryBean import org.grails.web.mapping.CachingLinkGenerator -import org.grails.web.mapping.DefaultLinkGenerator import grails.web.mapping.LinkGenerator import grails.web.mapping.UrlMappings import grails.web.mapping.UrlMappingsHolder import org.grails.web.mapping.UrlMappingsHolderFactoryBean import org.grails.web.mapping.mvc.UrlMappingsHandlerMapping -import org.grails.web.mapping.mvc.UrlMappingsInfoHandlerAdapter -import org.grails.web.mapping.servlet.UrlMappingsErrorPageCustomizer import org.springframework.aop.framework.ProxyFactoryBean import org.springframework.aop.target.HotSwappableTargetSource import org.springframework.context.ApplicationContext @@ -61,31 +54,15 @@ class UrlMappingsGrailsPlugin extends Plugin { } def config = application.config - String serverURL = config.getProperty(Settings.SERVER_URL) ?: null - String urlConverterType = config.getProperty(Settings.WEB_URL_CONVERTER) boolean isReloadEnabled = Environment.isDevelopmentMode() || Environment.current.isReloadEnabled() - boolean cacheUrls = config.getProperty(Settings.WEB_LINK_GENERATOR_USE_CACHE, Boolean, !isReloadEnabled) - - "${grails.web.UrlConverter.BEAN_NAME}"('hyphenated' == urlConverterType ? HyphenatedUrlConverter : CamelCaseUrlConverter) - boolean corsFilterEnabled = config.getProperty(Settings.SETTING_CORS_FILTER, Boolean, true) - grailsCorsConfiguration(GrailsCorsConfiguration) - urlMappingsHandlerMapping(UrlMappingsHandlerMapping, ref("grailsUrlMappingsHolder")) { if (!corsFilterEnabled) { grailsCorsConfiguration = ref("grailsCorsConfiguration") } } - if (corsFilterEnabled) { - grailsCorsFilter(GrailsCorsFilter, ref("grailsCorsConfiguration")) - } - - urlMappingsInfoHandlerAdapter(UrlMappingsInfoHandlerAdapter) - urlMappingsErrorPageCustomizer(UrlMappingsErrorPageCustomizer) - grailsLinkGenerator(cacheUrls ? CachingLinkGenerator : DefaultLinkGenerator, serverURL) - if (isReloadEnabled) { urlMappingsTargetSource(HotSwappableTargetSourceFactoryBean) { it.lazyInit = true @@ -98,11 +75,7 @@ class UrlMappingsGrailsPlugin extends Plugin { targetSource = urlMappingsTargetSource proxyInterfaces = [UrlMappings] } - } else { - grailsUrlMappingsHolder(UrlMappingsHolderFactoryBean) { bean -> - bean.lazyInit = true - } - } + } }} @Override diff --git a/grails-plugin-url-mappings/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports b/grails-plugin-url-mappings/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports new file mode 100644 index 00000000000..7adda4bc5fc --- /dev/null +++ b/grails-plugin-url-mappings/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports @@ -0,0 +1 @@ +org.grails.plugins.web.mapping.UrlMappingsAutoConfiguration \ No newline at end of file From b54ffaf4d987906bd44d94a769277fdb715306a7 Mon Sep 17 00:00:00 2001 From: Scott Murphy Heiberg Date: Fri, 15 Nov 2024 23:05:45 -0800 Subject: [PATCH 2/9] remove non live reload autoconfiugraion --- .../web/mapping/UrlMappingsAutoConfiguration.java | 13 ------------- .../web/mapping/UrlMappingsGrailsPlugin.groovy | 6 +++++- 2 files changed, 5 insertions(+), 14 deletions(-) diff --git a/grails-plugin-url-mappings/src/main/groovy/org/grails/plugins/web/mapping/UrlMappingsAutoConfiguration.java b/grails-plugin-url-mappings/src/main/groovy/org/grails/plugins/web/mapping/UrlMappingsAutoConfiguration.java index 0eb6f391378..daf1fe71653 100644 --- a/grails-plugin-url-mappings/src/main/groovy/org/grails/plugins/web/mapping/UrlMappingsAutoConfiguration.java +++ b/grails-plugin-url-mappings/src/main/groovy/org/grails/plugins/web/mapping/UrlMappingsAutoConfiguration.java @@ -63,12 +63,6 @@ public GrailsCorsFilter grailsCorsFilter(GrailsCorsConfiguration grailsCorsConfi return new GrailsCorsFilter(grailsCorsConfiguration); } - @Bean("grailsUrlMappingsHolder") - @Conditional(NonLiveReloadEnabledCondition.class) - public UrlMappingsHolderFactoryBean grailsUrlMappingsHolderNonLiveReload() { - return new UrlMappingsHolderFactoryBean(); - } - @Bean public UrlMappingsErrorPageCustomizer urlMappingsErrorPageCustomizer(ObjectProvider urlMappingsProvider) { UrlMappingsErrorPageCustomizer errorPageCustomizer = new UrlMappingsErrorPageCustomizer(); @@ -80,11 +74,4 @@ public UrlMappingsErrorPageCustomizer urlMappingsErrorPageCustomizer(ObjectProvi public UrlMappingsInfoHandlerAdapter urlMappingsInfoHandlerAdapter() { return new UrlMappingsInfoHandlerAdapter(); } - - public static class NonLiveReloadEnabledCondition implements Condition { - @Override - public boolean matches(ConditionContext context, AnnotatedTypeMetadata metadata) { - return !(Environment.isDevelopmentMode() || Environment.getCurrent().isReloadEnabled()); - } - } } diff --git a/grails-plugin-url-mappings/src/main/groovy/org/grails/plugins/web/mapping/UrlMappingsGrailsPlugin.groovy b/grails-plugin-url-mappings/src/main/groovy/org/grails/plugins/web/mapping/UrlMappingsGrailsPlugin.groovy index 940be4ced3a..51b79a22fc0 100644 --- a/grails-plugin-url-mappings/src/main/groovy/org/grails/plugins/web/mapping/UrlMappingsGrailsPlugin.groovy +++ b/grails-plugin-url-mappings/src/main/groovy/org/grails/plugins/web/mapping/UrlMappingsGrailsPlugin.groovy @@ -75,7 +75,11 @@ class UrlMappingsGrailsPlugin extends Plugin { targetSource = urlMappingsTargetSource proxyInterfaces = [UrlMappings] } - } + } else { + grailsUrlMappingsHolder(UrlMappingsHolderFactoryBean) { bean -> + bean.lazyInit = true + } + } }} @Override From 492b976402503da60b58be41a79af78415121b1f Mon Sep 17 00:00:00 2001 From: Scott Murphy Heiberg Date: Sat, 16 Nov 2024 12:53:23 -0800 Subject: [PATCH 3/9] Move filters to AutoConfiguration --- .../ControllersAutoConfiguration.java | 67 +++++++++++++++++++ .../ControllersGrailsPlugin.groovy | 36 ---------- ...ot.autoconfigure.AutoConfiguration.imports | 1 + 3 files changed, 68 insertions(+), 36 deletions(-) create mode 100644 grails-plugin-controllers/src/main/groovy/org/grails/plugins/web/controllers/ControllersAutoConfiguration.java create mode 100644 grails-plugin-controllers/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports diff --git a/grails-plugin-controllers/src/main/groovy/org/grails/plugins/web/controllers/ControllersAutoConfiguration.java b/grails-plugin-controllers/src/main/groovy/org/grails/plugins/web/controllers/ControllersAutoConfiguration.java new file mode 100644 index 00000000000..3caa335a940 --- /dev/null +++ b/grails-plugin-controllers/src/main/groovy/org/grails/plugins/web/controllers/ControllersAutoConfiguration.java @@ -0,0 +1,67 @@ +package org.grails.plugins.web.controllers; + +import grails.config.Settings; +import jakarta.servlet.DispatcherType; +import jakarta.servlet.Filter; +import org.grails.spring.config.http.GrailsFilters; +import org.grails.web.filters.HiddenHttpMethodFilter; +import org.grails.web.servlet.mvc.GrailsWebRequestFilter; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.boot.autoconfigure.AutoConfiguration; +import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; +import org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication; +import org.springframework.boot.autoconfigure.web.servlet.WebMvcAutoConfiguration; +import org.springframework.boot.web.servlet.FilterRegistrationBean; +import org.springframework.context.annotation.Bean; +import org.springframework.web.filter.CharacterEncodingFilter; + +import java.util.EnumSet; + +@AutoConfiguration(before = { WebMvcAutoConfiguration.class }) +@ConditionalOnWebApplication(type = ConditionalOnWebApplication.Type.SERVLET) +public class ControllersAutoConfiguration { + + @Value("${" + Settings.FILTER_ENCODING + ":utf-8}") + private String filtersEncoding; + + @Value("${" + Settings.FILTER_FORCE_ENCODING + ":false}") + private boolean filtersForceEncoding; + + @Bean + @ConditionalOnMissingBean(HiddenHttpMethodFilter.class) + public FilterRegistrationBean characterEncodingFilter() { + FilterRegistrationBean registrationBean = new FilterRegistrationBean<>(); + CharacterEncodingFilter characterEncodingFilter = new CharacterEncodingFilter(); + characterEncodingFilter.setEncoding(filtersEncoding); + characterEncodingFilter.setForceEncoding(filtersForceEncoding); + registrationBean.setFilter(characterEncodingFilter); + registrationBean.addUrlPatterns(Settings.DEFAULT_WEB_SERVLET_PATH); + registrationBean.setOrder(GrailsFilters.CHARACTER_ENCODING_FILTER.getOrder()); + return registrationBean; + } + + @Bean + @ConditionalOnMissingBean(HiddenHttpMethodFilter.class) + public FilterRegistrationBean hiddenHttpMethodFilter() { + FilterRegistrationBean registrationBean = new FilterRegistrationBean<>(); + registrationBean.setFilter(new HiddenHttpMethodFilter()); + registrationBean.addUrlPatterns(Settings.DEFAULT_WEB_SERVLET_PATH); + registrationBean.setOrder(GrailsFilters.HIDDEN_HTTP_METHOD_FILTER.getOrder()); + return registrationBean; + } + + @Bean + @ConditionalOnMissingBean(GrailsWebRequestFilter.class) + public FilterRegistrationBean grailsWebRequestFilter() { + FilterRegistrationBean registrationBean = new FilterRegistrationBean<>(); + registrationBean.setFilter(new GrailsWebRequestFilter()); + registrationBean.setDispatcherTypes(EnumSet.of( + DispatcherType.FORWARD, + DispatcherType.INCLUDE, + DispatcherType.REQUEST) + ); + registrationBean.addUrlPatterns(Settings.DEFAULT_WEB_SERVLET_PATH); + registrationBean.setOrder(GrailsFilters.GRAILS_WEB_REQUEST_FILTER.getOrder()); + return registrationBean; + } +} diff --git a/grails-plugin-controllers/src/main/groovy/org/grails/plugins/web/controllers/ControllersGrailsPlugin.groovy b/grails-plugin-controllers/src/main/groovy/org/grails/plugins/web/controllers/ControllersGrailsPlugin.groovy index e41f3e7505b..650c141e1aa 100644 --- a/grails-plugin-controllers/src/main/groovy/org/grails/plugins/web/controllers/ControllersGrailsPlugin.groovy +++ b/grails-plugin-controllers/src/main/groovy/org/grails/plugins/web/controllers/ControllersGrailsPlugin.groovy @@ -23,25 +23,19 @@ import groovy.transform.CompileStatic import groovy.util.logging.Slf4j import org.grails.core.artefact.ControllerArtefactHandler import org.grails.plugins.web.servlet.context.BootStrapClassRunner -import org.grails.spring.config.http.GrailsFilters import org.grails.web.errors.GrailsExceptionResolver -import org.grails.web.filters.HiddenHttpMethodFilter import org.grails.web.servlet.mvc.GrailsDispatcherServlet -import org.grails.web.servlet.mvc.GrailsWebRequestFilter import org.grails.web.servlet.mvc.TokenResponseActionResultTransformer import org.grails.web.servlet.view.CompositeViewResolver import org.springframework.beans.factory.support.AbstractBeanDefinition import org.springframework.boot.autoconfigure.web.servlet.DispatcherServletRegistrationBean -import org.springframework.boot.web.servlet.FilterRegistrationBean import org.springframework.context.ApplicationContext import org.springframework.util.ClassUtils -import org.springframework.web.filter.CharacterEncodingFilter import org.springframework.web.multipart.support.StandardServletMultipartResolver import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry import org.springframework.web.servlet.config.annotation.WebMvcConfigurer import org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter import org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping -import jakarta.servlet.DispatcherType import jakarta.servlet.MultipartConfigElement /** @@ -71,8 +65,6 @@ class ControllersGrailsPlugin extends Plugin { long maxFileSize = config.getProperty(Settings.CONTROLLERS_UPLOAD_MAX_FILE_SIZE, Long, 128000L) long maxRequestSize = config.getProperty(Settings.CONTROLLERS_UPLOAD_MAX_REQUEST_SIZE, Long, 128000L) int fileSizeThreashold = config.getProperty(Settings.CONTROLLERS_UPLOAD_FILE_SIZE_THRESHOLD, Integer, 0) - String filtersEncoding = config.getProperty(Settings.FILTER_ENCODING, 'utf-8') - boolean filtersForceEncoding = config.getProperty(Settings.FILTER_FORCE_ENCODING, Boolean, false) boolean isTomcat = ClassUtils.isPresent("org.apache.catalina.startup.Tomcat", application.classLoader) String grailsServletPath = config.getProperty(Settings.WEB_SERVLET_PATH, isTomcat ? Settings.DEFAULT_TOMCAT_SERVLET_PATH : Settings.DEFAULT_WEB_SERVLET_PATH) int resourcesCachePeriod = config.getProperty(Settings.RESOURCES_CACHE_PERIOD, Integer, 0) @@ -85,34 +77,6 @@ class ControllersGrailsPlugin extends Plugin { tokenResponseActionResultTransformer(TokenResponseActionResultTransformer) - def catchAllMapping = [Settings.DEFAULT_WEB_SERVLET_PATH] - - characterEncodingFilter(FilterRegistrationBean) { - filter = bean(CharacterEncodingFilter) { - encoding = filtersEncoding - forceEncoding = filtersForceEncoding - } - urlPatterns = catchAllMapping - order = GrailsFilters.CHARACTER_ENCODING_FILTER.order - } - - hiddenHttpMethodFilter(FilterRegistrationBean) { - filter = bean(HiddenHttpMethodFilter) - urlPatterns = catchAllMapping - order = GrailsFilters.HIDDEN_HTTP_METHOD_FILTER.order - } - - grailsWebRequestFilter(FilterRegistrationBean) { - filter = bean(GrailsWebRequestFilter) - urlPatterns = catchAllMapping - order = GrailsFilters.GRAILS_WEB_REQUEST_FILTER.order - dispatcherTypes = EnumSet.of( - DispatcherType.FORWARD, - DispatcherType.INCLUDE, - DispatcherType.REQUEST - ) - } - exceptionHandler(GrailsExceptionResolver) { exceptionMappings = ['java.lang.Exception': '/error'] } diff --git a/grails-plugin-controllers/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports b/grails-plugin-controllers/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports new file mode 100644 index 00000000000..070ecd4bead --- /dev/null +++ b/grails-plugin-controllers/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports @@ -0,0 +1 @@ +org.grails.plugins.web.controllers.ControllersAutoConfiguration From 6b938a198cc843ab1fed862b9c07126b5777e988 Mon Sep 17 00:00:00 2001 From: Scott Murphy Heiberg Date: Sat, 16 Nov 2024 12:54:15 -0800 Subject: [PATCH 4/9] move check --- .../plugins/web/mapping/UrlMappingsAutoConfiguration.java | 3 +-- ...pringframework.boot.autoconfigure.AutoConfiguration.imports | 2 +- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/grails-plugin-url-mappings/src/main/groovy/org/grails/plugins/web/mapping/UrlMappingsAutoConfiguration.java b/grails-plugin-url-mappings/src/main/groovy/org/grails/plugins/web/mapping/UrlMappingsAutoConfiguration.java index daf1fe71653..9ba6c4da632 100644 --- a/grails-plugin-url-mappings/src/main/groovy/org/grails/plugins/web/mapping/UrlMappingsAutoConfiguration.java +++ b/grails-plugin-url-mappings/src/main/groovy/org/grails/plugins/web/mapping/UrlMappingsAutoConfiguration.java @@ -50,9 +50,8 @@ public UrlConverter hyphenatedUrlConverter() { @Bean public LinkGenerator grailsLinkGenerator() { - boolean isReloadEnabled = Environment.isDevelopmentMode() || Environment.getCurrent().isReloadEnabled(); if (cacheUrls == null) { - cacheUrls = !isReloadEnabled; + cacheUrls = !Environment.isDevelopmentMode() || Environment.getCurrent().isReloadEnabled(); } return cacheUrls? new CachingLinkGenerator(serverURL) : new DefaultLinkGenerator(serverURL); } diff --git a/grails-plugin-url-mappings/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports b/grails-plugin-url-mappings/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports index 7adda4bc5fc..ff41944b742 100644 --- a/grails-plugin-url-mappings/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports +++ b/grails-plugin-url-mappings/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports @@ -1 +1 @@ -org.grails.plugins.web.mapping.UrlMappingsAutoConfiguration \ No newline at end of file +org.grails.plugins.web.mapping.UrlMappingsAutoConfiguration From d714b28575db00b9bd7a649dd8001b8697faef87 Mon Sep 17 00:00:00 2001 From: Scott Murphy Heiberg Date: Sat, 16 Nov 2024 18:06:04 -0800 Subject: [PATCH 5/9] fix cachingUrls logic --- .../plugins/web/mapping/UrlMappingsAutoConfiguration.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/grails-plugin-url-mappings/src/main/groovy/org/grails/plugins/web/mapping/UrlMappingsAutoConfiguration.java b/grails-plugin-url-mappings/src/main/groovy/org/grails/plugins/web/mapping/UrlMappingsAutoConfiguration.java index 9ba6c4da632..b7d978f01a5 100644 --- a/grails-plugin-url-mappings/src/main/groovy/org/grails/plugins/web/mapping/UrlMappingsAutoConfiguration.java +++ b/grails-plugin-url-mappings/src/main/groovy/org/grails/plugins/web/mapping/UrlMappingsAutoConfiguration.java @@ -51,7 +51,7 @@ public UrlConverter hyphenatedUrlConverter() { @Bean public LinkGenerator grailsLinkGenerator() { if (cacheUrls == null) { - cacheUrls = !Environment.isDevelopmentMode() || Environment.getCurrent().isReloadEnabled(); + cacheUrls = !Environment.isDevelopmentMode() && !Environment.getCurrent().isReloadEnabled(); } return cacheUrls? new CachingLinkGenerator(serverURL) : new DefaultLinkGenerator(serverURL); } From d095cadd75d6211c815bfee5914e7a0e3753bdaf Mon Sep 17 00:00:00 2001 From: Scott Murphy Heiberg Date: Sat, 16 Nov 2024 18:18:07 -0800 Subject: [PATCH 6/9] unused imports --- .../plugins/web/mapping/UrlMappingsAutoConfiguration.java | 2 -- 1 file changed, 2 deletions(-) diff --git a/grails-plugin-url-mappings/src/main/groovy/org/grails/plugins/web/mapping/UrlMappingsAutoConfiguration.java b/grails-plugin-url-mappings/src/main/groovy/org/grails/plugins/web/mapping/UrlMappingsAutoConfiguration.java index b7d978f01a5..f1b9ebd5c22 100644 --- a/grails-plugin-url-mappings/src/main/groovy/org/grails/plugins/web/mapping/UrlMappingsAutoConfiguration.java +++ b/grails-plugin-url-mappings/src/main/groovy/org/grails/plugins/web/mapping/UrlMappingsAutoConfiguration.java @@ -11,7 +11,6 @@ import grails.web.mapping.cors.GrailsCorsFilter; import org.grails.web.mapping.CachingLinkGenerator; import org.grails.web.mapping.DefaultLinkGenerator; -import org.grails.web.mapping.UrlMappingsHolderFactoryBean; import org.grails.web.mapping.mvc.UrlMappingsInfoHandlerAdapter; import org.grails.web.mapping.servlet.UrlMappingsErrorPageCustomizer; import org.springframework.beans.factory.ObjectProvider; @@ -22,7 +21,6 @@ import org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication; import org.springframework.boot.context.properties.EnableConfigurationProperties; import org.springframework.context.annotation.*; -import org.springframework.core.type.AnnotatedTypeMetadata; @AutoConfiguration @ConditionalOnWebApplication(type = ConditionalOnWebApplication.Type.SERVLET) From 4b2318338f8534f06f8819ff0f7b79bf838f6beb Mon Sep 17 00:00:00 2001 From: Scott Murphy Heiberg Date: Sat, 16 Nov 2024 20:23:43 -0800 Subject: [PATCH 7/9] fix tests --- .../grails/boot/EmbeddedContainerWithGrailsSpec.groovy | 6 ++---- .../groovy/grails/boot/GrailsSpringApplicationSpec.groovy | 7 ++----- 2 files changed, 4 insertions(+), 9 deletions(-) diff --git a/grails-web-boot/src/test/groovy/grails/boot/EmbeddedContainerWithGrailsSpec.groovy b/grails-web-boot/src/test/groovy/grails/boot/EmbeddedContainerWithGrailsSpec.groovy index ef225586026..729cb09440f 100644 --- a/grails-web-boot/src/test/groovy/grails/boot/EmbeddedContainerWithGrailsSpec.groovy +++ b/grails-web-boot/src/test/groovy/grails/boot/EmbeddedContainerWithGrailsSpec.groovy @@ -3,12 +3,11 @@ package grails.boot import grails.artefact.Artefact import grails.boot.config.GrailsAutoConfiguration import grails.web.Controller +import org.springframework.boot.autoconfigure.SpringBootApplication import org.springframework.boot.web.embedded.tomcat.TomcatServletWebServerFactory import org.springframework.boot.web.servlet.context.AnnotationConfigServletWebServerApplicationContext import org.springframework.boot.web.servlet.server.ConfigurableServletWebServerFactory import org.springframework.context.annotation.Bean -import org.springframework.context.annotation.Configuration -import org.springframework.web.servlet.config.annotation.EnableWebMvc import spock.lang.Specification /** @@ -32,8 +31,7 @@ class EmbeddedContainerWithGrailsSpec extends Specification { new URL("http://localhost:${context.webServer.port}/foos").text == 'all foos' } - @Configuration - @EnableWebMvc + @SpringBootApplication static class Application extends GrailsAutoConfiguration { @Bean ConfigurableServletWebServerFactory webServerFactory() { diff --git a/grails-web-boot/src/test/groovy/grails/boot/GrailsSpringApplicationSpec.groovy b/grails-web-boot/src/test/groovy/grails/boot/GrailsSpringApplicationSpec.groovy index 7581b22ed9f..d02c981a27a 100644 --- a/grails-web-boot/src/test/groovy/grails/boot/GrailsSpringApplicationSpec.groovy +++ b/grails-web-boot/src/test/groovy/grails/boot/GrailsSpringApplicationSpec.groovy @@ -2,13 +2,11 @@ package grails.boot import grails.boot.config.GrailsAutoConfiguration import org.springframework.boot.SpringApplication +import org.springframework.boot.autoconfigure.SpringBootApplication import org.springframework.boot.web.embedded.tomcat.TomcatServletWebServerFactory import org.springframework.boot.web.servlet.context.AnnotationConfigServletWebServerApplicationContext import org.springframework.boot.web.servlet.server.ConfigurableServletWebServerFactory -import org.springframework.context.ConfigurableApplicationContext import org.springframework.context.annotation.Bean -import org.springframework.context.annotation.Configuration -import org.springframework.web.servlet.config.annotation.EnableWebMvc import spock.lang.Specification /** @@ -34,8 +32,7 @@ class GrailsSpringApplicationSpec extends Specification{ } - @Configuration - @EnableWebMvc + @SpringBootApplication static class Application extends GrailsAutoConfiguration { @Bean ConfigurableServletWebServerFactory webServerFactory() { From 0667c5330fa8a74e661d1455353a4ce058ad10cf Mon Sep 17 00:00:00 2001 From: Scott Murphy Heiberg Date: Sat, 16 Nov 2024 21:57:39 -0800 Subject: [PATCH 8/9] Fix characterEncodingFilter order --- .../ControllersAutoConfiguration.java | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/grails-plugin-controllers/src/main/groovy/org/grails/plugins/web/controllers/ControllersAutoConfiguration.java b/grails-plugin-controllers/src/main/groovy/org/grails/plugins/web/controllers/ControllersAutoConfiguration.java index 3caa335a940..7273ab0c528 100644 --- a/grails-plugin-controllers/src/main/groovy/org/grails/plugins/web/controllers/ControllersAutoConfiguration.java +++ b/grails-plugin-controllers/src/main/groovy/org/grails/plugins/web/controllers/ControllersAutoConfiguration.java @@ -10,14 +10,17 @@ import org.springframework.boot.autoconfigure.AutoConfiguration; import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; import org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication; +import org.springframework.boot.autoconfigure.web.servlet.HttpEncodingAutoConfiguration; import org.springframework.boot.autoconfigure.web.servlet.WebMvcAutoConfiguration; import org.springframework.boot.web.servlet.FilterRegistrationBean; +import org.springframework.boot.web.servlet.filter.OrderedCharacterEncodingFilter; import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Primary; import org.springframework.web.filter.CharacterEncodingFilter; import java.util.EnumSet; -@AutoConfiguration(before = { WebMvcAutoConfiguration.class }) +@AutoConfiguration(before = { HttpEncodingAutoConfiguration.class, WebMvcAutoConfiguration.class }) @ConditionalOnWebApplication(type = ConditionalOnWebApplication.Type.SERVLET) public class ControllersAutoConfiguration { @@ -28,16 +31,14 @@ public class ControllersAutoConfiguration { private boolean filtersForceEncoding; @Bean - @ConditionalOnMissingBean(HiddenHttpMethodFilter.class) - public FilterRegistrationBean characterEncodingFilter() { + @ConditionalOnMissingBean(CharacterEncodingFilter.class) + public CharacterEncodingFilter characterEncodingFilter() { FilterRegistrationBean registrationBean = new FilterRegistrationBean<>(); - CharacterEncodingFilter characterEncodingFilter = new CharacterEncodingFilter(); + OrderedCharacterEncodingFilter characterEncodingFilter = new OrderedCharacterEncodingFilter(); characterEncodingFilter.setEncoding(filtersEncoding); characterEncodingFilter.setForceEncoding(filtersForceEncoding); - registrationBean.setFilter(characterEncodingFilter); - registrationBean.addUrlPatterns(Settings.DEFAULT_WEB_SERVLET_PATH); - registrationBean.setOrder(GrailsFilters.CHARACTER_ENCODING_FILTER.getOrder()); - return registrationBean; + characterEncodingFilter.setOrder(GrailsFilters.CHARACTER_ENCODING_FILTER.getOrder()); + return characterEncodingFilter; } @Bean From 040d4227ce2472dfe2687422eadbbedcef4ac970 Mon Sep 17 00:00:00 2001 From: Scott Murphy Heiberg Date: Sat, 16 Nov 2024 22:04:17 -0800 Subject: [PATCH 9/9] StandardServletMultipartResolver is already resolved by org.springframework.boot.autoconfigure.web.servlet.MultipartAutoConfiguration --- .../plugins/web/controllers/ControllersGrailsPlugin.groovy | 2 -- 1 file changed, 2 deletions(-) diff --git a/grails-plugin-controllers/src/main/groovy/org/grails/plugins/web/controllers/ControllersGrailsPlugin.groovy b/grails-plugin-controllers/src/main/groovy/org/grails/plugins/web/controllers/ControllersGrailsPlugin.groovy index 650c141e1aa..2995ed8add1 100644 --- a/grails-plugin-controllers/src/main/groovy/org/grails/plugins/web/controllers/ControllersGrailsPlugin.groovy +++ b/grails-plugin-controllers/src/main/groovy/org/grails/plugins/web/controllers/ControllersGrailsPlugin.groovy @@ -81,8 +81,6 @@ class ControllersGrailsPlugin extends Plugin { exceptionMappings = ['java.lang.Exception': '/error'] } - multipartResolver(StandardServletMultipartResolver) - "${CompositeViewResolver.BEAN_NAME}"(CompositeViewResolver) multipartConfigElement(MultipartConfigElement, uploadTmpDir, maxFileSize, maxRequestSize, fileSizeThreashold)