diff --git a/apis/cloudstack/src/main/java/org/jclouds/cloudstack/handlers/RetryOnRenewAndLogoutOnClose.java b/apis/cloudstack/src/main/java/org/jclouds/cloudstack/handlers/RetryOnRenewAndLogoutOnClose.java index 1b3c0b07f5..35487f436b 100644 --- a/apis/cloudstack/src/main/java/org/jclouds/cloudstack/handlers/RetryOnRenewAndLogoutOnClose.java +++ b/apis/cloudstack/src/main/java/org/jclouds/cloudstack/handlers/RetryOnRenewAndLogoutOnClose.java @@ -18,12 +18,9 @@ */ package org.jclouds.cloudstack.handlers; -import static org.jclouds.http.HttpUtils.closeClientButKeepContentStream; -import static org.jclouds.http.HttpUtils.releasePayload; - -import javax.annotation.PreDestroy; -import javax.annotation.Resource; - +import com.google.common.cache.LoadingCache; +import com.google.inject.Inject; +import com.google.inject.Singleton; import org.jclouds.cloudstack.domain.LoginResponse; import org.jclouds.cloudstack.features.SessionClient; import org.jclouds.domain.Credentials; @@ -32,9 +29,10 @@ import org.jclouds.http.HttpResponse; import org.jclouds.http.HttpRetryHandler; import org.jclouds.logging.Logger; -import com.google.common.cache.LoadingCache; -import com.google.inject.Inject; -import com.google.inject.Singleton; +import javax.annotation.PreDestroy; +import javax.annotation.Resource; + +import static org.jclouds.http.HttpUtils.releasePayload; /** * This will parse and set an appropriate exception on the command object. @@ -59,18 +57,14 @@ public class RetryOnRenewAndLogoutOnClose implements HttpRetryHandler { @Override public boolean shouldRetryRequest(HttpCommand command, HttpResponse response) { - boolean retry = false; // default try { switch (response.getStatusCode()) { case 401: - byte[] content = closeClientButKeepContentStream(response); - if (new String(content).equals("TODO: What state can we retry?")) { - logger.debug("invalidating session"); - authenticationResponseCache.invalidateAll(); - retry = true; - } + authenticationResponseCache.invalidateAll(); + return true; } - return retry; + return false; + } finally { releasePayload(response); } diff --git a/apis/cloudstack/src/test/java/org/jclouds/cloudstack/handlers/RetryOnRenewAndLogoutOnCloseTest.java b/apis/cloudstack/src/test/java/org/jclouds/cloudstack/handlers/RetryOnRenewAndLogoutOnCloseTest.java index 36622d8448..cdfd66d4e5 100644 --- a/apis/cloudstack/src/test/java/org/jclouds/cloudstack/handlers/RetryOnRenewAndLogoutOnCloseTest.java +++ b/apis/cloudstack/src/test/java/org/jclouds/cloudstack/handlers/RetryOnRenewAndLogoutOnCloseTest.java @@ -18,12 +18,7 @@ */ package org.jclouds.cloudstack.handlers; -import static org.easymock.EasyMock.createMock; -import static org.easymock.EasyMock.expectLastCall; -import static org.easymock.EasyMock.replay; -import static org.easymock.EasyMock.verify; -import static org.testng.Assert.assertTrue; - +import com.google.common.cache.LoadingCache; import org.jclouds.cloudstack.domain.LoginResponse; import org.jclouds.cloudstack.features.SessionClient; import org.jclouds.domain.Credentials; @@ -32,11 +27,15 @@ import org.jclouds.http.HttpResponse; import org.jclouds.io.Payloads; import org.testng.annotations.Test; -import com.google.common.cache.LoadingCache; +import static org.easymock.EasyMock.createMock; +import static org.easymock.EasyMock.expectLastCall; +import static org.easymock.EasyMock.replay; +import static org.easymock.EasyMock.verify; +import static org.testng.Assert.assertTrue; /** * Tests behavior of {@code RetryOnRenewAndLogoutOnClose} handler - * + * * @author grkvlt@apache.org */ @Test(groups = "unit", testName = "RetryOnRenewAndLogoutOnCloseTest") @@ -54,7 +53,7 @@ public class RetryOnRenewAndLogoutOnCloseTest { replay(cache, command); HttpResponse response = HttpResponse.builder().payload( - Payloads.newStringPayload("TODO: What state can we retry?")).statusCode(401).build(); + Payloads.newStringPayload("Not relevant")).statusCode(401).build(); RetryOnRenewAndLogoutOnClose retry = new RetryOnRenewAndLogoutOnClose(cache, sessionClient);