-
-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
753a9bc
commit d9f810f
Showing
2 changed files
with
84 additions
and
64 deletions.
There are no files selected for viewing
39 changes: 39 additions & 0 deletions
39
self-core-impl/src/main/java/com/selfxdsd/core/GlobalHttpClient.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package com.selfxdsd.core; | ||
|
||
import java.net.http.HttpClient; | ||
import java.time.Duration; | ||
|
||
/** | ||
* Global singleton {@link java.net.http.HttpClient} to be used for making | ||
* HTTP Requests throughout the application, especially to the providers' | ||
* APIs (Github, Gitlab, BitBucket etc). | ||
*/ | ||
public final class GlobalHttpClient { | ||
|
||
/** | ||
* The HttpClient. | ||
*/ | ||
private static HttpClient client; | ||
|
||
/** | ||
* Hidden ctor. | ||
*/ | ||
private GlobalHttpClient() {} | ||
|
||
/** | ||
* Get the instance of the HttpClient. | ||
* @param version HTTP Version 1.1 or 2. | ||
* @return HttpClient. | ||
*/ | ||
public static HttpClient instance(final HttpClient.Version version) { | ||
if(client == null || !client.version().equals(version)) { | ||
client = HttpClient | ||
.newBuilder() | ||
.version(version) | ||
.followRedirects(HttpClient.Redirect.NORMAL) | ||
.connectTimeout(Duration.ofSeconds(10)) | ||
.build(); | ||
} | ||
return client; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters