Honor overridden AcceptHeaderLocaleContextResolver.getDefaultLocale()

Closes gh-24871
This commit is contained in:
Juergen Hoeller
2020-04-09 12:03:29 +02:00
parent 906583c40a
commit a4bba6aff2
2 changed files with 8 additions and 4 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2018 the original author or authors.
* Copyright 2002-2020 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.
@@ -39,6 +39,7 @@ import org.springframework.web.server.ServerWebExchange;
* @author Sebastien Deleuze
* @author Juergen Hoeller
* @since 5.0
* @see HttpHeaders#getAcceptLanguageAsLocales()
*/
public class AcceptHeaderLocaleContextResolver implements LocaleContextResolver {
@@ -76,6 +77,7 @@ public class AcceptHeaderLocaleContextResolver implements LocaleContextResolver
/**
* The configured default locale, if any.
* <p>This method may be overridden in subclasses.
*/
@Nullable
public Locale getDefaultLocale() {
@@ -98,7 +100,7 @@ public class AcceptHeaderLocaleContextResolver implements LocaleContextResolver
@Nullable
private Locale resolveSupportedLocale(@Nullable List<Locale> requestLocales) {
if (CollectionUtils.isEmpty(requestLocales)) {
return this.defaultLocale; // may be null
return getDefaultLocale(); // may be null
}
List<Locale> supportedLocales = getSupportedLocales();
if (supportedLocales.isEmpty()) {
@@ -128,7 +130,8 @@ public class AcceptHeaderLocaleContextResolver implements LocaleContextResolver
return languageMatch;
}
return (this.defaultLocale != null ? this.defaultLocale : requestLocales.get(0));
Locale defaultLocale = getDefaultLocale();
return (defaultLocale != null ? defaultLocale : requestLocales.get(0));
}
@Override