16
16
17
17
package org .springframework .web .reactive .result .method .annotation ;
18
18
19
+ import java .time .ZoneId ;
20
+ import java .util .Locale ;
21
+ import java .util .TimeZone ;
22
+
23
+ import org .springframework .context .i18n .LocaleContext ;
24
+ import org .springframework .context .i18n .TimeZoneAwareLocaleContext ;
19
25
import org .springframework .core .MethodParameter ;
20
26
import org .springframework .core .ReactiveAdapterRegistry ;
21
27
import org .springframework .http .HttpMethod ;
22
28
import org .springframework .http .HttpRequest ;
23
29
import org .springframework .http .server .reactive .ServerHttpRequest ;
24
30
import org .springframework .http .server .reactive .ServerHttpResponse ;
31
+ import org .springframework .lang .Nullable ;
25
32
import org .springframework .web .reactive .BindingContext ;
26
33
import org .springframework .web .reactive .result .method .HandlerMethodArgumentResolverSupport ;
27
34
import org .springframework .web .reactive .result .method .SyncHandlerMethodArgumentResolver ;
36
43
* <li>{@link ServerHttpRequest}
37
44
* <li>{@link ServerHttpResponse}
38
45
* <li>{@link HttpMethod}
46
+ * <li>{@link Locale}
47
+ * <li>{@link TimeZone}
48
+ * <li>{@link ZoneId}
39
49
* <li>{@link UriBuilder} or {@link UriComponentsBuilder} -- for building URL's
40
50
* relative to the current request
41
51
* </ul>
@@ -63,6 +73,9 @@ public boolean supportsParameter(MethodParameter parameter) {
63
73
ServerHttpRequest .class .isAssignableFrom (type ) ||
64
74
ServerHttpResponse .class .isAssignableFrom (type ) ||
65
75
HttpMethod .class == type ||
76
+ Locale .class == type ||
77
+ TimeZone .class == type ||
78
+ ZoneId .class == type ||
66
79
UriBuilder .class == type || UriComponentsBuilder .class == type );
67
80
}
68
81
@@ -83,6 +96,19 @@ else if (ServerHttpResponse.class.isAssignableFrom(paramType)) {
83
96
else if (HttpMethod .class == paramType ) {
84
97
return exchange .getRequest ().getMethod ();
85
98
}
99
+ else if (Locale .class == paramType ) {
100
+ return exchange .getLocaleContext ().getLocale ();
101
+ }
102
+ else if (TimeZone .class == paramType ) {
103
+ LocaleContext localeContext = exchange .getLocaleContext ();
104
+ TimeZone timeZone = getTimeZone (localeContext );
105
+ return timeZone != null ? timeZone : TimeZone .getDefault ();
106
+ }
107
+ else if (ZoneId .class == paramType ) {
108
+ LocaleContext localeContext = exchange .getLocaleContext ();
109
+ TimeZone timeZone = getTimeZone (localeContext );
110
+ return timeZone != null ? timeZone .toZoneId () : ZoneId .systemDefault ();
111
+ }
86
112
else if (UriBuilder .class == paramType || UriComponentsBuilder .class == paramType ) {
87
113
return UriComponentsBuilder .fromHttpRequest (exchange .getRequest ());
88
114
}
@@ -93,4 +119,13 @@ else if (UriBuilder.class == paramType || UriComponentsBuilder.class == paramTyp
93
119
}
94
120
}
95
121
122
+ @ Nullable
123
+ private TimeZone getTimeZone (LocaleContext localeContext ) {
124
+ TimeZone timeZone = null ;
125
+ if (localeContext instanceof TimeZoneAwareLocaleContext ) {
126
+ timeZone = ((TimeZoneAwareLocaleContext ) localeContext ).getTimeZone ();
127
+ }
128
+ return timeZone ;
129
+ }
130
+
96
131
}
0 commit comments