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 Summary
ConstructorsConstructorDescriptionHttpBodySubscriber(Consumer<String> consumer) Creates a new body subscriber with the specified consumer. -
Method Summary
Modifier and TypeMethodDescriptionvoidCalled when the body streaming is complete.voidCalled when an error occurs during body streaming.voidonNext(ByteBuffer item) Called for each chunk of body data.voidonSubscribe(Flow.Subscription subscription) Called when the subscription is established.
-
Constructor Details
-
HttpBodySubscriber
Creates a new body subscriber with the specified consumer.- Parameters:
consumer- function to process captured body content
-
-
Method Details
-
onSubscribe
Called when the subscription is established. Requests all available data.- Specified by:
onSubscribein interfaceFlow.Subscriber<ByteBuffer>- Parameters:
subscription- the subscription for controlling data flow
-
onNext
Called for each chunk of body data. Converts ByteBuffer to UTF-8 string and passes it to the consumer for logging.- Specified by:
onNextin interfaceFlow.Subscriber<ByteBuffer>- Parameters:
item- ByteBuffer containing body data chunk
-
onError
Called when an error occurs during body streaming. Currently, does not perform any error handling.- Specified by:
onErrorin interfaceFlow.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:
onCompletein interfaceFlow.Subscriber<ByteBuffer>
-