Clean up conditional use of ChannelOperationsId
Closes gh-29224
This commit is contained in:
parent
e81d30160c
commit
5d2c9d946a
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue