Browse Source

Consistent id for ReactorServerHttpRequest

Closes gh-27885
pull/28119/head
rstoyanchev 4 years ago
parent
commit
34cb5df859
  1. 13
      spring-web/src/main/java/org/springframework/http/server/reactive/AbstractServerHttpRequest.java
  2. 20
      spring-web/src/main/java/org/springframework/http/server/reactive/ReactorServerHttpRequest.java

13
spring-web/src/main/java/org/springframework/http/server/reactive/AbstractServerHttpRequest.java

@ -1,5 +1,5 @@ @@ -1,5 +1,5 @@
/*
* Copyright 2002-2020 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.
@ -218,9 +218,18 @@ public abstract class AbstractServerHttpRequest implements ServerHttpRequest { @@ -218,9 +218,18 @@ public abstract class AbstractServerHttpRequest implements ServerHttpRequest {
*/
String getLogPrefix() {
if (this.logPrefix == null) {
this.logPrefix = "[" + getId() + "] ";
this.logPrefix = "[" + initLogPrefix() + "] ";
}
return this.logPrefix;
}
/**
* Subclasses can override this to provide the prefix to use for log messages.
* <p>By default, this is {@link #getId()}.
* @since 5.3.15
*/
protected String initLogPrefix() {
return getId();
}
}

20
spring-web/src/main/java/org/springframework/http/server/reactive/ReactorServerHttpRequest.java

@ -1,5 +1,5 @@ @@ -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.
@ -77,7 +77,7 @@ class ReactorServerHttpRequest extends AbstractServerHttpRequest { @@ -77,7 +77,7 @@ class ReactorServerHttpRequest extends AbstractServerHttpRequest {
private static URI initUri(HttpServerRequest request) throws URISyntaxException {
Assert.notNull(request, "HttpServerRequest must not be null");
return new URI(resolveBaseUrl(request).toString() + resolveRequestUri(request));
return new URI(resolveBaseUrl(request) + resolveRequestUri(request));
}
private static URI resolveBaseUrl(HttpServerRequest request) throws URISyntaxException {
@ -197,14 +197,26 @@ class ReactorServerHttpRequest extends AbstractServerHttpRequest { @@ -197,14 +197,26 @@ class ReactorServerHttpRequest extends AbstractServerHttpRequest {
@Override
@Nullable
protected String initId() {
if (this.request instanceof Connection) {
return ((Connection) this.request).channel().id().asShortText() +
"-" + logPrefixIndex.incrementAndGet();
}
return null;
}
@Override
protected String initLogPrefix() {
if (reactorNettyRequestChannelOperationsIdPresent) {
return (ChannelOperationsIdHelper.getId(this.request));
String id = (ChannelOperationsIdHelper.getId(this.request));
if (id != null) {
return id;
}
}
if (this.request instanceof Connection) {
return ((Connection) this.request).channel().id().asShortText() +
"-" + logPrefixIndex.incrementAndGet();
}
return null;
return getId();
}

Loading…
Cancel
Save