Class HttpResultObject<T>

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

public class HttpResultObject<T> extends de.cuioss.uimodel.result.ResultObject<T>
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

    Constructors
    Constructor
    Description
    HttpResultObject(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 Type
    Method
    Description
    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.
    Gets the HTTP ETag if present.
    Gets the HTTP-specific error code if present.
    Gets the HTTP status code if present.
    boolean
    Checks if the error condition is retryable.
    map(Function<T,U> mapper, U defaultValue)
    Transforms this result to a different type while preserving HTTP metadata.
    static <U> HttpResultObject<U>
    success(U result, String etag, int httpStatus)
    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

    Methods inherited from class java.lang.Object

    clone, finalize, getClass, notify, notifyAll, wait, wait, wait
  • 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 value
      state - the result state (using CUI base types)
      resultDetail - result detail
      httpErrorCategory - HTTP-specific error code
      etag - optional HTTP ETag
      httpStatus - optional HTTP status code
    • HttpResultObject

      public HttpResultObject(HttpResultObject<R> previousResult, Function<R,T> mapper, T validDefault)
      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 from
      mapper - function to transform the result value
      validDefault - default value if previous result was invalid
  • Method Details

    • getETag

      public Optional<String> 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

      public boolean 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

      public <U> HttpResultObject<U> map(Function<T,U> mapper, U defaultValue)
      Transforms this result to a different type while preserving HTTP metadata.
      Type Parameters:
      U - target result type
      Parameters:
      mapper - function to transform the result value
      defaultValue - default value if this result is invalid
      Returns:
      new HttpResultObject with transformed value
    • copyStateAndDetails

      public <U> HttpResultObject<U> copyStateAndDetails(U newResult)
      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

      public static <U> HttpResultObject<U> success(U result, String etag, int httpStatus)
      Creates a successful HTTP result.
      Type Parameters:
      U - result type
      Parameters:
      result - the result content
      etag - optional ETag
      httpStatus - 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 content
      httpErrorCategory - the error classification
      detail - error details
      Returns:
      HttpResultObject in ERROR state