|
41 | 41 | import org.jdom.JDOMException; |
42 | 42 | import org.locationtech.jts.util.Assert; |
43 | 43 | import org.springframework.context.ApplicationContext; |
| 44 | +import org.springframework.util.StringUtils; |
44 | 45 | import org.springframework.web.context.request.RequestContextHolder; |
45 | 46 | import org.springframework.web.context.request.ServletRequestAttributes; |
46 | 47 |
|
@@ -99,14 +100,23 @@ static Map<String, SchemaLocalization> loadSchemaLocalizations(ApplicationContex |
99 | 100 | public static SchemaLocalizations create(String schema) throws IOException, JDOMException { |
100 | 101 | Object obj = RequestContextHolder.getRequestAttributes(); |
101 | 102 |
|
102 | | - ServletRequestAttributes attributes = (ServletRequestAttributes) obj; |
103 | | - HttpServletRequest request = attributes.getRequest(); |
| 103 | + String lang3 = null; |
| 104 | + if (obj instanceof ServletRequestAttributes) { |
104 | 105 |
|
105 | | - final ApplicationContext appContext = ApplicationContextHolder.get(); |
106 | | - final ServiceContext serviceContext = ServiceContext.get(); |
107 | | - final String lang3 = serviceContext != null ? |
108 | | - serviceContext.getLanguage() : |
109 | | - appContext.getBean(LanguageUtils.class).getIso3langCode(request.getLocales()); |
| 106 | + ServletRequestAttributes attributes = (ServletRequestAttributes) obj; |
| 107 | + HttpServletRequest request = attributes.getRequest(); |
| 108 | + |
| 109 | + final ApplicationContext appContext = ApplicationContextHolder.get(); |
| 110 | + final ServiceContext serviceContext = ServiceContext.get(); |
| 111 | + lang3 = serviceContext != null ? |
| 112 | + serviceContext.getLanguage() : |
| 113 | + appContext.getBean(LanguageUtils.class).getIso3langCode(request.getLocales()); |
| 114 | + } |
| 115 | + if (!StringUtils.hasLength(lang3)) { |
| 116 | + // It may be null if executed from a jobs which don't have servlet request attributes. |
| 117 | + // Use the system default locale when language not detected. |
| 118 | + lang3 = Locale.getDefault().getISO3Language(); |
| 119 | + } |
110 | 120 | return create(schema, lang3); |
111 | 121 | } |
112 | 122 |
|
|
0 commit comments