Source:
private AccessTokenResponse doRequest(final String grantType, HttpClient httpClient, final Request request, Fields fields) throws OAuthResponseException, OAuthException, IOException { try { final FormContentProvider entity = new FormContentProvider(fields); final ContentResponse response = AccessController .doPrivileged((PrivilegedExceptionAction<ContentResponse>) () -> { Request requestWithContent = request.content(entity); return requestWithContent.send(); }); int statusCode = response.getStatus(); String content = response.getContentAsString(); if (statusCode == HttpStatus.OK_200) { AccessTokenResponse jsonResponse = gson.fromJson(content, AccessTokenResponse.class); jsonResponse.setCreatedOn(LocalDateTime.now()); logger.info("grant type to URL success", grantType, request.getURI()); return jsonResponse; } else if (statusCode == HttpStatus.BAD_REQUEST_400) { OAuthResponseException errorResponse = gson.fromJson(content, OAuthResponseException.class); logger.error("grant type to URL failed with error code {}, description {}", grantType, request.getURI(), errorResponse.getError(), errorResponse.getErrorDescription()); throw errorResponse; } else { logger.error("grant type to URL failed with HTTP response code {}", grantType, request.getURI(), statusCode); throw new OAuthException("Bad http response, http code " + statusCode); } } catch (PrivilegedActionException pae) { Exception underlyingException = pae.getException(); if (underlyingException instanceof InterruptedException || underlyingException instanceof TimeoutException || underlyingException instanceof ExecutionException) { throw new IOException("Exception in oauth communication, grant type " + grantType, underlyingException); } throw new OAuthException("Exception in oauth communication, grant type " + grantType, underlyingException); } }

Target:
private AccessTokenResponse doRequest(final String grantType, HttpClient httpClient, final Request request, Fields fields) throws OAuthResponseException, OAuthException, IOException { int statusCode = 0; String content = ""; try { final FormContentProvider entity = new FormContentProvider(fields); final ContentResponse response = AccessController .doPrivileged((PrivilegedExceptionAction<ContentResponse>) () -> { Request requestWithContent = request.content(entity); return requestWithContent.send(); }); statusCode = response.getStatus(); content = response.getContentAsString(); if (statusCode == HttpStatus.OK_200) { AccessTokenResponse jsonResponse = gson.fromJson(content, AccessTokenResponse.class); jsonResponse.setCreatedOn(LocalDateTime.now()); logger.info("grant type to URL success", grantType, request.getURI()); return jsonResponse; } else if (statusCode == HttpStatus.BAD_REQUEST_400) { OAuthResponseException errorResponse = gson.fromJson(content, OAuthResponseException.class); logger.error("grant type to URL failed with error code {}, description {}", grantType, request.getURI(), errorResponse.getError(), errorResponse.getErrorDescription()); throw errorResponse; } else { logger.error("grant type to URL failed with HTTP response code {}", grantType, request.getURI(), statusCode); throw new OAuthException("Bad http response, http code " + statusCode); } } catch (PrivilegedActionException pae) { Exception underlyingException = pae.getException(); if (underlyingException instanceof InterruptedException || underlyingException instanceof TimeoutException || underlyingException instanceof ExecutionException) { throw new IOException("Exception in oauth communication, grant type " + grantType, underlyingException); } throw new OAuthException("Exception in oauth communication, grant type " + grantType, underlyingException); } catch (JsonSyntaxException e) { throw new OAuthException(String.format( "Unable to deserialize json into AccessTokenResponse/ OAuthResponseException. httpCode: %i json: %s", statusCode, content), e); } }