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

29th
Mar 2019
Benjamin Ihrig
@ihrigb
Mar 29 09:54
Hi, can someone tell me, if spring.datasource.hikari.* properties do have an effect on datasources, created via the cloud connector? If so, where is the code, that takes care of this? Thanks!
Dave
@dave-fl
Mar 29 15:05
@spencergibb Is there a proper way to "Clone" the incoming request.
Part of the reason why the retry filter breaks is because the request body has already been subscribed too even if there is no body
Spencer Gibb
@spencergibb
Mar 29 17:33
@dave-fl yeah, we have a way to do it for the read body predicate. We should do similarly for retry.
Dave
@dave-fl
Mar 29 18:06
I'm testing it now
and having some issues
Spencer Gibb
@spencergibb
Mar 29 18:06
Yeah, it's not trivial
Dave
@dave-fl
Mar 29 18:07
Apparently one has to use slice.
    @Override
    public Mono<Void> filter(ServerWebExchange exchange, GatewayFilterChain chain) {
        Object body = exchange.getAttributeOrDefault(CUSTOM_CACHED_REQUEST_BODY_KEY,
                null);

        if (body != null) {
            return chain.filter(exchange);
        }

        Mono<Flux<DataBuffer>> fluxMono = DataBufferUtils.join(exchange.getRequest().getBody())
                .flatMap(dataBuffer -> Mono.defer(() -> Mono.just(Flux.just(dataBuffer))))
                .defaultIfEmpty(Flux.empty());
        return fluxMono.doOnNext(dataBufferFlux -> {
            exchange.getAttributes().put(CUSTOM_CACHED_REQUEST_BODY_KEY, dataBufferFlux);
        }).then(chain.filter(exchange));
    }
    public Mono<Void> filter(ServerWebExchange exchange, GatewayFilterChain chain) {
        Flux<DataBuffer> body = exchange.getAttributeOrDefault(CUSTOM_CACHED_REQUEST_BODY_KEY,
                null);

        if (body != null) {
            ServerHttpRequestDecorator decorator = new ServerHttpRequestDecorator(
                    exchange.getRequest()) {
                @Override
                public Flux<DataBuffer> getBody() {
                    return body.map(dataBuffer ->
                            DataBufferUtils.retain(dataBuffer.slice(0, dataBuffer.readableByteCount())));
                }
            };
            return chain.filter(exchange.mutate().request(decorator).build());
        }
        return chain.filter(exchange);
    }
seems to do the trick
I am not certain of the mechanics of retain
Spencer Gibb
@spencergibb
Mar 29 18:12
We have experts that can look at that.
Spencer Gibb
@spencergibb
Mar 29 18:20
@dave-fl is that in the retry filter?
Dave
@dave-fl
Mar 29 18:29
No, but we will need something like that for it to work.
Dave
@dave-fl
Mar 29 19:21
The above change works, but it leaks (even with doOnDiscard)