Copilot commented on code in PR #15541: URL: https://github.com/apache/grails-core/pull/15541#discussion_r3018487375
########## grails-web-common/src/main/groovy/org/grails/web/config/http/GrailsFilterOrder.java: ########## @@ -0,0 +1,48 @@ +/* + * 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.web.config.http; + +/** + * Constants for filter ordering in Grails applications. + * <p> + * These constants were previously obtained from Spring Boot's {@code SecurityProperties} + * class, but were removed in Spring Boot 4.0. They are now defined here for use by + * Grails filter configuration. + * + * @since 8.0 + */ +public final class GrailsFilterOrder { + + private GrailsFilterOrder() { + // Utility class + } + + /** + * Default order of Spring Security's Filter in the servlet container (i.e. amongst + * other filters registered with the container). There is no connection between this + * and the {@code @Order} on a {@code SecurityFilterChain}. + * <p> + * Value is {@code REQUEST_WRAPPER_FILTER_MAX_ORDER - 100 = -100}. + * <p> + * This value matches what was previously defined in Spring Boot's + * {@code SecurityProperties.DEFAULT_FILTER_ORDER} before it was removed in Spring Boot 4.0. Review Comment: The Javadoc references `REQUEST_WRAPPER_FILTER_MAX_ORDER`, but that constant isn’t defined in this class/module, making the explanation confusing/out-of-context. Consider rewriting this to state the concrete value (`-100`) and (optionally) cite the original Spring Boot/Spring Security source for the calculation, without referencing an undefined symbol. ########## grails-web-boot/src/test/groovy/grails/boot/EmbeddedContainerWithGrailsSpec.groovy: ########## @@ -37,44 +40,34 @@ import org.apache.grails.core.plugins.PluginDiscovery /** * Created by graemerocher on 28/05/14. */ +@Ignore("Spring Boot 4.0: Embedded server test infrastructure needs significant rework due to modularization. " + + "Classes exist in new spring-boot-web-server and spring-boot-tomcat modules but require updated test patterns.") class EmbeddedContainerWithGrailsSpec extends Specification { - AnnotationConfigServletWebServerApplicationContext context + // AnnotationConfigServletWebServerApplicationContext context void cleanup() { - context.close() + // context.close() } void "Test that you can load Grails in an embedded server config"() { - given: 'bootstrapped context' - ConfigurableEnvironment env = new StandardServletEnvironment() - PluginDiscovery pluginDiscovery = new DefaultPluginDiscovery() - pluginDiscovery.init(env) - - when: "An embedded server config is created" - this.context = new AnnotationConfigServletWebServerApplicationContext() - // simulate spring's environment setup - this.context.setEnvironment(env) - // simulate what the bootstrap registry would do - this.context.registerBean(PluginDiscovery.BEAN_NAME, PluginDiscovery, () -> pluginDiscovery) - // mark the application for actual load - this.context.register(Application) - // load it - this.context.refresh() - - then: "The context is valid" - context != null - new URL("http://localhost:${context.webServer.port}/foo/bar").text == 'hello world' - new URL("http://localhost:${context.webServer.port}/foos").text == 'all foos' + when:"An embedded server config is created" + // this.context = new AnnotationConfigServletWebServerApplicationContext(Application) + true // Placeholder + + then:"The context is valid" + // context != null + // new URL("http://localhost:${context.webServer.port}/foo/bar").text == 'hello world' + // new URL("http://localhost:${context.webServer.port}/foos").text == 'all foos' + true // Placeholder Review Comment: This test has been reduced to a `true // Placeholder` assertion. Even though the spec is currently `@Ignore`, a placeholder that always passes can mask regressions if someone re-enables it later without reworking the assertions. Consider converting this to a tracked failing test (`@PendingFeature`/issue reference) or removing the placeholder body and adding an explicit issue to restore embedded-container coverage for Spring Boot 4. ########## grails-data-hibernate5/core/src/main/java/org/grails/orm/hibernate/support/hibernate5/support/OpenSessionInViewInterceptor.java: ########## @@ -0,0 +1,219 @@ +/* + * Copyright 2002-present the original author or authors. + * + * Licensed 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.orm.hibernate.support.hibernate5.support; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.hibernate.FlushMode; +import org.hibernate.HibernateException; +import org.hibernate.Session; +import org.hibernate.SessionFactory; + +import org.springframework.dao.DataAccessException; +import org.springframework.dao.DataAccessResourceFailureException; +import org.springframework.lang.Nullable; +import org.grails.orm.hibernate.support.hibernate5.SessionFactoryUtils; +import org.grails.orm.hibernate.support.hibernate5.SessionHolder; +import org.springframework.transaction.support.TransactionSynchronizationManager; +import org.springframework.ui.ModelMap; +import org.springframework.util.Assert; +import org.springframework.web.context.request.AsyncWebRequestInterceptor; +import org.springframework.web.context.request.WebRequest; +import org.springframework.web.context.request.async.CallableProcessingInterceptor; +import org.springframework.web.context.request.async.WebAsyncManager; +import org.springframework.web.context.request.async.WebAsyncUtils; + +/** + * Spring web request interceptor that binds a Hibernate {@code Session} to the + * thread for the entire processing of the request. + * + * <p>This class is a concrete expression of the "Open Session in View" pattern, which + * is a pattern that allows for the lazy loading of associations in web views despite + * the original transactions already being completed. + * + * <p>This interceptor makes Hibernate Sessions available via the current thread, + * which will be autodetected by transaction managers. It is suitable for service layer + * transactions via {@link org.springframework.orm.hibernate5.HibernateTransactionManager} + * as well as for non-transactional execution (if configured appropriately). + * Review Comment: This Javadoc still references `org.springframework.orm.hibernate5.HibernateTransactionManager`, but this PR vendors the Hibernate 5 integration under `org.grails.orm.hibernate.support.hibernate5.*` (and Spring Framework 7 no longer ships the original package). Please update the `@link`/`@see` references so the Javadoc doesn’t point to a non-existent class. ########## grails-web-boot/src/test/groovy/grails/boot/GrailsSpringApplicationSpec.groovy: ########## @@ -21,40 +21,46 @@ package grails.boot import grails.boot.config.GrailsAutoConfiguration import org.springframework.boot.SpringApplication import org.springframework.boot.autoconfigure.EnableAutoConfiguration -import org.springframework.boot.web.embedded.tomcat.TomcatServletWebServerFactory -import org.springframework.boot.web.servlet.context.AnnotationConfigServletWebServerApplicationContext -import org.springframework.boot.web.servlet.server.ConfigurableServletWebServerFactory +// Note: Spring Boot 4.0 modularization - embedded server classes exist but tests need significant rework +// See Spring Boot 4.0 Migration Guide for details on new module structure +// import org.springframework.boot.web.server.servlet.context.ServletWebServerApplicationContextFactory +// import org.springframework.boot.web.server.servlet.ConfigurableServletWebServerFactory +// import org.springframework.boot.tomcat.web.server.TomcatServletWebServerFactory import org.springframework.context.annotation.Bean +import spock.lang.Ignore import spock.lang.Specification /** * Created by graemerocher on 28/05/14. */ +@Ignore("Spring Boot 4.0: Embedded server test infrastructure needs significant rework due to modularization. " + + "Classes exist in new spring-boot-web-server and spring-boot-tomcat modules but require updated test patterns.") class GrailsSpringApplicationSpec extends Specification{ - AnnotationConfigServletWebServerApplicationContext context + // AnnotationConfigServletWebServerApplicationContext context void cleanup() { - context.close() + // context.close() } void "Test run Grails via SpringApplication"() { when:"SpringApplication is used to run a Grails app" SpringApplication springApplication = new SpringApplication(Application) springApplication.allowBeanDefinitionOverriding = true - context = (AnnotationConfigServletWebServerApplicationContext) springApplication.run() + // context = (AnnotationConfigServletWebServerApplicationContext) springApplication.run() then:"The application runs" - context != null - new URL("http://localhost:${context.webServer.port}/foo/bar").text == 'hello world' + // context != null + // new URL("http://localhost:${context.webServer.port}/foo/bar").text == 'hello world' + true // Placeholder - Spring Boot 4.0 embedded server API needs rework due to modularization } Review Comment: This spec is now effectively a placeholder (assertions are commented out and the test unconditionally passes). Even though the class is `@Ignore` right now, leaving a permanently-passing body makes it easy to accidentally re-enable without restoring meaningful coverage. Prefer either (a) keeping a real failing/`@PendingFeature` test with a tracked issue, or (b) removing the placeholder body and adding a dedicated follow-up issue/task for reintroducing an embedded-server integration test under Spring Boot 4’s modularized APIs. -- 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]
