Skip to content

Commit bd688c8

Browse files
authored
JCL-254: Make Http builders consistent (#297)
1 parent f06faa4 commit bd688c8

2 files changed

Lines changed: 23 additions & 1 deletion

File tree

‎httpclient/src/main/java/com/inrupt/client/httpclient/HttpClientService.java‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,9 @@ public class HttpClientService implements HttpService {
4747

4848
private final HttpClient client;
4949

50+
/**
51+
* Create an HTTP client service with a default {@link HttpClient}.
52+
*/
5053
public HttpClientService() {
5154
this(HttpClient.newBuilder().followRedirects(HttpClient.Redirect.ALWAYS).build());
5255
}
@@ -93,6 +96,12 @@ public <T> CompletionStage<Response<T>> send(final Request request, final Respon
9396
});
9497
}
9598

99+
/**
100+
* Create an HTTP client service with a pre-configured {@link HttpClient}.
101+
*
102+
* @param client the HttpClient
103+
* @return an HTTP client service
104+
*/
96105
public static HttpClientService ofHttpClient(final HttpClient client) {
97106
return new HttpClientService(client);
98107
}

‎okhttp/src/main/java/com/inrupt/client/okhttp/OkHttpService.java‎

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,11 +53,14 @@ public class OkHttpService implements HttpService {
5353

5454
private final OkHttpClient client;
5555

56+
/**
57+
* Create an HTTP client service with a default {@link OkHttpClient}.
58+
*/
5659
public OkHttpService() {
5760
this(new OkHttpClient());
5861
}
5962

60-
public OkHttpService(final OkHttpClient client) {
63+
private OkHttpService(final OkHttpClient client) {
6164
LOGGER.debug("Initializing OkHttpClient service for HTTP client support");
6265
this.client = client;
6366
}
@@ -96,6 +99,16 @@ public void onFailure(final Call call, final IOException ex) {
9699
return future;
97100
}
98101

102+
/**
103+
* Create an HTTP client service with a pre-configured {@link OkHttpClient}.
104+
*
105+
* @param client the OkHttpClient
106+
* @return an HTTP client service
107+
*/
108+
public static OkHttpService ofOkHttpClient(final OkHttpClient client) {
109+
return new OkHttpService(client);
110+
}
111+
99112
static RequestBody prepareBody(final Request request, final MediaType mediaType) {
100113
if (NO_BODY_METHODS.contains(request.method())) {
101114
return null;

0 commit comments

Comments
 (0)