Class WebResponse
java.lang.Object
io.fluxzero.sdk.common.Message
io.fluxzero.sdk.web.WebResponse
- All Implemented Interfaces:
HasMetadata, 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.
- See Also:
-
Nested Class Summary
Nested Classes -
Field Summary
FieldsFields inherited from interface HasMessage
warnedAboutMissingPropertyFields inherited from interface HasMetadata
FINAL_CHUNK -
Constructor Summary
ConstructorsConstructorDescriptionConstructs a new WebResponse instance using the provided Message object. -
Method Summary
Modifier and TypeMethodDescriptionaddMetadata(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 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.Retrieves 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(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.<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(Metadata metadata) Retrieves the status code from the provided metadata.static WebResponsestatic WebResponsenotModified(Map<String, String> headers) static WebResponsestatic WebResponseok(org.springframework.util.function.ThrowingSupplier<? extends InputStream> inputStreamSupplier, Map<String, String> headers) static WebResponsepartial(org.springframework.util.function.ThrowingSupplier<? extends InputStream> inputStreamSupplier, Map<String, String> headers) retainHeaders(String... headerNames) Retains only the specified headers from the current WebResponse.serialize(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) withMetadata(Metadata metadata) withPayload(Object payload) Returns a new message instance with the provided payload and existing metadata, ID, and timestamp.withTimestamp(Instant timestamp) Methods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface HasMessage
computeRoutingKey, getMessageId, getPayloadClass, getRoutingKey, getRoutingKey, getTimestampMethods inherited from interface HasMetadata
chunked, getMetadata, lastChunk
-
Field Details
-
headersKey
- See Also:
-
statusKey
- 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
-
ok
public static WebResponse ok(org.springframework.util.function.ThrowingSupplier<? extends InputStream> inputStreamSupplier, Map<String, String> headers) -
partial
public static WebResponse partial(org.springframework.util.function.ThrowingSupplier<? extends InputStream> inputStreamSupplier, Map<String, String> headers) -
notModified
-
notFound
-
serialize
Serializes the response using the content type if applicable. -
asMetadata
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
-
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
-
withTimestamp
-
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
-
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.- 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.
-