jamesfredley commented on code in PR #16760: URL: https://github.com/apache/grails-core/pull/16760#discussion_r4392597365
########## grails-controllers/src/main/groovy/org/grails/plugins/web/controllers/GrailsCharacterEncodingInitializer.java: ########## @@ -0,0 +1,82 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.grails.plugins.web.controllers; + +import java.util.LinkedHashMap; +import java.util.Map; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import org.springframework.boot.env.DefaultPropertiesPropertySource; +import org.springframework.context.ApplicationContextInitializer; +import org.springframework.context.ConfigurableApplicationContext; +import org.springframework.core.env.ConfigurableEnvironment; + +import grails.config.Settings; + +/** + * Translates the deprecated {@code grails.filter.encoding} and {@code grails.filter.forceEncoding} into + * {@code spring.servlet.encoding.charset} and {@code spring.servlet.encoding.force}, which configure the + * character encoding filter Spring Boot registers. Grails no longer registers an encoding filter of its own. + * + * <p>It is a context initializer, not an environment post-processor, because files named by + * {@code grails.config.locations} are loaded by {@code ExternalConfigRunListener} after the post-processors run. + * A translated value is contributed as a Spring Boot default property (lowest precedence), and only when the + * application does not set the Spring Boot property itself. + * + * @since 9.0 + * @deprecated only needed while applications move to {@code spring.servlet.encoding}; it will be removed + * together with the two properties it translates + */ +@Deprecated(since = "9.0", forRemoval = true) +public class GrailsCharacterEncodingInitializer implements ApplicationContextInitializer<ConfigurableApplicationContext> { + + private static final Logger logger = LoggerFactory.getLogger(GrailsCharacterEncodingInitializer.class); + + @Override + @SuppressWarnings("removal") + public void initialize(ConfigurableApplicationContext applicationContext) { + var environment = applicationContext.getEnvironment(); + var translated = new LinkedHashMap<String, Object>(); + translate(environment, Settings.FILTER_ENCODING, "spring.servlet.encoding.charset", translated); Review Comment: `initialize` runs before Spring processes `@PropertySource`. `translate` does not see `Settings.FILTER_ENCODING` from that annotation, and `spring.servlet.encoding.charset` stays at Boot's default. A context that used to resolve ISO-8859-1 now resolves UTF-8. Translate after those property sources are registered, and before the encoding properties are bound. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
