Class ServerWebExchangeUtils


  • public final class ServerWebExchangeUtils
    extends Object
    Author:
    Spencer Gibb
    • 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.
      • GATEWAY_LOADBALANCER_RESPONSE_ATTR

        public static final String GATEWAY_LOADBALANCER_RESPONSE_ATTR
        Gateway LoadBalancer Response 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 created ServerHttpRequestDecorator in ServerWebExchange attributes. Those attributes are CACHED_REQUEST_BODY_ATTR and CACHED_SERVER_HTTP_REQUEST_DECORATOR_ATTR respectively. This method is useful when the ServerWebExchange can not be modified, such as a RoutePredicateFactory.
        Type Parameters:
        T - generic type for the return Mono.
        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 is CACHED_REQUEST_BODY_ATTR. This method is useful when the ServerWebExchange can be mutated, such as a GatewayFilterFactory/
        Type Parameters:
        T - generic type for the return Mono.
        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.