These are chat archives for spring-cloud/spring-cloud

13th
Jan 2018
Andrew Fitzgerald
@fitzoh
Jan 13 2018 03:44
@spencergibb, In spring-cloud-gateway is there an easy way to set the uri of route based on a header?
The use case I’m thinking of is a PCF route service
Or would it make more sense to just use webflux and make the downstream request manually?
yelhouti
@yelhouti
Jan 13 2018 19:18
Hi guys, I'm trying to use zuul (or may be something else) to aggregate data from all my microservices. Each microservice will expose his permissions at the same endpoint /api/permissions, and the gateway would (using probably zuul) request from all and aggregate the data
any idea on how to do that using spring cloud?
Andrew Fitzgerald
@fitzoh
Jan 13 2018 23:33

Think I’ve got it btw:

@Component
public class RouteServiceForwardingFilter implements GatewayFilter {

    @Override
    public Mono<Void> filter(ServerWebExchange exchange, GatewayFilterChain chain) {
        try {
            String forwardUrl = exchange.getRequest().getHeaders().get(FORWARDED_URL).get(0);
            exchange.getAttributes().put(GATEWAY_REQUEST_URL_ATTR, new URI(forwardUrl));
            return chain.filter(exchange);
        } catch (URISyntaxException e) {
            exchange.getResponse().setStatusCode(HttpStatus.INTERNAL_SERVER_ERROR);
            return Mono.empty();
        }
    }
}

+


    @Bean
    public RouteLocator customRouteLocator(RouteLocatorBuilder builder, RouteServiceForwardingFilter forwardFilter) {
        return builder.routes()
                .route(r ->
                        r.header(FORWARDED_URL, ".*")
                                .and()
                                .header(PROXY_METADATA, ".*")
                                .and()
                                .header(PROXY_SIGNATURE, ".*")
                                .filter(forwardFilter, 10000)
                                .uri("http://doesntmatter.com:80"))
                .build();
    }