Package io.fluxcapacitor.javaclient.web
Class WebResponse
java.lang.Object
io.fluxcapacitor.javaclient.common.Message
io.fluxcapacitor.javaclient.web.WebResponse
- All Implemented Interfaces:
HasMetadata
,HasMessage
Represents a response to a
WebRequest
in the Flux platform.
WebResponse
extends Message
and includes:
status
– HTTP status code (e.g. 200, 404)headers
– HTTP headerscookies
– parsed fromSet-Cookie
contentType
– 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 io.fluxcapacitor.javaclient.common.HasMessage
warnedAboutMissingProperty
Fields inherited from interface io.fluxcapacitor.common.api.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 Metadata
asMetadata
(int statusCode, Map<String, List<String>> headers) Constructs a Metadata object containing the provided status code and headers.static WebResponse.Builder
builder()
Creates a newWebResponse.Builder
instance for constructingWebResponse
objects.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> R
Retrieves the decoded payload from the response and casts it to the specified type.<R> R
getPayloadAs
(Type type) Retrieves the payload and converts it to the specified type.Returns the HTTP status code associated with the current response.static Integer
getStatusCode
(Metadata metadata) Retrieves the status code from the provided metadata.static WebResponse
static WebResponse
notModified
(Map<String, String> headers) static WebResponse
static WebResponse
ok
(org.springframework.util.function.ThrowingSupplier<? extends InputStream> inputStreamSupplier, Map<String, String> headers) static WebResponse
partial
(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 java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface io.fluxcapacitor.javaclient.common.HasMessage
computeRoutingKey, getMessageId, getPayloadClass, getRoutingKey, getRoutingKey, getTimestamp
Methods inherited from interface io.fluxcapacitor.common.api.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
- theMessage
object 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:Message
Returns a new message with the combined metadata.- Overrides:
addMetadata
in classMessage
-
addMetadata
Description copied from class:Message
Adds a single metadata entry.- Overrides:
addMetadata
in classMessage
-
addMetadata
Description copied from class:Message
Adds multiple metadata entries.- Overrides:
addMetadata
in classMessage
-
addMetadata
Description copied from class:Message
Adds metadata from a given map.- Overrides:
addMetadata
in classMessage
-
addUser
Description copied from class:Message
Attaches a user object to the metadata using the configuredUserProvider
. -
withPayload
Description copied from class:Message
Returns a new message instance with the provided payload and existing metadata, ID, and timestamp.- Overrides:
withPayload
in 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.Builder
initialized with the properties of the current WebResponse instance.
-
builder
Creates a newWebResponse.Builder
instance for constructingWebResponse
objects.- 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:
getPayload
in interfaceHasMessage
- Overrides:
getPayload
in 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
Retrieves the value of the first occurrence of the specified header name.- Parameters:
name
- the name of the HTTP header to retrieve- Returns:
- the first value associated with the specified header name, or null if the header is not present
-
getCookies
Retrieves a list of cookies from the response's "Set-Cookie" headers. The cookies are parsed from the headers using theWebUtils.parseResponseCookieHeader
method.- Returns:
- a list of
HttpCookie
objects 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
Returns all HTTP headers associated with the current response. -
getStatus
Returns the HTTP status code associated with the current response.
-