Search in sources :

Example 6 with Route

use of org.springframework.cloud.gateway.route.Route in project spring-cloud-gateway by spring-cloud.

the class RouteToRequestUrlFilter method filter.

@Override
public Mono<Void> filter(ServerWebExchange exchange, GatewayFilterChain chain) {
    Route route = exchange.getAttribute(GATEWAY_ROUTE_ATTR);
    if (route == null) {
        return chain.filter(exchange);
    }
    log.trace("RouteToRequestUrlFilter start");
    URI uri = exchange.getRequest().getURI();
    boolean encoded = containsEncodedParts(uri);
    URI routeUri = route.getUri();
    if (hasAnotherScheme(routeUri)) {
        // this is a special url, save scheme to special attribute
        // replace routeUri with schemeSpecificPart
        exchange.getAttributes().put(GATEWAY_SCHEME_PREFIX_ATTR, routeUri.getScheme());
        routeUri = URI.create(routeUri.getSchemeSpecificPart());
    }
    URI requestUrl = UriComponentsBuilder.fromUri(uri).uri(routeUri).build(encoded).toUri();
    exchange.getAttributes().put(GATEWAY_REQUEST_URL_ATTR, requestUrl);
    return chain.filter(exchange);
}
Also used : URI(java.net.URI) Route(org.springframework.cloud.gateway.route.Route)

Aggregations

Route (org.springframework.cloud.gateway.route.Route)6 GatewayFilter (org.springframework.cloud.gateway.filter.GatewayFilter)3 URI (java.net.URI)2 OrderedGatewayFilter (org.springframework.cloud.gateway.filter.OrderedGatewayFilter)2 ArrayList (java.util.ArrayList)1 Collections (java.util.Collections)1 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)1 Test (org.junit.Test)1 ArgumentCaptor (org.mockito.ArgumentCaptor)1 Mockito.mock (org.mockito.Mockito.mock)1 Mockito.when (org.mockito.Mockito.when)1 KeyResolver (org.springframework.cloud.gateway.filter.ratelimit.KeyResolver)1 RateLimiter (org.springframework.cloud.gateway.filter.ratelimit.RateLimiter)1 ServerWebExchangeUtils (org.springframework.cloud.gateway.support.ServerWebExchangeUtils)1 GATEWAY_REQUEST_URL_ATTR (org.springframework.cloud.gateway.support.ServerWebExchangeUtils.GATEWAY_REQUEST_URL_ATTR)1 GATEWAY_ROUTE_ATTR (org.springframework.cloud.gateway.support.ServerWebExchangeUtils.GATEWAY_ROUTE_ATTR)1 GATEWAY_SCHEME_PREFIX_ATTR (org.springframework.cloud.gateway.support.ServerWebExchangeUtils.GATEWAY_SCHEME_PREFIX_ATTR)1 ConfigurableApplicationContext (org.springframework.context.ConfigurableApplicationContext)1 Ordered (org.springframework.core.Ordered)1 HttpMethod (org.springframework.http.HttpMethod)1