mirror of
https://github.com/apache/httpcomponents-client.git
synced 2025-02-16 15:07:27 +00:00
Deprecated request factory classes in favor of request builders
This commit is contained in:
parent
e0c19c0b53
commit
2404540f1f
@ -41,7 +41,6 @@
|
||||
import java.util.Locale;
|
||||
import java.util.TimeZone;
|
||||
|
||||
import org.apache.hc.client5.http.classic.methods.ClassicHttpRequests;
|
||||
import org.apache.hc.client5.http.classic.methods.HttpUriRequestBase;
|
||||
import org.apache.hc.client5.http.config.Configurable;
|
||||
import org.apache.hc.client5.http.config.RequestConfig;
|
||||
@ -60,6 +59,7 @@
|
||||
import org.apache.hc.core5.http.io.entity.ByteArrayEntity;
|
||||
import org.apache.hc.core5.http.io.entity.FileEntity;
|
||||
import org.apache.hc.core5.http.io.entity.InputStreamEntity;
|
||||
import org.apache.hc.core5.http.message.BasicClassicHttpRequest;
|
||||
import org.apache.hc.core5.net.WWWFormCodec;
|
||||
import org.apache.hc.core5.util.Timeout;
|
||||
|
||||
@ -95,67 +95,67 @@ public static Request create(final String methodName, final URI uri) {
|
||||
}
|
||||
|
||||
public static Request get(final URI uri) {
|
||||
return new Request(ClassicHttpRequests.get(uri));
|
||||
return new Request(new BasicClassicHttpRequest(Method.GET, uri));
|
||||
}
|
||||
|
||||
public static Request get(final String uri) {
|
||||
return new Request(ClassicHttpRequests.get(uri));
|
||||
return new Request(new BasicClassicHttpRequest(Method.GET, uri));
|
||||
}
|
||||
|
||||
public static Request head(final URI uri) {
|
||||
return new Request(ClassicHttpRequests.head(uri));
|
||||
return new Request(new BasicClassicHttpRequest(Method.HEAD, uri));
|
||||
}
|
||||
|
||||
public static Request head(final String uri) {
|
||||
return new Request(ClassicHttpRequests.head(uri));
|
||||
return new Request(new BasicClassicHttpRequest(Method.HEAD, uri));
|
||||
}
|
||||
|
||||
public static Request post(final URI uri) {
|
||||
return new Request(ClassicHttpRequests.post(uri));
|
||||
return new Request(new BasicClassicHttpRequest(Method.POST, uri));
|
||||
}
|
||||
|
||||
public static Request post(final String uri) {
|
||||
return new Request(ClassicHttpRequests.post(uri));
|
||||
return new Request(new BasicClassicHttpRequest(Method.POST, uri));
|
||||
}
|
||||
|
||||
public static Request patch(final URI uri) {
|
||||
return new Request(ClassicHttpRequests.patch(uri));
|
||||
return new Request(new BasicClassicHttpRequest(Method.PATCH, uri));
|
||||
}
|
||||
|
||||
public static Request patch(final String uri) {
|
||||
return new Request(ClassicHttpRequests.patch(uri));
|
||||
return new Request(new BasicClassicHttpRequest(Method.PATCH, uri));
|
||||
}
|
||||
|
||||
public static Request put(final URI uri) {
|
||||
return new Request(ClassicHttpRequests.put(uri));
|
||||
return new Request(new BasicClassicHttpRequest(Method.PUT, uri));
|
||||
}
|
||||
|
||||
public static Request put(final String uri) {
|
||||
return new Request(ClassicHttpRequests.put(uri));
|
||||
return new Request(new BasicClassicHttpRequest(Method.PUT, uri));
|
||||
}
|
||||
|
||||
public static Request trace(final URI uri) {
|
||||
return new Request(ClassicHttpRequests.trace(uri));
|
||||
return new Request(new BasicClassicHttpRequest(Method.TRACE, uri));
|
||||
}
|
||||
|
||||
public static Request trace(final String uri) {
|
||||
return new Request(ClassicHttpRequests.trace(uri));
|
||||
return new Request(new BasicClassicHttpRequest(Method.TRACE, uri));
|
||||
}
|
||||
|
||||
public static Request delete(final URI uri) {
|
||||
return new Request(ClassicHttpRequests.delete(uri));
|
||||
return new Request(new BasicClassicHttpRequest(Method.DELETE, uri));
|
||||
}
|
||||
|
||||
public static Request delete(final String uri) {
|
||||
return new Request(ClassicHttpRequests.delete(uri));
|
||||
return new Request(new BasicClassicHttpRequest(Method.DELETE, uri));
|
||||
}
|
||||
|
||||
public static Request options(final URI uri) {
|
||||
return new Request(ClassicHttpRequests.options(uri));
|
||||
return new Request(new BasicClassicHttpRequest(Method.OPTIONS, uri));
|
||||
}
|
||||
|
||||
public static Request options(final String uri) {
|
||||
return new Request(ClassicHttpRequests.options(uri));
|
||||
return new Request(new BasicClassicHttpRequest(Method.OPTIONS, uri));
|
||||
}
|
||||
|
||||
Request(final ClassicHttpRequest request) {
|
||||
|
@ -27,30 +27,60 @@
|
||||
|
||||
package org.apache.hc.client5.http.fluent;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
import java.net.URI;
|
||||
import java.util.Arrays;
|
||||
|
||||
import org.apache.hc.client5.http.classic.methods.HttpGet;
|
||||
import org.apache.hc.core5.http.ClassicHttpRequest;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.runners.Parameterized;
|
||||
|
||||
@RunWith(Parameterized.class)
|
||||
public class TestRequest {
|
||||
|
||||
private static final String URI_STRING_FIXTURE = "http://localhost";
|
||||
private static final URI URI_FIXTURE = URI.create(URI_STRING_FIXTURE);
|
||||
private static final String URI_STRING_FIXTURE = "http://localhost";
|
||||
private static final URI URI_FIXTURE = URI.create(URI_STRING_FIXTURE);
|
||||
|
||||
@Test
|
||||
public void testGetFromString() {
|
||||
final ClassicHttpRequest request = Request.get(URI_STRING_FIXTURE).getRequest();
|
||||
Assert.assertEquals(HttpGet.class, request.getClass());
|
||||
Assert.assertEquals("GET", request.getMethod());
|
||||
}
|
||||
@Parameterized.Parameters(name = "{index}: {0} => {1}")
|
||||
public static Iterable<Object[]> data() {
|
||||
return Arrays.asList(new Object[][]{
|
||||
// @formatter:off
|
||||
{"delete", "DELETE"},
|
||||
{"get", "GET"},
|
||||
{"head", "HEAD"},
|
||||
{"options", "OPTIONS"},
|
||||
{"patch", "PATCH"},
|
||||
{"post", "POST"},
|
||||
{"put", "PUT"},
|
||||
{"trace", "TRACE"}
|
||||
// @formatter:on
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetFromURI() {
|
||||
final ClassicHttpRequest request = Request.get(URI_FIXTURE).getRequest();
|
||||
Assert.assertEquals(HttpGet.class, request.getClass());
|
||||
Assert.assertEquals("GET", request.getMethod());
|
||||
}
|
||||
private final String methodName;
|
||||
private final String expectedMethod;
|
||||
|
||||
public TestRequest(final String methodName, final String expectedMethod) {
|
||||
this.methodName = methodName;
|
||||
this.expectedMethod = expectedMethod;
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCreateFromString() throws Exception {
|
||||
final Method method = Request.class.getMethod(methodName, String.class);
|
||||
final Request request = (Request) method.invoke(null, URI_STRING_FIXTURE);
|
||||
final ClassicHttpRequest classicHttpRequest = request.getRequest();
|
||||
Assert.assertEquals(expectedMethod, classicHttpRequest.getMethod());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCreateFromURI() throws Exception {
|
||||
final Method method = Request.class.getMethod(methodName, URI.class);
|
||||
final Request request = (Request) method.invoke(null, URI_FIXTURE);
|
||||
final ClassicHttpRequest classicHttpRequest = request.getRequest();
|
||||
Assert.assertEquals(expectedMethod, classicHttpRequest.getMethod());
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -34,16 +34,16 @@
|
||||
|
||||
import org.apache.hc.client5.http.AuthenticationStrategy;
|
||||
import org.apache.hc.client5.http.async.methods.SimpleHttpRequest;
|
||||
import org.apache.hc.client5.http.async.methods.SimpleHttpRequests;
|
||||
import org.apache.hc.client5.http.async.methods.SimpleHttpResponse;
|
||||
import org.apache.hc.client5.http.async.methods.SimpleRequestBuilder;
|
||||
import org.apache.hc.client5.http.auth.AuthChallenge;
|
||||
import org.apache.hc.client5.http.auth.AuthScheme;
|
||||
import org.apache.hc.client5.http.auth.AuthSchemeFactory;
|
||||
import org.apache.hc.client5.http.auth.StandardAuthScheme;
|
||||
import org.apache.hc.client5.http.auth.AuthScope;
|
||||
import org.apache.hc.client5.http.auth.ChallengeType;
|
||||
import org.apache.hc.client5.http.auth.Credentials;
|
||||
import org.apache.hc.client5.http.auth.CredentialsStore;
|
||||
import org.apache.hc.client5.http.auth.StandardAuthScheme;
|
||||
import org.apache.hc.client5.http.auth.UsernamePasswordCredentials;
|
||||
import org.apache.hc.client5.http.config.RequestConfig;
|
||||
import org.apache.hc.client5.http.impl.DefaultAuthenticationStrategy;
|
||||
@ -164,7 +164,10 @@ public AsyncServerExchangeHandler get() {
|
||||
final HttpClientContext context = HttpClientContext.create();
|
||||
context.setCredentialsProvider(credsProvider);
|
||||
|
||||
final Future<SimpleHttpResponse> future = httpclient.execute(SimpleHttpRequests.get(target, "/"), context, null);
|
||||
final Future<SimpleHttpResponse> future = httpclient.execute(SimpleRequestBuilder.get()
|
||||
.setHttpHost(target)
|
||||
.setPath("/")
|
||||
.build(), context, null);
|
||||
final HttpResponse response = future.get();
|
||||
|
||||
Assert.assertNotNull(response);
|
||||
@ -191,7 +194,10 @@ public AsyncServerExchangeHandler get() {
|
||||
final HttpClientContext context = HttpClientContext.create();
|
||||
context.setCredentialsProvider(credsProvider);
|
||||
|
||||
final Future<SimpleHttpResponse> future = httpclient.execute(SimpleHttpRequests.get(target, "/"), context, null);
|
||||
final Future<SimpleHttpResponse> future = httpclient.execute(SimpleRequestBuilder.get()
|
||||
.setHttpHost(target)
|
||||
.setPath("/")
|
||||
.build(), context, null);
|
||||
final HttpResponse response = future.get();
|
||||
|
||||
Assert.assertNotNull(response);
|
||||
@ -218,7 +224,11 @@ public AsyncServerExchangeHandler get() {
|
||||
final HttpClientContext context = HttpClientContext.create();
|
||||
context.setCredentialsProvider(credsProvider);
|
||||
|
||||
final Future<SimpleHttpResponse> future = httpclient.execute(SimpleHttpRequests.get(target, "/"), context, null);
|
||||
final Future<SimpleHttpResponse> future = httpclient.execute(
|
||||
SimpleRequestBuilder.get()
|
||||
.setHttpHost(target)
|
||||
.setPath("/")
|
||||
.build(), context, null);
|
||||
final HttpResponse response = future.get();
|
||||
|
||||
Assert.assertNotNull(response);
|
||||
@ -244,10 +254,12 @@ public AsyncServerExchangeHandler get() {
|
||||
new UsernamePasswordCredentials("test", "test".toCharArray()));
|
||||
final HttpClientContext context = HttpClientContext.create();
|
||||
context.setCredentialsProvider(credsProvider);
|
||||
|
||||
final SimpleHttpRequest put = SimpleHttpRequests.put(target, "/");
|
||||
put.setBody("Some important stuff", ContentType.TEXT_PLAIN);
|
||||
final Future<SimpleHttpResponse> future = httpclient.execute(put, context, null);
|
||||
final Future<SimpleHttpResponse> future = httpclient.execute(
|
||||
SimpleRequestBuilder.put()
|
||||
.setHttpHost(target)
|
||||
.setPath("/")
|
||||
.setBody("Some important stuff", ContentType.TEXT_PLAIN)
|
||||
.build(), context, null);
|
||||
final HttpResponse response = future.get();
|
||||
|
||||
Assert.assertNotNull(response);
|
||||
@ -274,10 +286,12 @@ public AsyncServerExchangeHandler get() {
|
||||
final HttpClientContext context = HttpClientContext.create();
|
||||
context.setCredentialsProvider(credsProvider);
|
||||
context.setRequestConfig(RequestConfig.custom().setExpectContinueEnabled(true).build());
|
||||
|
||||
final SimpleHttpRequest put = SimpleHttpRequests.put(target, "/");
|
||||
put.setBody("Some important stuff", ContentType.TEXT_PLAIN);
|
||||
final Future<SimpleHttpResponse> future = httpclient.execute(put, context, null);
|
||||
final Future<SimpleHttpResponse> future = httpclient.execute(
|
||||
SimpleRequestBuilder.put()
|
||||
.setHttpHost(target)
|
||||
.setPath("/")
|
||||
.setBody("Some important stuff", ContentType.TEXT_PLAIN)
|
||||
.build(), context, null);
|
||||
final HttpResponse response = future.get();
|
||||
|
||||
Assert.assertNotNull(response);
|
||||
@ -301,10 +315,12 @@ public AsyncServerExchangeHandler get() {
|
||||
final HttpClientContext context = HttpClientContext.create();
|
||||
context.setCredentialsProvider(credsProvider);
|
||||
context.setRequestConfig(RequestConfig.custom().setExpectContinueEnabled(true).build());
|
||||
|
||||
final SimpleHttpRequest put = SimpleHttpRequests.put(target, "/");
|
||||
put.setBody("Some important stuff", ContentType.TEXT_PLAIN);
|
||||
final Future<SimpleHttpResponse> future = httpclient.execute(put, context, null);
|
||||
final Future<SimpleHttpResponse> future = httpclient.execute(
|
||||
SimpleRequestBuilder.put()
|
||||
.setHttpHost(target)
|
||||
.setPath("/")
|
||||
.setBody("Some important stuff", ContentType.TEXT_PLAIN)
|
||||
.build(), context, null);
|
||||
final HttpResponse response = future.get();
|
||||
|
||||
Assert.assertNotNull(response);
|
||||
@ -345,12 +361,18 @@ public List<AuthScheme> select(
|
||||
final HttpClientContext context = HttpClientContext.create();
|
||||
context.setCredentialsProvider(credsProvider);
|
||||
|
||||
final Future<SimpleHttpResponse> future1 = httpclient.execute(SimpleHttpRequests.get(target, "/"), context, null);
|
||||
final Future<SimpleHttpResponse> future1 = httpclient.execute(SimpleRequestBuilder.get()
|
||||
.setHttpHost(target)
|
||||
.setPath("/")
|
||||
.build(), context, null);
|
||||
final HttpResponse response1 = future1.get();
|
||||
Assert.assertNotNull(response1);
|
||||
Assert.assertEquals(HttpStatus.SC_OK, response1.getCode());
|
||||
|
||||
final Future<SimpleHttpResponse> future2 = httpclient.execute(SimpleHttpRequests.get(target, "/"), context, null);
|
||||
final Future<SimpleHttpResponse> future2 = httpclient.execute(SimpleRequestBuilder.get()
|
||||
.setHttpHost(target)
|
||||
.setPath("/")
|
||||
.build(), context, null);
|
||||
final HttpResponse response2 = future2.get();
|
||||
Assert.assertNotNull(response2);
|
||||
Assert.assertEquals(HttpStatus.SC_OK, response2.getCode());
|
||||
@ -372,7 +394,11 @@ public AsyncServerExchangeHandler get() {
|
||||
|
||||
final HttpClientContext context = HttpClientContext.create();
|
||||
final Future<SimpleHttpResponse> future = httpclient.execute(
|
||||
SimpleHttpRequests.get(target.getSchemeName() + "://test:test@" + target.toHostString() + "/"), context, null);
|
||||
SimpleRequestBuilder.get()
|
||||
.setScheme(target.getSchemeName())
|
||||
.setAuthority(new URIAuthority("test:test", target.getHostName(), target.getPort()))
|
||||
.setPath("/")
|
||||
.build(), context, null);
|
||||
final SimpleHttpResponse response = future.get();
|
||||
|
||||
Assert.assertNotNull(response);
|
||||
@ -392,8 +418,11 @@ public AsyncServerExchangeHandler get() {
|
||||
final HttpHost target = start();
|
||||
|
||||
final HttpClientContext context = HttpClientContext.create();
|
||||
final Future<SimpleHttpResponse> future = httpclient.execute(
|
||||
SimpleHttpRequests.get(target.getSchemeName() + "://test:all-worng@" + target.toHostString() + "/"), context, null);
|
||||
final Future<SimpleHttpResponse> future = httpclient.execute(SimpleRequestBuilder.get()
|
||||
.setScheme(target.getSchemeName())
|
||||
.setAuthority(new URIAuthority("test:all-worng", target.getHostName(), target.getPort()))
|
||||
.setPath("/")
|
||||
.build(), context, null);
|
||||
final SimpleHttpResponse response = future.get();
|
||||
|
||||
Assert.assertNotNull(response);
|
||||
@ -431,7 +460,11 @@ protected SimpleHttpResponse handle(
|
||||
|
||||
final HttpClientContext context = HttpClientContext.create();
|
||||
final Future<SimpleHttpResponse> future = httpclient.execute(
|
||||
SimpleHttpRequests.get(target.getSchemeName() + "://test:test@" + target.toHostString() + "/thatway"), context, null);
|
||||
SimpleRequestBuilder.get()
|
||||
.setScheme(target.getSchemeName())
|
||||
.setAuthority(new URIAuthority("test:test", target.getHostName(), target.getPort()))
|
||||
.setPath("/thatway")
|
||||
.build(), context, null);
|
||||
final SimpleHttpResponse response = future.get();
|
||||
|
||||
Assert.assertNotNull(response);
|
||||
@ -511,7 +544,10 @@ protected void customizeUnauthorizedResponse(final HttpResponse unauthorized) {
|
||||
context.setCredentialsProvider(credsProvider);
|
||||
|
||||
for (int i = 0; i < 10; i++) {
|
||||
final SimpleHttpRequest request = SimpleHttpRequests.get(target, "/");
|
||||
final SimpleHttpRequest request = SimpleRequestBuilder.get()
|
||||
.setHttpHost(target)
|
||||
.setPath("/")
|
||||
.build();
|
||||
request.setConfig(config);
|
||||
final Future<SimpleHttpResponse> future = httpclient.execute(request, context, null);
|
||||
final SimpleHttpResponse response = future.get();
|
||||
@ -552,7 +588,10 @@ protected void customizeUnauthorizedResponse(final HttpResponse unauthorized) {
|
||||
final HttpClientContext context = HttpClientContext.create();
|
||||
context.setCredentialsProvider(credsProvider);
|
||||
|
||||
final Future<SimpleHttpResponse> future = httpclient.execute(SimpleHttpRequests.get(target, "/"), context, null);
|
||||
final Future<SimpleHttpResponse> future = httpclient.execute(SimpleRequestBuilder.get()
|
||||
.setHttpHost(target)
|
||||
.setPath("/")
|
||||
.build(), context, null);
|
||||
final SimpleHttpResponse response = future.get();
|
||||
Assert.assertNotNull(response);
|
||||
Assert.assertEquals(HttpStatus.SC_OK, response.getCode());
|
||||
|
@ -36,8 +36,8 @@
|
||||
import java.util.concurrent.Future;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
|
||||
import org.apache.hc.client5.http.async.methods.SimpleHttpRequests;
|
||||
import org.apache.hc.client5.http.async.methods.SimpleHttpResponse;
|
||||
import org.apache.hc.client5.http.async.methods.SimpleRequestBuilder;
|
||||
import org.apache.hc.client5.http.impl.async.CloseableHttpAsyncClient;
|
||||
import org.apache.hc.client5.http.protocol.HttpClientContext;
|
||||
import org.apache.hc.core5.concurrent.FutureCallback;
|
||||
@ -66,7 +66,10 @@ public void testSequenctialGetRequests() throws Exception {
|
||||
final HttpHost target = start();
|
||||
for (int i = 0; i < 3; i++) {
|
||||
final Future<SimpleHttpResponse> future = httpclient.execute(
|
||||
SimpleHttpRequests.get(target, "/random/2048"), null);
|
||||
SimpleRequestBuilder.get()
|
||||
.setHttpHost(target)
|
||||
.setPath("/random/2048")
|
||||
.build(), null);
|
||||
final SimpleHttpResponse response = future.get();
|
||||
Assert.assertThat(response, CoreMatchers.notNullValue());
|
||||
Assert.assertThat(response.getCode(), CoreMatchers.equalTo(200));
|
||||
@ -81,7 +84,10 @@ public void testSequenctialHeadRequests() throws Exception {
|
||||
final HttpHost target = start();
|
||||
for (int i = 0; i < 3; i++) {
|
||||
final Future<SimpleHttpResponse> future = httpclient.execute(
|
||||
SimpleHttpRequests.head(target, "/random/2048"), null);
|
||||
SimpleRequestBuilder.head()
|
||||
.setHttpHost(target)
|
||||
.setPath("/random/2048")
|
||||
.build(), null);
|
||||
final SimpleHttpResponse response = future.get();
|
||||
Assert.assertThat(response, CoreMatchers.notNullValue());
|
||||
Assert.assertThat(response.getCode(), CoreMatchers.equalTo(200));
|
||||
@ -154,7 +160,11 @@ public void completed(final SimpleHttpResponse result) {
|
||||
try {
|
||||
resultQueue.add(result);
|
||||
if (count.decrementAndGet() > 0) {
|
||||
httpclient.execute(SimpleHttpRequests.get(target, "/random/2048"), this);
|
||||
httpclient.execute(
|
||||
SimpleRequestBuilder.get()
|
||||
.setHttpHost(target)
|
||||
.setPath("/random/2048")
|
||||
.build(), this);
|
||||
}
|
||||
} finally {
|
||||
countDownLatch.countDown();
|
||||
@ -180,7 +190,11 @@ public void cancelled() {
|
||||
@Override
|
||||
public void run() {
|
||||
if (!Thread.currentThread().isInterrupted()) {
|
||||
httpclient.execute(SimpleHttpRequests.get(target, "/random/2048"), callback);
|
||||
httpclient.execute(
|
||||
SimpleRequestBuilder.get()
|
||||
.setHttpHost(target)
|
||||
.setPath("/random/2048")
|
||||
.build(), callback);
|
||||
}
|
||||
}
|
||||
|
||||
@ -205,7 +219,10 @@ public void run() {
|
||||
public void testBadRequest() throws Exception {
|
||||
final HttpHost target = start();
|
||||
final Future<SimpleHttpResponse> future = httpclient.execute(
|
||||
SimpleHttpRequests.get(target, "/random/boom"), null);
|
||||
SimpleRequestBuilder.get()
|
||||
.setHttpHost(target)
|
||||
.setPath("/random/boom")
|
||||
.build(), null);
|
||||
final SimpleHttpResponse response = future.get();
|
||||
Assert.assertThat(response, CoreMatchers.notNullValue());
|
||||
Assert.assertThat(response.getCode(), CoreMatchers.equalTo(400));
|
||||
|
@ -35,8 +35,8 @@
|
||||
import org.apache.hc.client5.http.CircularRedirectException;
|
||||
import org.apache.hc.client5.http.RedirectException;
|
||||
import org.apache.hc.client5.http.async.methods.SimpleHttpRequest;
|
||||
import org.apache.hc.client5.http.async.methods.SimpleHttpRequests;
|
||||
import org.apache.hc.client5.http.async.methods.SimpleHttpResponse;
|
||||
import org.apache.hc.client5.http.async.methods.SimpleRequestBuilder;
|
||||
import org.apache.hc.client5.http.config.RequestConfig;
|
||||
import org.apache.hc.client5.http.cookie.BasicCookieStore;
|
||||
import org.apache.hc.client5.http.cookie.CookieStore;
|
||||
@ -113,7 +113,10 @@ public AsyncServerExchangeHandler decorate(final AsyncServerExchangeHandler exch
|
||||
|
||||
final HttpClientContext context = HttpClientContext.create();
|
||||
final Future<SimpleHttpResponse> future = httpclient.execute(
|
||||
SimpleHttpRequests.get(target, "/oldlocation/"), context, null);
|
||||
SimpleRequestBuilder.get()
|
||||
.setHttpHost(target)
|
||||
.setPath("/oldlocation/")
|
||||
.build(), context, null);
|
||||
final HttpResponse response = future.get();
|
||||
Assert.assertNotNull(response);
|
||||
|
||||
@ -137,7 +140,10 @@ public AsyncServerExchangeHandler decorate(final AsyncServerExchangeHandler exch
|
||||
});
|
||||
final HttpClientContext context = HttpClientContext.create();
|
||||
final Future<SimpleHttpResponse> future = httpclient.execute(
|
||||
SimpleHttpRequests.get(target, "/oldlocation/100"), context, null);
|
||||
SimpleRequestBuilder.get()
|
||||
.setHttpHost(target)
|
||||
.setPath("/oldlocation/100")
|
||||
.build(), context, null);
|
||||
final HttpResponse response = future.get();
|
||||
Assert.assertNotNull(response);
|
||||
|
||||
@ -162,7 +168,10 @@ public AsyncServerExchangeHandler decorate(final AsyncServerExchangeHandler exch
|
||||
});
|
||||
final HttpClientContext context = HttpClientContext.create();
|
||||
final Future<SimpleHttpResponse> future = httpclient.execute(
|
||||
SimpleHttpRequests.get(target, "/oldlocation/123"), context, null);
|
||||
SimpleRequestBuilder.get()
|
||||
.setHttpHost(target)
|
||||
.setPath("/oldlocation/123")
|
||||
.build(), context, null);
|
||||
final HttpResponse response = future.get();
|
||||
Assert.assertNotNull(response);
|
||||
|
||||
@ -198,7 +207,10 @@ public Redirect resolve(final URI requestUri) throws URISyntaxException {
|
||||
});
|
||||
final HttpClientContext context = HttpClientContext.create();
|
||||
final Future<SimpleHttpResponse> future = httpclient.execute(
|
||||
SimpleHttpRequests.get(target, "/oldlocation/100"), context, null);
|
||||
SimpleRequestBuilder.get()
|
||||
.setHttpHost(target)
|
||||
.setPath("/oldlocation/100")
|
||||
.build(), context, null);
|
||||
final HttpResponse response = future.get();
|
||||
Assert.assertNotNull(response);
|
||||
|
||||
@ -222,7 +234,10 @@ public AsyncServerExchangeHandler decorate(final AsyncServerExchangeHandler exch
|
||||
});
|
||||
final HttpClientContext context = HttpClientContext.create();
|
||||
final Future<SimpleHttpResponse> future = httpclient.execute(
|
||||
SimpleHttpRequests.get(target, "/oldlocation/123"), context, null);
|
||||
SimpleRequestBuilder.get()
|
||||
.setHttpHost(target)
|
||||
.setPath("/oldlocation/123")
|
||||
.build(), context, null);
|
||||
final HttpResponse response = future.get();
|
||||
Assert.assertNotNull(response);
|
||||
|
||||
@ -254,7 +269,10 @@ protected SimpleHttpResponse handle(final SimpleHttpRequest request,
|
||||
final HttpHost target = start();
|
||||
final HttpClientContext context = HttpClientContext.create();
|
||||
final Future<SimpleHttpResponse> future = httpclient.execute(
|
||||
SimpleHttpRequests.get(target, "/oldlocation/"), context, null);
|
||||
SimpleRequestBuilder.get()
|
||||
.setHttpHost(target)
|
||||
.setPath("/oldlocation/")
|
||||
.build(), context, null);
|
||||
final HttpResponse response = future.get();
|
||||
Assert.assertNotNull(response);
|
||||
|
||||
@ -285,7 +303,10 @@ protected SimpleHttpResponse handle(final SimpleHttpRequest request,
|
||||
final HttpHost target = start();
|
||||
final HttpClientContext context = HttpClientContext.create();
|
||||
final Future<SimpleHttpResponse> future = httpclient.execute(
|
||||
SimpleHttpRequests.get(target, "/oldlocation/"), context, null);
|
||||
SimpleRequestBuilder.get()
|
||||
.setHttpHost(target)
|
||||
.setPath("/oldlocation/")
|
||||
.build(), context, null);
|
||||
final HttpResponse response = future.get();
|
||||
Assert.assertNotNull(response);
|
||||
|
||||
@ -309,7 +330,10 @@ public AsyncServerExchangeHandler decorate(final AsyncServerExchangeHandler exch
|
||||
});
|
||||
final HttpClientContext context = HttpClientContext.create();
|
||||
final Future<SimpleHttpResponse> future = httpclient.execute(
|
||||
SimpleHttpRequests.get(target, "/oldlocation/123"), context, null);
|
||||
SimpleRequestBuilder.get()
|
||||
.setHttpHost(target)
|
||||
.setPath("/oldlocation/123")
|
||||
.build(), context, null);
|
||||
final HttpResponse response = future.get();
|
||||
Assert.assertNotNull(response);
|
||||
|
||||
@ -338,9 +362,11 @@ public AsyncServerExchangeHandler decorate(final AsyncServerExchangeHandler exch
|
||||
.setCircularRedirectsAllowed(true)
|
||||
.setMaxRedirects(5).build();
|
||||
try {
|
||||
final SimpleHttpRequest request = SimpleHttpRequests.get(target, "/circular-oldlocation/");
|
||||
request.setConfig(config);
|
||||
final Future<SimpleHttpResponse> future = httpclient.execute(request, null);
|
||||
final Future<SimpleHttpResponse> future = httpclient.execute(SimpleRequestBuilder.get()
|
||||
.setHttpHost(target)
|
||||
.setPath("/circular-oldlocation/")
|
||||
.setRequestConfig(config)
|
||||
.build(), null);
|
||||
future.get();
|
||||
} catch (final ExecutionException e) {
|
||||
Assert.assertTrue(e.getCause() instanceof RedirectException);
|
||||
@ -366,9 +392,12 @@ public AsyncServerExchangeHandler decorate(final AsyncServerExchangeHandler exch
|
||||
.setCircularRedirectsAllowed(false)
|
||||
.build();
|
||||
try {
|
||||
final SimpleHttpRequest request = SimpleHttpRequests.get(target, "/circular-oldlocation/");
|
||||
request.setConfig(config);
|
||||
final Future<SimpleHttpResponse> future = httpclient.execute(request, null);
|
||||
final Future<SimpleHttpResponse> future = httpclient.execute(
|
||||
SimpleRequestBuilder.get()
|
||||
.setHttpHost(target)
|
||||
.setPath("/circular-oldlocation/")
|
||||
.setRequestConfig(config)
|
||||
.build(), null);
|
||||
future.get();
|
||||
} catch (final ExecutionException e) {
|
||||
Assert.assertTrue(e.getCause() instanceof CircularRedirectException);
|
||||
@ -390,10 +419,12 @@ public AsyncServerExchangeHandler decorate(final AsyncServerExchangeHandler exch
|
||||
});
|
||||
|
||||
final HttpClientContext context = HttpClientContext.create();
|
||||
|
||||
final SimpleHttpRequest post = SimpleHttpRequests.post(target, "/oldlocation/stuff");
|
||||
post.setBody("stuff", ContentType.TEXT_PLAIN);
|
||||
final Future<SimpleHttpResponse> future = httpclient.execute(post, context, null);
|
||||
final Future<SimpleHttpResponse> future = httpclient.execute(
|
||||
SimpleRequestBuilder.post()
|
||||
.setHttpHost(target)
|
||||
.setPath("/oldlocation/stuff")
|
||||
.setBody("stuff", ContentType.TEXT_PLAIN)
|
||||
.build(), context, null);
|
||||
final HttpResponse response = future.get();
|
||||
Assert.assertNotNull(response);
|
||||
|
||||
@ -418,10 +449,12 @@ public AsyncServerExchangeHandler decorate(final AsyncServerExchangeHandler exch
|
||||
});
|
||||
|
||||
final HttpClientContext context = HttpClientContext.create();
|
||||
|
||||
final SimpleHttpRequest post = SimpleHttpRequests.post(target, "/oldlocation/stuff");
|
||||
post.setBody("stuff", ContentType.TEXT_PLAIN);
|
||||
final Future<SimpleHttpResponse> future = httpclient.execute(post, context, null);
|
||||
final Future<SimpleHttpResponse> future = httpclient.execute(
|
||||
SimpleRequestBuilder.post()
|
||||
.setHttpHost(target)
|
||||
.setPath("/oldlocation/stuff")
|
||||
.setBody("stuff", ContentType.TEXT_PLAIN)
|
||||
.build(), context, null);
|
||||
final HttpResponse response = future.get();
|
||||
Assert.assertNotNull(response);
|
||||
|
||||
@ -460,7 +493,10 @@ public Redirect resolve(final URI requestUri) throws URISyntaxException {
|
||||
final HttpClientContext context = HttpClientContext.create();
|
||||
|
||||
final Future<SimpleHttpResponse> future = httpclient.execute(
|
||||
SimpleHttpRequests.get(target, "/oldlocation/stuff"), context, null);
|
||||
SimpleRequestBuilder.get()
|
||||
.setHttpHost(target)
|
||||
.setPath("/oldlocation/stuff")
|
||||
.build(), context, null);
|
||||
final HttpResponse response = future.get();
|
||||
Assert.assertNotNull(response);
|
||||
|
||||
@ -499,7 +535,10 @@ public Redirect resolve(final URI requestUri) throws URISyntaxException {
|
||||
final HttpClientContext context = HttpClientContext.create();
|
||||
|
||||
final Future<SimpleHttpResponse> future = httpclient.execute(
|
||||
SimpleHttpRequests.get(target, "/random/oldlocation"), context, null);
|
||||
SimpleRequestBuilder.get()
|
||||
.setHttpHost(target)
|
||||
.setPath("/random/oldlocation")
|
||||
.build(), context, null);
|
||||
final HttpResponse response = future.get();
|
||||
Assert.assertNotNull(response);
|
||||
|
||||
@ -537,7 +576,10 @@ public Redirect resolve(final URI requestUri) throws URISyntaxException {
|
||||
|
||||
try {
|
||||
final Future<SimpleHttpResponse> future = httpclient.execute(
|
||||
SimpleHttpRequests.get(target, "/oldlocation/"), null);
|
||||
SimpleRequestBuilder.get()
|
||||
.setHttpHost(target)
|
||||
.setPath("/oldlocation/")
|
||||
.build(), null);
|
||||
future.get();
|
||||
} catch (final ExecutionException ex) {
|
||||
Assert.assertTrue(ex.getCause() instanceof HttpException);
|
||||
@ -572,7 +614,10 @@ public Redirect resolve(final URI requestUri) throws URISyntaxException {
|
||||
|
||||
try {
|
||||
final Future<SimpleHttpResponse> future = httpclient.execute(
|
||||
SimpleHttpRequests.get(target, "/oldlocation/"), null);
|
||||
SimpleRequestBuilder.get()
|
||||
.setHttpHost(target)
|
||||
.setPath("/oldlocation/")
|
||||
.build(), null);
|
||||
future.get();
|
||||
} catch (final ExecutionException e) {
|
||||
Assert.assertTrue(e.getCause() instanceof ProtocolException);
|
||||
@ -604,7 +649,10 @@ public AsyncServerExchangeHandler decorate(final AsyncServerExchangeHandler exch
|
||||
cookieStore.addCookie(cookie);
|
||||
|
||||
final Future<SimpleHttpResponse> future = httpclient.execute(
|
||||
SimpleHttpRequests.get(target, "/oldlocation/100"), context, null);
|
||||
SimpleRequestBuilder.get()
|
||||
.setHttpHost(target)
|
||||
.setPath("/oldlocation/100")
|
||||
.build(), context, null);
|
||||
final HttpResponse response = future.get();
|
||||
Assert.assertNotNull(response);
|
||||
|
||||
@ -670,7 +718,10 @@ public Redirect resolve(final URI requestUri) throws URISyntaxException {
|
||||
|
||||
final HttpClientContext context = HttpClientContext.create();
|
||||
final Future<SimpleHttpResponse> future = httpclient.execute(
|
||||
SimpleHttpRequests.get(target, "/oldlocation"), context, null);
|
||||
SimpleRequestBuilder.get()
|
||||
.setHttpHost(target)
|
||||
.setPath("/oldlocation")
|
||||
.build(), context, null);
|
||||
final HttpResponse response = future.get();
|
||||
Assert.assertNotNull(response);
|
||||
|
||||
|
@ -30,9 +30,8 @@
|
||||
import java.util.Collection;
|
||||
import java.util.concurrent.Future;
|
||||
|
||||
import org.apache.hc.client5.http.async.methods.SimpleHttpRequest;
|
||||
import org.apache.hc.client5.http.async.methods.SimpleHttpRequests;
|
||||
import org.apache.hc.client5.http.async.methods.SimpleHttpResponse;
|
||||
import org.apache.hc.client5.http.async.methods.SimpleRequestBuilder;
|
||||
import org.apache.hc.client5.http.config.RequestConfig;
|
||||
import org.apache.hc.client5.http.impl.async.CloseableHttpAsyncClient;
|
||||
import org.apache.hc.client5.http.impl.async.HttpAsyncClientBuilder;
|
||||
@ -121,9 +120,12 @@ public HttpHost start() throws Exception {
|
||||
public void testSequenctialGetRequestsCloseConnection() throws Exception {
|
||||
final HttpHost target = start();
|
||||
for (int i = 0; i < 3; i++) {
|
||||
final SimpleHttpRequest get = SimpleHttpRequests.get(target, "/random/2048");
|
||||
get.setHeader(HttpHeaders.CONNECTION, HeaderElements.CLOSE);
|
||||
final Future<SimpleHttpResponse> future = httpclient.execute(get, null);
|
||||
final Future<SimpleHttpResponse> future = httpclient.execute(
|
||||
SimpleRequestBuilder.get()
|
||||
.setHttpHost(target)
|
||||
.setPath("/random/2048")
|
||||
.addHeader(HttpHeaders.CONNECTION, HeaderElements.CLOSE)
|
||||
.build(), null);
|
||||
final SimpleHttpResponse response = future.get();
|
||||
Assert.assertThat(response, CoreMatchers.notNullValue());
|
||||
Assert.assertThat(response.getCode(), CoreMatchers.equalTo(200));
|
||||
@ -151,7 +153,10 @@ public void testConcurrentPostsOverSingleConnection() throws Exception {
|
||||
public void testSharedPool() throws Exception {
|
||||
final HttpHost target = start();
|
||||
final Future<SimpleHttpResponse> future1 = httpclient.execute(
|
||||
SimpleHttpRequests.get(target, "/random/2048"), null);
|
||||
SimpleRequestBuilder.get()
|
||||
.setHttpHost(target)
|
||||
.setPath("/random/2048")
|
||||
.build(), null);
|
||||
final SimpleHttpResponse response1 = future1.get();
|
||||
Assert.assertThat(response1, CoreMatchers.notNullValue());
|
||||
Assert.assertThat(response1.getCode(), CoreMatchers.equalTo(200));
|
||||
@ -166,7 +171,10 @@ public void testSharedPool() throws Exception {
|
||||
.build()) {
|
||||
httpclient2.start();
|
||||
final Future<SimpleHttpResponse> future2 = httpclient2.execute(
|
||||
SimpleHttpRequests.get(target, "/random/2048"), null);
|
||||
SimpleRequestBuilder.get()
|
||||
.setHttpHost(target)
|
||||
.setPath("/random/2048")
|
||||
.build(), null);
|
||||
final SimpleHttpResponse response2 = future2.get();
|
||||
Assert.assertThat(response2, CoreMatchers.notNullValue());
|
||||
Assert.assertThat(response2.getCode(), CoreMatchers.equalTo(200));
|
||||
@ -176,7 +184,10 @@ public void testSharedPool() throws Exception {
|
||||
}
|
||||
|
||||
final Future<SimpleHttpResponse> future3 = httpclient.execute(
|
||||
SimpleHttpRequests.get(target, "/random/2048"), null);
|
||||
SimpleRequestBuilder.get()
|
||||
.setHttpHost(target)
|
||||
.setPath("/random/2048")
|
||||
.build(), null);
|
||||
final SimpleHttpResponse response3 = future3.get();
|
||||
Assert.assertThat(response3, CoreMatchers.notNullValue());
|
||||
Assert.assertThat(response3.getCode(), CoreMatchers.equalTo(200));
|
||||
|
@ -32,8 +32,8 @@
|
||||
import java.util.List;
|
||||
import java.util.concurrent.Future;
|
||||
|
||||
import org.apache.hc.client5.http.async.methods.SimpleHttpRequests;
|
||||
import org.apache.hc.client5.http.async.methods.SimpleHttpResponse;
|
||||
import org.apache.hc.client5.http.async.methods.SimpleRequestBuilder;
|
||||
import org.apache.hc.client5.http.config.RequestConfig;
|
||||
import org.apache.hc.client5.http.impl.async.CloseableHttpAsyncClient;
|
||||
import org.apache.hc.client5.http.impl.async.HttpAsyncClientBuilder;
|
||||
@ -137,8 +137,10 @@ public AsyncServerExchangeHandler decorate(final AsyncServerExchangeHandler exch
|
||||
|
||||
});
|
||||
final HttpClientContext context = HttpClientContext.create();
|
||||
final Future<SimpleHttpResponse> future = httpclient.execute(
|
||||
SimpleHttpRequests.get(target, "/oldlocation/"), context, null);
|
||||
final Future<SimpleHttpResponse> future = httpclient.execute(SimpleRequestBuilder.get()
|
||||
.setHttpHost(target)
|
||||
.setPath("/oldlocation/")
|
||||
.build(), context, null);
|
||||
final HttpResponse response = future.get();
|
||||
Assert.assertNotNull(response);
|
||||
|
||||
@ -162,8 +164,10 @@ public AsyncServerExchangeHandler decorate(final AsyncServerExchangeHandler exch
|
||||
|
||||
});
|
||||
final HttpClientContext context = HttpClientContext.create();
|
||||
final Future<SimpleHttpResponse> future = httpclient.execute(
|
||||
SimpleHttpRequests.get(target, "/oldlocation/100"), context, null);
|
||||
final Future<SimpleHttpResponse> future = httpclient.execute(SimpleRequestBuilder.get()
|
||||
.setHttpHost(target)
|
||||
.setPath("/oldlocation/100")
|
||||
.build(), context, null);
|
||||
final HttpResponse response = future.get();
|
||||
Assert.assertNotNull(response);
|
||||
|
||||
@ -194,8 +198,10 @@ public AsyncServerExchangeHandler decorate(final AsyncServerExchangeHandler exch
|
||||
|
||||
final HttpClientContext context = HttpClientContext.create();
|
||||
|
||||
final Future<SimpleHttpResponse> future = httpclient.execute(
|
||||
SimpleHttpRequests.get(target, "/oldlocation/123"), context, null);
|
||||
final Future<SimpleHttpResponse> future = httpclient.execute(SimpleRequestBuilder.get()
|
||||
.setHttpHost(target)
|
||||
.setPath("/oldlocation/123")
|
||||
.build(), context, null);
|
||||
final HttpResponse response = future.get();
|
||||
Assert.assertNotNull(response);
|
||||
|
||||
|
@ -31,8 +31,8 @@
|
||||
import org.apache.hc.client5.http.HttpRoute;
|
||||
import org.apache.hc.client5.http.UserTokenHandler;
|
||||
import org.apache.hc.client5.http.async.methods.SimpleHttpRequest;
|
||||
import org.apache.hc.client5.http.async.methods.SimpleHttpRequests;
|
||||
import org.apache.hc.client5.http.async.methods.SimpleHttpResponse;
|
||||
import org.apache.hc.client5.http.async.methods.SimpleRequestBuilder;
|
||||
import org.apache.hc.client5.http.config.RequestConfig;
|
||||
import org.apache.hc.client5.http.impl.async.CloseableHttpAsyncClient;
|
||||
import org.apache.hc.client5.http.impl.async.HttpAsyncClientBuilder;
|
||||
@ -53,6 +53,7 @@
|
||||
import org.apache.hc.core5.http.protocol.BasicHttpContext;
|
||||
import org.apache.hc.core5.http.protocol.HttpContext;
|
||||
import org.apache.hc.core5.http.protocol.HttpCoreContext;
|
||||
import org.apache.hc.core5.net.URIAuthority;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
@ -216,8 +217,11 @@ public void run() {
|
||||
try {
|
||||
context.setAttribute("user", uid);
|
||||
for (int r = 0; r < requestCount; r++) {
|
||||
final SimpleHttpRequest httpget = SimpleHttpRequests.get(target, "/");
|
||||
final Future<SimpleHttpResponse> future = httpclient.execute(httpget, null);
|
||||
final SimpleHttpRequest request = SimpleRequestBuilder.get()
|
||||
.setHttpHost(target)
|
||||
.setPath("/")
|
||||
.build();
|
||||
final Future<SimpleHttpResponse> future = httpclient.execute(request, null);
|
||||
future.get();
|
||||
|
||||
count++;
|
||||
@ -277,7 +281,11 @@ public Object getUserToken(final HttpRoute route, final HttpContext context) {
|
||||
final HttpContext context1 = new BasicHttpContext();
|
||||
context1.setAttribute("user", "stuff");
|
||||
|
||||
final Future<SimpleHttpResponse> future1 = httpclient.execute(SimpleHttpRequests.get(target, "/"), context1, null);
|
||||
final SimpleHttpRequest request1 = SimpleRequestBuilder.get()
|
||||
.setHttpHost(target)
|
||||
.setPath("/")
|
||||
.build();
|
||||
final Future<SimpleHttpResponse> future1 = httpclient.execute(request1, context1, null);
|
||||
final HttpResponse response1 = future1.get();
|
||||
Assert.assertNotNull(response1);
|
||||
Assert.assertEquals(200, response1.getCode());
|
||||
@ -292,8 +300,12 @@ public Object getUserToken(final HttpRoute route, final HttpContext context) {
|
||||
// Send it to another route. Must be a keepalive.
|
||||
final HttpContext context2 = new BasicHttpContext();
|
||||
|
||||
final Future<SimpleHttpResponse> future2 = httpclient.execute(SimpleHttpRequests.get(
|
||||
new HttpHost(target.getSchemeName(), "127.0.0.1", target.getPort()),"/"), context2, null);
|
||||
final SimpleHttpRequest request2 = SimpleRequestBuilder.get()
|
||||
.setScheme(target.getSchemeName())
|
||||
.setAuthority(new URIAuthority("127.0.0.1", target.getPort()))
|
||||
.setPath("/")
|
||||
.build();
|
||||
final Future<SimpleHttpResponse> future2 = httpclient.execute(request2, context2, null);
|
||||
final HttpResponse response2 = future2.get();
|
||||
Assert.assertNotNull(response2);
|
||||
Assert.assertEquals(200, response2.getCode());
|
||||
@ -310,7 +322,12 @@ public Object getUserToken(final HttpRoute route, final HttpContext context) {
|
||||
// The killed conn is the oldest, which means the first HTTPGet ([localhost][stuff]).
|
||||
// When this happens, the RouteSpecificPool becomes empty.
|
||||
final HttpContext context3 = new BasicHttpContext();
|
||||
final Future<SimpleHttpResponse> future3 = httpclient.execute(SimpleHttpRequests.get(target, "/"), context3, null);
|
||||
|
||||
final SimpleHttpRequest request3 = SimpleRequestBuilder.get()
|
||||
.setHttpHost(target)
|
||||
.setPath("/")
|
||||
.build();
|
||||
final Future<SimpleHttpResponse> future3 = httpclient.execute(request3, context3, null);
|
||||
final HttpResponse response3 = future3.get();
|
||||
Assert.assertNotNull(response3);
|
||||
Assert.assertEquals(200, response3.getCode());
|
||||
|
@ -31,8 +31,9 @@
|
||||
import java.util.concurrent.Future;
|
||||
|
||||
import org.apache.hc.client5.http.AuthenticationStrategy;
|
||||
import org.apache.hc.client5.http.async.methods.SimpleHttpRequests;
|
||||
import org.apache.hc.client5.http.async.methods.SimpleHttpRequest;
|
||||
import org.apache.hc.client5.http.async.methods.SimpleHttpResponse;
|
||||
import org.apache.hc.client5.http.async.methods.SimpleRequestBuilder;
|
||||
import org.apache.hc.client5.http.auth.AuthSchemeFactory;
|
||||
import org.apache.hc.client5.http.auth.AuthScope;
|
||||
import org.apache.hc.client5.http.auth.UsernamePasswordCredentials;
|
||||
@ -166,7 +167,11 @@ protected void customizeUnauthorizedResponse(final HttpResponse unauthorized) {
|
||||
final HttpClientContext context = HttpClientContext.create();
|
||||
context.setCredentialsProvider(credsProvider);
|
||||
|
||||
final Future<SimpleHttpResponse> future = httpclient.execute(SimpleHttpRequests.get(target, "/"), context, null);
|
||||
final SimpleHttpRequest request = SimpleRequestBuilder.get()
|
||||
.setHttpHost(target)
|
||||
.setPath("/")
|
||||
.build();
|
||||
final Future<SimpleHttpResponse> future = httpclient.execute(request, context, null);
|
||||
final HttpResponse response = future.get();
|
||||
|
||||
Assert.assertNotNull(response);
|
||||
|
@ -31,7 +31,7 @@
|
||||
import java.util.Collection;
|
||||
|
||||
import org.apache.hc.client5.http.async.methods.SimpleHttpRequest;
|
||||
import org.apache.hc.client5.http.async.methods.SimpleHttpRequests;
|
||||
import org.apache.hc.client5.http.async.methods.SimpleRequestBuilder;
|
||||
import org.apache.hc.client5.http.config.RequestConfig;
|
||||
import org.apache.hc.client5.http.impl.async.CloseableHttpAsyncClient;
|
||||
import org.apache.hc.client5.http.impl.async.HttpAsyncClientBuilder;
|
||||
@ -126,7 +126,10 @@ public HttpHost start() throws Exception {
|
||||
public void testSequentialGetRequestsCloseConnection() throws Exception {
|
||||
final HttpHost target = start();
|
||||
for (int i = 0; i < 3; i++) {
|
||||
final SimpleHttpRequest get = SimpleHttpRequests.get(target, "/random/2048");
|
||||
final SimpleHttpRequest get = SimpleRequestBuilder.get()
|
||||
.setHttpHost(target)
|
||||
.setPath("/random/2048")
|
||||
.build();
|
||||
get.setHeader(HttpHeaders.CONNECTION, HeaderElements.CLOSE);
|
||||
final AsyncRequestProducer request = AsyncRequestBuilder.get(target + "/random/2048").build();
|
||||
final ReactiveResponseConsumer consumer = new ReactiveResponseConsumer();
|
||||
|
@ -38,8 +38,8 @@
|
||||
import javax.net.ssl.SSLContext;
|
||||
|
||||
import org.apache.hc.client5.http.async.methods.SimpleHttpRequest;
|
||||
import org.apache.hc.client5.http.async.methods.SimpleHttpRequests;
|
||||
import org.apache.hc.client5.http.async.methods.SimpleHttpResponse;
|
||||
import org.apache.hc.client5.http.async.methods.SimpleRequestBuilder;
|
||||
import org.apache.hc.client5.http.cache.CacheResponseStatus;
|
||||
import org.apache.hc.client5.http.cache.HttpCacheContext;
|
||||
import org.apache.hc.client5.http.impl.async.CloseableHttpAsyncClient;
|
||||
@ -131,7 +131,10 @@ void execute() throws Exception {
|
||||
// Initial ping
|
||||
{
|
||||
final HttpCacheContext context = HttpCacheContext.create();
|
||||
final SimpleHttpRequest options = SimpleHttpRequests.options(target, "*");
|
||||
final SimpleHttpRequest options = SimpleRequestBuilder.options()
|
||||
.setHttpHost(target)
|
||||
.setPath("*")
|
||||
.build();
|
||||
final Future<SimpleHttpResponse> future = client.execute(options, context, null);
|
||||
try {
|
||||
final SimpleHttpResponse response = future.get(TIMEOUT.getDuration(), TIMEOUT.getTimeUnit());
|
||||
@ -155,7 +158,10 @@ void execute() throws Exception {
|
||||
|
||||
final Pattern linkPattern = Pattern.compile("^<(.*)>;rel=preload$");
|
||||
final List<String> links = new ArrayList<>();
|
||||
final SimpleHttpRequest getRoot1 = SimpleHttpRequests.get(target, "/");
|
||||
final SimpleHttpRequest getRoot1 = SimpleRequestBuilder.get()
|
||||
.setHttpHost(target)
|
||||
.setPath("/")
|
||||
.build();
|
||||
final Future<SimpleHttpResponse> future1 = client.execute(getRoot1, context, null);
|
||||
try {
|
||||
final SimpleHttpResponse response = future1.get(TIMEOUT.getDuration(), TIMEOUT.getTimeUnit());
|
||||
@ -179,7 +185,10 @@ void execute() throws Exception {
|
||||
logResult(TestResult.NOK, getRoot1, "(time out)");
|
||||
}
|
||||
for (final String link: links) {
|
||||
final SimpleHttpRequest getLink = SimpleHttpRequests.get(target, link);
|
||||
final SimpleHttpRequest getLink = SimpleRequestBuilder.get()
|
||||
.setHttpHost(target)
|
||||
.setPath(link)
|
||||
.build();
|
||||
final Future<SimpleHttpResponse> linkFuture = client.execute(getLink, context, null);
|
||||
try {
|
||||
final SimpleHttpResponse response = linkFuture.get(TIMEOUT.getDuration(), TIMEOUT.getTimeUnit());
|
||||
@ -198,7 +207,10 @@ void execute() throws Exception {
|
||||
}
|
||||
}
|
||||
|
||||
final SimpleHttpRequest getRoot2 = SimpleHttpRequests.get(target, "/");
|
||||
final SimpleHttpRequest getRoot2 = SimpleRequestBuilder.get()
|
||||
.setHttpHost(target)
|
||||
.setPath("/")
|
||||
.build();
|
||||
final Future<SimpleHttpResponse> future2 = client.execute(getRoot2, context, null);
|
||||
try {
|
||||
final SimpleHttpResponse response = future2.get(TIMEOUT.getDuration(), TIMEOUT.getTimeUnit());
|
||||
@ -216,7 +228,10 @@ void execute() throws Exception {
|
||||
logResult(TestResult.NOK, getRoot2, "(time out)");
|
||||
}
|
||||
for (final String link: links) {
|
||||
final SimpleHttpRequest getLink = SimpleHttpRequests.get(target, link);
|
||||
final SimpleHttpRequest getLink = SimpleRequestBuilder.get()
|
||||
.setHttpHost(target)
|
||||
.setPath(link)
|
||||
.build();
|
||||
final Future<SimpleHttpResponse> linkFuture = client.execute(getLink, context, null);
|
||||
try {
|
||||
final SimpleHttpResponse response = linkFuture.get(TIMEOUT.getDuration(), TIMEOUT.getTimeUnit());
|
||||
|
@ -34,8 +34,8 @@
|
||||
import javax.net.ssl.SSLContext;
|
||||
|
||||
import org.apache.hc.client5.http.async.methods.SimpleHttpRequest;
|
||||
import org.apache.hc.client5.http.async.methods.SimpleHttpRequests;
|
||||
import org.apache.hc.client5.http.async.methods.SimpleHttpResponse;
|
||||
import org.apache.hc.client5.http.async.methods.SimpleRequestBuilder;
|
||||
import org.apache.hc.client5.http.auth.AuthScope;
|
||||
import org.apache.hc.client5.http.auth.Credentials;
|
||||
import org.apache.hc.client5.http.auth.UsernamePasswordCredentials;
|
||||
@ -177,7 +177,10 @@ void execute() throws Exception {
|
||||
final HttpClientContext context = HttpClientContext.create();
|
||||
context.setCredentialsProvider(credentialsProvider);
|
||||
|
||||
final SimpleHttpRequest options = SimpleHttpRequests.options(target, "*");
|
||||
final SimpleHttpRequest options = SimpleRequestBuilder.options()
|
||||
.setHttpHost(target)
|
||||
.setPath("*")
|
||||
.build();
|
||||
final Future<SimpleHttpResponse> future = client.execute(options, context, null);
|
||||
try {
|
||||
final SimpleHttpResponse response = future.get(TIMEOUT.getDuration(), TIMEOUT.getTimeUnit());
|
||||
@ -202,7 +205,10 @@ void execute() throws Exception {
|
||||
|
||||
final String[] requestUris = new String[] {"/", "/news.html", "/status.html"};
|
||||
for (final String requestUri: requestUris) {
|
||||
final SimpleHttpRequest httpGet = SimpleHttpRequests.get(target, requestUri);
|
||||
final SimpleHttpRequest httpGet = SimpleRequestBuilder.get()
|
||||
.setHttpHost(target)
|
||||
.setPath(requestUri)
|
||||
.build();
|
||||
final Future<SimpleHttpResponse> future = client.execute(httpGet, context, null);
|
||||
try {
|
||||
final SimpleHttpResponse response = future.get(TIMEOUT.getDuration(), TIMEOUT.getTimeUnit());
|
||||
@ -229,7 +235,10 @@ void execute() throws Exception {
|
||||
final HttpClientContext context = HttpClientContext.create();
|
||||
context.setCredentialsProvider(credentialsProvider);
|
||||
|
||||
final SimpleHttpRequest httpGetSecret = SimpleHttpRequests.get(target, "/private/big-secret.txt");
|
||||
final SimpleHttpRequest httpGetSecret = SimpleRequestBuilder.get()
|
||||
.setHttpHost(target)
|
||||
.setPath("/private/big-secret.txt")
|
||||
.build();
|
||||
final Future<SimpleHttpResponse> future = client.execute(httpGetSecret, context, null);
|
||||
try {
|
||||
final SimpleHttpResponse response = future.get(TIMEOUT.getDuration(), TIMEOUT.getTimeUnit());
|
||||
@ -255,7 +264,10 @@ void execute() throws Exception {
|
||||
final HttpClientContext context = HttpClientContext.create();
|
||||
context.setCredentialsProvider(credentialsProvider);
|
||||
|
||||
final SimpleHttpRequest httpGetSecret = SimpleHttpRequests.get(target, "/private/big-secret.txt");
|
||||
final SimpleHttpRequest httpGetSecret = SimpleRequestBuilder.get()
|
||||
.setHttpHost(target)
|
||||
.setPath("/private/big-secret.txt")
|
||||
.build();
|
||||
final Future<SimpleHttpResponse> future = client.execute(httpGetSecret, context, null);
|
||||
try {
|
||||
final SimpleHttpResponse response = future.get(TIMEOUT.getDuration(), TIMEOUT.getTimeUnit());
|
||||
@ -281,7 +293,10 @@ void execute() throws Exception {
|
||||
final HttpClientContext context = HttpClientContext.create();
|
||||
context.setCredentialsProvider(credentialsProvider);
|
||||
|
||||
final SimpleHttpRequest httpGetSecret = SimpleHttpRequests.get(target, "/private/big-secret.txt");
|
||||
final SimpleHttpRequest httpGetSecret = SimpleRequestBuilder.get()
|
||||
.setHttpHost(target)
|
||||
.setPath("/private/big-secret.txt")
|
||||
.build();
|
||||
final Future<SimpleHttpResponse> future = client.execute(httpGetSecret, context, null);
|
||||
try {
|
||||
final SimpleHttpResponse response = future.get(TIMEOUT.getDuration(), TIMEOUT.getTimeUnit());
|
||||
@ -308,7 +323,10 @@ void execute() throws Exception {
|
||||
final HttpClientContext context = HttpClientContext.create();
|
||||
context.setCredentialsProvider(credentialsProvider);
|
||||
|
||||
final SimpleHttpRequest httpGetSecret = SimpleHttpRequests.get(target, "/private/big-secret.txt");
|
||||
final SimpleHttpRequest httpGetSecret = SimpleRequestBuilder.get()
|
||||
.setHttpHost(target)
|
||||
.setPath("/private/big-secret.txt")
|
||||
.build();
|
||||
httpGetSecret.setHeader(HttpHeaders.CONNECTION, HeaderElements.CLOSE);
|
||||
final Future<SimpleHttpResponse> future = client.execute(httpGetSecret, context, null);
|
||||
try {
|
||||
|
@ -37,7 +37,10 @@
|
||||
* Common HTTP methods using {@link BasicHttpRequest} as a HTTP request message representation.
|
||||
*
|
||||
* @since 5.0
|
||||
*
|
||||
* @deprecated Use {@link org.apache.hc.core5.http.support.BasicRequestBuilder}.
|
||||
*/
|
||||
@Deprecated
|
||||
public final class BasicHttpRequests {
|
||||
|
||||
/**
|
||||
|
@ -36,7 +36,10 @@
|
||||
* Common HTTP methods using {@link SimpleHttpRequest} as a HTTP request message representation.
|
||||
*
|
||||
* @since 5.0
|
||||
*
|
||||
* @deprecated Use {@link SimpleRequestBuilder}.
|
||||
*/
|
||||
@Deprecated
|
||||
public final class SimpleHttpRequests {
|
||||
|
||||
/**
|
||||
|
@ -39,7 +39,10 @@
|
||||
* with a non-null URI.
|
||||
*
|
||||
* @since 5.0
|
||||
*
|
||||
* @deprecated Use {@link org.apache.hc.core5.http.io.support.ClassicRequestBuilder}
|
||||
*/
|
||||
@Deprecated
|
||||
public final class ClassicHttpRequests {
|
||||
|
||||
/**
|
||||
|
@ -1,91 +0,0 @@
|
||||
/*
|
||||
* ====================================================================
|
||||
* 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.async.methods;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
import java.net.URI;
|
||||
import java.util.Arrays;
|
||||
|
||||
import org.apache.hc.core5.http.HttpRequest;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.runners.Parameterized;
|
||||
import org.junit.runners.Parameterized.Parameters;
|
||||
|
||||
@RunWith(Parameterized.class)
|
||||
public class SimpleBasicHttpRequests {
|
||||
|
||||
private static final String URI_STRING_FIXTURE = "http://localhost";
|
||||
private static final URI URI_FIXTURE = URI.create(URI_STRING_FIXTURE);
|
||||
|
||||
@Parameters(name = "{index}: {0} => {1}")
|
||||
public static Iterable<Object[]> data() {
|
||||
return Arrays.asList(new Object[][] {
|
||||
// @formatter:off
|
||||
{ "delete", "DELETE" },
|
||||
{ "get", "GET" },
|
||||
{ "head", "HEAD" },
|
||||
{ "options", "OPTIONS" },
|
||||
{ "patch", "PATCH" },
|
||||
{ "post", "POST" },
|
||||
{ "put", "PUT" },
|
||||
{ "trace", "TRACE" }
|
||||
// @formatter:on
|
||||
});
|
||||
}
|
||||
|
||||
private final String methodName;
|
||||
|
||||
private final String expectedMethod;
|
||||
|
||||
public SimpleBasicHttpRequests(final String methodName, final String expectedMethod) {
|
||||
this.methodName = methodName;
|
||||
this.expectedMethod = expectedMethod;
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCreateMethodUri() {
|
||||
Assert.assertEquals(SimpleHttpRequest.class, SimpleHttpRequests.create(methodName, URI_FIXTURE).getClass());
|
||||
Assert.assertEquals(SimpleHttpRequest.class, SimpleHttpRequests.create(expectedMethod, URI_FIXTURE).getClass());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCreateMethodUriString() {
|
||||
Assert.assertEquals(SimpleHttpRequest.class, SimpleHttpRequests.create(methodName, URI_STRING_FIXTURE).getClass());
|
||||
Assert.assertEquals(SimpleHttpRequest.class, SimpleHttpRequests.create(expectedMethod, URI_STRING_FIXTURE).getClass());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCreateClassicHttpRequest() throws Exception {
|
||||
final Method httpMethod = SimpleHttpRequests.class.getMethod(methodName, URI.class);
|
||||
final HttpRequest basicHttpRequest = (HttpRequest) httpMethod.invoke(null, URI_FIXTURE);
|
||||
Assert.assertEquals(SimpleHttpRequest.class, basicHttpRequest.getClass());
|
||||
Assert.assertEquals(expectedMethod, basicHttpRequest.getMethod());
|
||||
}
|
||||
}
|
@ -1,92 +0,0 @@
|
||||
/*
|
||||
* ====================================================================
|
||||
* 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.async.methods;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
import java.net.URI;
|
||||
import java.util.Arrays;
|
||||
|
||||
import org.apache.hc.core5.http.HttpRequest;
|
||||
import org.apache.hc.core5.http.message.BasicHttpRequest;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.runners.Parameterized;
|
||||
import org.junit.runners.Parameterized.Parameters;
|
||||
|
||||
@RunWith(Parameterized.class)
|
||||
public class TestBasicHttpRequests {
|
||||
|
||||
private static final String URI_STRING_FIXTURE = "http://localhost";
|
||||
private static final URI URI_FIXTURE = URI.create(URI_STRING_FIXTURE);
|
||||
|
||||
@Parameters(name = "{index}: {0} => {1}")
|
||||
public static Iterable<Object[]> data() {
|
||||
return Arrays.asList(new Object[][] {
|
||||
// @formatter:off
|
||||
{ "delete", "DELETE" },
|
||||
{ "get", "GET" },
|
||||
{ "head", "HEAD" },
|
||||
{ "options", "OPTIONS" },
|
||||
{ "patch", "PATCH" },
|
||||
{ "post", "POST" },
|
||||
{ "put", "PUT" },
|
||||
{ "trace", "TRACE" }
|
||||
// @formatter:on
|
||||
});
|
||||
}
|
||||
|
||||
private final String methodName;
|
||||
|
||||
private final String expectedMethod;
|
||||
|
||||
public TestBasicHttpRequests(final String methodName, final String expectedMethod) {
|
||||
this.methodName = methodName;
|
||||
this.expectedMethod = expectedMethod;
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCreateMethodUri() {
|
||||
Assert.assertEquals(BasicHttpRequest.class, BasicHttpRequests.create(methodName, URI_FIXTURE).getClass());
|
||||
Assert.assertEquals(BasicHttpRequest.class, BasicHttpRequests.create(expectedMethod, URI_FIXTURE).getClass());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCreateMethodUriString() {
|
||||
Assert.assertEquals(BasicHttpRequest.class, BasicHttpRequests.create(methodName, URI_STRING_FIXTURE).getClass());
|
||||
Assert.assertEquals(BasicHttpRequest.class, BasicHttpRequests.create(expectedMethod, URI_STRING_FIXTURE).getClass());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCreateClassicHttpRequest() throws Exception {
|
||||
final Method httpMethod = BasicHttpRequests.class.getMethod(methodName, URI.class);
|
||||
final HttpRequest basicHttpRequest = (HttpRequest) httpMethod.invoke(null, URI_FIXTURE);
|
||||
Assert.assertEquals(BasicHttpRequest.class, basicHttpRequest.getClass());
|
||||
Assert.assertEquals(expectedMethod, basicHttpRequest.getMethod());
|
||||
}
|
||||
}
|
@ -1,96 +0,0 @@
|
||||
/*
|
||||
* ====================================================================
|
||||
* 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.classic.methods;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
import java.net.URI;
|
||||
import java.util.Arrays;
|
||||
|
||||
import org.apache.hc.core5.http.ClassicHttpRequest;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.runners.Parameterized;
|
||||
import org.junit.runners.Parameterized.Parameters;
|
||||
|
||||
@RunWith(Parameterized.class)
|
||||
public class TestClassicHttpRequests {
|
||||
|
||||
private static final String URI_STRING_FIXTURE = "http://localhost";
|
||||
private static final URI URI_FIXTURE = URI.create(URI_STRING_FIXTURE);
|
||||
|
||||
@Parameters(name = "{index}: {0} => {1}")
|
||||
public static Iterable<Object[]> data() {
|
||||
return Arrays.asList(new Object[][] {
|
||||
// @formatter:off
|
||||
{ "delete", HttpDelete.class },
|
||||
{ "get", HttpGet.class },
|
||||
{ "head", HttpHead.class },
|
||||
{ "options", HttpOptions.class },
|
||||
{ "patch", HttpPatch.class },
|
||||
{ "post", HttpPost.class },
|
||||
{ "put", HttpPut.class },
|
||||
{ "trace", HttpTrace.class }
|
||||
// @formatter:on
|
||||
});
|
||||
}
|
||||
|
||||
private final String methodName;
|
||||
|
||||
private final Class<ClassicHttpRequest> expectedClass;
|
||||
|
||||
public TestClassicHttpRequests(final String methodName,
|
||||
final Class<ClassicHttpRequest> expectedClass) {
|
||||
this.methodName = methodName;
|
||||
this.expectedClass = expectedClass;
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCreateMethodUri() {
|
||||
Assert.assertEquals(expectedClass, ClassicHttpRequests.create(methodName, URI_FIXTURE).getClass());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCreateMethodUriString() {
|
||||
Assert.assertEquals(expectedClass, ClassicHttpRequests.create(methodName, URI_STRING_FIXTURE).getClass());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCreateFromString() throws Exception {
|
||||
final Method httpMethod = ClassicHttpRequests.class.getMethod(methodName, String.class);
|
||||
Assert.assertEquals(expectedClass,
|
||||
httpMethod.invoke(null, URI_STRING_FIXTURE).getClass());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCreateFromURI() throws Exception {
|
||||
final Method httpMethod = ClassicHttpRequests.class.getMethod(methodName, URI.class);
|
||||
Assert.assertEquals(expectedClass,
|
||||
httpMethod.invoke(null, URI_FIXTURE).getClass());
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user