boolean requestCookie(HttpConnectionInterceptorContext context) { return requestCookie(context, sessionURL, sessionRequestBody, sessionRequestMimeType, "application/json", new OnExecuteCallable() { @Override public boolean call(HttpConnection connection) throws IOException { if (sessionHasStarted(connection.responseAsInputStream())) { return storeCookiesFromResponse(connection.getConnection()); } else { // If the session did not start, consume the error stream to avoid // leaking connections. Utils.consumeAndCloseStream(connection.getConnection().getErrorStream ()); return false; } } } ); }
private String getBearerToken(HttpConnectionInterceptorContext context) { final AtomicReference<String> iamTokenResponse = new AtomicReference<String>(); boolean result = super.requestCookie(context, iamServerUrl, iamTokenRequestBody, "application/x-www-form-urlencoded", "application/json", new StoreBearerCallable(iamTokenResponse)); if (result) { return iamTokenResponse.get(); } else { return null; } }
return super.requestCookie(context);
@Override public HttpConnectionInterceptorContext interceptResponse(HttpConnectionInterceptorContext context) { // Check if this interceptor is valid before attempting any kind of renewal try { if (shouldAttemptCookieRequest.get()) { HttpURLConnection connection = context.connection.getConnection(); int statusCode = connection.getResponseCode(); if (statusCode == HttpURLConnection.HTTP_UNAUTHORIZED) { boolean success = requestCookie(context); if (success) { context.replayRequest = true; // Consume the error stream to avoid leaking connections Utils.consumeAndCloseStream(connection.getErrorStream()); logger.log(Level.FINEST, "Consumed error response"); } else { context.replayRequest = false; // Don't replay shouldAttemptCookieRequest.set(false); // Set the flag to stop trying } } else { // Store any cookies provided on the response storeCookiesFromResponse(connection); } } } catch (IOException e) { logger.log(Level.SEVERE, "Error reading response code or body from request", e); } return context; }
if (!requestCookie(context)) {