httpClient#doOnConnected invalid
- Dominant language
- Java
- Stars
- 8.8k
- Forks
- 3.1k
- Avg merge
- 7d 1h
- Merged PRs (30d)
- 85
Description
### Is there an existing issue for this?
- [X] I have searched the existing issues
### Current Behavior
@Override
protected HttpClient createInstance() {
// configure pool resources.
HttpClientProperties.Pool pool = properties.getPool();
ConnectionProvider connectionProvider = buildConnectionProvider(pool);
HttpClient httpClient = HttpClient.create(connectionProvider)
.option(ChannelOption.CONNECT_TIMEOUT_MILLIS, properties.getConnectTimeout());
if (serverProperties.getHttp2().isEnabled()) {
httpClient = httpClient.protocol(HttpProtocol.HTTP11, HttpProtocol.H2);
}
HttpClientProperties.Proxy proxy = properties.getProxy();
if (StringUtils.isNotEmpty(proxy.getHost())) {
httpClient = setHttpClientProxy(httpClient, proxy);
}
httpClient.doOnConnected(connection -> {
connection.addHandlerLast(new IdleStateHandler(properties.getReaderIdleTime(), properties.getWriterIdleTime(), properties.getAllIdleTime(), TimeUnit.MILLISECONDS));
connection.addHandlerLast(new WriteTimeoutHandler(properties.getWriteTimeout(), TimeUnit.MILLISECONDS));
connection.addHandlerLast(new ReadTimeoutHandler(properties.getReadTimeout(), TimeUnit.MILLISECONDS));
});
if (Objects.nonNull(loopResources)) {
httpClient.runOn(loopResources);
}
HttpClientProperties.Ssl ssl = properties.getSsl();
if (StringUtils.isNotEmpty(ssl.getKeyStorePath())
|| ArrayUtils.isNotEmpty(ssl.getTrustedX509CertificatesForTrustManager())
|| ssl.isUseInsecureTrustManager()) {
httpClient = httpClient.secure(sslContextSpec -> setSsl(sslContextSpec, ssl));
}
if (properties.isWiretap()) {
httpClient = httpClient.wiretap(true);
}
// set to false, fix java.io.IOException: Connection reset by peer
// see https://github.com/reactor/reactor-netty/issues/388
return httpClient.keepAlive(properties.isKeepAlive());
}
### Expected Behavior
@Override
protected HttpClient createInstance() {
// configure pool resources.
HttpClientProperties.Pool pool = properties.getPool();
ConnectionProvider connectionProvider = buildConnectionProvider(pool);
HttpClient httpClient = HttpClient.create(connectionProvider)
.option(ChannelOption.CONNECT_TIMEOUT_MILLIS, properties.getConnectTimeout());
if (serverProperties.getHttp2().isEnabled()) {
httpClient = httpClient.protocol(HttpProtocol.HTTP11, HttpProtocol.H2);
}
HttpClientProperties.Proxy proxy = properties.getProxy();
if (StringUtils.isNotEmpty(proxy.getHost())) {
httpClient = setHttpClientProxy(httpClient, proxy);
}
// The httpClient needs to be reassigned
// The httpClient needs to be reassigned
// The httpClient needs to be reassigned
httpClient = httpClient.doOnConnected(connection -> {
connection.addHandlerLast(new IdleStateHandler(properties.getReaderIdleTime(), properties.getWriterIdleTime(), properties.getAllIdleTime(), TimeUnit.MILLISECONDS));
connection.addHandlerLast(new WriteTimeoutHandler(properties.getWriteTimeout(), TimeUnit.MILLISECONDS));
connection.addHandlerLast(new ReadTimeoutHandler(properties.getReadTimeout(), TimeUnit.MILLISECONDS));
});
if (Objects.nonNull(loopResources)) {
// The httpClient needs to be reassigned
// The httpClient needs to be reassigned
// The httpClient needs to be reassigned
httpClient = httpClient.runOn(loopResources);
}
HttpClientProperties.Ssl ssl = properties.getSsl();
if (StringUtils.isNotEmpty(ssl.getKeyStorePath())
|| ArrayUtils.isNotEmpty(ssl.getTrustedX509CertificatesForTrustManager())
|| ssl.isUseInsecureTrustManager()) {
httpClient = httpClient.secure(sslContextSpec -> setSsl(sslContextSpec, ssl));
}
if (properties.isWiretap()) {
httpClient = httpClient.wiretap(true);
}
// set to false, fix java.io.IOException: Connection reset by peer
// see https://github.com/reactor/reactor-netty/issues/388
return httpClient.keepAlive(properties.isKeepAlive());
}
### Steps To Reproduce
no
### Environment
```markdown
ShenYu version(s):2.6.1
```
### Debug logs
no
### Anything else?
no
Contributor guide
No contributing guide indexed for this repository
Research direction
Start at the HttpClient createInstance entry point shown in the issue and locate its implementation in ShenYu. Compare the fluent configuration calls with the expected behavior, especially doOnConnected and runOn. Done means the configured client retains those changes and the relevant HTTP client behavior is verified.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java
- Domain
- api, backend
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100