Why does a GET request to retrieve the current locale for a user result in error 500?

Matthias Küspert November 12, 2017

From my Connect plugin I call /rest/api/2/mypreferences/locale to retrieve the locale currently set for my user. This results in a error 500 (Internal server error).

This is the corresponding log:

2017-11-12 16:28:51.500  INFO 6534 --- [nio-3000-exec-1] c.xqual.jira.xstudio.helper.JiraHelper   : GET from URL: https://kuespert-dev.atlassian.net/rest/api/2/mypreferences/locale
2017-11-12 16:28:51.556 DEBUG 6534 --- [nio-3000-exec-1] a.c.s.i.r.o.JwtBearerAccessTokenProvider : Requesting OAuth 2.0 access token using urn:ietf:params:oauth:grant-type:jwt-bearer
2017-11-12 16:28:51.558 DEBUG 6534 --- [nio-3000-exec-1] .a.c.s.i.r.o.OAuth2JwtAssertionGenerator : Created OAuth 2.0 JWT assertion: {"sub":"urn:atlassian:connect:userkey:admin","aud":"https:\/\/auth.atlassian.io","iss":"urn:atlassian:connect:clientid:eyJob3N0S2V5IjoiZjhlZjY2NzktMTM1NS0zNmM0LTliNmMtMTRmZjEzOGJmMGM4IiwiYWRkb25LZXkiOiJjb20ueHF1YWwuamlyYS5qaXJhLXhzdHVkaW8tY29ubmVjdC1wbHVnaW4ifQ==","tnt":"https:\/\/kuespert-dev.atlassian.net","exp":1510500591,"iat":1510500531}
2017-11-12 16:28:51.604 DEBUG 6534 --- [nio-3000-exec-1] o.s.web.client.RestTemplate              : Created POST request for "https://auth.atlassian.io/oauth2/token"
2017-11-12 16:28:51.650 DEBUG 6534 --- [nio-3000-exec-1] o.s.web.client.RestTemplate              : Setting request Accept header to [application/json, application/json, application/*+json, application/*+json]
2017-11-12 16:28:51.651 DEBUG 6534 --- [nio-3000-exec-1] o.s.web.client.RestTemplate              : Writing [{grant_type=[urn:ietf:params:oauth:grant-type:jwt-bearer], assertion=[eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJzdWIiOiJ1cm46YXRsYXNzaWFuOmNvbm5lY3Q6dXNlcmtleTphZG1pbiIsImF1ZCI6Imh0dHBzOlwvXC9hdXRoLmF0bGFzc2lhbi5pbyIsImlzcyI6InVybjphdGxhc3NpYW46Y29ubmVjdDpjbGllbnRpZDpleUpvYjNOMFMyVjVJam9pWmpobFpqWTJOemt0TVRNMU5TMHpObU0wTFRsaU5tTXRNVFJtWmpFek9HSm1NR000SWl3aVlXUmtiMjVMWlhraU9pSmpiMjB1ZUhGMVlXd3VhbWx5WVM1cWFYSmhMWGh6ZEhWa2FXOHRZMjl1Ym1WamRDMXdiSFZuYVc0aWZRPT0iLCJ0bnQiOiJodHRwczpcL1wva3Vlc3BlcnQtZGV2LmF0bGFzc2lhbi5uZXQiLCJleHAiOjE1MTA1MDA1OTEsImlhdCI6MTUxMDUwMDUzMX0.Cv_v6cBlm_oh4YIS1qnrQly0wYoINLfdLVhVBe7O1Mw]}] as "application/x-www-form-urlencoded" using [org.springframework.http.converter.support.AllEncompassingFormHttpMessageConverter@11f9cbee]
2017-11-12 16:28:53.237 DEBUG 6534 --- [nio-3000-exec-1] o.s.web.client.RestTemplate              : POST request for "https://auth.atlassian.io/oauth2/token" resulted in 200 (OK)
2017-11-12 16:28:53.240 DEBUG 6534 --- [nio-3000-exec-1] o.s.web.client.RestTemplate              : Reading [java.util.Map<java.lang.String, java.lang.String>] as "application/json;charset=UTF-8" using [org.springframework.http.converter.json.MappingJackson2HttpMessageConverter@25dfb380]
2017-11-12 16:28:54.016 DEBUG 6534 --- [nio-3000-exec-1] .m.m.a.ExceptionHandlerExceptionResolver : Resolving exception from handler [public java.lang.String com.xqual.jira.xstudio.configuration.ConfigurationController.getEditPage(com.atlassian.connect.spring.AtlassianHostUser,org.springframework.ui.Model)]: org.springframework.web.client.HttpServerErrorException: 500 Internal Server Error
2017-11-12 16:28:54.017 DEBUG 6534 --- [nio-3000-exec-1] .w.s.m.a.ResponseStatusExceptionResolver : Resolving exception from handler [public java.lang.String com.xqual.jira.xstudio.configuration.ConfigurationController.getEditPage(com.atlassian.connect.spring.AtlassianHostUser,org.springframework.ui.Model)]: org.springframework.web.client.HttpServerErrorException: 500 Internal Server Error
2017-11-12 16:28:54.017 DEBUG 6534 --- [nio-3000-exec-1] .w.s.m.s.DefaultHandlerExceptionResolver : Resolving exception from handler [public java.lang.String com.xqual.jira.xstudio.configuration.ConfigurationController.getEditPage(com.atlassian.connect.spring.AtlassianHostUser,org.springframework.ui.Model)]: org.springframework.web.client.HttpServerErrorException: 500 Internal Server Error
2017-11-12 16:28:54.019 TRACE 6534 --- [nio-3000-exec-1] o.s.web.servlet.DispatcherServlet        : Cleared thread-bound request context: org.springframework.web.util.ContentCachingRequestWrapper@4e102ab4
2017-11-12 16:28:54.046 DEBUG 6534 --- [nio-3000-exec-1] o.s.web.servlet.DispatcherServlet        : Could not complete request

org.springframework.web.client.HttpServerErrorException: 500 Internal Server Error
    at org.springframework.web.client.DefaultResponseErrorHandler.handleError(DefaultResponseErrorHandler.java:81) ~[spring-web-4.3.12.RELEASE.jar:4.3.12.RELEASE]

And this is the code:

private static final Logger LOG = LoggerFactory.getLogger(JiraHelper.class);

private static final String JIRA_REST_BASE_PATH = "/rest/api/2/";

private static <T> T getJiraValue(RestTemplate template, String baseUrl, String restPath, Class<T> type) {
String url = baseUrl + JIRA_REST_BASE_PATH + restPath;
LOG.info("GET from URL: {}", url);
ResponseEntity<T> result = template.getForEntity(url, type);
LOG.info("Response status = {}", result.getStatusCode().toString());
return result.getBody();
}

public static Locale getCurrentLocale(RestTemplate template, String baseUrl) {
String jiraLocale = getJiraValue(template, baseUrl, "mypreferences/locale", String.class);
LOG.info("Jira user locale is: {}", jiraLocale);
Locale locale = new Locale(jiraLocale);
return locale;
}

Locale locale = JiraHelper.getCurrentLocale(atlassianHostRestClients.authenticatedAsHostActor(), hostBaseUrl);

If I try the same URL in my browser while being authenticated in another tab, I get the correct locale.

Any ideas what's wrong with the code?

0 answers

Suggest an answer

Log in or Sign up to answer