java.lang.Object
de.cuioss.uimodel.result.ResultObject<T>
de.cuioss.http.client.result.HttpResultObject<T>
- Type Parameters:
T- The type of the HTTP response content
- All Implemented Interfaces:
Serializable
HTTP-specific result object that extends the CUI result pattern with HTTP protocol semantics.
Key Features
- CUI result pattern integration (VALID/WARNING/ERROR states)
- ETag support for efficient caching
- HTTP status code tracking
- Fluent API for common HTTP operations
- Built-in fallback and default result handling
Usage Patterns
1. Basic HTTP Result Handling
HttpResultObject<String> result = httpHandler.load();
if (!result.isValid()) {
// Handle error case with retry logic
if (result.isRetryable()) {
scheduleRetry();
} else {
result.getResultDetail().ifPresent(detail ->
logger.error(detail.getDetail().getDisplayName()));
return result.copyStateAndDetails(fallbackContent);
}
}
// Process successful result
String content = result.getResult();
String etag = result.getETag().orElse("");
processContent(content, etag);
2. Factory Methods
// Successful HTTP operations HttpResultObject<String> fresh = HttpResultObject.success(content, etag, 200); HttpResultObject<String> cached = HttpResultObject.success(cachedContent, etag, 304); // Error with fallback content HttpResultObject<String> error = HttpResultObject.error(fallback, errorCode, detail);
CUI Result Pattern Integration
- VALID: HTTP operation succeeded (fresh or cached content)
- WARNING: Degraded state (stale cache, partial recovery)
- ERROR: Operation failed (with optional fallback content)
- Since:
- 1.0
- Author:
- Implementation for JWT HTTP operations
- See Also:
-
Nested Class Summary
Nested classes/interfaces inherited from class de.cuioss.uimodel.result.ResultObject
de.cuioss.uimodel.result.ResultObject.Builder<S> -
Constructor Summary
ConstructorsConstructorDescriptionHttpResultObject(HttpResultObject<R> previousResult, Function<R, T> mapper, T validDefault) Copy constructor that transforms the result while preserving HTTP metadata.HttpResultObject(T result, de.cuioss.uimodel.result.ResultState state, de.cuioss.uimodel.result.ResultDetail resultDetail, HttpErrorCategory httpErrorCategory, String etag, Integer httpStatus) Comprehensive constructor for HTTP result objects. -
Method Summary
Modifier and TypeMethodDescription<U> HttpResultObject<U> copyStateAndDetails(U newResult) Creates a new result object copying state and details from this one.static <U> HttpResultObject<U> error(U fallbackResult, HttpErrorCategory httpErrorCategory, de.cuioss.uimodel.result.ResultDetail detail) Creates an error result with optional fallback content.getETag()Gets the HTTP ETag if present.Gets the HTTP-specific error code if present.Gets the HTTP status code if present.booleanChecks if the error condition is retryable.<U> HttpResultObject<U> Transforms this result to a different type while preserving HTTP metadata.static <U> HttpResultObject<U> Creates a successful HTTP result.Methods inherited from class de.cuioss.uimodel.result.ResultObject
builder, canEqual, containsErrorCode, equals, getErrorCode, getResult, getResultDetail, getState, hashCode, isValid, logDetail, logDetail, toString
-
Constructor Details
-
HttpResultObject
public HttpResultObject(T result, de.cuioss.uimodel.result.ResultState state, de.cuioss.uimodel.result.ResultDetail resultDetail, HttpErrorCategory httpErrorCategory, String etag, Integer httpStatus) Comprehensive constructor for HTTP result objects.- Parameters:
result- the wrapped result valuestate- the result state (using CUI base types)resultDetail- result detailhttpErrorCategory- HTTP-specific error codeetag- optional HTTP ETaghttpStatus- optional HTTP status code
-
HttpResultObject
Copy constructor that transforms the result while preserving HTTP metadata.- Type Parameters:
R- type of the previous result- Parameters:
previousResult- the previous HTTP result to copy frommapper- function to transform the result valuevalidDefault- default value if previous result was invalid
-
-
Method Details
-
getETag
Gets the HTTP ETag if present.- Returns:
- Optional containing ETag, or empty if not available
-
getHttpStatus
Gets the HTTP status code if present.- Returns:
- Optional containing status code, or empty if not available
-
getHttpErrorCategory
Gets the HTTP-specific error code if present.- Returns:
- Optional containing HTTP error code, or empty if not available
-
isRetryable
Checks if the error condition is retryable. Only meaningful when the result is not valid.- Returns:
- true if error is retryable, false otherwise
-
map
Transforms this result to a different type while preserving HTTP metadata.- Type Parameters:
U- target result type- Parameters:
mapper- function to transform the result valuedefaultValue- default value if this result is invalid- Returns:
- new HttpResultObject with transformed value
-
copyStateAndDetails
Creates a new result object copying state and details from this one. Useful for error propagation without changing the result type.- Type Parameters:
U- new result type- Parameters:
newResult- the new result value- Returns:
- new HttpResultObject with copied state and details
-
success
Creates a successful HTTP result.- Type Parameters:
U- result type- Parameters:
result- the result contentetag- optional ETaghttpStatus- HTTP status code- Returns:
- HttpResultObject in VALID state
-
error
public static <U> HttpResultObject<U> error(U fallbackResult, HttpErrorCategory httpErrorCategory, de.cuioss.uimodel.result.ResultDetail detail) Creates an error result with optional fallback content.- Type Parameters:
U- result type- Parameters:
fallbackResult- optional fallback contenthttpErrorCategory- the error classificationdetail- error details- Returns:
- HttpResultObject in ERROR state
-