feat(http): core outbound HTTP interfaces and property records
This commit is contained in:
@@ -37,6 +37,10 @@
|
|||||||
<artifactId>spring-security-core</artifactId>
|
<artifactId>spring-security-core</artifactId>
|
||||||
<scope>provided</scope>
|
<scope>provided</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.apache.httpcomponents.client5</groupId>
|
||||||
|
<artifactId>httpclient5</artifactId>
|
||||||
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.fasterxml.jackson.datatype</groupId>
|
<groupId>com.fasterxml.jackson.datatype</groupId>
|
||||||
<artifactId>jackson-datatype-jsr310</artifactId>
|
<artifactId>jackson-datatype-jsr310</artifactId>
|
||||||
|
|||||||
@@ -0,0 +1,8 @@
|
|||||||
|
package com.cameleer.server.core.http;
|
||||||
|
|
||||||
|
import org.apache.hc.client5.http.impl.classic.CloseableHttpClient;
|
||||||
|
|
||||||
|
public interface OutboundHttpClientFactory {
|
||||||
|
/** Returns a memoized client configured for the given TLS/timeout context. */
|
||||||
|
CloseableHttpClient clientFor(OutboundHttpRequestContext context);
|
||||||
|
}
|
||||||
@@ -0,0 +1,20 @@
|
|||||||
|
package com.cameleer.server.core.http;
|
||||||
|
|
||||||
|
import java.time.Duration;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public record OutboundHttpProperties(
|
||||||
|
boolean trustAll,
|
||||||
|
List<String> trustedCaPemPaths,
|
||||||
|
Duration defaultConnectTimeout,
|
||||||
|
Duration defaultReadTimeout,
|
||||||
|
String proxyUrl,
|
||||||
|
String proxyUsername,
|
||||||
|
String proxyPassword
|
||||||
|
) {
|
||||||
|
public OutboundHttpProperties {
|
||||||
|
trustedCaPemPaths = trustedCaPemPaths == null ? List.of() : List.copyOf(trustedCaPemPaths);
|
||||||
|
if (defaultConnectTimeout == null) defaultConnectTimeout = Duration.ofMillis(2000);
|
||||||
|
if (defaultReadTimeout == null) defaultReadTimeout = Duration.ofMillis(5000);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,20 @@
|
|||||||
|
package com.cameleer.server.core.http;
|
||||||
|
|
||||||
|
import java.time.Duration;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public record OutboundHttpRequestContext(
|
||||||
|
TrustMode trustMode,
|
||||||
|
List<String> trustedCaPemPaths,
|
||||||
|
Duration connectTimeout,
|
||||||
|
Duration readTimeout
|
||||||
|
) {
|
||||||
|
public OutboundHttpRequestContext {
|
||||||
|
if (trustMode == null) trustMode = TrustMode.SYSTEM_DEFAULT;
|
||||||
|
trustedCaPemPaths = trustedCaPemPaths == null ? List.of() : List.copyOf(trustedCaPemPaths);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static OutboundHttpRequestContext systemDefault() {
|
||||||
|
return new OutboundHttpRequestContext(TrustMode.SYSTEM_DEFAULT, List.of(), null, null);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
package com.cameleer.server.core.http;
|
||||||
|
|
||||||
|
public enum TrustMode {
|
||||||
|
SYSTEM_DEFAULT,
|
||||||
|
TRUST_ALL,
|
||||||
|
TRUST_PATHS
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user