Repository navigation
Description
Manuel Jordan opened SPR-16454 and commented
I have a Spring Project 4.3.10.RELEASE, MVC and Rest are tested (working with JUnit 4).
In some scenarios the Accept-Language header is applied. Until here all work fine.
I have created other project working with Spring Project 5.0.3.RELEASE, practically the same infrastructure is used, but all the Test classes have migrated to JUnit 5. Remember the business and infrastructure code remains the same.
When I test MVC it fails with the following error message:
Error Message
range=en_us
Stacktrace
java.lang.IllegalArgumentException: range=en_us
at java.util.Locale$LanguageRange.<init>(Locale.java:2913)
at sun.util.locale.LocaleMatcher.parse(LocaleMatcher.java:284)
at java.util.Locale$LanguageRange.parse(Locale.java:3028)
at org.springframework.http.HttpHeaders.getAcceptLanguage(HttpHeaders.java:479)
at org.springframework.http.HttpHeaders.getAcceptLanguageAsLocales(HttpHeaders.java:499)
at org.springframework.mock.web.MockHttpServletRequest.addHeader(MockHttpServletRequest.java:996)
at org.springframework.test.web.servlet.request.MockHttpServletRequestBuilder.buildRequest(MockHttpServletRequestBuilder.java:624)
at org.springframework.test.web.servlet.MockMvc.perform(MockMvc.java:141)
at com.manuel.jordan.controller.persona.AbstractPersonaDeleteOneControllerTest.deleteOneDeleteTest(AbstractPersonaDeleteOneControllerTest.java:112)
at com.manuel.jordan.controller
What is strange is range=en_us , the Locale is created in this way within an enum new Locale("en","US").
The Rest Test classes fails with:
Error Message
500 Internal Server Error
Stacktrace
org.springframework.web.client.HttpServerErrorException: 500 Internal Server Error
at org.springframework.web.client.DefaultResponseErrorHandler.handleError(DefaultResponseErrorHandler.java:97)
at org.springframework.web.client.DefaultResponseErrorHandler.handleError(DefaultResponseErrorHandler.java:79)
at org.springframework.web.client.ResponseErrorHandler.handleError(ResponseErrorHandler.java:63)
at org.springframework.web.client.RestTemplate.handleResponse(RestTemplate.java:773)
at org.springframework.web.client.RestTemplate.doExecute(RestTemplate.java:726)
at org.springframework.web.client.RestTemplate.execute(RestTemplate.java:700)
at org.springframework.web.client.RestTemplate.exchange(RestTemplate.java:670)
at
Sadly the error message is not useful
Note I get the same error messages if for the first project I create a new branch through Git and use Spring updated to 5.0.3.RELEASE.
Thus not sure if it is bug or something extra about configuration is mandatory now. I am confused
Thanks
Affects: 5.0 GA, 5.0.3
Issue Links:
- Spring WebFlux fails with 500 if Accept-Language is set to an empty string [SPR-15603] #20162 Spring WebFlux fails with 500 if Accept-Language is set to an empty string
- Add HttpHeaders getter and setter for Accept-Language [SPR-15024] #19591 Add HttpHeaders getter and setter for Accept-Language
- Spring MVC in runtime fails when the locale is changed according with BCP 47 [SPR-16775] #21315 Spring MVC in runtime fails when the locale is changed according with BCP 47
- MockHttpServletRequest changes Accept-Language header values [SPR-17566] #22098 MockHttpServletRequest changes Accept-Language header values
Referenced from: commits b3e21ec
Activity
spring-projects-issues commentedon Feb 1, 2018
Juergen Hoeller commented
As far as I can tell, that
Accept-Languageheader is invalid in HTTP: It should really say "en-US" in the BCP 47 language tag format instead of using Java's nativeLocale.toString()format.That said,
MockHttpServletRequest.addHeadershouldn't fail in such a case. It needs to leniently accept invalid header values as well. We'll revise this for 5.0.4.spring-projects-issues commentedon Feb 1, 2018
Manuel Jordan commented
I am confused why you say that
Accept-Languageis invalid if it appears in:I will do a research about
BCP 47in Tags for Identifying LanguagesThanks by the explanation
spring-projects-issues commentedon Feb 1, 2018
Juergen Hoeller commented
I didn't mean to imply that
Accept-Languageas a header was invalid. My point was that your value for it needs to say "en-US" according to the HTTP definitions, not "en_US" (which is just the default representation for ajava.util.Locale).spring-projects-issues commentedon Feb 2, 2018
Manuel Jordan commented
Oh I understand now, sorry by the confusion. Thanks a lot by the quick fix.
Please share the pull request, I want see the code. Thank you.