JAVA-4338: Upgrade spring-5-reactive-client module (#10486)
* JAVA-4338: Upgrade spring-5-reactive-client module * JAVA-4338: removed duplicate entry
This commit is contained in:
parent
2838922e1b
commit
8ad0682993
@ -8,7 +8,6 @@ The "REST With Spring" Classes: http://bit.ly/restwithspring
|
||||
### Relevant Articles
|
||||
- [Logging Spring WebClient Calls](https://www.baeldung.com/spring-log-webclient-calls)
|
||||
- [Simultaneous Spring WebClient Calls](https://www.baeldung.com/spring-webclient-simultaneous-calls)
|
||||
- [Logging Spring WebClient Calls](https://www.baeldung.com/spring-log-webclient-calls)
|
||||
- [Mocking a WebClient in Spring](https://www.baeldung.com/spring-mocking-webclient)
|
||||
- [Spring WebClient Filters](https://www.baeldung.com/spring-webclient-filters)
|
||||
- [Get List of JSON Objects with WebClient](https://www.baeldung.com/spring-webclient-json-list)
|
||||
|
@ -176,7 +176,6 @@
|
||||
<commons-collections4.version>4.1</commons-collections4.version>
|
||||
<jetty-reactive-httpclient.version>1.0.3</jetty-reactive-httpclient.version>
|
||||
<okhttp.version>4.0.1</okhttp.version>
|
||||
<spring-boot.version>2.3.3.RELEASE</spring-boot.version>
|
||||
</properties>
|
||||
|
||||
</project>
|
||||
|
@ -1,3 +1,5 @@
|
||||
logging.level.root=INFO
|
||||
|
||||
server.port=8081
|
||||
server.port=8081
|
||||
|
||||
logging.level.reactor.netty.http.client.HttpClient=DEBUG
|
@ -1,13 +1,13 @@
|
||||
package com.baeldung.reactive.logging;
|
||||
|
||||
import ch.qos.logback.classic.spi.LoggingEvent;
|
||||
import ch.qos.logback.core.Appender;
|
||||
import com.baeldung.reactive.logging.filters.LogFilters;
|
||||
import com.baeldung.reactive.logging.netty.CustomLogger;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import static com.baeldung.reactive.logging.jetty.RequestLogEnhancer.enhance;
|
||||
import static org.mockito.ArgumentMatchers.argThat;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import java.net.URI;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
|
||||
import org.eclipse.jetty.client.api.Request;
|
||||
import org.eclipse.jetty.util.ssl.SslContextFactory;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
@ -17,14 +17,17 @@ import org.springframework.http.client.reactive.JettyClientHttpConnector;
|
||||
import org.springframework.http.client.reactive.ReactorClientHttpConnector;
|
||||
import org.springframework.web.reactive.function.BodyInserters;
|
||||
import org.springframework.web.reactive.function.client.WebClient;
|
||||
import reactor.netty.channel.BootstrapHandlers;
|
||||
import reactor.netty.http.client.HttpClient;
|
||||
|
||||
import static com.baeldung.reactive.logging.jetty.RequestLogEnhancer.enhance;
|
||||
import static org.mockito.ArgumentMatchers.argThat;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
import com.baeldung.reactive.logging.filters.LogFilters;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
|
||||
import ch.qos.logback.classic.spi.LoggingEvent;
|
||||
import ch.qos.logback.core.Appender;
|
||||
import io.netty.handler.logging.LogLevel;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import reactor.netty.http.client.HttpClient;
|
||||
import reactor.netty.transport.logging.AdvancedByteBufFormat;
|
||||
|
||||
|
||||
public class WebClientLoggingIntegrationTest {
|
||||
@ -114,21 +117,17 @@ public class WebClientLoggingIntegrationTest {
|
||||
|
||||
@Test
|
||||
public void givenNettyHttpClientWithCustomLogger_whenEndpointIsConsumed_thenRequestAndResponseBodyLogged() {
|
||||
reactor.netty.http.client.HttpClient httpClient = HttpClient.create()
|
||||
.wiretap("reactor.netty.http.client.HttpClient", LogLevel.DEBUG, AdvancedByteBufFormat.TEXTUAL);
|
||||
|
||||
reactor.netty.http.client.HttpClient httpClient = HttpClient
|
||||
.create()
|
||||
.tcpConfiguration(
|
||||
tc -> tc.bootstrap(
|
||||
b -> BootstrapHandlers.updateLogSupport(b, new CustomLogger(HttpClient.class))));
|
||||
WebClient
|
||||
.builder()
|
||||
.clientConnector(new ReactorClientHttpConnector(httpClient))
|
||||
.build()
|
||||
.post()
|
||||
.uri(sampleUrl)
|
||||
.body(BodyInserters.fromObject(post))
|
||||
.exchange()
|
||||
.block();
|
||||
WebClient.builder()
|
||||
.clientConnector(new ReactorClientHttpConnector(httpClient))
|
||||
.build()
|
||||
.post()
|
||||
.uri(sampleUrl)
|
||||
.body(BodyInserters.fromObject(post))
|
||||
.exchange()
|
||||
.block();
|
||||
|
||||
verify(nettyAppender).doAppend(argThat(argument -> (((LoggingEvent) argument).getFormattedMessage()).contains(sampleResponseBody)));
|
||||
}
|
||||
|
@ -1,42 +0,0 @@
|
||||
package com.baeldung.reactive.logging.netty;
|
||||
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import io.netty.channel.ChannelHandlerContext;
|
||||
import io.netty.handler.logging.LoggingHandler;
|
||||
import java.nio.charset.Charset;
|
||||
|
||||
import static io.netty.util.internal.PlatformDependent.allocateUninitializedArray;
|
||||
import static java.lang.Math.max;
|
||||
import static java.nio.charset.Charset.defaultCharset;
|
||||
|
||||
public class CustomLogger extends LoggingHandler {
|
||||
public CustomLogger(Class<?> clazz) {
|
||||
super(clazz);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String format(ChannelHandlerContext ctx, String event, Object arg) {
|
||||
if (arg instanceof ByteBuf) {
|
||||
ByteBuf msg = (ByteBuf) arg;
|
||||
return decode(msg, msg.readerIndex(), msg.readableBytes(), defaultCharset());
|
||||
}
|
||||
return super.format(ctx, event, arg);
|
||||
}
|
||||
|
||||
private String decode(ByteBuf src, int readerIndex, int len, Charset charset) {
|
||||
if (len != 0) {
|
||||
byte[] array;
|
||||
int offset;
|
||||
if (src.hasArray()) {
|
||||
array = src.array();
|
||||
offset = src.arrayOffset() + readerIndex;
|
||||
} else {
|
||||
array = allocateUninitializedArray(max(len, 1024));
|
||||
offset = 0;
|
||||
src.getBytes(readerIndex, array, 0, len);
|
||||
}
|
||||
return new String(array, offset, len, charset);
|
||||
}
|
||||
return "";
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user