Configured ExchangeFilterFunction
using andThen
and expected them to be applied in the order provided. That is first handled for bad request, then retried and then handled for any other status codes. However any expection including 400 is handled by handleUnexpectedStatus()
filter only.
WebClientExchangeFilter.zip
@Bean
public ExchangeFilterFunction webClientFilterChain() {
return handleBadRequest()
.andThen(retry())
.andThen(handleUnexpectedStatus());
}
Comment From: sbrannen
At a quick glance, it appears that andThen()
is applied in the correct order, since the following test passes.
@Test
void andThen() {
ClientRequest request = ClientRequest.create(HttpMethod.GET, DEFAULT_URL).build();
ClientResponse response = mock();
ExchangeFunction exchange = r -> Mono.just(response);
List<String> filters = new ArrayList<>();
ExchangeFilterFunction filter1 = (r, n) -> {
filters.add("filter1");
return n.exchange(r);
};
ExchangeFilterFunction filter2 = (r, n) -> {
filters.add("filter2");
return n.exchange(r);
};
ExchangeFilterFunction filter3 = (r, n) -> {
filters.add("filter3");
return n.exchange(r);
};
ExchangeFilterFunction filter = filter1.andThen(filter2).andThen(filter3);
ClientResponse result = filter.filter(request, exchange).block();
assertThat(filters).containsExactly("filter1", "filter2", "filter3");
}
Thus, perhaps something else is going on in your scenario, and we'll take a deeper look.
Comment From: sdeleuze
Please provide a self contained reproducer (full project).
Comment From: sruthigunti
Please find the test in the attached zip WebClientExchangeFilter.zip
Comment From: sdeleuze
@sruthigunti As far as I can tell, this new archive still only contains 2 Java files like the initial attached file in the description. In my previous comment, I was asking you a self contained reproducer (full project including the Maven or Gradle build). Please provide that if you want us to have a deeper look.
Comment From: sruthigunti
Attached the full demo project demo.zip
Comment From: sdeleuze
What happens is that request processors (created with ExchangeFilterFunction#ofRequestProcessor
) are applied in the order they are defined and response processors (created with ExchangeFilterFunction#ofResponseProcessor
) in the reverse order, I think by design and as expected.