Module de.cuioss.http
Package de.cuioss.http.client.result
package de.cuioss.http.client.result
HTTP-specific result pattern implementation that extends the CUI result framework
with semantics tailored for HTTP operations and ETag caching.
Core Components
HttpResultObject- HTTP-specialized result wrapperHttpResultState- HTTP-specific state constantsResultDetail- CUI error details with user messagesHttpErrorCategory- HTTP error classifications with retry logic
Key Benefits
- Unified API - Single result type across all HTTP operations
- HTTP Semantics - Built-in support for ETag caching and HTTP status codes
- Error Classification - Standardized error codes for consistent handling
- CUI Integration - Full compatibility with existing CUI result patterns
Usage Examples
1. Basic HTTP Operations
// HTTP operation with result pattern
HttpResultObject<String> result = httpClient.get("https://api.example.com/data");
if (result.isValid()) {
String content = result.getResult();
processContent(content);
} else {
handleError(result);
}
2. ETag-Aware Caching
// ETag-aware HTTP loading
HttpResultObject<JwksKeys> result = jwksLoader.loadWithETag(previousETag);
if (result.isValid()) {
// Process successful result
updateCache(result.getResult(), result.getETag().orElse(""));
// Check HTTP status for caching behavior
if (result.getHttpStatus().orElse(0) == 304) {
logger.debug("JWKS content unchanged, using cache");
} else {
logger.debug("JWKS content updated");
}
} else {
// Handle error case with fallback
result.getResultDetail().ifPresent(detail ->
logger.warn("JWKS loading failed: {}", detail.getDetail().getDisplayName()));
}
3. Error Handling with Retry Logic
// HTTP operation with error handling
HttpResultObject<Config> result = httpHandler.loadConfig();
if (!result.isValid()) {
// Check if error is retryable
if (result.isRetryable()) {
logger.info("Retryable error, scheduling retry");
scheduleRetry();
} else {
// Handle non-retryable error
result.getHttpErrorCategory().ifPresent(code -> {
if (code == HttpErrorCategory.INVALID_CONTENT) {
logger.error("Invalid content received");
}
});
}
}
4. Factory Methods for Common Scenarios
// Successful HTTP response
HttpResultObject<Document> result = HttpResultObject.success(document, etag, 200);
// Error with fallback content
HttpResultObject<Document> errorResult = HttpResultObject.error(
fallbackDocument,
HttpErrorCategory.NETWORK_ERROR,
new ResultDetail(new DisplayName("Connection failed"))
);
Result States
HttpResultObject uses the standard CUI result states:
- VALID - HTTP operation succeeded (status 200, 304, etc.)
- WARNING - Degraded state (fallback content, recovery scenarios)
- ERROR - Operation failed (with optional fallback content)
HTTP-specific context is provided through:
- ETag for caching optimization
- HTTP status code for protocol semantics
- HttpErrorCategory for retry decision making
Integration with CUI Result Pattern
This package extends the proven result framework from cui-core-ui-model, adding HTTP-specific semantics while maintaining full compatibility:
- Extends
ResultObjectfor HTTP operations - Uses standard
ResultStatevalues - Uses
ResultDetailfor error information - Preserves thread safety and serialization support
- Maintains copy and transformation semantics
Migration from Legacy Patterns
This framework replaces custom result types like LoadResult and HttpFetchResult
with a unified approach:
Before (Legacy)
LoadResult result = httpHandler.load();
if (result.content() == null) {
// Handle error with exceptions
throw new HttpException("Failed to load");
}
String content = result.content();
After (Result Pattern)
HttpResultObject<String> result = httpHandler.load();
if (!result.isValid()) {
// Handle error with structured details
result.getResultDetail().ifPresent(this::logError);
return result.copyStateAndDetails(defaultContent);
}
String content = result.getResult();
- Since:
- 1.0
- Author:
- Implementation for JWT HTTP operations
- See Also:
-
ClassDescriptionEssential HTTP error codes for resilient operations.HTTP-specific result object that extends the CUI result pattern with HTTP protocol semantics.HTTP-specific result states that extend the basic CUI result pattern with semantics tailored for HTTP operations, particularly ETag-aware caching and retry scenarios.