Skip to content

Commit

Permalink
[HTTPCLIENT-1696]: Add convenience methods to fluent API class Request.
Browse files Browse the repository at this point in the history
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
  • Loading branch information
garydgregory committed Nov 12, 2015
1 parent 70e603f commit 28040a3
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 1 deletion.
8 changes: 7 additions & 1 deletion RELEASE_NOTES.txt
Original file line number Diff line number Diff line change
@@ -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
-------------------

Expand Down Expand Up @@ -32,7 +39,6 @@ Changelog:
Contributed by Michael Osipov <michaelo at apache.org>



Release 4.4.1
-------------------

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@

import java.io.File;
import java.io.IOException;
import java.net.URI;
import java.nio.charset.Charset;

import org.apache.http.HttpEntity;
Expand Down Expand Up @@ -106,6 +107,22 @@ public void testGetRequest() throws Exception {
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();
Expand Down

0 comments on commit 28040a3

Please sign in to comment.