Class HttpLogger.HttpBodySubscriber

java.lang.Object
io.fliqa.client.interledger.logging.HttpLogger.HttpBodySubscriber
All Implemented Interfaces:
Flow.Subscriber<ByteBuffer>
Enclosing class:
HttpLogger

protected static class HttpLogger.HttpBodySubscriber extends Object implements Flow.Subscriber<ByteBuffer>
Custom subscriber for capturing HTTP request body content from reactive streams.

This subscriber is necessary because the Java 11+ HTTP client uses reactive streams for request bodies, and the body content is consumed as it's sent to the server. Standard logging approaches can't access the body content after it has been consumed.

The subscriber converts ByteBuffer chunks to UTF-8 strings and passes them to a consumer function for logging. This allows us to capture and log request bodies without interfering with the actual HTTP request transmission.

See Also:
  • Constructor Details

    • HttpBodySubscriber

      public HttpBodySubscriber(Consumer<String> consumer)
      Creates a new body subscriber with the specified consumer.
      Parameters:
      consumer - function to process captured body content
  • Method Details

    • onSubscribe

      public void onSubscribe(Flow.Subscription subscription)
      Called when the subscription is established. Requests all available data.
      Specified by:
      onSubscribe in interface Flow.Subscriber<ByteBuffer>
      Parameters:
      subscription - the subscription for controlling data flow
    • onNext

      public void onNext(ByteBuffer item)
      Called for each chunk of body data. Converts ByteBuffer to UTF-8 string and passes it to the consumer for logging.
      Specified by:
      onNext in interface Flow.Subscriber<ByteBuffer>
      Parameters:
      item - ByteBuffer containing body data chunk
    • onError

      public void onError(Throwable throwable)
      Called when an error occurs during body streaming. Currently, does not perform any error handling.
      Specified by:
      onError in interface Flow.Subscriber<ByteBuffer>
      Parameters:
      throwable - the error that occurred
    • onComplete

      public void onComplete()
      Called when the body streaming is complete. Currently, does not perform any completion handling.
      Specified by:
      onComplete in interface Flow.Subscriber<ByteBuffer>