HttpClientBase¶
Abstract base class shared by every Guidewire data-api client (ActivityDataApiClient, ClaimDataApiClient, FinancialDataApiClient, ProviderDataApiClient, WorkerDataApiClient). It owns the underlying HttpClient, resolves the client's base address from environment configuration, lazily attaches Basic authentication headers on first use, and provides cached/uncached GET and POST helpers that subclasses call to reach the Guidewire REST APIs. It depends on IEnvironmentService for configuration and secure credential lookup, IDataClientConfiguration for system identity and cache settings, and an optional Polly IReadOnlyPolicyRegistry<string> for response caching.
Purpose¶
- Centralizes base-address resolution, Basic authentication, and cached/uncached HTTP GET/POST plumbing so concrete Guidewire clients only need to implement their route-specific methods.
- Defers authentication header creation until the first outbound call (
Clientgetter), rather than at construction.
Context¶
- Namespace:
SAIF.Data.Guidewire.Clients - Assembly/package:
SAIF.Data.Guidewire(packaged inSAIF.SAIFCode.Core)
Public members¶
| Member | Signature | Purpose |
|---|---|---|
| Client | protected HttpClient Client { get; } |
Returns the underlying HttpClient, triggering SDG-BR-002 Basic-auth header initialization on first access if not already retrieved |
| UrlKey | protected abstract string UrlKey { get; } |
Environment configuration key subclasses must supply to resolve the API's base URL, used per SDG-BR-001 |
| AuthKey | protected abstract string AuthKey { get; } |
Environment secure-configuration key subclasses must supply to look up Basic auth credentials; an empty/whitespace value skips authentication header setup |
| HttpClientBase(IEnvironmentService, HttpClient, SystemType, string) | [Obsolete] protected HttpClientBase(IEnvironmentService environmentService, HttpClient client, SystemType systemType, string baseUrlOverride) |
Obsolete constructor that forwards to the primary constructor using a new DataClientConfiguration with the given SystemType and UseCache = false; ignores baseUrlOverride |
| HttpClientBase(IEnvironmentService, HttpClient, IDataClientConfiguration, IReadOnlyPolicyRegistry\<string>) | protected HttpClientBase(IEnvironmentService environmentService, HttpClient client, IDataClientConfiguration configuration, IReadOnlyPolicyRegistry<string> policyRegistry) |
Primary constructor; resolves the cache policy (from the registry when UseCache is true, otherwise a Polly NoOpAsync), resolves the base URL via SDG-BR-001, and assigns it to client.BaseAddress |
| GetAsyncCached\<T>(string, bool, CancellationToken) | protected Task<T> GetAsyncCached<T>(string url, bool ensureSuccess = false, CancellationToken cancellationToken = default) |
Executes a GET through the configured Polly cache policy per SDG-BR-003 and deserializes the response body as T using Newtonsoft.Json, returning default for empty content |
| GetAsync(string, bool, CancellationToken) | protected Task<string> GetAsync(string url, bool ensureSuccess = false, CancellationToken cancellationToken = default) |
Issues an uncached GET against Client and returns the raw response body as a string |
| GetAsyncCached\<T>(string, string, bool, CancellationToken) | protected Task<T> GetAsyncCached<T>(string url, string body, bool ensureSuccess = false, CancellationToken cancellationToken = default) |
Executes a POST with the given JSON body through the configured Polly cache policy per SDG-BR-003 and deserializes the response as T |
Behavioral notes¶
InitializeClientAuthorization(private) computes the system hash viaSystemHashUtil.ComputeHash(SystemType, SystemName)whenSystemNameis set, otherwiseSystemHashUtil.Get(SystemType), then splits the secure setting on|into username/password and adds a Base64-encodedAuthorization: Basicheader, per SDG-BR-002.- When
ensureSuccessis true and the response is not a success status code,GetContent(private) callsresponse.EnsureSuccessStatusCode(), which throwsHttpRequestException. - The obsolete constructor always disables caching (
UseCache = false) and silently ignores anybaseUrlOverridevalue passed by the caller. - Cache keys are built from
{typeof(T).FullName}-{url}-{ensureSuccess}plus an appended body hash code when a request body is present; this is used only whenUseCacheis true and a policy registry was supplied.
Constraints and usage notes¶
- Concrete subclasses must implement
UrlKeyandAuthKey; a null or emptyUrlKeywill causeUriconstruction to fail at construction time. - The
Client,GetAsync, andGetAsyncCached<T>members areprotected, so they are usable only from within derived classes, not directly by external callers. - If
UseCacheis true but nopolicyRegistryis supplied, the cache policy falls back toPolicy.NoOpAsync(), effectively disabling caching despiteUseCachebeing true.
Sources¶
Data/SAIF.Data.Guidewire/Clients/HttpClientBase.cs