Source:
public static String getAccessToken(String userName, String password) { for (User user : User.values()) { if (userName.equals(user.getUserName()) && StringUtils.isNotBlank(user.getAccessToken())) { tokenCache.put(userName, user.getAccessToken()); } } String heliosGetTokenURL = HeliosConfig.getUrl(HeliosConfig.HeliosController.TOKEN); CloseableHttpClient httpClient = getDefaultClient(); if (StringUtils.isNotBlank(getTokenFromCache(userName))) { return tokenCache.get(userName); } HttpPost httpPost = new HttpPost(heliosGetTokenURL); httpPost.setConfig(requestConfig); List<NameValuePair> nvps = new ArrayList<>(); nvps.add(new BasicNameValuePair("grant_type", HeliosConfig.GrantType.PASSWORD.getGrantType())); nvps.add(new BasicNameValuePair("username", userName)); nvps.add(new BasicNameValuePair("password", password)); CloseableHttpResponse response = null; String token = ""; JSONObject responseValue = null; httpPost.setEntity(new UrlEncodedFormEntity(nvps, StandardCharsets.UTF_8)); try { try { response = httpClient.execute(httpPost); } catch (ConnectTimeoutException e) { PageObjectLogging.log("Timeout when connecting to helios", e, true); response = httpClient.execute(httpPost); } HttpEntity entity = response.getEntity(); responseValue = new JSONObject(EntityUtils.toString(entity)); EntityUtils.consume(entity); token = responseValue.getString("access_token"); tokenCache.put(userName, token); } catch (JSONException e) { PageObjectLogging.log("JSON EXCEPTION", ExceptionUtils.getStackTrace(e), false); throw new WebDriverException(e); } catch (ClientProtocolException e) { PageObjectLogging.log("CLIENT PROTOCOL EXCEPTION", ExceptionUtils.getStackTrace(e), false); throw new WebDriverException(e); } catch (IOException e) { PageObjectLogging.log(IOEXCEPTION_COMMAND, IOEXCEPTION_ERROR_MESSAGE + ExceptionUtils.getStackTrace(e), false); throw new WebDriverException(e); } finally { PageObjectLogging.log("LOGIN HEADERS: ", response != null ? response.toString() : null, true); PageObjectLogging.log("LOGIN RESPONSE: ", responseValue != null ? responseValue.toString() : null, true); } return token; }

Target:
public static String getAccessToken(String userName, String password) { for (User user : User.values()) { if (userName.equals(user.getUserName()) && StringUtils.isNotBlank(user.getAccessToken())) { tokenCache.put(userName, user.getAccessToken()); } } String heliosGetTokenURL = HeliosConfig.getUrl(HeliosConfig.HeliosController.TOKEN); CloseableHttpClient httpClient = getDefaultClient(); if (StringUtils.isNotBlank(getTokenFromCache(userName))) { return tokenCache.get(userName); } HttpPost httpPost = new HttpPost(heliosGetTokenURL); httpPost.setConfig(requestConfig); List<NameValuePair> nvps = new ArrayList<>(); nvps.add(new BasicNameValuePair("grant_type", HeliosConfig.GrantType.PASSWORD.getGrantType())); nvps.add(new BasicNameValuePair("username", userName)); nvps.add(new BasicNameValuePair("password", password)); CloseableHttpResponse response = null; String token = ""; httpPost.setEntity(new UrlEncodedFormEntity(nvps, StandardCharsets.UTF_8)); try { try { response = httpClient.execute(httpPost); } catch (ConnectTimeoutException e) { PageObjectLogging.log("Timeout when connecting to helios", e, true); response = httpClient.execute(httpPost); } HttpEntity entity = response.getEntity(); JSONObject responseValue = new JSONObject(EntityUtils.toString(entity)); EntityUtils.consume(entity); token = responseValue.getString("access_token"); tokenCache.put(userName, token); } catch (JSONException e) { PageObjectLogging.log("JSON EXCEPTION", ExceptionUtils.getStackTrace(e), false); throw new WebDriverException(e); } catch (ClientProtocolException e) { PageObjectLogging.log("CLIENT PROTOCOL EXCEPTION", ExceptionUtils.getStackTrace(e), false); throw new WebDriverException(e); } catch (IOException e) { PageObjectLogging.log(IOEXCEPTION_COMMAND, IOEXCEPTION_ERROR_MESSAGE + ExceptionUtils.getStackTrace(e), false); throw new WebDriverException(e); } finally { PageObjectLogging.log("LOGIN HEADERS: ", response != null ? response.toString() : null, true); PageObjectLogging.log("LOGIN RESPONSE: ", response != null ? response.getEntity().toString() : null, true); } return token; }