Package io.fluxcapacitor.javaclient.web
Class WebRequest
java.lang.Object
io.fluxcapacitor.javaclient.common.Message
io.fluxcapacitor.javaclient.web.WebRequest
- All Implemented Interfaces:
HasMetadata
,HasMessage
Represents a web request message within the Flux platform.
This message is routed to handlers using annotations like HandleWeb
, HandleGet
, or
HandleSocketOpen
.
WebRequest
extends Message
and includes additional metadata such as:
path
– the requested URI path including query parametersmethod
– HTTP or WebSocket method (e.g. GET, WS_OPEN)headers
– structured request headerscookies
– parsed from the Cookie header
It also provides a fluent WebRequest.Builder
API to construct requests programmatically.
Example Usage
WebRequest request = WebRequest.post("https://api.example.com/projects")
.body(new ProjectDetails("My Project", "My Description"))
.build();
Outbound requests with an absolute URL that are dispatched using the WebRequestGateway
will be forwarded
by the proxy in Flux Platform.
- See Also:
-
Nested Class Summary
Nested Classes -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final String
static final String
static final String
static final String
Fields 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 WebRequest instance using the provided Message. -
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 WebRequest.Builder
builder()
Creates a newWebRequest.Builder
instance for constructing aWebRequest
.static WebRequest.Builder
Creates a newWebRequest.Builder
instance for constructing aDELETE request
to given url.static WebRequest.Builder
Creates a newWebRequest.Builder
instance for constructing aGET request
to given url.Returns the content type of the request (based onContent-Type
header).static Optional
<HttpCookie> Retrieves the first cookie with the given name from the provided Metadata object.Finds a cookie by name.Retrieves the first header value for the given name from the provided Metadata object.Returns a single header value, ornull
if not present.The HTTP headers as a case-sensitive map.getHeaders
(Metadata metadata) Retrieves a case-insensitive map of headers from the provided Metadata object.getHeaders
(String name) Returns all values for the specified header.@NonNull String
The HTTP or WebSocket method (e.g.static String
Extracts the HTTP or WebSocket method (e.g., "GET", "POST", "WS_OPEN") from the provided Metadata object.@NonNull String
getPath()
The request path including query parameters (e.g.<R> R
getPayloadAs
(Type type) Deserializes the payload into a given type, using JSON if content type isapplication/json
.static String
getSocketSessionId
(Metadata metadata) Retrieves the WebSocket session ID from the provided metadata, ornull
if it is missing.static String
Extracts the request path from the provided Metadata object.static WebRequest.Builder
Creates a newWebRequest.Builder
instance for constructing aPATCH request
to given url.static WebRequest.Builder
Creates a newWebRequest.Builder
instance for constructing aPOST request
to given url.static WebRequest.Builder
Creates a newWebRequest.Builder
instance for constructing aPUT request
to given url.static String
requireSocketSessionId
(Metadata metadata) Retrieves the WebSocket session ID from the provided metadata or throws an exception if it is missing.serialize
(Serializer serializer) Serializes the request using the content type if applicable.Creates a mutable builder for this request.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 io.fluxcapacitor.javaclient.common.Message
asMessage, getPayload, toMessage
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
-
urlKey
- See Also:
-
methodKey
- See Also:
-
headersKey
- See Also:
-
sessionIdKey
- See Also:
-
-
Constructor Details
-
WebRequest
Constructs a new WebRequest instance using the provided Message.- Parameters:
m
- the Message instance containing the payload, metadata, message ID, and timestamp
-
-
Method Details
-
builder
Creates a newWebRequest.Builder
instance for constructing aWebRequest
. -
get
Creates a newWebRequest.Builder
instance for constructing aGET request
to given url. -
post
Creates a newWebRequest.Builder
instance for constructing aPOST request
to given url. -
put
Creates a newWebRequest.Builder
instance for constructing aPUT request
to given url. -
patch
Creates a newWebRequest.Builder
instance for constructing aPATCH request
to given url. -
delete
Creates a newWebRequest.Builder
instance for constructing aDELETE request
to given url. -
serialize
Serializes the request using the content type if applicable. -
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
-
getHeader
Returns a single header value, ornull
if not present.- Parameters:
name
- the header name- Returns:
- the first value or
null
-
getHeaders
Returns all values for the specified header.- Parameters:
name
- the header name- Returns:
- list of values, possibly empty
-
getContentType
Returns the content type of the request (based onContent-Type
header). -
getPayloadAs
Deserializes the payload into a given type, using JSON if content type isapplication/json
.- Type Parameters:
R
- the expected payload type- Parameters:
type
- the target type- Returns:
- deserialized payload
-
getCookie
Finds a cookie by name.- Parameters:
name
- the cookie name- Returns:
- optional cookie
-
getPath
The request path including query parameters (e.g."/api/users?id=123"
). May contain the full URL for outbound web requests. -
getMethod
The HTTP or WebSocket method (e.g."GET"
,"POST"
,"WS_OPEN"
). -
getHeaders
The HTTP headers as a case-sensitive map. Header values are lists to support repeated headers. -
toBuilder
Creates a mutable builder for this request. -
getUrl
Extracts the request path from the provided Metadata object.- Parameters:
metadata
- the metadata object containing the request path information- Returns:
- the request path as a string
- Throws:
IllegalStateException
- if the request path information is missing in the metadata
-
getMethod
Extracts the HTTP or WebSocket method (e.g., "GET", "POST", "WS_OPEN") from the provided Metadata object.- Parameters:
metadata
- the metadata object containing the method information- Returns:
- the HTTP or WebSocket method as a string
- Throws:
IllegalStateException
- if the method information is missing in the metadata
-
getHeaders
Retrieves a case-insensitive map of headers from the provided Metadata object. -
getHeader
Retrieves the first header value for the given name from the provided Metadata object. -
getCookie
Retrieves the first cookie with the given name from the provided Metadata object. -
getSocketSessionId
Retrieves the WebSocket session ID from the provided metadata, ornull
if it is missing. -
requireSocketSessionId
Retrieves the WebSocket session ID from the provided metadata or throws an exception if it is missing.
-