Source:
private String requestAccessToken() { final Multimap<String, String> params = ArrayListMultimap.create(); params.put("client_id", clientId); params.put("client_secret", clientSecret); params.put("grant_type", "client_credentials"); String response = retryHelper.requestWithRetry(new StringJetty92ResponseEntityReader(readTimeoutMillis), new Jetty92SingleRequester() { @Override public void requestOnce(HttpClient client, Response.Listener responseListener) { Request request = client.newRequest(identityEndPoint + MarketoRESTEndpoint.ACCESS_TOKEN.getEndpoint()).method(HttpMethod.GET); for (String key : params.keySet()) { for (String value : params.get(key)) { request.param(key, value); } } request.send(responseListener); } @Override protected boolean isResponseStatusToRetry(Response response) { return response.getStatus() == 502; } @Override protected boolean isExceptionToRetry(Exception exception) { if (exception instanceof ExecutionException || (exception instanceof IOException && exception.getCause() != null)) { return this.toRetry((Exception) exception.getCause()); } return exception instanceof TimeoutException || exception instanceof SocketTimeoutException || exception instanceof EOFException || super.isExceptionToRetry(exception); } }); MarketoAccessTokenResponse accessTokenResponse; try { accessTokenResponse = OBJECT_MAPPER.readValue(response, MarketoAccessTokenResponse.class); } catch (IOException e) { LOGGER.error("Exception when parse access token response", e); throw new DataException("Can't parse access token response"); } if (accessTokenResponse.hasError()) { throw new DataException(accessTokenResponse.getErrorDescription()); } LOGGER.info("Acquired new access token"); return accessTokenResponse.getAccessToken(); }

Target:
private String requestAccessToken() { final Multimap<String, String> params = ArrayListMultimap.create(); params.put("client_id", clientId); params.put("client_secret", clientSecret); params.put("grant_type", "client_credentials"); String response = retryHelper.requestWithRetry(new StringJetty92ResponseEntityReader(readTimeoutMillis), new Jetty92SingleRequester() { @Override public void requestOnce(HttpClient client, Response.Listener responseListener) { Request request = client.newRequest(identityEndPoint + MarketoRESTEndpoint.ACCESS_TOKEN.getEndpoint()).method(HttpMethod.GET); for (String key : params.keySet()) { for (String value : params.get(key)) { request.param(key, value); } } request.send(responseListener); } @Override protected boolean isResponseStatusToRetry(Response response) { return response.getStatus() == 502; } @Override protected boolean isExceptionToRetry(Exception exception) { if (exception instanceof TimeoutException || exception instanceof SocketTimeoutException || exception instanceof EOFException || super.isExceptionToRetry(exception)) { return true; } if (exception instanceof ExecutionException || (exception instanceof IOException && exception.getCause() != null)) { return this.toRetry((Exception) exception.getCause()); } return false; } }); MarketoAccessTokenResponse accessTokenResponse; try { accessTokenResponse = OBJECT_MAPPER.readValue(response, MarketoAccessTokenResponse.class); } catch (IOException e) { LOGGER.error("Exception when parse access token response", e); throw new DataException("Can't parse access token response"); } if (accessTokenResponse.hasError()) { throw new DataException(accessTokenResponse.getErrorDescription()); } LOGGER.info("Acquired new access token"); return accessTokenResponse.getAccessToken(); }