use of org.springframework.web.reactive.function.client.ClientRequest in project spring-security by spring-projects.
the class ServletBearerExchangeFilterFunctionTests method filterWhenAuthenticatedWithOtherTokenThenAuthorizationHeaderNull.
// gh-7353
@Test
public void filterWhenAuthenticatedWithOtherTokenThenAuthorizationHeaderNull() {
TestingAuthenticationToken token = new TestingAuthenticationToken("user", "pass");
ClientRequest request = ClientRequest.create(HttpMethod.GET, URI.create("https://example.com")).build();
this.function.filter(request, this.exchange).subscriberContext(context(token)).block();
assertThat(this.exchange.getRequest().headers().getFirst(HttpHeaders.AUTHORIZATION)).isNull();
}
use of org.springframework.web.reactive.function.client.ClientRequest in project spring-security by spring-projects.
the class ServletBearerExchangeFilterFunctionTests method filterWhenAuthenticatedThenAuthorizationHeader.
@Test
public void filterWhenAuthenticatedThenAuthorizationHeader() {
ClientRequest request = ClientRequest.create(HttpMethod.GET, URI.create("https://example.com")).build();
this.function.filter(request, this.exchange).subscriberContext(context(this.authentication)).block();
assertThat(this.exchange.getRequest().headers().getFirst(HttpHeaders.AUTHORIZATION)).isEqualTo("Bearer " + this.accessToken.getTokenValue());
}
use of org.springframework.web.reactive.function.client.ClientRequest in project spring-boot by spring-projects.
the class MetricsWebClientFilterFunction method instrumentResponse.
private Mono<ClientResponse> instrumentResponse(ClientRequest request, Mono<ClientResponse> responseMono) {
final AtomicBoolean responseReceived = new AtomicBoolean();
return Mono.deferContextual((ctx) -> responseMono.doOnEach((signal) -> {
if (signal.isOnNext() || signal.isOnError()) {
responseReceived.set(true);
Iterable<Tag> tags = this.tagProvider.tags(request, signal.get(), signal.getThrowable());
recordTimer(tags, getStartTime(ctx));
}
}).doFinally((signalType) -> {
if (!responseReceived.get() && SignalType.CANCEL.equals(signalType)) {
Iterable<Tag> tags = this.tagProvider.tags(request, null, null);
recordTimer(tags, getStartTime(ctx));
}
}));
}
use of org.springframework.web.reactive.function.client.ClientRequest in project spring-boot by spring-projects.
the class MetricsWebClientFilterFunctionTests method filterWhenIoExceptionThrownShouldRecordTimer.
@Test
void filterWhenIoExceptionThrownShouldRecordTimer() {
ClientRequest request = ClientRequest.create(HttpMethod.GET, URI.create("https://example.com/projects/spring-boot")).build();
ExchangeFunction errorExchange = (r) -> Mono.error(new IOException());
this.filterFunction.filter(request, errorExchange).onErrorResume(IOException.class, (t) -> Mono.empty()).block(Duration.ofSeconds(5));
assertThat(this.registry.get("http.client.requests").tags("method", "GET", "uri", "/projects/spring-boot", "status", "IO_ERROR").timer().count()).isEqualTo(1);
}
use of org.springframework.web.reactive.function.client.ClientRequest in project spring-boot by spring-projects.
the class MetricsWebClientFilterFunctionTests method filterWhenExceptionThrownShouldRecordTimer.
@Test
void filterWhenExceptionThrownShouldRecordTimer() {
ClientRequest request = ClientRequest.create(HttpMethod.GET, URI.create("https://example.com/projects/spring-boot")).build();
ExchangeFunction exchange = (r) -> Mono.error(new IllegalArgumentException());
this.filterFunction.filter(request, exchange).onErrorResume(IllegalArgumentException.class, (t) -> Mono.empty()).block(Duration.ofSeconds(5));
assertThat(this.registry.get("http.client.requests").tags("method", "GET", "uri", "/projects/spring-boot", "status", "CLIENT_ERROR").timer().count()).isEqualTo(1);
}
Aggregations