Open RomainWilbert opened 4 days ago
Nothing you've described makes me think this is a problem with gateway. You've only supplied snippets, not the full filter, so I can't make any comment at all.
Hi @spencergibb.
Do you require all sources or only the filter and its purpose explained ?
The filter method
```
@Override
public Mono
String fullPath = gestionPathParam(request);
logger.debug("Request {} sur le path {}", request.getMethod().name(), fullPath);
if (estAIgnorer(exchange)) {
logger.debug("Request sans double run sur le path {}", fullPath);
return chain.filter(exchange);
}
return chain.filter(generateNewExchange(exchange, fullPath, dateActeMetier));
}
private ServerWebExchange generateNewExchange(ServerWebExchange exchange, String fullPath, Date dateActeMetier) {
CompletableFuture<String> completableAppelSecondaire = appelSystemeSecondaire(exchange, fullPath);
ServerHttpResponseDecorator decoratedResponse = getDecoratedResponse(exchange, completableAppelSecondaire, dateActeMetier);
return exchange.mutate().response(decoratedResponse).build();
}
The response decorator which call the get method on the completableFuture
@Override
public Mono<Void> writeWith(final Publisher<? extends DataBuffer> body) {
// Après traitement du flux principal de GW
if (body instanceof Flux<? extends DataBuffer> fluxBody) {
long dureeAppelPrimaire = System.currentTimeMillis() - startTime;
return super.writeWith(fluxBody.buffer().map(dataBuffers -> {
String reponsePrincipale = decodeAppelPrincipal(dataBuffers);
String reponse = getReponse(reponsePrincipale, dureeAppelPrimaire);
traceSiUtilisteurOuService(reponse);
return exchange.getResponse().bufferFactory().wrap(reponse.getBytes());
})).onErrorResume(err -> {
logger.error("error while decorating Response: " + err.getMessage(), err);
return Mono.empty();
});
}
return super.writeWith(body);
}
Hello,
I have a GlobalFilter which calls an external URL using RestTemplate.
While everything is fine while running on my computer, when I run the code on K8s I get a strange behavior : it seems the external call ends up in the Filter again, causing an inifinite loop.
A quick fix is to instanciate RestTemplate every time :
I have the same behavior using RestClient or WebClient.
Versions used : spring-cloud.version 2023.0.3 spring-boot 3.3.2