diff --git a/RELEASE_NOTES.txt b/RELEASE_NOTES.txt index c8c18d8d9..2d2992fcc 100644 --- a/RELEASE_NOTES.txt +++ b/RELEASE_NOTES.txt @@ -1,3 +1,10 @@ +Release 5.0 +------------------- + +* [HTTPCLIENT-1696]: Add convenience methods to fluent API class Request. + Contributed by Gary Gregory + + Release 4.5 ------------------- @@ -32,7 +39,6 @@ Changelog: Contributed by Michael Osipov - Release 4.4.1 ------------------- diff --git a/fluent-hc/src/main/java/org/apache/http/client/fluent/Request.java b/fluent-hc/src/main/java/org/apache/http/client/fluent/Request.java index 8456eb6f1..3378c5b82 100644 --- a/fluent-hc/src/main/java/org/apache/http/client/fluent/Request.java +++ b/fluent-hc/src/main/java/org/apache/http/client/fluent/Request.java @@ -78,6 +78,14 @@ public class Request { private SimpleDateFormat dateFormatter; + public static Request create(final String methodName, final String uri) { + return new Request(new InternalHttpRequest(methodName, URI.create(uri))); + } + + public static Request create(final String methodName, final URI uri) { + return new Request(new InternalHttpRequest(methodName, uri)); + } + public static Request Get(final URI uri) { return new Request(new InternalHttpRequest(HttpGet.METHOD_NAME, uri)); } diff --git a/fluent-hc/src/test/java/org/apache/http/client/fluent/TestFluent.java b/fluent-hc/src/test/java/org/apache/http/client/fluent/TestFluent.java index 1a1d86df4..0af7468be 100644 --- a/fluent-hc/src/test/java/org/apache/http/client/fluent/TestFluent.java +++ b/fluent-hc/src/test/java/org/apache/http/client/fluent/TestFluent.java @@ -28,6 +28,7 @@ package org.apache.http.client.fluent; import java.io.File; import java.io.IOException; +import java.net.URI; import java.nio.charset.Charset; import org.apache.http.HttpEntity; @@ -106,6 +107,22 @@ public class TestFluent extends LocalServerTestBase { Assert.assertEquals("All is well", message); } + @Test + public void testGetRequestByName() throws Exception { + final HttpHost target = start(); + final String baseURL = "http://localhost:" + target.getPort(); + final String message = Request.create("GET", baseURL + "/").execute().returnContent().asString(); + Assert.assertEquals("All is well", message); + } + + @Test + public void testGetRequestByNameWithURI() throws Exception { + final HttpHost target = start(); + final String baseURL = "http://localhost:" + target.getPort(); + final String message = Request.create("GET", new URI(baseURL + "/")).execute().returnContent().asString(); + Assert.assertEquals("All is well", message); + } + @Test(expected = ClientProtocolException.class) public void testGetRequestFailure() throws Exception { final HttpHost target = start();