Class WebResponse
java.lang.Object
io.fluxzero.sdk.common.Message
io.fluxzero.sdk.web.WebResponse
- All Implemented Interfaces:
HasMessage
Represents a response to a
WebRequest in the Fluxzero Runtime.
WebResponse extends Message and includes:
status– HTTP status code (e.g. 200, 404)headers– HTTP headerscookies– parsed fromSet-CookiecontentType– inferred from headers
The response payload may be encoded and compressed (e.g. gzip) based on metadata.
It supports transformation, enrichment, and construction via a Builder.
Serialized GZIP responses received through the SDK request/response gateway are decompressed before payload
deserialization. Their Content-Encoding header is removed and any Content-Length reflects the decoded bytes.
Empty bodies retain their representation headers, as required for responses such as HEAD and 304.
- See Also:
-
Nested Class Summary
Nested Classes -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final StringFields inherited from interface HasMessage
warnedAboutMissingProperty -
Constructor Summary
ConstructorsConstructorDescriptionConstructs a new WebResponse instance using the provided Message object. -
Method Summary
Modifier and TypeMethodDescriptionaddMetadata(io.fluxzero.common.api.Metadata metadata) Returns a new message with the combined metadata.addMetadata(Object... keyValues) Adds multiple metadata entries.addMetadata(String key, Object value) Adds a single metadata entry.addMetadata(Map<String, ?> values) Adds metadata from a given map.Attaches a user object to the metadata using the configuredUserProvider.static io.fluxzero.common.api.MetadataasMetadata(int statusCode, Map<String, List<String>> headers) Constructs a Metadata object containing the provided status code and headers.static WebResponse.Builderbuilder()Creates a newWebResponse.Builderinstance for constructingWebResponseobjects.default booleanchunked()default booleanRetrieves the value of the "Content-Type" header from the HTTP response.Retrieves a list of cookies from the response's "Set-Cookie" headers.Retrieves the value of the first occurrence of the specified header name.Returns all HTTP headers associated with the current response.getHeaders(io.fluxzero.common.api.Metadata metadata) Retrieves a case-insensitive map of headers from the provided Metadata object.getHeaders(String name) Retrieves the list of header values associated with the given header name.io.fluxzero.common.api.Metadata<R> RRetrieves the decoded payload from the response and casts it to the specified type.<R> RgetPayloadAs(Type type) Retrieves the payload and converts it to the specified type.Returns the HTTP status code associated with the current response.static IntegergetStatusCode(io.fluxzero.common.api.Metadata metadata) Retrieves the status code from the provided metadata.default booleanstatic WebResponseCreates a 404 Not Found response containing the supplied reason as its payload.static WebResponsenotModified(Map<String, String> headers) Creates a bodyless 304 Not Modified response with the supplied headers.static WebResponseok(io.fluxzero.common.ThrowingSupplier<? extends InputStream> inputStreamSupplier, Map<String, String> headers) Creates a 200 OK response whose body stream is opened lazily through the supplier, with the supplied headers.static WebResponseCreates a 200 OK response with the supplied payload and single-valued headers.static WebResponsepartial(io.fluxzero.common.ThrowingSupplier<? extends InputStream> inputStreamSupplier, Map<String, String> headers) Creates a 206 Partial Content response with a lazily opened body stream.retainHeaders(String... headerNames) Retains only the specified headers from the current WebResponse.io.fluxzero.common.api.SerializedMessageserialize(Serializer serializer) Serializes the response using the content type if applicable.Converts this WebResponse instance into a builder, which can be used to create a modified copy of the instance.withMessageId(String messageId) Returns a new message with the supplied technical identifier.withMetadata(io.fluxzero.common.api.Metadata metadata) Returns a new message with the supplied metadata.withPayload(Object payload) Returns a new message instance with the provided payload and existing metadata, ID, and timestamp.withTimestamp(Instant timestamp) Returns a new message with the supplied timestamp.Methods inherited from class Message
asMessage, getRoutingKey, toMessageMethods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface HasMessage
computeRoutingKey, getMessageId, getPayloadClass, getRoutingKey, getRoutingKey, getTimestamp
-
Field Details
-
headersKey
- See Also:
-
statusKey
- See Also:
-
FIRST_CHUNK
- See Also:
-
FINAL_CHUNK
- See Also:
-
CHUNK_INDEX
- See Also:
-
-
Constructor Details
-
WebResponse
Constructs a new WebResponse instance using the provided Message object.- Parameters:
m- theMessageobject from which the payload, metadata, message ID, and timestamp are extracted to initialize the WebResponse.
-
-
Method Details
-
ok
Creates a 200 OK response with the supplied payload and single-valued headers. -
ok
public static WebResponse ok(io.fluxzero.common.ThrowingSupplier<? extends InputStream> inputStreamSupplier, Map<String, String> headers) Creates a 200 OK response whose body stream is opened lazily through the supplier, with the supplied headers. -
partial
public static WebResponse partial(io.fluxzero.common.ThrowingSupplier<? extends InputStream> inputStreamSupplier, Map<String, String> headers) Creates a 206 Partial Content response with a lazily opened body stream. The caller supplies range headers and the stream for the requested range. -
notModified
Creates a bodyless 304 Not Modified response with the supplied headers. -
notFound
Creates a 404 Not Found response containing the supplied reason as its payload. -
serialize
Serializes the response using the content type if applicable. A Graph payload is sent as its composed JSON document, not as a reconstructible Graph implementation. Content filtering must precede serialization. -
asMetadata
public static io.fluxzero.common.api.Metadata asMetadata(int statusCode, Map<String, List<String>> headers) Constructs a Metadata object containing the provided status code and headers.- Parameters:
statusCode- the HTTP status code to be included in the metadataheaders- a map of HTTP headers where each key is a header name and the corresponding value is a list of header values- Returns:
- a Metadata object containing the status code and headers
-
withMetadata
Description copied from class:MessageReturns a new message with the supplied metadata.- Overrides:
withMetadatain classMessage
-
addMetadata
Description copied from class:MessageReturns a new message with the combined metadata.- Overrides:
addMetadatain classMessage
-
addMetadata
Description copied from class:MessageAdds a single metadata entry.- Overrides:
addMetadatain classMessage
-
addMetadata
Description copied from class:MessageAdds multiple metadata entries.- Overrides:
addMetadatain classMessage
-
addMetadata
Description copied from class:MessageAdds metadata from a given map.- Overrides:
addMetadatain classMessage
-
addUser
Description copied from class:MessageAttaches a user object to the metadata using the configuredUserProvider. -
withPayload
Description copied from class:MessageReturns a new message instance with the provided payload and existing metadata, ID, and timestamp.- Overrides:
withPayloadin classMessage
-
withMessageId
Description copied from class:MessageReturns a new message with the supplied technical identifier.- Overrides:
withMessageIdin classMessage
-
withTimestamp
Description copied from class:MessageReturns a new message with the supplied timestamp.- Overrides:
withTimestampin classMessage
-
toBuilder
Converts this WebResponse instance into a builder, which can be used to create a modified copy of the instance.- Returns:
- a new
WebResponse.Builderinitialized with the properties of the current WebResponse instance.
-
builder
Creates a newWebResponse.Builderinstance for constructingWebResponseobjects.- Returns:
- a new instance of the
WebResponse.Builder.
-
getHeaders
Retrieves a case-insensitive map of headers from the provided Metadata object.- Parameters:
metadata- the Metadata object from which headers should be extracted- Returns:
- a map of headers where the keys are header names and the values are lists of header values; if no headers are found, returns an empty case-insensitive map
-
getStatusCode
Retrieves the status code from the provided metadata.- Parameters:
metadata- the metadata containing information associated with the response- Returns:
- the status code as an Integer if present; otherwise, null
-
getPayload
public <R> R getPayload()Retrieves the decoded payload from the response and casts it to the specified type.- Specified by:
getPayloadin interfaceHasMessage- Overrides:
getPayloadin classMessage- Type Parameters:
R- The type to which the payload will be cast.- Returns:
- The decoded payload of the response, cast to the specified type.
-
getPayloadAs
Retrieves the payload and converts it to the specified type. Gzip-encoded streams are decoded when converted to a body value; consuming a stream remains a one-shot operation. Requesting the stream itself (orObject) does not consume or decode it, and its owner remains responsible for closing it. Streamed responses received through the request gateway have a byte-array payload, including when their content type is JSON. Use this method to convert those bytes to a desired body type.- Type Parameters:
R- the desired type of the returned payload- Parameters:
type- the target type to which the payload should be converted- Returns:
- the payload converted to the specified type R
-
getHeaders
Retrieves the list of header values associated with the given header name. If no headers are found for the provided name, an empty list is returned.- Parameters:
name- the name of the header to retrieve- Returns:
- a list of header values associated with the specified name, or an empty list if none are found
-
retainHeaders
Retains only the specified headers from the current WebResponse. Any headers not listed in the provided header names will be removed.- Parameters:
headerNames- the names of headers to be retained in the WebResponse- Returns:
- a new WebResponse instance containing only the specified headers
-
getHeader
-
getCookies
Retrieves a list of cookies from the response's "Set-Cookie" headers. The cookies are parsed from the headers using theWebUtils.parseResponseCookieHeadermethod.- Returns:
- a list of
HttpCookieobjects parsed from the "Set-Cookie" headers; an empty list if there are no cookies or the headers are absent
-
getContentType
Retrieves the value of the "Content-Type" header from the HTTP response. If the header is not present, returns null.- Returns:
- the value of the "Content-Type" header, or null if the header is absent
-
getHeaders
-
getStatus
Returns the HTTP status code associated with the current response. -
getMetadata
io.fluxzero.common.api.Metadata getMetadata() -
chunked
default boolean chunked() -
lastChunk
default boolean lastChunk() -
firstChunk
default boolean firstChunk()
-