Class BusPolicy.Builder
- Enclosing class:
- BusPolicy
BusPolicy.
Example:
BusPolicy
-
Method Summary
Modifier and TypeMethodDescriptionallowedOrigins(String... values) Sets the exact origins a WebSocket handshake may carry when no boundary is set.Grants every declared topic to any caller that can reach the bus endpoints.authorizer(BiPredicate<jakarta.servlet.http.HttpServletRequest, String> value) Sets a per-request, per-topic authorizer, consulted for every requested topic at session open.boundary(RequestBoundary value) Sets the request boundary.build()Builds the policy.downstream(String topicPattern, boolean retain) Allows a topic pattern downstream (server → page).maxFrameBytes(int value) maxQueuedFrames(int value) maxSessionAge(Duration value) maxSessions(int value) maxUpstreamPerSecond(int value) Turns off the default same-origin check applied when no boundary is set.sessionAttributes(Function<jakarta.servlet.http.HttpServletRequest, Map<String, Object>> value) Sets the function that captures attributes onto eachBusSessionat session open.sessionGrace(Duration value) upstream(String topic, UpstreamHandler handler) Allows an exact custom topic upstream (page → server, WebSocket only) and names its handler.
-
Method Details
-
downstream
Allows a topic pattern downstream (server → page).- Parameters:
topicPattern-ns.name,ns.name:key,ns.name:*,job:<id>,job:*orcmd:<cardId>.retain- Whether values are retained and resent on every (re)connect.- Returns:
- This object.
- Throws:
IllegalArgumentException- E-57 on an invalid or repeated pattern.
-
upstream
Allows an exact custom topic upstream (page → server, WebSocket only) and names its handler.- Parameters:
topic- The topic (ns.nameorns.name:key).handler- The handler. Must not benull .- Returns:
- This object.
- Throws:
IllegalArgumentException- E-57 on an invalid or repeated topic, or anull handler.
-
authorizer
public BusPolicy.Builder authorizer(BiPredicate<jakarta.servlet.http.HttpServletRequest, String> value) Sets a per-request, per-topic authorizer, consulted for every requested topic at session open.- Parameters:
value- The authorizer. Must not benull .- Returns:
- This object.
-
anyCaller
Grants every declared topic to any caller that can reach the bus endpoints.Without this or
authorizer(BiPredicate), no topic is granted. Use it only when the endpoints are already protected by the application (a filter, a boundary, or a private network).- Returns:
- This object.
-
boundary
Sets the request boundary. The session POST and SSE stream apply itscheck.The WebSocket handshake cannot run
check, so it applies the boundary's own handshake rules: aLoopbackBoundary's exactorigin()andauthority(), or aCsrfBoundary'sOriginmatch against the handshake's ownHostand scheme.BusWebSockets.registerrefuses any other boundary type.- Parameters:
value- The boundary. Can benull .- Returns:
- This object.
-
noSameOriginCheck
Turns off the default same-origin check applied when no boundary is set.With no
boundary(RequestBoundary), the session POST and SSE stream refuse a request that carries anOriginheader whose authority differs from itsHostheader; a request with noOriginpasses. Call this only when the application guards the endpoints itself, for example when they are served to pages on another origin behind its own CORS and authentication rules.- Returns:
- This object.
-
allowedOrigins
Sets the exact origins a WebSocket handshake may carry when no boundary is set. Ignored when a boundary is set.- Parameters:
values- Origins such ashttps://console.example.org. None may be blank.- Returns:
- This object.
-
sessionGrace
- Parameters:
value- Grace after the last connection closes. Default 60 s. @return This object.
-
maxSessionAge
- Parameters:
value- Absolute session lifetime. Default 12 h. @return This object.
-
heartbeat
- Parameters:
value- Idle interval before apingframe. Default 15 s. @return This object.
-
maxSessions
- Parameters:
value- Maximum live sessions. Default 256. @return This object.
-
maxQueuedFrames
- Parameters:
value- Per-connection outbound queue bound. Default 1024. @return This object.
-
maxFrameBytes
- Parameters:
value- Maximum encoded frame size, UTF-8 bytes. Default 65536. @return This object.
-
maxUpstreamPerSecond
- Parameters:
value- Per-session upstream frames per second. Default 20. @return This object.
-
sessionAttributes
public BusPolicy.Builder sessionAttributes(Function<jakarta.servlet.http.HttpServletRequest, Map<String, Object>> value) Sets the function that captures attributes onto eachBusSessionat session open.- Parameters:
value- The function. Must not benull ; it may returnnull for "none".- Returns:
- This object.
-
build
Builds the policy.- Returns:
- A new immutable policy.
-