Skip to content

DefaultWebClient logs URI without the port number #30519

@zvae

Description

@zvae

Affects: 6.0.9
Call the interface of ResourceService, and the interface response status is 500,
webclient execute this method org.springframework.web.reactive.function.client.DefaultWebClient.DefaultResponseSpec#applyStatusHandlers

in DefaultResponseSpec the uri is : http://127.0.0.1:8012/fileUpload?storageType=permanent

applyStatusHandlers method will call

private static URI getUriToLog(URI uri) {
			if (StringUtils.hasText(uri.getQuery())) {
				try {
					uri = new URI(uri.getScheme(), uri.getHost(), uri.getPath(), null);
				}
				catch (URISyntaxException ex) {
					// ignore
				}
			}
			return uri;
		}

this method return uri is http://127.0.0.1/fileUpload, the code (uri = new URI(uri.getScheme(), uri.getHost(), uri.getPath(), null); )returned uri is missing the port number.

error log is :

Error has been observed at the following site(s):
	*__checkpoint ⇢ 500 INTERNAL_SERVER_ERROR from POST http://127.0.0.1/fileUpload [DefaultWebClient]

the config of webClient:

 HttpClient httpClient = HttpClient.create()
                // 配置超时时间
                .option(ChannelOption.CONNECT_TIMEOUT_MILLIS, 30000)
                .doOnConnected(conn -> conn
                        .addHandlerLast(new ReadTimeoutHandler(10))
                        .addHandlerLast(new WriteTimeoutHandler(10)));
        // 创建client
        WebClient client = WebClient.builder()
                .clientConnector(new ReactorClientHttpConnector(httpClient))
                .codecs(configurer -> configurer.defaultCodecs().maxInMemorySize(20 * 1024 * 1024))
                .baseUrl(host)
                .defaultStatusHandler(HttpStatusCode::isError, clientResponse -> {
                    System.out.println("发生异常了。。。。");
                    return Mono.error(new RuntimeException(
                            "请求异常"+ clientResponse.statusCode().value()));
                })
                .build();

      HttpServiceProxyFactory factory =  HttpServiceProxyFactory.builder(WebClientAdapter.forClient(client)).blockTimeout(Duration.ofSeconds(30)).build();
  return factory.createClient(ResourceService.class)

Metadata

Metadata

Assignees

Labels

in: webIssues in web modules (web, webmvc, webflux, websocket)type: bugA general bug

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions