Skip to content

feat(http): switch default http transport to jdk & enhance jdk http transport#445

Merged
AlbumenJ merged 3 commits intoagentscope-ai:mainfrom
AlbumenJ:0105-jdk
Jan 5, 2026
Merged

feat(http): switch default http transport to jdk & enhance jdk http transport#445
AlbumenJ merged 3 commits intoagentscope-ai:mainfrom
AlbumenJ:0105-jdk

Conversation

@AlbumenJ
Copy link
Collaborator

@AlbumenJ AlbumenJ commented Jan 5, 2026

Change-Id: I502d8ecd96642f41057b1d92e4b2995cca26ed54

AgentScope-Java Version

[The version of AgentScope-Java you are working on, e.g. 1.0.5, check your pom.xml dependency version or run mvn dependency:tree | grep agentscope-parent:pom(only mac/linux)]

Description

[Please describe the background, purpose, changes made, and how to test this PR]

Checklist

Please check the following items before code is ready to be reviewed.

  • Code has been formatted with mvn spotless:apply
  • All tests are passing (mvn test)
  • Javadoc comments are complete and follow project conventions
  • Related documentation has been updated (e.g. links, examples, etc.)
  • Code is ready for review

…ransport

Change-Id: I502d8ecd96642f41057b1d92e4b2995cca26ed54
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR switches the default HTTP transport implementation from OkHttp to JDK's built-in HttpClient, eliminating external dependencies and improving maintainability. The changes include enhanced error handling for streaming responses, SSL certificate verification bypass support for testing, and improved resource management using Reactor's Flux.using pattern.

Key Changes

  • Changed default HttpTransport from OkHttpTransport to JdkHttpTransport in HttpTransportFactory
  • Added SSL certificate verification bypass capability with ignoreSsl configuration option
  • Refactored streaming error handling to read error response bodies immediately before stream closure
  • Reduced constructor visibility to package-private, encouraging use of builder pattern

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 6 comments.

File Description
agentscope-distribution/agentscope-all/pom.xml Reordered dependencies for better organization (no functional changes)
agentscope-core/src/main/java/io/agentscope/core/model/transport/HttpTransportFactory.java Updated default transport from OkHttpTransport to JdkHttpTransport with corresponding documentation
agentscope-core/src/main/java/io/agentscope/core/model/transport/JdkHttpTransport.java Added SSL bypass support, refactored streaming with better error handling, changed constructor visibility, made buildClient static
agentscope-core/src/test/java/io/agentscope/core/model/transport/JdkHttpTransportTest.java Added comprehensive tests for SSL ignore feature and streaming error body handling across different HTTP status codes

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +104 to 126
private static HttpClient buildClient(HttpTransportConfig config) {
HttpClient.Builder builder =
HttpClient.newBuilder()
.version(Version.HTTP_2)
.followRedirects(Redirect.NORMAL)
.connectTimeout(config.getConnectTimeout());

if (config.isIgnoreSsl()) {
try {
SSLContext sslContext = SSLContext.getInstance("TLS");
sslContext.init(
null, new TrustManager[] {new TrustAllManager()}, new SecureRandom());
builder.sslContext(sslContext);
log.warn(
"SSL certificate verification is disabled. "
+ "This should only be used for testing.");
} catch (NoSuchAlgorithmException | KeyManagementException e) {
throw new HttpTransportException("Failed to create insecure SSL context", e);
}
}

return builder.build();
}
Copy link

Copilot AI Jan 5, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The buildClient method has been changed from instance method to static method. While this is generally a good practice since the method doesn't use instance state, ensure this doesn't break any potential mocking or testing scenarios that relied on the instance method behavior. The change appears safe since the method only depends on the config parameter.

Copilot uses AI. Check for mistakes.
Comment on lines +164 to +178
String errorBody = readInputStream(response.body());
log.warn(
"HTTP request failed. URL: {} | Status: {} | Error:"
+ " {}",
request.getUrl(),
statusCode,
errorBody);
throw new CompletionException(
new HttpTransportException(
"HTTP request failed with status "
+ statusCode
+ " | "
+ errorBody,
statusCode,
errorBody));
Copy link

Copilot AI Jan 5, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the stream error handling, when an IOException occurs while reading the error body in readInputStream (line 323), the method catches the exception and returns null. This means if the error body cannot be read, the HttpTransportException will contain null as the error body. Consider whether it would be better to include a placeholder message like "(error body could not be read)" or rethrow the exception to properly surface the I/O error.

Copilot uses AI. Check for mistakes.
Comment on lines +399 to +414
private static class TrustAllManager implements X509TrustManager {
@Override
public void checkClientTrusted(X509Certificate[] chain, String authType) {
// Trust all client certificates
}

@Override
public void checkServerTrusted(X509Certificate[] chain, String authType) {
// Trust all server certificates
}

@Override
public X509Certificate[] getAcceptedIssuers() {
return new X509Certificate[0];
}
}
Copy link

Copilot AI Jan 5, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The TrustAllManager implementation disables SSL certificate verification. While the Javadoc includes a warning, this is a significant security risk. Consider adding a runtime warning log when this is used, and ensure that the documentation clearly explains when this should be used (e.g., only in development/testing environments with trusted self-signed certificates). The warning log on line 117-119 is good, but it would be helpful to also include the URL being accessed in the log message for debugging purposes.

Copilot uses AI. Check for mistakes.
synchronized (lock) {
if (defaultTransport == null) {
defaultTransport = new OkHttpTransport();
defaultTransport = new JdkHttpTransport();
Copy link

Copilot AI Jan 5, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Potential race condition. This assignment to defaultTransport is visible to other threads before the subsequent statements are executed.

Copilot uses AI. Check for mistakes.
…ransport

Change-Id: I16c5458efee05d411be87179804fcfe1f0b9b0e0
…ransport

Change-Id: I62798a7bda442da1bca704e312e4a3baba98de00
@codecov
Copy link

codecov bot commented Jan 5, 2026

Codecov Report

❌ Patch coverage is 78.84615% with 11 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
...ntscope/core/model/transport/JdkHttpTransport.java 78.43% 7 Missing and 4 partials ⚠️

📢 Thoughts on this report? Let us know!

@AlbumenJ AlbumenJ merged commit 746254d into agentscope-ai:main Jan 5, 2026
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants