/** * Executes fetch access token request. * * @param request the http request to fetch access token from the authentication server * @return {@link AccessToken} object containing the access token * @throws IOException IOException in case of a problem or the connection was aborted or if the access token is not * received successfully from the authentication server */ private AccessToken execute(HttpRequest request) throws IOException { HttpResponse response = HttpRequests.execute(request, getHttpRequestConfig()); LOG.debug("Got response {} - {} from {}", response.getResponseCode(), response.getResponseMessage(), pingURI); if (response.getResponseCode() != HttpURLConnection.HTTP_OK) { throw new HttpFailureException(response.getResponseMessage(), response.getResponseCode()); } Map<String, String> responseMap = ObjectResponse.fromJsonBody(response, ACCESS_TOKEN_RESPONSE_TYPE_TOKEN).getResponseObject(); String tokenValue = responseMap.get(ACCESS_TOKEN_KEY); String tokenType = responseMap.get(TOKEN_TYPE_KEY); String expiresInStr = responseMap.get(EXPIRES_IN_KEY); LOG.debug("Response map from auth server: {}", responseMap); if (StringUtils.isEmpty(tokenValue) || StringUtils.isEmpty(tokenType) || StringUtils.isEmpty(expiresInStr)) { throw new IOException("Unexpected response was received from the authentication server."); } return new AccessToken(tokenValue, Long.valueOf(expiresInStr), tokenType); }