You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hc.apache.org by ol...@apache.org on 2017/05/01 11:11:11 UTC
svn commit: r1793308 [7/11] - in /httpcomponents/httpclient/trunk:
httpclient5-cache/src/main/java/org/apache/hc/client5/http/impl/cache/
httpclient5-cache/src/test/java/org/apache/hc/client5/http/impl/cache/
httpclient5-cache/src/test/java/org/apache/...
Modified: httpcomponents/httpclient/trunk/httpclient5-cache/src/test/java/org/apache/hc/client5/http/impl/cache/TestRFC5861Compliance.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient5-cache/src/test/java/org/apache/hc/client5/http/impl/cache/TestRFC5861Compliance.java?rev=1793308&r1=1793307&r2=1793308&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient5-cache/src/test/java/org/apache/hc/client5/http/impl/cache/TestRFC5861Compliance.java (original)
+++ httpcomponents/httpclient/trunk/httpclient5-cache/src/test/java/org/apache/hc/client5/http/impl/cache/TestRFC5861Compliance.java Mon May 1 11:11:09 2017
@@ -33,8 +33,8 @@ import static org.junit.Assert.assertTru
import java.io.ByteArrayInputStream;
import java.util.Date;
-import org.apache.hc.client5.http.impl.sync.RoutedHttpRequest;
import org.apache.hc.client5.http.utils.DateUtils;
+import org.apache.hc.core5.http.ClassicHttpRequest;
import org.apache.hc.core5.http.ClassicHttpResponse;
import org.apache.hc.core5.http.Header;
import org.apache.hc.core5.http.HttpEntity;
@@ -69,20 +69,20 @@ public class TestRFC5861Compliance exten
public void testStaleIfErrorInResponseIsTrueReturnsStaleEntryWithWarning()
throws Exception{
final Date tenSecondsAgo = new Date(new Date().getTime() - 10 * 1000L);
- final RoutedHttpRequest req1 = RoutedHttpRequest.adapt(HttpTestUtils.makeDefaultRequest(), route);
+ final ClassicHttpRequest req1 = HttpTestUtils.makeDefaultRequest();
final ClassicHttpResponse resp1 = HttpTestUtils.make200Response(tenSecondsAgo,
"public, max-age=5, stale-if-error=60");
backendExpectsAnyRequestAndReturn(resp1);
- final RoutedHttpRequest req2 = RoutedHttpRequest.adapt(HttpTestUtils.makeDefaultRequest(), route);
+ final ClassicHttpRequest req2 = HttpTestUtils.makeDefaultRequest();
final ClassicHttpResponse resp2 = HttpTestUtils.make500Response();
backendExpectsAnyRequestAndReturn(resp2);
replayMocks();
- impl.execute(req1, context, null);
- final ClassicHttpResponse result = impl.execute(req2, context, null);
+ execute(req1);
+ final ClassicHttpResponse result = execute(req2);
verifyMocks();
HttpTestUtils.assert110WarningFound(result);
@@ -92,13 +92,13 @@ public class TestRFC5861Compliance exten
public void testConsumesErrorResponseWhenServingStale()
throws Exception{
final Date tenSecondsAgo = new Date(new Date().getTime() - 10 * 1000L);
- final RoutedHttpRequest req1 = RoutedHttpRequest.adapt(HttpTestUtils.makeDefaultRequest(), route);
+ final ClassicHttpRequest req1 = HttpTestUtils.makeDefaultRequest();
final ClassicHttpResponse resp1 = HttpTestUtils.make200Response(tenSecondsAgo,
"public, max-age=5, stale-if-error=60");
backendExpectsAnyRequestAndReturn(resp1);
- final RoutedHttpRequest req2 = RoutedHttpRequest.adapt(HttpTestUtils.makeDefaultRequest(), route);
+ final ClassicHttpRequest req2 = HttpTestUtils.makeDefaultRequest();
final ClassicHttpResponse resp2 = HttpTestUtils.make500Response();
final byte[] body101 = HttpTestUtils.getRandomBytes(101);
final ByteArrayInputStream buf = new ByteArrayInputStream(body101);
@@ -109,8 +109,8 @@ public class TestRFC5861Compliance exten
backendExpectsAnyRequestAndReturn(resp2);
replayMocks();
- impl.execute(req1, context, null);
- impl.execute(req2, context, null);
+ execute(req1);
+ execute(req2);
verifyMocks();
assertTrue(cis.wasClosed());
@@ -120,20 +120,20 @@ public class TestRFC5861Compliance exten
public void testStaleIfErrorInResponseYieldsToMustRevalidate()
throws Exception{
final Date tenSecondsAgo = new Date(new Date().getTime() - 10 * 1000L);
- final RoutedHttpRequest req1 = RoutedHttpRequest.adapt(HttpTestUtils.makeDefaultRequest(), route);
+ final ClassicHttpRequest req1 = HttpTestUtils.makeDefaultRequest();
final ClassicHttpResponse resp1 = HttpTestUtils.make200Response(tenSecondsAgo,
"public, max-age=5, stale-if-error=60, must-revalidate");
backendExpectsAnyRequestAndReturn(resp1);
- final RoutedHttpRequest req2 = RoutedHttpRequest.adapt(HttpTestUtils.makeDefaultRequest(), route);
+ final ClassicHttpRequest req2 = HttpTestUtils.makeDefaultRequest();
final ClassicHttpResponse resp2 = HttpTestUtils.make500Response();
backendExpectsAnyRequestAndReturn(resp2);
replayMocks();
- impl.execute(req1, context, null);
- final ClassicHttpResponse result = impl.execute(req2, context, null);
+ execute(req1);
+ final ClassicHttpResponse result = execute(req2);
verifyMocks();
assertTrue(HttpStatus.SC_OK != result.getCode());
@@ -144,20 +144,20 @@ public class TestRFC5861Compliance exten
throws Exception{
assertTrue(config.isSharedCache());
final Date tenSecondsAgo = new Date(new Date().getTime() - 10 * 1000L);
- final RoutedHttpRequest req1 = RoutedHttpRequest.adapt(HttpTestUtils.makeDefaultRequest(), route);
+ final ClassicHttpRequest req1 = HttpTestUtils.makeDefaultRequest();
final ClassicHttpResponse resp1 = HttpTestUtils.make200Response(tenSecondsAgo,
"public, max-age=5, stale-if-error=60, proxy-revalidate");
backendExpectsAnyRequestAndReturn(resp1);
- final RoutedHttpRequest req2 = RoutedHttpRequest.adapt(HttpTestUtils.makeDefaultRequest(), route);
+ final ClassicHttpRequest req2 = HttpTestUtils.makeDefaultRequest();
final ClassicHttpResponse resp2 = HttpTestUtils.make500Response();
backendExpectsAnyRequestAndReturn(resp2);
replayMocks();
- impl.execute(req1, context, null);
- final ClassicHttpResponse result = impl.execute(req2, context, null);
+ execute(req1);
+ final ClassicHttpResponse result = execute(req2);
verifyMocks();
assertTrue(HttpStatus.SC_OK != result.getCode());
@@ -168,23 +168,23 @@ public class TestRFC5861Compliance exten
throws Exception{
final CacheConfig configUnshared = CacheConfig.custom()
.setSharedCache(false).build();
- impl = new CachingExec(mockBackend, new BasicHttpCache(configUnshared), configUnshared);
+ impl = new CachingExec(new BasicHttpCache(configUnshared), configUnshared);
final Date tenSecondsAgo = new Date(new Date().getTime() - 10 * 1000L);
- final RoutedHttpRequest req1 = RoutedHttpRequest.adapt(HttpTestUtils.makeDefaultRequest(), route);
+ final ClassicHttpRequest req1 = HttpTestUtils.makeDefaultRequest();
final ClassicHttpResponse resp1 = HttpTestUtils.make200Response(tenSecondsAgo,
"public, max-age=5, stale-if-error=60, proxy-revalidate");
backendExpectsAnyRequestAndReturn(resp1);
- final RoutedHttpRequest req2 = RoutedHttpRequest.adapt(HttpTestUtils.makeDefaultRequest(), route);
+ final ClassicHttpRequest req2 = HttpTestUtils.makeDefaultRequest();
final ClassicHttpResponse resp2 = HttpTestUtils.make500Response();
backendExpectsAnyRequestAndReturn(resp2);
replayMocks();
- impl.execute(req1, context, null);
- final ClassicHttpResponse result = impl.execute(req2, context, null);
+ execute(req1);
+ final ClassicHttpResponse result = execute(req2);
verifyMocks();
HttpTestUtils.assert110WarningFound(result);
@@ -194,21 +194,21 @@ public class TestRFC5861Compliance exten
public void testStaleIfErrorInResponseYieldsToExplicitFreshnessRequest()
throws Exception{
final Date tenSecondsAgo = new Date(new Date().getTime() - 10 * 1000L);
- final RoutedHttpRequest req1 = RoutedHttpRequest.adapt(HttpTestUtils.makeDefaultRequest(), route);
+ final ClassicHttpRequest req1 = HttpTestUtils.makeDefaultRequest();
final ClassicHttpResponse resp1 = HttpTestUtils.make200Response(tenSecondsAgo,
"public, max-age=5, stale-if-error=60");
backendExpectsAnyRequestAndReturn(resp1);
- final RoutedHttpRequest req2 = RoutedHttpRequest.adapt(HttpTestUtils.makeDefaultRequest(), route);
+ final ClassicHttpRequest req2 = HttpTestUtils.makeDefaultRequest();
req2.setHeader("Cache-Control","min-fresh=2");
final ClassicHttpResponse resp2 = HttpTestUtils.make500Response();
backendExpectsAnyRequestAndReturn(resp2);
replayMocks();
- impl.execute(req1, context, null);
- final ClassicHttpResponse result = impl.execute(req2, context, null);
+ execute(req1);
+ final ClassicHttpResponse result = execute(req2);
verifyMocks();
assertTrue(HttpStatus.SC_OK != result.getCode());
@@ -218,21 +218,21 @@ public class TestRFC5861Compliance exten
public void testStaleIfErrorInRequestIsTrueReturnsStaleEntryWithWarning()
throws Exception{
final Date tenSecondsAgo = new Date(new Date().getTime() - 10 * 1000L);
- final RoutedHttpRequest req1 = RoutedHttpRequest.adapt(HttpTestUtils.makeDefaultRequest(), route);
+ final ClassicHttpRequest req1 = HttpTestUtils.makeDefaultRequest();
final ClassicHttpResponse resp1 = HttpTestUtils.make200Response(tenSecondsAgo,
"public, max-age=5");
backendExpectsAnyRequestAndReturn(resp1);
- final RoutedHttpRequest req2 = RoutedHttpRequest.adapt(HttpTestUtils.makeDefaultRequest(), route);
+ final ClassicHttpRequest req2 = HttpTestUtils.makeDefaultRequest();
req2.setHeader("Cache-Control","public, stale-if-error=60");
final ClassicHttpResponse resp2 = HttpTestUtils.make500Response();
backendExpectsAnyRequestAndReturn(resp2);
replayMocks();
- impl.execute(req1, context, null);
- final ClassicHttpResponse result = impl.execute(req2, context, null);
+ execute(req1);
+ final ClassicHttpResponse result = execute(req2);
verifyMocks();
HttpTestUtils.assert110WarningFound(result);
@@ -242,22 +242,22 @@ public class TestRFC5861Compliance exten
public void testStaleIfErrorInRequestIsTrueReturnsStaleNonRevalidatableEntryWithWarning()
throws Exception {
final Date tenSecondsAgo = new Date(new Date().getTime() - 10 * 1000L);
- final RoutedHttpRequest req1 = RoutedHttpRequest.adapt(HttpTestUtils.makeDefaultRequest(), route);
+ final ClassicHttpRequest req1 = HttpTestUtils.makeDefaultRequest();
final ClassicHttpResponse resp1 = HttpTestUtils.make200Response();
resp1.setHeader("Date", DateUtils.formatDate(tenSecondsAgo));
resp1.setHeader("Cache-Control", "public, max-age=5");
backendExpectsAnyRequestAndReturn(resp1);
- final RoutedHttpRequest req2 = RoutedHttpRequest.adapt(HttpTestUtils.makeDefaultRequest(), route);
+ final ClassicHttpRequest req2 = HttpTestUtils.makeDefaultRequest();
req2.setHeader("Cache-Control", "public, stale-if-error=60");
final ClassicHttpResponse resp2 = HttpTestUtils.make500Response();
backendExpectsAnyRequestAndReturn(resp2);
replayMocks();
- impl.execute(req1, context, null);
- final ClassicHttpResponse result = impl.execute(req2, context, null);
+ execute(req1);
+ final ClassicHttpResponse result = execute(req2);
verifyMocks();
HttpTestUtils.assert110WarningFound(result);
@@ -268,20 +268,20 @@ public class TestRFC5861Compliance exten
throws Exception{
final Date now = new Date();
final Date tenSecondsAgo = new Date(now.getTime() - 10 * 1000L);
- final RoutedHttpRequest req1 = RoutedHttpRequest.adapt(HttpTestUtils.makeDefaultRequest(), route);
+ final ClassicHttpRequest req1 = HttpTestUtils.makeDefaultRequest();
final ClassicHttpResponse resp1 = HttpTestUtils.make200Response(tenSecondsAgo,
"public, max-age=5, stale-if-error=2");
backendExpectsAnyRequestAndReturn(resp1);
- final RoutedHttpRequest req2 = RoutedHttpRequest.adapt(HttpTestUtils.makeDefaultRequest(), route);
+ final ClassicHttpRequest req2 = HttpTestUtils.makeDefaultRequest();
final ClassicHttpResponse resp2 = HttpTestUtils.make500Response();
backendExpectsAnyRequestAndReturn(resp2);
replayMocks();
- impl.execute(req1, context, null);
- final ClassicHttpResponse result = impl.execute(req2, context, null);
+ execute(req1);
+ final ClassicHttpResponse result = execute(req2);
verifyMocks();
assertEquals(HttpStatus.SC_INTERNAL_SERVER_ERROR,
@@ -293,21 +293,21 @@ public class TestRFC5861Compliance exten
throws Exception{
final Date now = new Date();
final Date tenSecondsAgo = new Date(now.getTime() - 10 * 1000L);
- final RoutedHttpRequest req1 = RoutedHttpRequest.adapt(HttpTestUtils.makeDefaultRequest(), route);
+ final ClassicHttpRequest req1 = HttpTestUtils.makeDefaultRequest();
final ClassicHttpResponse resp1 = HttpTestUtils.make200Response(tenSecondsAgo,
"public, max-age=5");
backendExpectsAnyRequestAndReturn(resp1);
- final RoutedHttpRequest req2 = RoutedHttpRequest.adapt(HttpTestUtils.makeDefaultRequest(), route);
+ final ClassicHttpRequest req2 = HttpTestUtils.makeDefaultRequest();
req2.setHeader("Cache-Control","stale-if-error=2");
final ClassicHttpResponse resp2 = HttpTestUtils.make500Response();
backendExpectsAnyRequestAndReturn(resp2);
replayMocks();
- impl.execute(req1, context, null);
- final ClassicHttpResponse result = impl.execute(req2, context, null);
+ execute(req1);
+ final ClassicHttpResponse result = execute(req2);
verifyMocks();
assertEquals(HttpStatus.SC_INTERNAL_SERVER_ERROR,
@@ -331,10 +331,9 @@ public class TestRFC5861Compliance exten
.setAsynchronousWorkersMax(1)
.build();
- impl = new CachingExec(mockBackend, cache, config, new AsynchronousValidator(config));
+ impl = new CachingExec(cache, config, new AsynchronousValidator(config));
- final RoutedHttpRequest req1 = RoutedHttpRequest.adapt(
- new BasicClassicHttpRequest("GET", "/"), route);
+ final ClassicHttpRequest req1 = new BasicClassicHttpRequest("GET", "/");
final ClassicHttpResponse resp1 = HttpTestUtils.make200Response();
final Date now = new Date();
final Date tenSecondsAgo = new Date(now.getTime() - 10 * 1000L);
@@ -344,12 +343,11 @@ public class TestRFC5861Compliance exten
backendExpectsAnyRequestAndReturn(resp1).times(1,2);
- final RoutedHttpRequest req2 = RoutedHttpRequest.adapt(
- new BasicClassicHttpRequest("GET", "/"), route);
+ final ClassicHttpRequest req2 = new BasicClassicHttpRequest("GET", "/");
replayMocks();
- impl.execute(req1, context, null);
- final ClassicHttpResponse result = impl.execute(req2, context, null);
+ execute(req1);
+ final ClassicHttpResponse result = execute(req2);
verifyMocks();
assertEquals(HttpStatus.SC_OK, result.getCode());
@@ -367,7 +365,7 @@ public class TestRFC5861Compliance exten
@Test
public void testHTTPCLIENT1470() {
- impl = new CachingExec(mockBackend, cache, null, new AsynchronousValidator(config));
+ impl = new CachingExec(cache, null, new AsynchronousValidator(config));
}
@Test
@@ -376,9 +374,9 @@ public class TestRFC5861Compliance exten
config = CacheConfig.custom().setMaxCacheEntries(MAX_ENTRIES).setMaxObjectSize(MAX_BYTES)
.setAsynchronousWorkersMax(1).build();
- impl = new CachingExec(mockBackend, cache, config, new AsynchronousValidator(config));
+ impl = new CachingExec(cache, config, new AsynchronousValidator(config));
- final RoutedHttpRequest req1 = RoutedHttpRequest.adapt(new BasicClassicHttpRequest("GET", "/"), route);
+ final ClassicHttpRequest req1 = new BasicClassicHttpRequest("GET", "/");
final ClassicHttpResponse resp1 = HttpTestUtils.make200Response();
final Date now = new Date();
final Date tenSecondsAgo = new Date(now.getTime() - 10 * 1000L);
@@ -387,11 +385,11 @@ public class TestRFC5861Compliance exten
backendExpectsAnyRequestAndReturn(resp1).times(1, 2);
- final RoutedHttpRequest req2 = RoutedHttpRequest.adapt(new BasicClassicHttpRequest("GET", "/"), route);
+ final ClassicHttpRequest req2 = new BasicClassicHttpRequest("GET", "/");
replayMocks();
- impl.execute(req1, context, null);
- final ClassicHttpResponse result = impl.execute(req2, context, null);
+ execute(req1);
+ final ClassicHttpResponse result = execute(req2);
verifyMocks();
assertEquals(HttpStatus.SC_OK, result.getCode());
@@ -417,10 +415,9 @@ public class TestRFC5861Compliance exten
.setAsynchronousWorkersMax(1)
.setSharedCache(false)
.build();
- impl = new CachingExec(mockBackend, cache, config, new AsynchronousValidator(config));
+ impl = new CachingExec(cache, config, new AsynchronousValidator(config));
- final RoutedHttpRequest req1 = RoutedHttpRequest.adapt(
- new BasicClassicHttpRequest("GET", "/"), route);
+ final ClassicHttpRequest req1 = new BasicClassicHttpRequest("GET", "/");
final ClassicHttpResponse resp1 = HttpTestUtils.make200Response();
final Date now = new Date();
final Date tenSecondsAgo = new Date(now.getTime() - 10 * 1000L);
@@ -430,13 +427,12 @@ public class TestRFC5861Compliance exten
backendExpectsAnyRequestAndReturn(resp1).times(1,2);
- final RoutedHttpRequest req2 = RoutedHttpRequest.adapt(
- new BasicClassicHttpRequest("GET", "/"), route);
+ final ClassicHttpRequest req2 = new BasicClassicHttpRequest("GET", "/");
req2.setHeader("If-None-Match","\"etag\"");
replayMocks();
- impl.execute(req1, context, null);
- final ClassicHttpResponse result = impl.execute(req2, context, null);
+ execute(req1);
+ final ClassicHttpResponse result = execute(req2);
verifyMocks();
assertEquals(HttpStatus.SC_NOT_MODIFIED, result.getCode());
@@ -465,10 +461,9 @@ public class TestRFC5861Compliance exten
.setMaxObjectSize(MAX_BYTES)
.setAsynchronousWorkersMax(1)
.build();
- impl = new CachingExec(mockBackend, cache, config);
+ impl = new CachingExec(cache, config);
- final RoutedHttpRequest req1 = RoutedHttpRequest.adapt(
- new BasicClassicHttpRequest("GET", "/"), route);
+ final ClassicHttpRequest req1 = new BasicClassicHttpRequest("GET", "/");
final ClassicHttpResponse resp1 = HttpTestUtils.make200Response();
resp1.setHeader("Cache-Control", "public, max-age=5, stale-while-revalidate=15, must-revalidate");
resp1.setHeader("ETag","\"etag\"");
@@ -476,8 +471,7 @@ public class TestRFC5861Compliance exten
backendExpectsAnyRequestAndReturn(resp1);
- final RoutedHttpRequest req2 = RoutedHttpRequest.adapt(
- new BasicClassicHttpRequest("GET", "/"), route);
+ final ClassicHttpRequest req2 = new BasicClassicHttpRequest("GET", "/");
final ClassicHttpResponse resp2 = HttpTestUtils.make200Response();
resp2.setHeader("Cache-Control", "public, max-age=5, stale-while-revalidate=15, must-revalidate");
resp2.setHeader("ETag","\"etag\"");
@@ -486,8 +480,8 @@ public class TestRFC5861Compliance exten
backendExpectsAnyRequestAndReturn(resp2);
replayMocks();
- impl.execute(req1, context, null);
- final ClassicHttpResponse result = impl.execute(req2, context, null);
+ execute(req1);
+ final ClassicHttpResponse result = execute(req2);
verifyMocks();
assertEquals(HttpStatus.SC_OK, result.getCode());
@@ -516,10 +510,9 @@ public class TestRFC5861Compliance exten
.setAsynchronousWorkersMax(1)
.setSharedCache(true)
.build();
- impl = new CachingExec(mockBackend, cache, config);
+ impl = new CachingExec(cache, config);
- final RoutedHttpRequest req1 = RoutedHttpRequest.adapt(
- new BasicClassicHttpRequest("GET", "/"), route);
+ final ClassicHttpRequest req1 = new BasicClassicHttpRequest("GET", "/");
final ClassicHttpResponse resp1 = HttpTestUtils.make200Response();
resp1.setHeader("Cache-Control", "public, max-age=5, stale-while-revalidate=15, proxy-revalidate");
resp1.setHeader("ETag","\"etag\"");
@@ -527,8 +520,7 @@ public class TestRFC5861Compliance exten
backendExpectsAnyRequestAndReturn(resp1);
- final RoutedHttpRequest req2 = RoutedHttpRequest.adapt(
- new BasicClassicHttpRequest("GET", "/"), route);
+ final ClassicHttpRequest req2 = new BasicClassicHttpRequest("GET", "/");
final ClassicHttpResponse resp2 = HttpTestUtils.make200Response();
resp2.setHeader("Cache-Control", "public, max-age=5, stale-while-revalidate=15, proxy-revalidate");
resp2.setHeader("ETag","\"etag\"");
@@ -537,8 +529,8 @@ public class TestRFC5861Compliance exten
backendExpectsAnyRequestAndReturn(resp2);
replayMocks();
- impl.execute(req1, context, null);
- final ClassicHttpResponse result = impl.execute(req2, context, null);
+ execute(req1);
+ final ClassicHttpResponse result = execute(req2);
verifyMocks();
assertEquals(HttpStatus.SC_OK, result.getCode());
@@ -567,10 +559,9 @@ public class TestRFC5861Compliance exten
.setAsynchronousWorkersMax(1)
.setSharedCache(true)
.build();
- impl = new CachingExec(mockBackend, cache, config);
+ impl = new CachingExec(cache, config);
- final RoutedHttpRequest req1 = RoutedHttpRequest.adapt(
- new BasicClassicHttpRequest("GET", "/"), route);
+ final ClassicHttpRequest req1 = new BasicClassicHttpRequest("GET", "/");
final ClassicHttpResponse resp1 = HttpTestUtils.make200Response();
resp1.setHeader("Cache-Control", "public, max-age=5, stale-while-revalidate=15");
resp1.setHeader("ETag","\"etag\"");
@@ -578,8 +569,7 @@ public class TestRFC5861Compliance exten
backendExpectsAnyRequestAndReturn(resp1);
- final RoutedHttpRequest req2 = RoutedHttpRequest.adapt(
- new BasicClassicHttpRequest("GET", "/"), route);
+ final ClassicHttpRequest req2 = new BasicClassicHttpRequest("GET", "/");
req2.setHeader("Cache-Control","min-fresh=2");
final ClassicHttpResponse resp2 = HttpTestUtils.make200Response();
resp2.setHeader("Cache-Control", "public, max-age=5, stale-while-revalidate=15");
@@ -589,8 +579,8 @@ public class TestRFC5861Compliance exten
backendExpectsAnyRequestAndReturn(resp2);
replayMocks();
- impl.execute(req1, context, null);
- final ClassicHttpResponse result = impl.execute(req2, context, null);
+ execute(req1);
+ final ClassicHttpResponse result = execute(req2);
verifyMocks();
assertEquals(HttpStatus.SC_OK, result.getCode());
Modified: httpcomponents/httpclient/trunk/httpclient5-cache/src/test/java/org/apache/hc/client5/http/impl/cache/TestRequestProtocolCompliance.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient5-cache/src/test/java/org/apache/hc/client5/http/impl/cache/TestRequestProtocolCompliance.java?rev=1793308&r1=1793307&r2=1793308&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient5-cache/src/test/java/org/apache/hc/client5/http/impl/cache/TestRequestProtocolCompliance.java (original)
+++ httpcomponents/httpclient/trunk/httpclient5-cache/src/test/java/org/apache/hc/client5/http/impl/cache/TestRequestProtocolCompliance.java Mon May 1 11:11:09 2017
@@ -32,11 +32,9 @@ import static org.junit.Assert.assertTru
import java.util.Arrays;
-import org.apache.hc.client5.http.HttpRoute;
+import org.apache.hc.client5.http.impl.ExecSupport;
import org.apache.hc.client5.http.sync.methods.HttpPut;
-import org.apache.hc.client5.http.impl.sync.RoutedHttpRequest;
import org.apache.hc.core5.http.ClassicHttpRequest;
-import org.apache.hc.core5.http.HttpHost;
import org.apache.hc.core5.http.HttpVersion;
import org.apache.hc.core5.http.ProtocolVersion;
import org.apache.hc.core5.http.message.BasicClassicHttpRequest;
@@ -45,13 +43,11 @@ import org.junit.Test;
public class TestRequestProtocolCompliance {
- private HttpRoute route;
private RequestProtocolCompliance impl;
private ClassicHttpRequest req;
@Before
public void setUp() {
- route = new HttpRoute(new HttpHost("foo.example.com", 80));
req = HttpTestUtils.makeDefaultRequest();
impl = new RequestProtocolCompliance(false);
}
@@ -86,7 +82,7 @@ public class TestRequestProtocolComplian
@Test
public void doesNotModifyACompliantRequest() throws Exception {
- final RoutedHttpRequest wrapper = RoutedHttpRequest.adapt(req, route);
+ final ClassicHttpRequest wrapper = ExecSupport.copy(req);
impl.makeRequestCompliant(wrapper);
assertTrue(HttpTestUtils.equivalent(req, wrapper));
}
@@ -96,7 +92,7 @@ public class TestRequestProtocolComplian
final ClassicHttpRequest request = new BasicClassicHttpRequest("TRACE", "/");
request.setVersion(HttpVersion.HTTP_1_1);
request.setEntity(HttpTestUtils.makeBody(50));
- final RoutedHttpRequest wrapper = RoutedHttpRequest.adapt(request, route);
+ final ClassicHttpRequest wrapper = ExecSupport.copy(request);
impl.makeRequestCompliant(wrapper);
assertNull(wrapper.getEntity());
}
@@ -105,7 +101,7 @@ public class TestRequestProtocolComplian
public void upgrades1_0RequestTo1_1() throws Exception {
req = new BasicClassicHttpRequest("GET", "/");
req.setVersion(HttpVersion.HTTP_1_0);
- final RoutedHttpRequest wrapper = RoutedHttpRequest.adapt(req, route);
+ final ClassicHttpRequest wrapper = ExecSupport.copy(req);
impl.makeRequestCompliant(wrapper);
assertEquals(HttpVersion.HTTP_1_1, wrapper.getVersion());
}
@@ -114,7 +110,7 @@ public class TestRequestProtocolComplian
public void downgrades1_2RequestTo1_1() throws Exception {
req = new BasicClassicHttpRequest("GET", "/");
req.setVersion(new ProtocolVersion("HTTP", 1, 2));
- final RoutedHttpRequest wrapper = RoutedHttpRequest.adapt(req, route);
+ final ClassicHttpRequest wrapper = ExecSupport.copy(req);
impl.makeRequestCompliant(wrapper);
assertEquals(HttpVersion.HTTP_1_1, wrapper.getVersion());
}
@@ -123,7 +119,7 @@ public class TestRequestProtocolComplian
public void stripsMinFreshFromRequestIfNoCachePresent()
throws Exception {
req.setHeader("Cache-Control", "no-cache, min-fresh=10");
- final RoutedHttpRequest wrapper = RoutedHttpRequest.adapt(req, route);
+ final ClassicHttpRequest wrapper = ExecSupport.copy(req);
impl.makeRequestCompliant(wrapper);
assertEquals("no-cache",
wrapper.getFirstHeader("Cache-Control").getValue());
@@ -133,7 +129,7 @@ public class TestRequestProtocolComplian
public void stripsMaxFreshFromRequestIfNoCachePresent()
throws Exception {
req.setHeader("Cache-Control", "no-cache, max-stale=10");
- final RoutedHttpRequest wrapper = RoutedHttpRequest.adapt(req, route);
+ final ClassicHttpRequest wrapper = ExecSupport.copy(req);
impl.makeRequestCompliant(wrapper);
assertEquals("no-cache",
wrapper.getFirstHeader("Cache-Control").getValue());
@@ -143,7 +139,7 @@ public class TestRequestProtocolComplian
public void stripsMaxAgeFromRequestIfNoCachePresent()
throws Exception {
req.setHeader("Cache-Control", "no-cache, max-age=10");
- final RoutedHttpRequest wrapper = RoutedHttpRequest.adapt(req, route);
+ final ClassicHttpRequest wrapper = ExecSupport.copy(req);
impl.makeRequestCompliant(wrapper);
assertEquals("no-cache",
wrapper.getFirstHeader("Cache-Control").getValue());
@@ -153,7 +149,7 @@ public class TestRequestProtocolComplian
public void doesNotStripMinFreshFromRequestWithoutNoCache()
throws Exception {
req.setHeader("Cache-Control", "min-fresh=10");
- final RoutedHttpRequest wrapper = RoutedHttpRequest.adapt(req, route);
+ final ClassicHttpRequest wrapper = ExecSupport.copy(req);
impl.makeRequestCompliant(wrapper);
assertEquals("min-fresh=10",
wrapper.getFirstHeader("Cache-Control").getValue());
@@ -163,7 +159,7 @@ public class TestRequestProtocolComplian
public void correctlyStripsMinFreshFromMiddleIfNoCache()
throws Exception {
req.setHeader("Cache-Control", "no-cache,min-fresh=10,no-store");
- final RoutedHttpRequest wrapper = RoutedHttpRequest.adapt(req, route);
+ final ClassicHttpRequest wrapper = ExecSupport.copy(req);
impl.makeRequestCompliant(wrapper);
assertEquals("no-cache,no-store",
wrapper.getFirstHeader("Cache-Control").getValue());
Modified: httpcomponents/httpclient/trunk/httpclient5-cache/src/test/java/org/apache/hc/client5/http/impl/cache/TestResponseProtocolCompliance.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient5-cache/src/test/java/org/apache/hc/client5/http/impl/cache/TestResponseProtocolCompliance.java?rev=1793308&r1=1793307&r2=1793308&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient5-cache/src/test/java/org/apache/hc/client5/http/impl/cache/TestResponseProtocolCompliance.java (original)
+++ httpcomponents/httpclient/trunk/httpclient5-cache/src/test/java/org/apache/hc/client5/http/impl/cache/TestResponseProtocolCompliance.java Mon May 1 11:11:09 2017
@@ -33,10 +33,10 @@ import java.io.ByteArrayInputStream;
import java.util.Date;
import org.apache.hc.client5.http.HttpRoute;
+import org.apache.hc.client5.http.impl.ExecSupport;
import org.apache.hc.client5.http.protocol.ClientProtocolException;
import org.apache.hc.client5.http.sync.methods.HttpGet;
import org.apache.hc.client5.http.sync.methods.HttpHead;
-import org.apache.hc.client5.http.impl.sync.RoutedHttpRequest;
import org.apache.hc.client5.http.utils.DateUtils;
import org.apache.hc.core5.http.ClassicHttpRequest;
import org.apache.hc.core5.http.ClassicHttpResponse;
@@ -91,7 +91,8 @@ public class TestResponseProtocolComplia
@Test
public void consumesBodyIfOriginSendsOneInResponseToHEAD() throws Exception {
- final RoutedHttpRequest wrapper = RoutedHttpRequest.adapt(new HttpHead("http://foo.example.com/"), route);;
+ final HttpHead req = new HttpHead("http://foo.example.com/");
+ final ClassicHttpRequest wrapper = ExecSupport.copy(req);
final int nbytes = 128;
final ClassicHttpResponse resp = new BasicClassicHttpResponse(HttpStatus.SC_OK, "OK");
setMinimalResponseHeaders(resp);
@@ -101,24 +102,26 @@ public class TestResponseProtocolComplia
final ByteArrayInputStream bais = makeTrackableBody(nbytes, closed);
resp.setEntity(new InputStreamEntity(bais, -1));
- impl.ensureProtocolCompliance(wrapper, resp);
+ impl.ensureProtocolCompliance(wrapper, req, resp);
assertNull(resp.getEntity());
assertTrue(closed.set || bais.read() == -1);
}
@Test(expected=ClientProtocolException.class)
public void throwsExceptionIfOriginReturnsPartialResponseWhenNotRequested() throws Exception {
- final RoutedHttpRequest wrapper = RoutedHttpRequest.adapt(new HttpGet("http://foo.example.com/"), route);;
+ final HttpGet req = new HttpGet("http://foo.example.com/");
+ final ClassicHttpRequest wrapper = ExecSupport.copy(req);
final int nbytes = 128;
final ClassicHttpResponse resp = makePartialResponse(nbytes);
resp.setEntity(HttpTestUtils.makeBody(nbytes));
- impl.ensureProtocolCompliance(wrapper, resp);
+ impl.ensureProtocolCompliance(wrapper, req, resp);
}
@Test
public void consumesPartialContentFromOriginEvenIfNotRequested() throws Exception {
- final RoutedHttpRequest wrapper = RoutedHttpRequest.adapt(new HttpGet("http://foo.example.com/"), route);;
+ final HttpGet req = new HttpGet("http://foo.example.com/");
+ final ClassicHttpRequest wrapper = ExecSupport.copy(req);
final int nbytes = 128;
final ClassicHttpResponse resp = makePartialResponse(nbytes);
@@ -127,7 +130,7 @@ public class TestResponseProtocolComplia
resp.setEntity(new InputStreamEntity(bais, -1));
try {
- impl.ensureProtocolCompliance(wrapper, resp);
+ impl.ensureProtocolCompliance(wrapper, req, resp);
} catch (final ClientProtocolException expected) {
}
assertTrue(closed.set || bais.read() == -1);
@@ -141,7 +144,7 @@ public class TestResponseProtocolComplia
req.setHeader("Content-Type", "application/octet-stream");
final HttpEntity postBody = new ByteArrayEntity(HttpTestUtils.getRandomBytes(nbytes));
req.setEntity(postBody);
- final RoutedHttpRequest wrapper = RoutedHttpRequest.adapt(req, route);;
+ final ClassicHttpRequest wrapper = ExecSupport.copy(req);
final ClassicHttpResponse resp = new BasicClassicHttpResponse(HttpStatus.SC_CONTINUE, "Continue");
final Flag closed = new Flag();
@@ -149,7 +152,7 @@ public class TestResponseProtocolComplia
resp.setEntity(new InputStreamEntity(bais, -1));
try {
- impl.ensureProtocolCompliance(wrapper, resp);
+ impl.ensureProtocolCompliance(wrapper, req, resp);
} catch (final ClientProtocolException expected) {
}
assertTrue(closed.set || bais.read() == -1);
Modified: httpcomponents/httpclient/trunk/httpclient5-cache/src/test/java/org/apache/hc/client5/http/impl/cache/ehcache/TestEhcacheProtocolRequirements.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient5-cache/src/test/java/org/apache/hc/client5/http/impl/cache/ehcache/TestEhcacheProtocolRequirements.java?rev=1793308&r1=1793307&r2=1793308&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient5-cache/src/test/java/org/apache/hc/client5/http/impl/cache/ehcache/TestEhcacheProtocolRequirements.java (original)
+++ httpcomponents/httpclient/trunk/httpclient5-cache/src/test/java/org/apache/hc/client5/http/impl/cache/ehcache/TestEhcacheProtocolRequirements.java Mon May 1 11:11:09 2017
@@ -31,7 +31,7 @@ import org.apache.hc.client5.http.impl.c
import org.apache.hc.client5.http.impl.cache.CachingExec;
import org.apache.hc.client5.http.impl.cache.HeapResourceFactory;
import org.apache.hc.client5.http.impl.cache.TestProtocolRequirements;
-import org.apache.hc.client5.http.impl.sync.ClientExecChain;
+import org.apache.hc.client5.http.sync.ExecChain;
import org.easymock.EasyMock;
import org.junit.After;
import org.junit.AfterClass;
@@ -70,9 +70,9 @@ public class TestEhcacheProtocolRequirem
}
CACHE_MANAGER.addCache(TEST_EHCACHE_NAME);
final HttpCacheStorage storage = new EhcacheHttpCacheStorage(CACHE_MANAGER.getCache(TEST_EHCACHE_NAME));
- mockBackend = EasyMock.createNiceMock(ClientExecChain.class);
+ mockExecChain = EasyMock.createNiceMock(ExecChain.class);
- impl = new CachingExec(mockBackend, new HeapResourceFactory(), storage, config);
+ impl = new CachingExec(new HeapResourceFactory(), storage, config);
}
@After
Modified: httpcomponents/httpclient/trunk/httpclient5/src/examples/org/apache/hc/client5/http/examples/ClientFormLogin.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient5/src/examples/org/apache/hc/client5/http/examples/ClientFormLogin.java?rev=1793308&r1=1793307&r2=1793308&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient5/src/examples/org/apache/hc/client5/http/examples/ClientFormLogin.java (original)
+++ httpcomponents/httpclient/trunk/httpclient5/src/examples/org/apache/hc/client5/http/examples/ClientFormLogin.java Mon May 1 11:11:09 2017
@@ -35,8 +35,8 @@ import org.apache.hc.client5.http.impl.s
import org.apache.hc.client5.http.impl.sync.CloseableHttpResponse;
import org.apache.hc.client5.http.impl.sync.HttpClients;
import org.apache.hc.client5.http.sync.methods.HttpGet;
-import org.apache.hc.client5.http.sync.methods.HttpUriRequest;
import org.apache.hc.client5.http.sync.methods.RequestBuilder;
+import org.apache.hc.core5.http.ClassicHttpRequest;
import org.apache.hc.core5.http.HttpEntity;
import org.apache.hc.core5.http.io.entity.EntityUtils;
@@ -69,7 +69,7 @@ public class ClientFormLogin {
}
}
- final HttpUriRequest login = RequestBuilder.post()
+ final ClassicHttpRequest login = RequestBuilder.post()
.setUri(new URI("https://someportal/"))
.addParameter("IDToken1", "username")
.addParameter("IDToken2", "password")
Added: httpcomponents/httpclient/trunk/httpclient5/src/examples/org/apache/hc/client5/http/examples/ClientInterceptors.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient5/src/examples/org/apache/hc/client5/http/examples/ClientInterceptors.java?rev=1793308&view=auto
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient5/src/examples/org/apache/hc/client5/http/examples/ClientInterceptors.java (added)
+++ httpcomponents/httpclient/trunk/httpclient5/src/examples/org/apache/hc/client5/http/examples/ClientInterceptors.java Mon May 1 11:11:09 2017
@@ -0,0 +1,113 @@
+/*
+ * ====================================================================
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation. For more
+ * information on the Apache Software Foundation, please see
+ * <http://www.apache.org/>.
+ *
+ */
+
+package org.apache.hc.client5.http.examples;
+
+import java.io.IOException;
+import java.util.concurrent.atomic.AtomicLong;
+
+import org.apache.hc.client5.http.impl.sync.ChainElements;
+import org.apache.hc.client5.http.impl.sync.CloseableHttpClient;
+import org.apache.hc.client5.http.impl.sync.CloseableHttpResponse;
+import org.apache.hc.client5.http.impl.sync.HttpClients;
+import org.apache.hc.client5.http.sync.ExecChain;
+import org.apache.hc.client5.http.sync.ExecChainHandler;
+import org.apache.hc.client5.http.sync.methods.HttpGet;
+import org.apache.hc.core5.http.ClassicHttpRequest;
+import org.apache.hc.core5.http.ClassicHttpResponse;
+import org.apache.hc.core5.http.ContentType;
+import org.apache.hc.core5.http.EntityDetails;
+import org.apache.hc.core5.http.Header;
+import org.apache.hc.core5.http.HttpException;
+import org.apache.hc.core5.http.HttpRequest;
+import org.apache.hc.core5.http.HttpRequestInterceptor;
+import org.apache.hc.core5.http.HttpStatus;
+import org.apache.hc.core5.http.io.entity.EntityUtils;
+import org.apache.hc.core5.http.io.entity.StringEntity;
+import org.apache.hc.core5.http.message.BasicClassicHttpResponse;
+import org.apache.hc.core5.http.protocol.HttpContext;
+
+/**
+ * This example demonstrates how to insert custom request interceptor and an execution interceptor
+ * to the request execution chain.
+ */
+public class ClientInterceptors {
+
+ public final static void main(final String[] args) throws Exception {
+ try (CloseableHttpClient httpclient = HttpClients.custom()
+
+ // Add a simple request ID to each outgoing request
+
+ .addRequestInterceptorFirst(new HttpRequestInterceptor() {
+
+ private final AtomicLong count = new AtomicLong(0);
+
+ @Override
+ public void process(
+ final HttpRequest request,
+ final EntityDetails entity,
+ final HttpContext context) throws HttpException, IOException {
+ request.setHeader("request-id", Long.toString(count.incrementAndGet()));
+ }
+ })
+
+ // Simulate a 404 response for some requests without passing the message down to the backend
+
+ .addExecInterceptorAfter(ChainElements.PROTOCOL.name(), "custom", new ExecChainHandler() {
+
+ @Override
+ public ClassicHttpResponse execute(
+ final ClassicHttpRequest request,
+ final ExecChain.Scope scope,
+ final ExecChain chain) throws IOException, HttpException {
+
+ Header idHeader = request.getFirstHeader("request-id");
+ if (idHeader != null && "13".equalsIgnoreCase(idHeader.getValue())) {
+ ClassicHttpResponse response = new BasicClassicHttpResponse(HttpStatus.SC_NOT_FOUND, "Oppsie");
+ response.setEntity(new StringEntity("bad luck", ContentType.TEXT_PLAIN));
+ return response;
+ } else {
+ return chain.proceed(request, scope);
+ }
+ }
+
+ })
+ .build()) {
+ final HttpGet httpget = new HttpGet("http://httpbin.org/get");
+
+ System.out.println("Executing request " + httpget.getMethod() + " " + httpget.getUri());
+
+ try (CloseableHttpResponse response = httpclient.execute(httpget)) {
+ System.out.println("----------------------------------------");
+ System.out.println(response.getCode() + " " + response.getReasonPhrase());
+ System.out.println(EntityUtils.toString(response.getEntity()));
+ }
+ }
+ }
+
+}
+
Propchange: httpcomponents/httpclient/trunk/httpclient5/src/examples/org/apache/hc/client5/http/examples/ClientInterceptors.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: httpcomponents/httpclient/trunk/httpclient5/src/examples/org/apache/hc/client5/http/examples/ClientInterceptors.java
------------------------------------------------------------------------------
svn:keywords = Date Revision
Propchange: httpcomponents/httpclient/trunk/httpclient5/src/examples/org/apache/hc/client5/http/examples/ClientInterceptors.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Copied: httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http/CancellableAware.java (from r1793305, httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http/auth/CredentialsStore.java)
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http/CancellableAware.java?p2=httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http/CancellableAware.java&p1=httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http/auth/CredentialsStore.java&r1=1793305&r2=1793308&rev=1793308&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http/auth/CredentialsStore.java (original)
+++ httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http/CancellableAware.java Mon May 1 11:11:09 2017
@@ -24,34 +24,25 @@
* <http://www.apache.org/>.
*
*/
-package org.apache.hc.client5.http.auth;
+
+package org.apache.hc.client5.http;
+
+import org.apache.hc.core5.concurrent.Cancellable;
/**
- * Abstract store of authentication credentials.
- * <p>
- * Implementations of this interface must be thread-safe. Access to shared
- * data must be synchronized as methods of this interface may be executed
- * from multiple threads.
+ * This interface represents an object that can be made aware of
+ * long running, potentially blocking processes.
*
- * @since 4.0
+ * @since 5.0
*/
-public interface CredentialsStore extends CredentialsProvider {
+public interface CancellableAware {
/**
- * Sets the {@link Credentials credentials} for the given authentication
- * scope. Any previous credentials for the given scope will be overwritten.
- *
- * @param authscope the {@link AuthScope authentication scope}
- * @param credentials the authentication {@link Credentials credentials}
- * for the given scope.
- *
- * @see #getCredentials(AuthScope, HttpContext)
+ * Sets {@link Cancellable} for the ongoing operation.
*/
- void setCredentials(AuthScope authscope, Credentials credentials);
+ void setCancellable(Cancellable cancellable);
- /**
- * Clears all credentials.
- */
- void clear();
+ boolean isCancelled();
}
+
Added: httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http/StandardMethods.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http/StandardMethods.java?rev=1793308&view=auto
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http/StandardMethods.java (added)
+++ httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http/StandardMethods.java Mon May 1 11:11:09 2017
@@ -0,0 +1,82 @@
+/*
+ * ====================================================================
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation. For more
+ * information on the Apache Software Foundation, please see
+ * <http://www.apache.org/>.
+ *
+ */
+
+package org.apache.hc.client5.http;
+
+import java.util.Locale;
+
+public enum StandardMethods {
+
+ GET(true, true),
+ HEAD(true, true),
+ POST(false, false),
+ PUT(false, true),
+ DELETE(false, true),
+ CONNECT(false, false),
+ TRACE(true, true),
+ OPTIONS(true, true),
+ PATCH(false, false);
+
+ private final boolean safe;
+ private final boolean idempotent;
+
+ StandardMethods(final boolean safe, final boolean idempotent) {
+ this.safe = safe;
+ this.idempotent = idempotent;
+ }
+
+ public boolean isSafe() {
+ return safe;
+ }
+
+ public boolean isIdempotent() {
+ return idempotent;
+ }
+
+ public static boolean isSafe(final String value) {
+ if (value == null) {
+ return false;
+ }
+ try {
+ return valueOf(value.toUpperCase(Locale.ROOT)).safe;
+ } catch (IllegalArgumentException ex) {
+ return false;
+ }
+ }
+
+ public static boolean isIdempotent(final String value) {
+ if (value == null) {
+ return false;
+ }
+ try {
+ return valueOf(value.toUpperCase(Locale.ROOT)).idempotent;
+ } catch (IllegalArgumentException ex) {
+ return false;
+ }
+ }
+
+}
Propchange: httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http/StandardMethods.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http/StandardMethods.java
------------------------------------------------------------------------------
svn:keywords = Date Revision
Propchange: httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http/StandardMethods.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Modified: httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http/async/methods/AsyncRequestBuilder.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http/async/methods/AsyncRequestBuilder.java?rev=1793308&r1=1793307&r2=1793308&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http/async/methods/AsyncRequestBuilder.java (original)
+++ httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http/async/methods/AsyncRequestBuilder.java Mon May 1 11:11:09 2017
@@ -35,6 +35,7 @@ import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
+import org.apache.hc.client5.http.StandardMethods;
import org.apache.hc.client5.http.config.RequestConfig;
import org.apache.hc.core5.http.ContentType;
import org.apache.hc.core5.http.Header;
@@ -67,8 +68,6 @@ import org.apache.hc.core5.util.TextUtil
*/
public class AsyncRequestBuilder {
- private enum METHOD { GET, HEAD, POST, PUT, DELETE, PATCH, TRACE, OPTIONS }
-
private HttpHost host;
private String path;
private URI uri;
@@ -88,7 +87,7 @@ public class AsyncRequestBuilder {
this.method = method;
}
- AsyncRequestBuilder(final METHOD method) {
+ AsyncRequestBuilder(final StandardMethods method) {
this(method.name());
}
@@ -98,18 +97,18 @@ public class AsyncRequestBuilder {
this.uri = uri;
}
- AsyncRequestBuilder(final METHOD method, final HttpHost host, final String path) {
+ AsyncRequestBuilder(final StandardMethods method, final HttpHost host, final String path) {
super();
this.method = method.name();
this.host = host;
this.path = path;
}
- AsyncRequestBuilder(final METHOD method, final URI uri) {
+ AsyncRequestBuilder(final StandardMethods method, final URI uri) {
this(method.name(), uri);
}
- AsyncRequestBuilder(final METHOD method, final String uri) {
+ AsyncRequestBuilder(final StandardMethods method, final String uri) {
this(method.name(), uri != null ? URI.create(uri) : null);
}
@@ -123,131 +122,131 @@ public class AsyncRequestBuilder {
}
public static AsyncRequestBuilder get() {
- return new AsyncRequestBuilder(METHOD.GET);
+ return new AsyncRequestBuilder(StandardMethods.GET);
}
public static AsyncRequestBuilder get(final URI uri) {
- return new AsyncRequestBuilder(METHOD.GET, uri);
+ return new AsyncRequestBuilder(StandardMethods.GET, uri);
}
public static AsyncRequestBuilder get(final String uri) {
- return new AsyncRequestBuilder(METHOD.GET, uri);
+ return new AsyncRequestBuilder(StandardMethods.GET, uri);
}
public static AsyncRequestBuilder get(final HttpHost host, final String path) {
- return new AsyncRequestBuilder(METHOD.GET, host, path);
+ return new AsyncRequestBuilder(StandardMethods.GET, host, path);
}
public static AsyncRequestBuilder head() {
- return new AsyncRequestBuilder(METHOD.HEAD);
+ return new AsyncRequestBuilder(StandardMethods.HEAD);
}
public static AsyncRequestBuilder head(final URI uri) {
- return new AsyncRequestBuilder(METHOD.HEAD, uri);
+ return new AsyncRequestBuilder(StandardMethods.HEAD, uri);
}
public static AsyncRequestBuilder head(final String uri) {
- return new AsyncRequestBuilder(METHOD.HEAD, uri);
+ return new AsyncRequestBuilder(StandardMethods.HEAD, uri);
}
public static AsyncRequestBuilder head(final HttpHost host, final String path) {
- return new AsyncRequestBuilder(METHOD.HEAD, host, path);
+ return new AsyncRequestBuilder(StandardMethods.HEAD, host, path);
}
public static AsyncRequestBuilder patch() {
- return new AsyncRequestBuilder(METHOD.PATCH);
+ return new AsyncRequestBuilder(StandardMethods.PATCH);
}
public static AsyncRequestBuilder patch(final URI uri) {
- return new AsyncRequestBuilder(METHOD.PATCH, uri);
+ return new AsyncRequestBuilder(StandardMethods.PATCH, uri);
}
public static AsyncRequestBuilder patch(final String uri) {
- return new AsyncRequestBuilder(METHOD.PATCH, uri);
+ return new AsyncRequestBuilder(StandardMethods.PATCH, uri);
}
public static AsyncRequestBuilder patch(final HttpHost host, final String path) {
- return new AsyncRequestBuilder(METHOD.PATCH, host, path);
+ return new AsyncRequestBuilder(StandardMethods.PATCH, host, path);
}
public static AsyncRequestBuilder post() {
- return new AsyncRequestBuilder(METHOD.POST);
+ return new AsyncRequestBuilder(StandardMethods.POST);
}
public static AsyncRequestBuilder post(final URI uri) {
- return new AsyncRequestBuilder(METHOD.POST, uri);
+ return new AsyncRequestBuilder(StandardMethods.POST, uri);
}
public static AsyncRequestBuilder post(final String uri) {
- return new AsyncRequestBuilder(METHOD.POST, uri);
+ return new AsyncRequestBuilder(StandardMethods.POST, uri);
}
public static AsyncRequestBuilder post(final HttpHost host, final String path) {
- return new AsyncRequestBuilder(METHOD.POST, host, path);
+ return new AsyncRequestBuilder(StandardMethods.POST, host, path);
}
public static AsyncRequestBuilder put() {
- return new AsyncRequestBuilder(METHOD.PUT);
+ return new AsyncRequestBuilder(StandardMethods.PUT);
}
public static AsyncRequestBuilder put(final URI uri) {
- return new AsyncRequestBuilder(METHOD.PUT, uri);
+ return new AsyncRequestBuilder(StandardMethods.PUT, uri);
}
public static AsyncRequestBuilder put(final String uri) {
- return new AsyncRequestBuilder(METHOD.PUT, uri);
+ return new AsyncRequestBuilder(StandardMethods.PUT, uri);
}
public static AsyncRequestBuilder put(final HttpHost host, final String path) {
- return new AsyncRequestBuilder(METHOD.PUT, host, path);
+ return new AsyncRequestBuilder(StandardMethods.PUT, host, path);
}
public static AsyncRequestBuilder delete() {
- return new AsyncRequestBuilder(METHOD.DELETE);
+ return new AsyncRequestBuilder(StandardMethods.DELETE);
}
public static AsyncRequestBuilder delete(final URI uri) {
- return new AsyncRequestBuilder(METHOD.DELETE, uri);
+ return new AsyncRequestBuilder(StandardMethods.DELETE, uri);
}
public static AsyncRequestBuilder delete(final String uri) {
- return new AsyncRequestBuilder(METHOD.DELETE, uri);
+ return new AsyncRequestBuilder(StandardMethods.DELETE, uri);
}
public static AsyncRequestBuilder delete(final HttpHost host, final String path) {
- return new AsyncRequestBuilder(METHOD.DELETE, host, path);
+ return new AsyncRequestBuilder(StandardMethods.DELETE, host, path);
}
public static AsyncRequestBuilder trace() {
- return new AsyncRequestBuilder(METHOD.TRACE);
+ return new AsyncRequestBuilder(StandardMethods.TRACE);
}
public static AsyncRequestBuilder trace(final URI uri) {
- return new AsyncRequestBuilder(METHOD.TRACE, uri);
+ return new AsyncRequestBuilder(StandardMethods.TRACE, uri);
}
public static AsyncRequestBuilder trace(final String uri) {
- return new AsyncRequestBuilder(METHOD.TRACE, uri);
+ return new AsyncRequestBuilder(StandardMethods.TRACE, uri);
}
public static AsyncRequestBuilder trace(final HttpHost host, final String path) {
- return new AsyncRequestBuilder(METHOD.TRACE, host, path);
+ return new AsyncRequestBuilder(StandardMethods.TRACE, host, path);
}
public static AsyncRequestBuilder options() {
- return new AsyncRequestBuilder(METHOD.OPTIONS);
+ return new AsyncRequestBuilder(StandardMethods.OPTIONS);
}
public static AsyncRequestBuilder options(final URI uri) {
- return new AsyncRequestBuilder(METHOD.OPTIONS, uri);
+ return new AsyncRequestBuilder(StandardMethods.OPTIONS, uri);
}
public static AsyncRequestBuilder options(final String uri) {
- return new AsyncRequestBuilder(METHOD.OPTIONS, uri);
+ return new AsyncRequestBuilder(StandardMethods.OPTIONS, uri);
}
public static AsyncRequestBuilder options(final HttpHost host, final String path) {
- return new AsyncRequestBuilder(METHOD.OPTIONS, host, path);
+ return new AsyncRequestBuilder(StandardMethods.OPTIONS, host, path);
}
public AsyncRequestBuilder setCharset(final Charset charset) {
@@ -411,8 +410,8 @@ public class AsyncRequestBuilder {
public AsyncRequestProducer build() {
AsyncEntityProducer entityProducerCopy = this.entityProducer;
if (parameters != null && !parameters.isEmpty()) {
- if (entityProducerCopy == null && (METHOD.POST.name().equalsIgnoreCase(method)
- || METHOD.PUT.name().equalsIgnoreCase(method))) {
+ if (entityProducerCopy == null && (StandardMethods.POST.name().equalsIgnoreCase(method)
+ || StandardMethods.PUT.name().equalsIgnoreCase(method))) {
final String content = URLEncodedUtils.format(
parameters,
charset != null ? charset : ContentType.APPLICATION_FORM_URLENCODED.getCharset());
Modified: httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http/auth/CredentialsStore.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http/auth/CredentialsStore.java?rev=1793308&r1=1793307&r2=1793308&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http/auth/CredentialsStore.java (original)
+++ httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http/auth/CredentialsStore.java Mon May 1 11:11:09 2017
@@ -45,7 +45,7 @@ public interface CredentialsStore extend
* @param credentials the authentication {@link Credentials credentials}
* for the given scope.
*
- * @see #getCredentials(AuthScope, HttpContext)
+ * @see #getCredentials(AuthScope, org.apache.hc.core5.http.protocol.HttpContext)
*/
void setCredentials(AuthScope authscope, Credentials credentials);
Added: httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http/auth/util/CredentialSupport.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http/auth/util/CredentialSupport.java?rev=1793308&view=auto
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http/auth/util/CredentialSupport.java (added)
+++ httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http/auth/util/CredentialSupport.java Mon May 1 11:11:09 2017
@@ -0,0 +1,68 @@
+/*
+ * ====================================================================
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation. For more
+ * information on the Apache Software Foundation, please see
+ * <http://www.apache.org/>.
+ *
+ */
+
+package org.apache.hc.client5.http.auth.util;
+
+import org.apache.hc.client5.http.auth.AuthScope;
+import org.apache.hc.client5.http.auth.CredentialsStore;
+import org.apache.hc.client5.http.auth.UsernamePasswordCredentials;
+import org.apache.hc.client5.http.config.AuthSchemes;
+import org.apache.hc.core5.net.URIAuthority;
+import org.apache.hc.core5.util.Args;
+
+/**
+ * @since 5.0
+ */
+public class CredentialSupport {
+
+ public static void extractFromAuthority(
+ final URIAuthority authority,
+ final CredentialsStore credentialsStore) {
+ Args.notNull(credentialsStore, "Credentials store");
+ if (authority == null) {
+ return;
+ }
+ final String userinfo = authority.getUserInfo();
+ if (userinfo == null) {
+ return;
+ }
+ final int atColon = userinfo.indexOf(':');
+ final String userName;
+ final char[] password;
+ if (atColon >= 0) {
+ userName = userinfo.substring(0, atColon);
+ password = userinfo.substring(atColon + 1).toCharArray();
+ } else {
+ userName = userinfo.substring(0, atColon);
+ password = null;
+ }
+ credentialsStore.setCredentials(
+ new AuthScope(authority.getHostName(), authority.getPort(), null, AuthSchemes.BASIC),
+ new UsernamePasswordCredentials(userName, password));
+ }
+
+}
Propchange: httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http/auth/util/CredentialSupport.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http/auth/util/CredentialSupport.java
------------------------------------------------------------------------------
svn:keywords = Date Revision
Propchange: httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http/auth/util/CredentialSupport.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http/impl/ExecSupport.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http/impl/ExecSupport.java?rev=1793308&view=auto
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http/impl/ExecSupport.java (added)
+++ httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http/impl/ExecSupport.java Mon May 1 11:11:09 2017
@@ -0,0 +1,104 @@
+/*
+ * ====================================================================
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation. For more
+ * information on the Apache Software Foundation, please see
+ * <http://www.apache.org/>.
+ *
+ */
+package org.apache.hc.client5.http.impl;
+
+import java.util.Iterator;
+
+import org.apache.hc.core5.http.ClassicHttpRequest;
+import org.apache.hc.core5.http.ClassicHttpResponse;
+import org.apache.hc.core5.http.Header;
+import org.apache.hc.core5.http.HttpMessage;
+import org.apache.hc.core5.http.HttpRequest;
+import org.apache.hc.core5.http.HttpResponse;
+import org.apache.hc.core5.http.HttpVersion;
+import org.apache.hc.core5.http.message.BasicClassicHttpRequest;
+import org.apache.hc.core5.http.message.BasicClassicHttpResponse;
+import org.apache.hc.core5.http.message.BasicHttpRequest;
+import org.apache.hc.core5.http.message.BasicHttpResponse;
+
+public final class ExecSupport {
+
+ private static void copyMessageProperties(final HttpMessage original, final HttpMessage copy) {
+ copy.setVersion(original.getVersion());
+ for (final Iterator<Header> it = original.headerIterator(); it.hasNext(); ) {
+ copy.addHeader(it.next());
+ }
+ }
+
+ private static void copyRequestProperties(final HttpRequest original, final HttpRequest copy) {
+ copyMessageProperties(original, copy);
+ if (copy.getVersion() == null) {
+ copy.setVersion(HttpVersion.DEFAULT);
+ }
+ copy.setAuthority(original.getAuthority());
+ }
+
+ private static void copyResponseProperties(final HttpResponse original, final HttpResponse copy) {
+ copyMessageProperties(original, copy);
+ copy.setLocale(copy.getLocale());
+ copy.setReasonPhrase(copy.getReasonPhrase());
+ }
+
+ public static HttpRequest copy(final HttpRequest original) {
+ if (original == null) {
+ return null;
+ }
+ final BasicHttpRequest copy = new BasicHttpRequest(original.getMethod(), original.getPath());
+ copyRequestProperties(original, copy);
+ return copy;
+ }
+
+ public static HttpResponse copy(final HttpResponse original) {
+ if (original == null) {
+ return null;
+ }
+ final BasicHttpResponse copy = new BasicHttpResponse(original.getCode());
+ copyResponseProperties(original, copy);
+ return copy;
+ }
+
+ public static ClassicHttpRequest copy(final ClassicHttpRequest original) {
+ if (original == null) {
+ return null;
+ }
+ final BasicClassicHttpRequest copy = new BasicClassicHttpRequest(original.getMethod(), original.getPath());
+ copyRequestProperties(original, copy);
+ copy.setEntity(original.getEntity());
+ return copy;
+ }
+
+ public static ClassicHttpResponse copy(final ClassicHttpResponse original) {
+ if (original == null) {
+ return null;
+ }
+ final BasicClassicHttpResponse copy = new BasicClassicHttpResponse(original.getCode());
+ copyResponseProperties(original, copy);
+ copy.setEntity(original.getEntity());
+ return copy;
+ }
+
+}
Propchange: httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http/impl/ExecSupport.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http/impl/ExecSupport.java
------------------------------------------------------------------------------
svn:keywords = Date Revision
Propchange: httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http/impl/ExecSupport.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Modified: httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http/impl/IdleConnectionEvictor.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http/impl/IdleConnectionEvictor.java?rev=1793308&r1=1793307&r2=1793308&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http/impl/IdleConnectionEvictor.java (original)
+++ httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http/impl/IdleConnectionEvictor.java Mon May 1 11:11:09 2017
@@ -62,7 +62,9 @@ public final class IdleConnectionEvictor
connectionManager.closeIdle(maxIdleTime);
}
}
- } catch (final Exception ignore) {
+ } catch (final InterruptedException ex) {
+ Thread.currentThread().interrupt();
+ } catch (final Exception ex) {
}
}
Added: httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http/impl/NamedElementChain.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http/impl/NamedElementChain.java?rev=1793308&view=auto
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http/impl/NamedElementChain.java (added)
+++ httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http/impl/NamedElementChain.java Mon May 1 11:11:09 2017
@@ -0,0 +1,212 @@
+/*
+ * ====================================================================
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation. For more
+ * information on the Apache Software Foundation, please see
+ * <http://www.apache.org/>.
+ *
+ */
+
+package org.apache.hc.client5.http.impl;
+
+import org.apache.hc.core5.util.Args;
+
+/**
+ * Chain of doubly linked elements.
+ * <p>
+ * This implementation makes no attempts to ensure uniqueness of element names.
+ *
+ * @param <E>
+ */
+public class NamedElementChain<E> {
+
+ private final Node master;
+ private int size;
+
+ public NamedElementChain() {
+ this.master = new Node("master", null);
+ this.master.previous = this.master;
+ this.master.next = this.master;
+ this.size = 0;
+ }
+
+ public Node getFirst() {
+ if (master.next != master) {
+ return master.next;
+ } else {
+ return null;
+ }
+ }
+
+ public Node getLast() {
+ if (master.previous != master) {
+ return master.previous;
+ } else {
+ return null;
+ }
+ }
+
+ public Node addFirst(final E value, final String name) {
+ Args.notBlank(name, "Name");
+ Args.notNull(value, "Value");
+ final Node newNode = new Node(name, value);
+ final Node oldNode = master.next;
+ master.next = newNode;
+ newNode.previous = master;
+ newNode.next = oldNode;
+ oldNode.previous = newNode;
+ size++;
+ return newNode;
+ }
+
+ public Node addLast(final E value, final String name) {
+ Args.notBlank(name, "Name");
+ Args.notNull(value, "Value");
+ final Node newNode = new Node(name, value);
+ final Node oldNode = master.previous;
+ master.previous = newNode;
+ newNode.previous = oldNode;
+ newNode.next = master;
+ oldNode.next = newNode;
+ size++;
+ return newNode;
+ }
+
+ public Node find(final String name) {
+ Args.notBlank(name, "Name");
+ return doFind(name);
+ }
+
+ private Node doFind(final String name) {
+ Node current = master.next;
+ while (current != master) {
+ if (name.equals(current.name)) {
+ return current;
+ }
+ current = current.next;
+ }
+ return null;
+ }
+
+ public Node addBefore(final String existing, final E value, final String name) {
+ Args.notBlank(name, "Name");
+ Args.notNull(value, "Value");
+ final Node current = doFind(existing);
+ if (current == null) {
+ return null;
+ }
+ final Node newNode = new Node(name, value);
+ final Node previousNode = current.previous;
+ previousNode.next = newNode;
+ newNode.previous = previousNode;
+ newNode.next = current;
+ current.previous = newNode;
+ size++;
+ return newNode;
+ }
+
+ public Node addAfter(final String existing, final E value, final String name) {
+ Args.notBlank(name, "Name");
+ Args.notNull(value, "Value");
+ final Node current = doFind(existing);
+ if (current == null) {
+ return null;
+ }
+ final Node newNode = new Node(name, value);
+ final Node nextNode = current.next;
+ current.next = newNode;
+ newNode.previous = current;
+ newNode.next = nextNode;
+ nextNode.previous = newNode;
+ size++;
+ return newNode;
+ }
+
+ public boolean remove(final String name) {
+ final Node node = doFind(name);
+ if (node == null) {
+ return false;
+ }
+ node.previous.next = node.next;
+ node.next.previous = node.previous;
+ node.previous = null;
+ node.next = null;
+ size--;
+ return true;
+ }
+
+ public boolean replace(final String existing, final E value) {
+ final Node node = doFind(existing);
+ if (node == null) {
+ return false;
+ }
+ node.value = value;
+ return true;
+ }
+
+ public int getSize() {
+ return size;
+ }
+
+ public class Node {
+
+ private final String name;
+ private E value;
+ private Node previous;
+ private Node next;
+
+ Node(final String name, final E value) {
+ this.name = name;
+ this.value = value;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public E getValue() {
+ return value;
+ }
+
+ public Node getPrevious() {
+ if (previous != master) {
+ return previous;
+ } else {
+ return null;
+ }
+ }
+
+ public Node getNext() {
+ if (next != master) {
+ return next;
+ } else {
+ return null;
+ }
+ }
+
+ @Override
+ public String toString() {
+ return name + ": " + value;
+ }
+
+ }
+
+}
\ No newline at end of file
Propchange: httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http/impl/NamedElementChain.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http/impl/NamedElementChain.java
------------------------------------------------------------------------------
svn:keywords = Date Revision
Propchange: httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http/impl/NamedElementChain.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Modified: httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http/impl/protocol/DefaultRedirectStrategy.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http/impl/protocol/DefaultRedirectStrategy.java?rev=1793308&r1=1793307&r2=1793308&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http/impl/protocol/DefaultRedirectStrategy.java (original)
+++ httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http/impl/protocol/DefaultRedirectStrategy.java Mon May 1 11:11:09 2017
@@ -38,13 +38,9 @@ import org.apache.hc.client5.http.protoc
import org.apache.hc.client5.http.protocol.HttpClientContext;
import org.apache.hc.client5.http.protocol.RedirectLocations;
import org.apache.hc.client5.http.protocol.RedirectStrategy;
-import org.apache.hc.client5.http.sync.methods.HttpGet;
-import org.apache.hc.client5.http.sync.methods.HttpUriRequest;
-import org.apache.hc.client5.http.sync.methods.RequestBuilder;
import org.apache.hc.client5.http.utils.URIUtils;
import org.apache.hc.core5.annotation.Contract;
import org.apache.hc.core5.annotation.ThreadingBehavior;
-import org.apache.hc.core5.http.ClassicHttpRequest;
import org.apache.hc.core5.http.Header;
import org.apache.hc.core5.http.HttpException;
import org.apache.hc.core5.http.HttpHeaders;
@@ -69,7 +65,7 @@ import org.apache.logging.log4j.Logger;
* @since 4.1
*/
@Contract(threading = ThreadingBehavior.IMMUTABLE)
-public class DefaultRedirectStrategy<T extends HttpRequest> implements RedirectStrategy {
+public class DefaultRedirectStrategy implements RedirectStrategy {
private final Logger log = LogManager.getLogger(getClass());
@@ -112,6 +108,7 @@ public class DefaultRedirectStrategy<T e
}
}
+ @Override
public URI getLocationURI(
final HttpRequest request,
final HttpResponse response,
@@ -179,27 +176,4 @@ public class DefaultRedirectStrategy<T e
}
}
- @Override
- public HttpUriRequest getRedirect(
- final ClassicHttpRequest request,
- final HttpResponse response,
- final HttpContext context) throws HttpException {
- final URI uri = getLocationURI(request, response, context);
- final int statusCode = response.getCode();
- switch (statusCode) {
- case HttpStatus.SC_MOVED_PERMANENTLY:
- case HttpStatus.SC_MOVED_TEMPORARILY:
- case HttpStatus.SC_SEE_OTHER:
- final String method = request.getMethod().toUpperCase(Locale.ROOT);
- if (!this.safeMethods.containsKey(method)) {
- final HttpGet httpGet = new HttpGet(uri);
- httpGet.setHeaders(request.getAllHeaders());
- return httpGet;
- }
- case HttpStatus.SC_TEMPORARY_REDIRECT:
- default:
- return RequestBuilder.copy(request).setUri(uri).build();
- }
- }
-
}
Modified: httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http/impl/sync/BackoffStrategyExec.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http/impl/sync/BackoffStrategyExec.java?rev=1793308&r1=1793307&r2=1793308&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http/impl/sync/BackoffStrategyExec.java (original)
+++ httpcomponents/httpclient/trunk/httpclient5/src/main/java/org/apache/hc/client5/http/impl/sync/BackoffStrategyExec.java Mon May 1 11:11:09 2017
@@ -28,15 +28,15 @@
package org.apache.hc.client5.http.impl.sync;
import java.io.IOException;
-import java.lang.reflect.UndeclaredThrowableException;
import org.apache.hc.client5.http.HttpRoute;
-import org.apache.hc.client5.http.protocol.HttpClientContext;
import org.apache.hc.client5.http.sync.BackoffManager;
import org.apache.hc.client5.http.sync.ConnectionBackoffStrategy;
-import org.apache.hc.client5.http.sync.methods.HttpExecutionAware;
+import org.apache.hc.client5.http.sync.ExecChain;
+import org.apache.hc.client5.http.sync.ExecChainHandler;
import org.apache.hc.core5.annotation.Contract;
import org.apache.hc.core5.annotation.ThreadingBehavior;
+import org.apache.hc.core5.http.ClassicHttpRequest;
import org.apache.hc.core5.http.ClassicHttpResponse;
import org.apache.hc.core5.http.HttpException;
import org.apache.hc.core5.util.Args;
@@ -45,61 +45,45 @@ import org.apache.hc.core5.util.Args;
* @since 4.3
*/
@Contract(threading = ThreadingBehavior.IMMUTABLE)
-public class BackoffStrategyExec implements ClientExecChain {
+final class BackoffStrategyExec implements ExecChainHandler {
- private final ClientExecChain requestExecutor;
private final ConnectionBackoffStrategy connectionBackoffStrategy;
private final BackoffManager backoffManager;
public BackoffStrategyExec(
- final ClientExecChain requestExecutor,
final ConnectionBackoffStrategy connectionBackoffStrategy,
final BackoffManager backoffManager) {
super();
- Args.notNull(requestExecutor, "HTTP client request executor");
Args.notNull(connectionBackoffStrategy, "Connection backoff strategy");
Args.notNull(backoffManager, "Backoff manager");
- this.requestExecutor = requestExecutor;
this.connectionBackoffStrategy = connectionBackoffStrategy;
this.backoffManager = backoffManager;
}
@Override
public ClassicHttpResponse execute(
- final RoutedHttpRequest request,
- final HttpClientContext context,
- final HttpExecutionAware execAware) throws IOException, HttpException {
+ final ClassicHttpRequest request,
+ final ExecChain.Scope scope,
+ final ExecChain chain) throws IOException, HttpException {
Args.notNull(request, "HTTP request");
- Args.notNull(context, "HTTP context");
- final HttpRoute route = request.getRoute();
+ Args.notNull(scope, "Scope");
+ final HttpRoute route = scope.route;
- ClassicHttpResponse out = null;
+ final ClassicHttpResponse response;
try {
- out = this.requestExecutor.execute(request, context, execAware);
- } catch (final Exception ex) {
- if (out != null) {
- out.close();
- }
+ response = chain.proceed(request, scope);
+ } catch (final IOException | HttpException ex) {
if (this.connectionBackoffStrategy.shouldBackoff(ex)) {
this.backoffManager.backOff(route);
}
- if (ex instanceof RuntimeException) {
- throw (RuntimeException) ex;
- }
- if (ex instanceof HttpException) {
- throw (HttpException) ex;
- }
- if (ex instanceof IOException) {
- throw (IOException) ex;
- }
- throw new UndeclaredThrowableException(ex);
+ throw ex;
}
- if (this.connectionBackoffStrategy.shouldBackoff(out)) {
+ if (this.connectionBackoffStrategy.shouldBackoff(response)) {
this.backoffManager.backOff(route);
} else {
this.backoffManager.probe(route);
}
- return out;
+ return response;
}
}