Class WebRequest
- All Implemented Interfaces:
HasMessage
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 Fluxzero Runtime.
- See Also:
-
Nested Class Summary
Nested Classes -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final StringFields inherited from interface HasMessage
warnedAboutMissingProperty -
Constructor Summary
ConstructorsConstructorDescriptionConstructs a new WebRequest instance using the provided Message. -
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 WebRequest.Builderbuilder()Creates a newWebRequest.Builderinstance for constructing aWebRequest.default booleanchunked()static WebRequest.BuilderCreates a newWebRequest.Builderinstance for constructing aDELETE requestto given url.default booleanstatic WebRequest.BuilderCreates a newWebRequest.Builderinstance for constructing aGET requestto given url.Returns the content type of the request (based onContent-Typeheader).static Optional<HttpCookie> Retrieves the first cookie with the given name from the provided Metadata object.Finds the first cookie with the given name in logical wire order.getCookie(String name, CookieValueConflictPolicy conflictPolicy) Finds a cookie with the given name using the requested conflict policy.getCookies(String name) Returns all cookies with the given name in logical wire order, without collapsing duplicates.Retrieves the first header value for the given name from the provided Metadata object.Returns a single header value, ornullif not present.The HTTP headers as a case-insensitive map.getHeaders(io.fluxzero.common.api.Metadata metadata) Retrieves a case-insensitive map of headers from the provided Metadata object.getHeaders(String name) Returns all values for the specified header.io.fluxzero.common.api.Metadata@NonNull StringThe HTTP or WebSocket method (e.g.static StringgetMethod(io.fluxzero.common.api.Metadata metadata) Extracts the HTTP or WebSocket method (e.g., "GET", "POST", "WS_OPEN") from the provided Metadata object.@NonNull StringgetPath()The request path including query parameters (e.g.<R> RgetPayloadAs(Type type) Deserializes the payload into a given type, using JSON if content type isapplication/json.static StringgetSocketSessionId(io.fluxzero.common.api.Metadata metadata) Retrieves the WebSocket session ID from the provided metadata, ornullif it is missing.static StringgetUrl(io.fluxzero.common.api.Metadata metadata) Extracts the request path from the provided Metadata object.default booleanstatic WebRequest.BuilderCreates a newWebRequest.Builderinstance for constructing aPATCH requestto given url.static WebRequest.BuilderCreates a newWebRequest.Builderinstance for constructing aPOST requestto given url.static WebRequest.BuilderCreates a newWebRequest.Builderinstance for constructing aPUT requestto given url.static StringrequireSocketSessionId(io.fluxzero.common.api.Metadata metadata) Retrieves the WebSocket session ID from the provided metadata or throws an exception if it is missing.io.fluxzero.common.api.SerializedMessageserialize(Serializer serializer) Serializes the request using the content type if applicable.Creates a mutable builder for this request.withMessageId(String messageId) withMetadata(io.fluxzero.common.api.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 Message
asMessage, getPayload, 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
-
urlKey
- See Also:
-
methodKey
- See Also:
-
headersKey
- See Also:
-
sessionIdKey
- See Also:
-
FIRST_CHUNK
- See Also:
-
FINAL_CHUNK
- See Also:
-
CHUNK_INDEX
- 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.Builderinstance for constructing aWebRequest. -
get
Creates a newWebRequest.Builderinstance for constructing aGET requestto given url. -
post
Creates a newWebRequest.Builderinstance for constructing aPOST requestto given url. -
put
Creates a newWebRequest.Builderinstance for constructing aPUT requestto given url. -
patch
Creates a newWebRequest.Builderinstance for constructing aPATCH requestto given url. -
delete
Creates a newWebRequest.Builderinstance for constructing aDELETE requestto given url. -
serialize
Serializes the request using the content type if applicable. -
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
-
getHeader
-
getHeaders
-
getContentType
Returns the content type of the request (based onContent-Typeheader). -
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 the first cookie with the given name in logical wire order.This method retains its first-match behavior and is equivalent to calling
getCookie(String, CookieValueConflictPolicy)withCookieValueConflictPolicy.DEFAULT. Cookies in laterCookieheader values are now included in the lookup.- Parameters:
name- the case-sensitive cookie name- Returns:
- the first matching cookie, or empty if it is absent
-
getCookie
Finds a cookie with the given name using the requested conflict policy.Identical repeated values are accepted by both policies.
CookieValueConflictPolicy.REJECT_CONFLICTING_VALUESthrows a redactedCookieConflictExceptionwhen at least one matching value differs.- Parameters:
name- the case-sensitive cookie nameconflictPolicy- the policy for matching cookies with different values- Returns:
- the first matching cookie, or empty if it is absent
- Throws:
CookieConflictException- if conflicting values are present and rejection is requested
-
getCookies
Returns all cookies with the given name in logical wire order, without collapsing duplicates.- Parameters:
name- the case-sensitive cookie name- Returns:
- all matching cookies, possibly empty
-
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
-
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
-
getHeader
-
getCookie
Retrieves the first cookie with the given name from the provided Metadata object. -
getSocketSessionId
Retrieves the WebSocket session ID from the provided metadata, ornullif it is missing. -
requireSocketSessionId
Retrieves the WebSocket session ID from the provided metadata or throws an exception if it is missing. -
getMetadata
io.fluxzero.common.api.Metadata getMetadata() -
chunked
default boolean chunked() -
lastChunk
default boolean lastChunk() -
firstChunk
default boolean firstChunk()
-