Class ServerWebExchangeUtils
java.lang.Object
org.springframework.cloud.gateway.support.ServerWebExchangeUtils
- Author:
- Spencer Gibb
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final StringCached request body key.static final StringCached ServerHttpRequestDecorator attribute name.static final StringCircuitBreaker execution exception attribute name.static final StringClient response attribute name.static final StringClient response connection attribute name.static final StringClient response header names attribute name.static final StringGateway already prefixed attribute name.static final StringUsed when a routing filter has been successfully called.static final StringGateway handler mapper attribute name.static final StringGateway LoadBalancerResponseattribute name.static final StringGateway ClientObservationattribute name.static final StringGateway original request URL attribute name.static final StringGateway predicate matched path attribute name.static final StringGateway predicate matched path route id attribute name.static final StringGateway predicate path container attribute name.static final StringGateway predicate route attribute name.static final StringOriginal Reactor Context corresponding to the processed request.static final StringGateway request URL attribute name.static final StringGateway route attribute name.static final StringGateway scheme prefix attribute name.static final StringOriginal response Content-Type attribute name.static final StringPreserve-Host header attribute name.static final StringURI template variables attribute name.static final StringWeight attribute name. -
Method Summary
Modifier and TypeMethodDescriptionstatic voidaddOriginalRequestUrl(org.springframework.web.server.ServerWebExchange exchange, URI url) static <T> reactor.core.publisher.Mono<T> cacheRequestBody(org.springframework.web.server.ServerWebExchange exchange, Function<org.springframework.http.server.reactive.ServerHttpRequest, reactor.core.publisher.Mono<T>> function) Caches the request body in a ServerWebExchange attributes.static <T> reactor.core.publisher.Mono<T> cacheRequestBodyAndRequest(org.springframework.web.server.ServerWebExchange exchange, Function<org.springframework.http.server.reactive.ServerHttpRequest, reactor.core.publisher.Mono<T>> function) Caches the request body and the createdServerHttpRequestDecoratorin ServerWebExchange attributes.static voidclearCachedRequestBody(org.springframework.web.server.ServerWebExchange exchange) clear the request body in a ServerWebExchange attribute.static booleancontainsEncodedParts(URI uri) encodeQueryParams(org.springframework.util.MultiValueMap<String, String> params) static StringgetUriTemplateVariables(org.springframework.web.server.ServerWebExchange exchange) static reactor.core.publisher.Mono<Void> handle(org.springframework.web.reactive.DispatcherHandler handler, org.springframework.web.server.ServerWebExchange exchange) One place to handle forwarding using DispatcherHandler.static booleanisAlreadyRouted(org.springframework.web.server.ServerWebExchange exchange) static org.springframework.http.HttpStatusstatic voidputUriTemplateVariables(org.springframework.web.server.ServerWebExchange exchange, Map<String, String> uriVariables) static voidremoveAlreadyRouted(org.springframework.web.server.ServerWebExchange exchange) static voidreset(org.springframework.web.server.ServerWebExchange exchange) static voidsetAlreadyRouted(org.springframework.web.server.ServerWebExchange exchange) static booleansetResponseStatus(org.springframework.web.server.ServerWebExchange exchange, HttpStatusHolder statusHolder) static booleansetResponseStatus(org.springframework.web.server.ServerWebExchange exchange, org.springframework.http.HttpStatus httpStatus) static AsyncPredicate<org.springframework.web.server.ServerWebExchange> toAsyncPredicate(Predicate<? super org.springframework.web.server.ServerWebExchange> predicate)
-
Field Details
-
PRESERVE_HOST_HEADER_ATTRIBUTE
Preserve-Host header attribute name. -
URI_TEMPLATE_VARIABLES_ATTRIBUTE
URI template variables attribute name. -
CLIENT_RESPONSE_ATTR
Client response attribute name. -
CLIENT_RESPONSE_CONN_ATTR
Client response connection attribute name. -
CLIENT_RESPONSE_HEADER_NAMES
Client response header names attribute name. -
GATEWAY_ROUTE_ATTR
Gateway route attribute name. -
GATEWAY_REACTOR_CONTEXT_ATTR
Original Reactor Context corresponding to the processed request. -
GATEWAY_REQUEST_URL_ATTR
Gateway request URL attribute name. -
GATEWAY_ORIGINAL_REQUEST_URL_ATTR
Gateway original request URL attribute name. -
GATEWAY_HANDLER_MAPPER_ATTR
Gateway handler mapper attribute name. -
GATEWAY_SCHEME_PREFIX_ATTR
Gateway scheme prefix attribute name. -
GATEWAY_PREDICATE_ROUTE_ATTR
Gateway predicate route attribute name. -
GATEWAY_PREDICATE_MATCHED_PATH_ATTR
Gateway predicate matched path attribute name. -
GATEWAY_PREDICATE_MATCHED_PATH_ROUTE_ID_ATTR
Gateway predicate matched path route id attribute name. -
GATEWAY_PREDICATE_PATH_CONTAINER_ATTR
Gateway predicate path container attribute name. -
WEIGHT_ATTR
Weight attribute name. -
ORIGINAL_RESPONSE_CONTENT_TYPE_ATTR
Original response Content-Type attribute name.- See Also:
-
CIRCUITBREAKER_EXECUTION_EXCEPTION_ATTR
CircuitBreaker execution exception attribute name. -
GATEWAY_ALREADY_ROUTED_ATTR
Used when a routing filter has been successfully called. Allows users to write custom routing filters that disable built in routing filters. -
GATEWAY_ALREADY_PREFIXED_ATTR
Gateway already prefixed attribute name. -
CACHED_SERVER_HTTP_REQUEST_DECORATOR_ATTR
Cached ServerHttpRequestDecorator attribute name. Used whencacheRequestBodyAndRequest(ServerWebExchange, Function)is called.- See Also:
-
CACHED_REQUEST_BODY_ATTR
Cached request body key. Used whencacheRequestBodyAndRequest(ServerWebExchange, Function)orcacheRequestBody(ServerWebExchange, Function)are called.- See Also:
-
GATEWAY_LOADBALANCER_RESPONSE_ATTR
Gateway LoadBalancerResponseattribute name. -
GATEWAY_OBSERVATION_ATTR
Gateway ClientObservationattribute name.
-
-
Method Details
-
setAlreadyRouted
public static void setAlreadyRouted(org.springframework.web.server.ServerWebExchange exchange) -
removeAlreadyRouted
public static void removeAlreadyRouted(org.springframework.web.server.ServerWebExchange exchange) -
isAlreadyRouted
public static boolean isAlreadyRouted(org.springframework.web.server.ServerWebExchange exchange) -
setResponseStatus
public static boolean setResponseStatus(org.springframework.web.server.ServerWebExchange exchange, org.springframework.http.HttpStatus httpStatus) -
reset
public static void reset(org.springframework.web.server.ServerWebExchange exchange) -
setResponseStatus
public static boolean setResponseStatus(org.springframework.web.server.ServerWebExchange exchange, HttpStatusHolder statusHolder) -
containsEncodedParts
-
encodeQueryParams
-
parse
-
addOriginalRequestUrl
public static void addOriginalRequestUrl(org.springframework.web.server.ServerWebExchange exchange, URI url) -
toAsyncPredicate
public static AsyncPredicate<org.springframework.web.server.ServerWebExchange> toAsyncPredicate(Predicate<? super org.springframework.web.server.ServerWebExchange> predicate) -
expand
-
putUriTemplateVariables
-
getUriTemplateVariables
-
cacheRequestBodyAndRequest
public static <T> reactor.core.publisher.Mono<T> cacheRequestBodyAndRequest(org.springframework.web.server.ServerWebExchange exchange, Function<org.springframework.http.server.reactive.ServerHttpRequest, reactor.core.publisher.Mono<T>> function) Caches the request body and the createdServerHttpRequestDecoratorin ServerWebExchange attributes. Those attributes areCACHED_REQUEST_BODY_ATTRandCACHED_SERVER_HTTP_REQUEST_DECORATOR_ATTRrespectively. This method is useful when theServerWebExchangecan not be modified, such as aRoutePredicateFactory.- Type Parameters:
T- generic type for the returnMono.- Parameters:
exchange- the available ServerWebExchange.function- a function that accepts the created ServerHttpRequestDecorator.- Returns:
- Mono of type T created by the function parameter.
-
cacheRequestBody
public static <T> reactor.core.publisher.Mono<T> cacheRequestBody(org.springframework.web.server.ServerWebExchange exchange, Function<org.springframework.http.server.reactive.ServerHttpRequest, reactor.core.publisher.Mono<T>> function) Caches the request body in a ServerWebExchange attributes. The attribute isCACHED_REQUEST_BODY_ATTR. This method is useful when theServerWebExchangecan be mutated, such as aGatewayFilterFactory.- Type Parameters:
T- generic type for the returnMono.- Parameters:
exchange- the available ServerWebExchange.function- a function that accepts the created ServerHttpRequestDecorator.- Returns:
- Mono of type T created by the function parameter.
-
clearCachedRequestBody
public static void clearCachedRequestBody(org.springframework.web.server.ServerWebExchange exchange) clear the request body in a ServerWebExchange attribute. The attribute isCACHED_REQUEST_BODY_ATTR.- Parameters:
exchange- the available ServerWebExchange.
-
handle
public static reactor.core.publisher.Mono<Void> handle(org.springframework.web.reactive.DispatcherHandler handler, org.springframework.web.server.ServerWebExchange exchange) One place to handle forwarding using DispatcherHandler. Allows for common code to be reused.- Parameters:
handler- The DispatcherHandler.exchange- The ServerWebExchange.- Returns:
- value from handler.
-