Repository navigation
10.0: Resolve Grails formats with Spring MVC's content negotiation by default - #17106
Draft
codeconsole wants to merge 3 commits into
Draft
codeconsole wants to merge 3 commits into
codeconsole wants to merge 3 commits into
Conversation
grails.mime.negotiation.spring now defaults to true, as Grails 9 announced (apache#16698). Settings.MIME_NEGOTIATION_SPRING_DEFAULT and the configuration metadata say true, and every reader of the setting follows the constant. The URL mappings plugin no longer turns a missing configuration into false: it falls back to the default. The specs that pin the Grails rules set the setting to false, which keeps them: RequestAndResponseMimeTypesApiSpec, GrailsFormatNegotiationRespondSpec, ProblemDetailContentNegotiationSpec, and a new XmlProblemDetailGrailsRulesSpec for the lenient reading of an Accept header Spring cannot read, which GrailsFormatNegotiationRespondSpec now covers for a map too. SpringFormatNegotiationSpec and UrlMappingsGrailsPluginSpec state the new default, and ControllerJsonSerializationSpec expects a map to be answered 406 for an Accept header Spring cannot read.
The spring-format-negotiation test app no longer sets grails.mime.negotiation.spring, so its SpringFormatNegotiationSpec runs the Grails 10 default end to end. app1's GrailsFormatNegotiationSpec, which pins the Grails rules, moves to that app with @TestPropertySource(grails.mime.negotiation.spring=false), along with the end of app1's SpringWrittenController, which only it used. app1 has GORM, where a second test context breaks every later GORM spec; the format negotiation app has none. app1 now runs the default too.
The content negotiation section describes Spring MVC's manager as how Grails resolves formats, with false keeping the Grails rules, and notes that the Accept header rules above it are those rules. The configuration option gives the new default. The Grails 9 to 10 upgrade guide gains section 3 on the change, with the answers that differ and how to keep the Grails rules, and its announced-defaults table lists the setting as changed. The grails-upgrade skill covers the change the same way.
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Makes
grails.mime.negotiation.spring(#16996) the default in Grails 10, as the Grails 9 upgrade guide announces. Completes #16698.request.format,response.format,withFormatand the formatrespondwrites in are now resolved with Spring MVC's content negotiation manager by default, so thespring.mvc.contentnegotiation.*settings apply to them, and theformatparameter, URL extensions and thegrails.mimesettings of theAcceptheader decide what Spring MVC writes for an action too. A Spring MVC endpoint, and Spring Security's filters before a URL mapping has matched a request, negotiate as before.An application keeps the Grails rules with:
Changes
Settings.MIME_NEGOTIATION_SPRING_DEFAULTand the configuration metadata aretrue; every reader of the setting follows the constant. The URL mappings plugin falls back to the default, not tofalse, where it has no configuration.false, which keeps them:RequestAndResponseMimeTypesApiSpec,GrailsFormatNegotiationRespondSpec,ProblemDetailContentNegotiationSpec, and a newXmlProblemDetailGrailsRulesSpec. Specs about the default state it:SpringFormatNegotiationSpec,UrlMappingsGrailsPluginSpec,ControllerJsonSerializationSpec(a map is answered406for anAcceptheader Spring cannot read).spring-format-negotiationtest app runs the default, and app1'sGrailsFormatNegotiationSpec, which pins the Grails rules, moves there under@TestPropertySource(properties = 'grails.mime.negotiation.spring=false'). app1 has GORM, where a second test context breaks the GORM specs after it; that app has none. app1's whole suite now runs the default.falsekeeping the Grails rules; the configuration option gives the new default; the Grails 9 to 10 upgrade guide gains section 3 (anchorupgradingSpringFormatNegotiationDefault) with the answers that change and how to keep the Grails rules, and lists the setting as changed in its announced-defaults table. The Grails 10grails-upgradeskill covers the change the same way.Depends on #17102
WithFormatSpec's feature forAccept: application/problem+xml, application/atom+xml(answeredatom, as in Grails 8) fails here until #17102 reaches 10.0.x: with the setting, the+xmlpreference did not take an unconfiguredapplication/problem+xmlas the XML type. #17102 fixes that on 9.0.x. This pull request stays a draft until then. Merge order: