Package org.confng.sources
Class HttpConfigSource
- java.lang.Object
-
- org.confng.sources.HttpConfigSource
-
- All Implemented Interfaces:
ConfigSource
public class HttpConfigSource extends Object implements ConfigSource
Configuration source that fetches configuration from HTTP/REST endpoints.This source supports fetching configuration from any HTTP endpoint that returns JSON data. It includes caching, authentication, and retry support.
Example Usage:
// Simple usage HttpConfigSource source = new HttpConfigSource("https://config.example.com/api/config"); ConfNG.addSource(source); // With authentication HttpConfigSource source = HttpConfigSource.builder() .url("https://config.example.com/api/config") .bearerToken("your-token") .cacheTimeoutMs(60000) .build(); ConfNG.addSource(source);- Since:
- 1.1.0
- Author:
- Bharat Kumar Malviya, GitHub: github.com/imBharatMalviya
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classHttpConfigSource.Builder
-
Constructor Summary
Constructors Constructor Description HttpConfigSource(String url)Creates a new HTTP config source with default settings.HttpConfigSource(String url, Map<String,String> headers, int connectTimeoutMs, int readTimeoutMs, long cacheTimeoutMs, int priority)Creates a new HTTP config source with custom settings.HttpConfigSource(String url, Map<String,String> headers, int connectTimeoutMs, int readTimeoutMs, long cacheTimeoutMs, int priority, int maxRetries, long retryDelayMs)Creates a new HTTP config source with custom settings including retry configuration.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static HttpConfigSource.Builderbuilder()Builder for creating HttpConfigSource instances.Optional<String>get(String key)Retrieves a configuration value for the given key.StringgetName()Returns the name of this configuration source.intgetPriority()Returns the priority of this configuration source.booleanisFetchFailed()Checks if the last fetch failed.voidrefresh()Forces a refresh of the cached configuration.
-
-
-
Constructor Detail
-
HttpConfigSource
public HttpConfigSource(String url)
Creates a new HTTP config source with default settings.- Parameters:
url- the URL to fetch configuration from
-
HttpConfigSource
public HttpConfigSource(String url, Map<String,String> headers, int connectTimeoutMs, int readTimeoutMs, long cacheTimeoutMs, int priority)
Creates a new HTTP config source with custom settings.
-
-
Method Detail
-
getName
public String getName()
Description copied from interface:ConfigSourceReturns the name of this configuration source.- Specified by:
getNamein interfaceConfigSource- Returns:
- the source name, never null
-
get
public Optional<String> get(String key)
Description copied from interface:ConfigSourceRetrieves a configuration value for the given key.If the key is not found in this source, an empty Optional should be returned. This allows the ConfNG system to try other sources in the resolution chain.
- Specified by:
getin interfaceConfigSource- Parameters:
key- the configuration key to look up- Returns:
- an Optional containing the value if found, empty otherwise
-
getPriority
public int getPriority()
Description copied from interface:ConfigSourceReturns the priority of this configuration source.Sources with higher priority values are consulted first in the resolution chain. Default priorities:
- 100+ - Secret managers and secure sources
- 80-99 - TestNG parameters and test-specific sources
- 60-79 - Environment variables
- 40-59 - System properties
- 20-39 - Configuration files (JSON, Properties)
- 0-19 - Default and fallback sources
- Specified by:
getPriorityin interfaceConfigSource- Returns:
- the priority value, higher values have higher priority
-
refresh
public void refresh()
Forces a refresh of the cached configuration.
-
isFetchFailed
public boolean isFetchFailed()
Checks if the last fetch failed.
-
builder
public static HttpConfigSource.Builder builder()
Builder for creating HttpConfigSource instances.
-
-