diff --git a/spring-web/src/main/java/org/springframework/http/client/reactive/ReactorClientHttpResponse.java b/spring-web/src/main/java/org/springframework/http/client/reactive/ReactorClientHttpResponse.java index ff8354bca0..1dc275d666 100644 --- a/spring-web/src/main/java/org/springframework/http/client/reactive/ReactorClientHttpResponse.java +++ b/spring-web/src/main/java/org/springframework/http/client/reactive/ReactorClientHttpResponse.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2021 the original author or authors. + * Copyright 2002-2022 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -26,6 +26,7 @@ import io.netty.handler.codec.http.cookie.DefaultCookie; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import reactor.core.publisher.Flux; +import reactor.netty.ChannelOperationsId; import reactor.netty.Connection; import reactor.netty.NettyInbound; import reactor.netty.http.client.HttpClientResponse; @@ -37,7 +38,6 @@ import org.springframework.http.HttpMethod; import org.springframework.http.HttpStatusCode; import org.springframework.http.ResponseCookie; import org.springframework.lang.Nullable; -import org.springframework.util.ClassUtils; import org.springframework.util.CollectionUtils; import org.springframework.util.LinkedMultiValueMap; import org.springframework.util.MultiValueMap; @@ -53,11 +53,6 @@ import org.springframework.util.ObjectUtils; */ class ReactorClientHttpResponse implements ClientHttpResponse { - /** Reactor Netty 1.0.5+. */ - static final boolean reactorNettyRequestChannelOperationsIdPresent = ClassUtils.isPresent( - "reactor.netty.ChannelOperationsId", ReactorClientHttpResponse.class.getClassLoader()); - - private static final Log logger = LogFactory.getLog(ReactorClientHttpResponse.class); private final HttpClientResponse response; @@ -102,8 +97,8 @@ class ReactorClientHttpResponse implements ClientHttpResponse { @Override public String getId() { String id = null; - if (reactorNettyRequestChannelOperationsIdPresent) { - id = ChannelOperationsIdHelper.getId(this.response); + if (this.response instanceof ChannelOperationsId operationsId) { + id = (logger.isDebugEnabled() ? operationsId.asLongText() : operationsId.asShortText()); } if (id == null && this.response instanceof Connection connection) { id = connection.channel().id().asShortText(); @@ -201,16 +196,4 @@ class ReactorClientHttpResponse implements ClientHttpResponse { "status=" + getRawStatusCode() + '}'; } - - private static class ChannelOperationsIdHelper { - - @Nullable - public static String getId(HttpClientResponse response) { - if (response instanceof reactor.netty.ChannelOperationsId id) { - return (logger.isDebugEnabled() ? id.asLongText() : id.asShortText()); - } - return null; - } - } - } diff --git a/spring-web/src/main/java/org/springframework/http/client/reactive/ReactorNetty2ClientHttpResponse.java b/spring-web/src/main/java/org/springframework/http/client/reactive/ReactorNetty2ClientHttpResponse.java index a12d25944a..0337ffe433 100644 --- a/spring-web/src/main/java/org/springframework/http/client/reactive/ReactorNetty2ClientHttpResponse.java +++ b/spring-web/src/main/java/org/springframework/http/client/reactive/ReactorNetty2ClientHttpResponse.java @@ -25,6 +25,7 @@ import io.netty5.handler.codec.http.cookie.DefaultCookie; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import reactor.core.publisher.Flux; +import reactor.netty5.ChannelOperationsId; import reactor.netty5.Connection; import reactor.netty5.NettyInbound; import reactor.netty5.http.client.HttpClientResponse; @@ -82,7 +83,10 @@ class ReactorNetty2ClientHttpResponse implements ClientHttpResponse { @Override public String getId() { - String id = ChannelOperationsIdHelper.getId(this.response); + String id = null; + if (this.response instanceof ChannelOperationsId operationsId) { + id = (logger.isDebugEnabled() ? operationsId.asLongText() : operationsId.asShortText()); + } if (id == null && this.response instanceof Connection connection) { id = connection.channel().id().asShortText(); } @@ -176,16 +180,4 @@ class ReactorNetty2ClientHttpResponse implements ClientHttpResponse { "status=" + getRawStatusCode() + '}'; } - - private static class ChannelOperationsIdHelper { - - @Nullable - public static String getId(HttpClientResponse response) { - if (response instanceof reactor.netty5.ChannelOperationsId id) { - return (logger.isDebugEnabled() ? id.asLongText() : id.asShortText()); - } - return null; - } - } - } diff --git a/spring-web/src/main/java/org/springframework/http/server/reactive/ReactorNetty2ServerHttpRequest.java b/spring-web/src/main/java/org/springframework/http/server/reactive/ReactorNetty2ServerHttpRequest.java index 217afc598e..fcee76c668 100644 --- a/spring-web/src/main/java/org/springframework/http/server/reactive/ReactorNetty2ServerHttpRequest.java +++ b/spring-web/src/main/java/org/springframework/http/server/reactive/ReactorNetty2ServerHttpRequest.java @@ -29,6 +29,7 @@ import io.netty5.handler.codec.http.cookie.Cookie; import io.netty5.handler.ssl.SslHandler; import org.apache.commons.logging.Log; import reactor.core.publisher.Flux; +import reactor.netty5.ChannelOperationsId; import reactor.netty5.Connection; import reactor.netty5.http.server.HttpServerRequest; @@ -208,7 +209,10 @@ class ReactorNetty2ServerHttpRequest extends AbstractServerHttpRequest { @Override protected String initLogPrefix() { - String id = (ChannelOperationsIdHelper.getId(this.request)); + String id = null; + if (this.request instanceof ChannelOperationsId operationsId) { + id = (logger.isDebugEnabled() ? operationsId.asLongText() : operationsId.asShortText()); + } if (id != null) { return id; } @@ -219,18 +223,4 @@ class ReactorNetty2ServerHttpRequest extends AbstractServerHttpRequest { return getId(); } - - private static class ChannelOperationsIdHelper { - - @Nullable - public static String getId(HttpServerRequest request) { - if (request instanceof reactor.netty.ChannelOperationsId) { - return (logger.isDebugEnabled() ? - ((reactor.netty.ChannelOperationsId) request).asLongText() : - ((reactor.netty.ChannelOperationsId) request).asShortText()); - } - return null; - } - } - } diff --git a/spring-web/src/main/java/org/springframework/http/server/reactive/ReactorNetty2ServerHttpResponse.java b/spring-web/src/main/java/org/springframework/http/server/reactive/ReactorNetty2ServerHttpResponse.java index fc75bf2aa1..332b8a6cba 100644 --- a/spring-web/src/main/java/org/springframework/http/server/reactive/ReactorNetty2ServerHttpResponse.java +++ b/spring-web/src/main/java/org/springframework/http/server/reactive/ReactorNetty2ServerHttpResponse.java @@ -128,28 +128,16 @@ class ReactorNetty2ServerHttpResponse extends AbstractServerHttpResponse impleme @Override protected void touchDataBuffer(DataBuffer buffer) { if (logger.isDebugEnabled()) { - if (ChannelOperationsIdHelper.touch(buffer, this.response)) { - return; + if (this.response instanceof ChannelOperationsId operationsId) { + DataBufferUtils.touch(buffer, "Channel id: " + operationsId.asLongText()); + } + else { + this.response.withConnection(connection -> { + ChannelId id = connection.channel().id(); + DataBufferUtils.touch(buffer, "Channel id: " + id.asShortText()); + }); } - this.response.withConnection(connection -> { - ChannelId id = connection.channel().id(); - DataBufferUtils.touch(buffer, "Channel id: " + id.asShortText()); - }); } } - - private static class ChannelOperationsIdHelper { - - public static boolean touch(DataBuffer dataBuffer, HttpServerResponse response) { - if (response instanceof ChannelOperationsId) { - String id = ((ChannelOperationsId) response).asLongText(); - DataBufferUtils.touch(dataBuffer, "Channel id: " + id); - return true; - } - return false; - } - } - - } diff --git a/spring-web/src/main/java/org/springframework/http/server/reactive/ReactorServerHttpRequest.java b/spring-web/src/main/java/org/springframework/http/server/reactive/ReactorServerHttpRequest.java index e9bd40958b..0dcbd3ed56 100644 --- a/spring-web/src/main/java/org/springframework/http/server/reactive/ReactorServerHttpRequest.java +++ b/spring-web/src/main/java/org/springframework/http/server/reactive/ReactorServerHttpRequest.java @@ -29,6 +29,7 @@ import io.netty.handler.codec.http.cookie.Cookie; import io.netty.handler.ssl.SslHandler; import org.apache.commons.logging.Log; import reactor.core.publisher.Flux; +import reactor.netty.ChannelOperationsId; import reactor.netty.Connection; import reactor.netty.http.server.HttpServerRequest; @@ -207,7 +208,10 @@ class ReactorServerHttpRequest extends AbstractServerHttpRequest { @Override protected String initLogPrefix() { - String id = (ChannelOperationsIdHelper.getId(this.request)); + String id = null; + if (this.request instanceof ChannelOperationsId operationsId) { + id = (logger.isDebugEnabled() ? operationsId.asLongText() : operationsId.asShortText()); + } if (id != null) { return id; } @@ -218,18 +222,4 @@ class ReactorServerHttpRequest extends AbstractServerHttpRequest { return getId(); } - - private static class ChannelOperationsIdHelper { - - @Nullable - public static String getId(HttpServerRequest request) { - if (request instanceof reactor.netty.ChannelOperationsId) { - return (logger.isDebugEnabled() ? - ((reactor.netty.ChannelOperationsId) request).asLongText() : - ((reactor.netty.ChannelOperationsId) request).asShortText()); - } - return null; - } - } - } diff --git a/spring-web/src/main/java/org/springframework/http/server/reactive/ReactorServerHttpResponse.java b/spring-web/src/main/java/org/springframework/http/server/reactive/ReactorServerHttpResponse.java index c688a20338..2449b72cf6 100644 --- a/spring-web/src/main/java/org/springframework/http/server/reactive/ReactorServerHttpResponse.java +++ b/spring-web/src/main/java/org/springframework/http/server/reactive/ReactorServerHttpResponse.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2021 the original author or authors. + * Copyright 2002-2022 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -127,28 +127,16 @@ class ReactorServerHttpResponse extends AbstractServerHttpResponse implements Ze @Override protected void touchDataBuffer(DataBuffer buffer) { if (logger.isDebugEnabled()) { - if (ChannelOperationsIdHelper.touch(buffer, this.response)) { - return; + if (this.response instanceof ChannelOperationsId operationsId) { + DataBufferUtils.touch(buffer, "Channel id: " + operationsId.asLongText()); + } + else { + this.response.withConnection(connection -> { + ChannelId id = connection.channel().id(); + DataBufferUtils.touch(buffer, "Channel id: " + id.asShortText()); + }); } - this.response.withConnection(connection -> { - ChannelId id = connection.channel().id(); - DataBufferUtils.touch(buffer, "Channel id: " + id.asShortText()); - }); } } - - private static class ChannelOperationsIdHelper { - - public static boolean touch(DataBuffer dataBuffer, HttpServerResponse response) { - if (response instanceof reactor.netty.ChannelOperationsId) { - String id = ((ChannelOperationsId) response).asLongText(); - DataBufferUtils.touch(dataBuffer, "Channel id: " + id); - return true; - } - return false; - } - } - - }