Skip to content

Commit

Permalink
Honor overridden AcceptHeaderLocaleContextResolver.getDefaultLocale()
Browse files Browse the repository at this point in the history
  • Loading branch information
jhoeller committed Apr 9, 2020
1 parent d9eacaa commit 4ec2844
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
@@ -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.
Expand Down Expand Up @@ -39,6 +39,7 @@
* @author Sebastien Deleuze
* @author Juergen Hoeller
* @since 5.0
* @see HttpHeaders#getAcceptLanguageAsLocales()
*/
public class AcceptHeaderLocaleContextResolver implements LocaleContextResolver {

Expand Down Expand Up @@ -76,6 +77,7 @@ public void setDefaultLocale(@Nullable Locale defaultLocale) {

/**
* The configured default locale, if any.
* <p>This method may be overridden in subclasses.
*/
@Nullable
public Locale getDefaultLocale() {
Expand All @@ -98,7 +100,7 @@ public LocaleContext resolveLocaleContext(ServerWebExchange exchange) {
@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()) {
Expand Down Expand Up @@ -128,7 +130,8 @@ else if (languageMatch == null) {
return languageMatch;
}

return (this.defaultLocale != null ? this.defaultLocale : requestLocales.get(0));
Locale defaultLocale = getDefaultLocale();
return (defaultLocale != null ? defaultLocale : requestLocales.get(0));
}

@Override
Expand Down
@@ -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.
Expand Down Expand Up @@ -83,6 +83,7 @@ public void setDefaultLocale(@Nullable Locale defaultLocale) {

/**
* The configured default locale, if any.
* <p>This method may be overridden in subclasses.
* @since 4.3
*/
@Nullable
Expand Down

0 comments on commit 4ec2844

Please sign in to comment.