[HTTPCLIENT-1696]: Add convenience methods to fluent API class Request.

Contributed by Gary Gregory <ggregory @ apache.org>

git-svn-id: https://svn.apache.org/repos/asf/httpcomponents/httpclient/trunk@1714136 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Gary D. Gregory 2015-11-12 23:10:58 +00:00
parent 70e603f819
commit 28040a3f2a
3 changed files with 32 additions and 1 deletions

View File

@ -1,3 +1,10 @@
Release 5.0
-------------------
* [HTTPCLIENT-1696]: Add convenience methods to fluent API class Request.
Contributed by Gary Gregory <ggregory @ apache.org>
Release 4.5
-------------------
@ -32,7 +39,6 @@ Changelog:
Contributed by Michael Osipov <michaelo at apache.org>
Release 4.4.1
-------------------

View File

@ -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));
}

View File

@ -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();