Class ServerWebExchangeUtils
- java.lang.Object
-
- org.springframework.cloud.gateway.support.ServerWebExchangeUtils
-
public final class ServerWebExchangeUtils extends Object
- Author:
- Spencer Gibb
-
-
Field Summary
Fields Modifier and Type Field Description static StringCACHED_REQUEST_BODY_ATTRCached request body key.static StringCACHED_SERVER_HTTP_REQUEST_DECORATOR_ATTRCached ServerHttpRequestDecorator attribute name.static StringCIRCUITBREAKER_EXECUTION_EXCEPTION_ATTRCircuitBreaker execution exception attribute name.static StringCLIENT_RESPONSE_ATTRClient response attribute name.static StringCLIENT_RESPONSE_CONN_ATTRClient response connection attribute name.static StringCLIENT_RESPONSE_HEADER_NAMESClient response header names attribute name.static StringGATEWAY_ALREADY_PREFIXED_ATTRGateway already prefixed attribute name.static StringGATEWAY_ALREADY_ROUTED_ATTRUsed when a routing filter has been successfully called.static StringGATEWAY_HANDLER_MAPPER_ATTRGateway handler mapper attribute name.static StringGATEWAY_LOADBALANCER_RESPONSE_ATTRGateway LoadBalancerResponseattribute name.static StringGATEWAY_ORIGINAL_REQUEST_URL_ATTRGateway original request URL attribute name.static StringGATEWAY_PREDICATE_MATCHED_PATH_ATTRGateway predicate matched path attribute name.static StringGATEWAY_PREDICATE_MATCHED_PATH_ROUTE_ID_ATTRGateway predicate matched path route id attribute name.static StringGATEWAY_PREDICATE_PATH_CONTAINER_ATTRGateway predicate path container attribute name.static StringGATEWAY_PREDICATE_ROUTE_ATTRGateway predicate route attribute name.static StringGATEWAY_REQUEST_URL_ATTRGateway request URL attribute name.static StringGATEWAY_ROUTE_ATTRGateway route attribute name.static StringGATEWAY_SCHEME_PREFIX_ATTRGateway scheme prefix attribute name.static StringORIGINAL_RESPONSE_CONTENT_TYPE_ATTROriginal response Content-Type attribute name.static StringPRESERVE_HOST_HEADER_ATTRIBUTEPreserve-Host header attribute name.static StringURI_TEMPLATE_VARIABLES_ATTRIBUTEURI template variables attribute name.static StringWEIGHT_ATTRWeight attribute name.
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static 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 booleancontainsEncodedParts(URI uri)static Stringexpand(org.springframework.web.server.ServerWebExchange exchange, String template)static Map<String,String>getUriTemplateVariables(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.HttpStatusparse(String statusString)static 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 Detail
-
PRESERVE_HOST_HEADER_ATTRIBUTE
public static final String PRESERVE_HOST_HEADER_ATTRIBUTE
Preserve-Host header attribute name.
-
URI_TEMPLATE_VARIABLES_ATTRIBUTE
public static final String URI_TEMPLATE_VARIABLES_ATTRIBUTE
URI template variables attribute name.
-
CLIENT_RESPONSE_ATTR
public static final String CLIENT_RESPONSE_ATTR
Client response attribute name.
-
CLIENT_RESPONSE_CONN_ATTR
public static final String CLIENT_RESPONSE_CONN_ATTR
Client response connection attribute name.
-
CLIENT_RESPONSE_HEADER_NAMES
public static final String CLIENT_RESPONSE_HEADER_NAMES
Client response header names attribute name.
-
GATEWAY_ROUTE_ATTR
public static final String GATEWAY_ROUTE_ATTR
Gateway route attribute name.
-
GATEWAY_REQUEST_URL_ATTR
public static final String GATEWAY_REQUEST_URL_ATTR
Gateway request URL attribute name.
-
GATEWAY_ORIGINAL_REQUEST_URL_ATTR
public static final String GATEWAY_ORIGINAL_REQUEST_URL_ATTR
Gateway original request URL attribute name.
-
GATEWAY_HANDLER_MAPPER_ATTR
public static final String GATEWAY_HANDLER_MAPPER_ATTR
Gateway handler mapper attribute name.
-
GATEWAY_SCHEME_PREFIX_ATTR
public static final String GATEWAY_SCHEME_PREFIX_ATTR
Gateway scheme prefix attribute name.
-
GATEWAY_PREDICATE_ROUTE_ATTR
public static final String GATEWAY_PREDICATE_ROUTE_ATTR
Gateway predicate route attribute name.
-
GATEWAY_PREDICATE_MATCHED_PATH_ATTR
public static final String GATEWAY_PREDICATE_MATCHED_PATH_ATTR
Gateway predicate matched path attribute name.
-
GATEWAY_PREDICATE_MATCHED_PATH_ROUTE_ID_ATTR
public static final String GATEWAY_PREDICATE_MATCHED_PATH_ROUTE_ID_ATTR
Gateway predicate matched path route id attribute name.
-
GATEWAY_PREDICATE_PATH_CONTAINER_ATTR
public static final String GATEWAY_PREDICATE_PATH_CONTAINER_ATTR
Gateway predicate path container attribute name.
-
WEIGHT_ATTR
public static final String WEIGHT_ATTR
Weight attribute name.
-
ORIGINAL_RESPONSE_CONTENT_TYPE_ATTR
public static final String ORIGINAL_RESPONSE_CONTENT_TYPE_ATTR
Original response Content-Type attribute name.- See Also:
- Constant Field Values
-
CIRCUITBREAKER_EXECUTION_EXCEPTION_ATTR
public static final String CIRCUITBREAKER_EXECUTION_EXCEPTION_ATTR
CircuitBreaker execution exception attribute name.
-
GATEWAY_ALREADY_ROUTED_ATTR
public static final String 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
public static final String GATEWAY_ALREADY_PREFIXED_ATTR
Gateway already prefixed attribute name.
-
CACHED_SERVER_HTTP_REQUEST_DECORATOR_ATTR
public static final String CACHED_SERVER_HTTP_REQUEST_DECORATOR_ATTR
Cached ServerHttpRequestDecorator attribute name. Used whencacheRequestBodyAndRequest(ServerWebExchange, Function)is called.- See Also:
- Constant Field Values
-
CACHED_REQUEST_BODY_ATTR
public static final String CACHED_REQUEST_BODY_ATTR
Cached request body key. Used whencacheRequestBodyAndRequest(ServerWebExchange, Function)orcacheRequestBody(ServerWebExchange, Function)are called.- See Also:
- Constant Field Values
-
GATEWAY_LOADBALANCER_RESPONSE_ATTR
public static final String GATEWAY_LOADBALANCER_RESPONSE_ATTR
Gateway LoadBalancerResponseattribute name.
-
-
Method Detail
-
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
public static boolean containsEncodedParts(URI uri)
-
parse
public static org.springframework.http.HttpStatus parse(String statusString)
-
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
public static String expand(org.springframework.web.server.ServerWebExchange exchange, String template)
-
putUriTemplateVariables
public static void putUriTemplateVariables(org.springframework.web.server.ServerWebExchange exchange, Map<String,String> uriVariables)
-
getUriTemplateVariables
public static Map<String,String> getUriTemplateVariables(org.springframework.web.server.ServerWebExchange exchange)
-
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.
-
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.
-
-