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 String
CACHED_REQUEST_BODY_ATTR
Cached request body key.static String
CACHED_SERVER_HTTP_REQUEST_DECORATOR_ATTR
Cached ServerHttpRequestDecorator attribute name.static String
CIRCUITBREAKER_EXECUTION_EXCEPTION_ATTR
CircuitBreaker execution exception attribute name.static String
CLIENT_RESPONSE_ATTR
Client response attribute name.static String
CLIENT_RESPONSE_CONN_ATTR
Client response connection attribute name.static String
CLIENT_RESPONSE_HEADER_NAMES
Client response header names attribute name.static String
GATEWAY_ALREADY_PREFIXED_ATTR
Gateway already prefixed attribute name.static String
GATEWAY_ALREADY_ROUTED_ATTR
Used when a routing filter has been successfully called.static String
GATEWAY_HANDLER_MAPPER_ATTR
Gateway handler mapper attribute name.static String
GATEWAY_LOADBALANCER_RESPONSE_ATTR
Gateway LoadBalancerResponse
attribute name.static String
GATEWAY_ORIGINAL_REQUEST_URL_ATTR
Gateway original request URL attribute name.static String
GATEWAY_PREDICATE_MATCHED_PATH_ATTR
Gateway predicate matched path attribute name.static String
GATEWAY_PREDICATE_MATCHED_PATH_ROUTE_ID_ATTR
Gateway predicate matched path route id attribute name.static String
GATEWAY_PREDICATE_PATH_CONTAINER_ATTR
Gateway predicate path container attribute name.static String
GATEWAY_PREDICATE_ROUTE_ATTR
Gateway predicate route attribute name.static String
GATEWAY_REQUEST_URL_ATTR
Gateway request URL attribute name.static String
GATEWAY_ROUTE_ATTR
Gateway route attribute name.static String
GATEWAY_SCHEME_PREFIX_ATTR
Gateway scheme prefix attribute name.static String
ORIGINAL_RESPONSE_CONTENT_TYPE_ATTR
Original response Content-Type attribute name.static String
PRESERVE_HOST_HEADER_ATTRIBUTE
Preserve-Host header attribute name.static String
URI_TEMPLATE_VARIABLES_ATTRIBUTE
URI template variables attribute name.static String
WEIGHT_ATTR
Weight attribute name.
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static void
addOriginalRequestUrl(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 createdServerHttpRequestDecorator
in ServerWebExchange attributes.static boolean
containsEncodedParts(URI uri)
static String
expand(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 boolean
isAlreadyRouted(org.springframework.web.server.ServerWebExchange exchange)
static org.springframework.http.HttpStatus
parse(String statusString)
static void
putUriTemplateVariables(org.springframework.web.server.ServerWebExchange exchange, Map<String,String> uriVariables)
static void
removeAlreadyRouted(org.springframework.web.server.ServerWebExchange exchange)
static void
reset(org.springframework.web.server.ServerWebExchange exchange)
static void
setAlreadyRouted(org.springframework.web.server.ServerWebExchange exchange)
static boolean
setResponseStatus(org.springframework.web.server.ServerWebExchange exchange, HttpStatusHolder statusHolder)
static boolean
setResponseStatus(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 LoadBalancerResponse
attribute 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 createdServerHttpRequestDecorator
in ServerWebExchange attributes. Those attributes areCACHED_REQUEST_BODY_ATTR
andCACHED_SERVER_HTTP_REQUEST_DECORATOR_ATTR
respectively. This method is useful when theServerWebExchange
can 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 theServerWebExchange
can 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.
-
-