Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Dec 24, 2025

升级到 Apache HttpClient 5.x 作为默认 HTTP 客户端

Apache HttpClient 4.x 已进入维护模式。项目已有完整的 HttpClient 5.x 实现(hc/ 目录),但配置为 provided scope。本 PR 将 HttpClient 5.x 设为默认,同时保持 4.x 兼容。

依赖变更

  • 添加 httpclient5.version=5.5 属性
  • httpclient5provided 改为默认依赖
  • 保留 httpclient 4.5.13 作为默认依赖(向后兼容)
  • 两个版本共存,通过配置选择

默认配置

对已有 *HttpComponentsImpl 实现的模块,将默认 HTTP 客户端改为 HttpComponents (5.x):

  • ✅ weixin-java-mp, channel, qidian, pay, open → 默认 HttpComponents
  • ⚠️ weixin-java-miniapp → 保持 HttpClient (4.x),暂无 5.x 实现
  • ℹ️ weixin-java-cp → 支持情况取决于具体使用的 Starter 版本

更新所有 HttpClientType 枚举添加 HttpComponents 选项。

配置示例

# Spring Boot 单体 Starter 配置
wx.mp.config-storage.http-client-type=HttpComponents  # 5.x (新默认)
wx.mp.config-storage.http-client-type=HttpClient      # 4.x (兼容)

# Spring Boot Multi-Starter 配置(注意使用大写下划线格式)
wx.mp.config-storage.http-client-type=HTTP_COMPONENTS  # 5.x
wx.mp.config-storage.http-client-type=HTTP_CLIENT      # 4.x
// 纯 Java 配置
WxMpService service = new WxMpServiceHttpComponentsImpl();  // 5.x
WxMpService service = new WxMpServiceHttpClientImpl();      // 4.x

文档

  • README.md: HTTP 客户端支持说明和配置表格,包含 Multi-Starter 配置注意事项
  • docs/HTTPCLIENT_UPGRADE_GUIDE.md: 详细迁移指南,使用通用版本号描述
  • Spring Boot Starter README: 更新配置示例

兼容性

  • 现有项目无需修改代码
  • HttpClient 4.x 代码和依赖保持不变
  • 用户可通过配置自由切换客户端类型

代码审查反馈已处理

  • ✅ 修复文档中的版本号引用问题,使用通用版本描述
  • ✅ 更正 CP 模块支持说明,明确其支持情况取决于具体 Starter 版本
  • ✅ 添加 Multi-Starter 枚举命名格式说明(HTTP_COMPONENTS vs HttpComponents)
  • ✅ 统一所有枚举类型的注释风格,使用简洁格式
Original prompt

This section details on the original issue you should resolve

<issue_title>请问什么时候升级Httpclient,或者换成其他库,现在Httpclient4.x已经改成Httpclient5.x了</issue_title>
<issue_description>请问什么时候升级Httpclient,或者换成其他库,现在Httpclient4.x已经改成Httpclient5.x了
</issue_description>

Comments on the Issue (you are @copilot in this section)

@binarywang 这可能是个大工程,欢迎提供PR代码来实现

Custom agent used: 全部用中文
需要用中文,包括PR标题和分析总结过程


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Copilot AI changed the title [WIP] Upgrade HttpClient from version 4.x to 5.x 升级到 Apache HttpClient 5.x 作为默认 HTTP 客户端 Dec 24, 2025
Copilot AI requested a review from binarywang December 24, 2025 08:39
@binarywang binarywang marked this pull request as ready for review December 26, 2025 06:33
Copilot AI review requested due to automatic review settings December 26, 2025 06:33
Copy link

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

本 PR 旨在将 WxJava 项目的默认 HTTP 客户端从 Apache HttpClient 4.x 升级到 5.x,同时保持向后兼容性。这是为了应对 HttpClient 4.x 进入维护模式的情况,并为用户提供更现代、性能更好的 HTTP 客户端选项。

主要变更

  • 依赖升级:将 httpclient5provided scope 改为默认依赖,添加 httpclient5.version=5.5 属性,同时保留 HttpClient 4.x 依赖以确保向后兼容
  • 默认配置更新:在 MP、CP、Channel、QiDian 等模块的 Spring Boot 和 Solon 配置中,将默认 HTTP 客户端从 HttpClient(4.x)改为 HttpComponents(5.x)
  • API 扩展:在所有支持的模块中为 HttpClientType 枚举添加 HttpComponents 选项,支持用户通过配置切换 HTTP 客户端类型

Reviewed changes

Copilot reviewed 19 out of 19 changed files in this pull request and generated 16 comments.

Show a summary per file
File Description
pom.xml 添加 httpclient5.version 属性,将 httpclient5 从 provided 改为默认依赖,保留 httpclient 4.x 依赖
weixin-java-common/pom.xml 移除 httpclient5 的 provided scope,调整依赖声明顺序
spring-boot-starters/wx-java-mp-spring-boot-starter/src/main/java/com/binarywang/spring/starter/wxjava/mp/properties/WxMpProperties.java 将 MP 模块默认 HTTP 客户端改为 HttpComponents
spring-boot-starters/wx-java-mp-spring-boot-starter/README.md 更新配置示例,说明 HttpComponents 为推荐选项
spring-boot-starters/wx-java-qidian-spring-boot-starter/src/main/java/com/binarywang/spring/starter/wxjava/qidian/properties/WxQidianProperties.java 将 QiDian 模块默认 HTTP 客户端改为 HttpComponents
spring-boot-starters/wx-java-qidian-spring-boot-starter/src/main/java/com/binarywang/spring/starter/wxjava/qidian/enums/HttpClientType.java 为 QiDian 模块添加 HttpComponents 枚举值
spring-boot-starters/wx-java-channel-spring-boot-starter/src/main/java/com/binarywang/spring/starter/wxjava/channel/properties/WxChannelProperties.java 将 Channel 模块默认 HTTP 客户端改为 HttpComponents
spring-boot-starters/wx-java-channel-spring-boot-starter/src/main/java/com/binarywang/spring/starter/wxjava/channel/enums/HttpClientType.java 为 Channel 模块添加 HttpComponents 枚举值,更新注释
spring-boot-starters/wx-java-channel-multi-spring-boot-starter/src/main/java/com/binarywang/spring/starter/wxjava/channel/enums/HttpClientType.java 为 Channel Multi 模块添加 HttpComponents 枚举值
spring-boot-starters/wx-java-miniapp-spring-boot-starter/src/main/java/com/binarywang/spring/starter/wxjava/miniapp/enums/HttpClientType.java 为 MiniApp 模块添加 HttpComponents 枚举值(但未改变默认配置)
solon-plugins/wx-java-mp-solon-plugin/src/main/java/com/binarywang/solon/wxjava/mp/properties/WxMpProperties.java 将 Solon MP 插件默认 HTTP 客户端改为 HttpComponents
solon-plugins/wx-java-mp-solon-plugin/src/main/java/com/binarywang/solon/wxjava/mp/enums/HttpClientType.java 为 Solon MP 插件添加 HttpComponents 枚举值
solon-plugins/wx-java-qidian-solon-plugin/src/main/java/com/binarywang/solon/wxjava/qidian/properties/WxQidianProperties.java 将 Solon QiDian 插件默认 HTTP 客户端改为 HttpComponents
solon-plugins/wx-java-qidian-solon-plugin/src/main/java/com/binarywang/solon/wxjava/qidian/enums/HttpClientType.java 为 Solon QiDian 插件添加 HttpComponents 枚举值
solon-plugins/wx-java-channel-solon-plugin/src/main/java/com/binarywang/solon/wxjava/channel/properties/WxChannelProperties.java 将 Solon Channel 插件默认 HTTP 客户端改为 HttpComponents
solon-plugins/wx-java-channel-solon-plugin/src/main/java/com/binarywang/solon/wxjava/channel/enums/HttpClientType.java 为 Solon Channel 插件添加 HttpComponents 枚举值
solon-plugins/wx-java-miniapp-solon-plugin/src/main/java/com/binarywang/solon/wxjava/miniapp/enums/HttpClientType.java 为 Solon MiniApp 插件添加 HttpComponents 枚举值
README.md 添加 HTTP 客户端支持说明章节,包括支持的客户端类型、配置方式和注意事项
docs/HTTPCLIENT_UPGRADE_GUIDE.md 新增详细的 HttpClient 升级迁移指南,包括升级原因、影响、迁移步骤和常见问题

Comment on lines 58 to 59
<version>4.7.9.B</version> <!-- 或更高版本 -->
</dependency>
Copy link

Copilot AI Dec 26, 2025

Choose a reason for hiding this comment

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

迁移指南中的版本号示例使用了 4.7.9.B,但 README.md 文档开头显示当前最新正式版本是 4.7.0

建议:

  1. 如果 4.7.9.B 是计划发布的版本号,应该在文档中明确说明
  2. 或者使用占位符如 4.7.x最新版本 来避免混淆

Copilot uses AI. Check for mistakes.
Copy link
Contributor Author

Choose a reason for hiding this comment

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

已修复。将文档中的版本号 4.7.9.B 替换为通用描述(如 4.7.x最新版本),避免版本号硬编码导致的维护问题。提交: 154da92

* http客户端类型.
*/
private HttpClientType httpClientType = HttpClientType.HttpClient;
private HttpClientType httpClientType = HttpClientType.HttpComponents;
Copy link

Copilot AI Dec 26, 2025

Choose a reason for hiding this comment

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

枚举命名不一致。在 wx-java-mp-spring-boot-starter 中,新增的枚举值使用 HttpComponents(PascalCase),而在其他单体 starter 如 QiDian 中也使用相同的命名。但这与该模块中 HttpClientOkHttpJoddHttp 的命名风格一致。

然而,在 multi-spring-boot-starter 模块中(如 WxMpMultiProperties),枚举值使用 HTTP_COMPONENTS(UPPER_SNAKE_CASE)。

问题:同一模块家族(MP)在不同 starter 中使用了不同的枚举命名约定,这会导致配置困惑。

建议确保同一模块在单体和 multi starter 中使用一致的枚举命名风格。

Copilot uses AI. Check for mistakes.
Copy link
Contributor Author

Choose a reason for hiding this comment

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

已在 README 中添加说明。Multi-Starter 使用 HTTP_COMPONENTS(大写下划线格式),单体 Starter 使用 HttpComponents(PascalCase)。枚举命名风格保持现状以维持向后兼容性,但通过文档明确说明了使用方式。提交: 154da92

*/
JoddHttp,
/**
* HttpComponents (Apache HttpClient 5.x).
Copy link

Copilot AI Dec 26, 2025

Choose a reason for hiding this comment

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

Solon MP 插件中的注释风格与其他模块类似,存在注释详细程度不一致的问题。建议统一所有枚举值的注释风格。

Suggested change
* HttpComponents (Apache HttpClient 5.x).
* HttpComponents.

Copilot uses AI. Check for mistakes.
Copy link
Contributor Author

Choose a reason for hiding this comment

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

已统一。所有枚举类型现在使用简洁的注释风格(如 HttpComponents.),与现有枚举值保持一致。提交: 154da92

Comment on lines +135 to +147
```properties
# 使用 HttpClient 5.x(推荐,MP/CP/Channel/QiDian 模块默认)
wx.mp.config-storage.http-client-type=HttpComponents

# 使用 HttpClient 4.x(兼容模式,MiniApp 模块默认)
wx.mp.config-storage.http-client-type=HttpClient

# 使用 OkHttp
wx.mp.config-storage.http-client-type=OkHttp

# 使用 Jodd-http
wx.mp.config-storage.http-client-type=JoddHttp
```
Copy link

Copilot AI Dec 26, 2025

Choose a reason for hiding this comment

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

README 配置示例中使用了 HttpComponents(PascalCase),这与部分模块的枚举命名一致,但与 multi-spring-boot-starter 模块中的 HTTP_COMPONENTS(UPPER_SNAKE_CASE)命名不一致。

这可能会让用户在配置 multi-starter 时感到困惑,因为文档示例使用的是单体 starter 的命名风格。

建议在文档中明确说明:

  1. 单体 starter 使用 HttpComponents
  2. Multi-starter 使用 HTTP_COMPONENTS
    或者统一两种 starter 的枚举命名风格。

Copilot uses AI. Check for mistakes.
Copy link
Contributor Author

Choose a reason for hiding this comment

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

已在 README 中添加专门说明。明确指出单体 Starter 使用 HttpComponents,Multi-Starter 使用 HTTP_COMPONENTS,避免用户配置时的困惑。提交: 154da92

README.md Outdated
Comment on lines 151 to 152
2. **MP、CP、Channel、QiDian 模块**已支持 HttpClient 5.x,默认推荐使用
3. 如需使用 OkHttp 或 Jodd-http,需在项目中添加对应的依赖(scope为provided)
Copy link

Copilot AI Dec 26, 2025

Choose a reason for hiding this comment

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

文档中描述「MP、CP、Channel、QiDian 模块已支持 HttpClient 5.x」,但实际上 PR 中没有修改 CP(企业微信)单体 starter 模块的 WxCpProperties

检查发现 wx-java-cp-spring-boot-starter 模块的 WxCpProperties 类中没有 httpClientType 字段和 HttpClientType 枚举的定义(与其他模块如 MP、QiDian 不同)。这意味着该模块可能尚未完整支持多种 HTTP 客户端类型的配置切换。

建议验证 CP 模块是否真正支持 HttpClient 5.x 配置,如果不支持,应从文档描述中移除。

Copilot uses AI. Check for mistakes.
Copy link
Contributor Author

Choose a reason for hiding this comment

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

已更正。将文档中的描述修改为 "CP 模块的支持情况取决于具体使用的 Starter 版本,请参考对应模块文档",更准确地反映了实际支持情况。提交: 154da92

Comment on lines 9 to 16
/**
* HttpClient
* HttpClient (Apache HttpClient 4.x)
*/
HttpClient
HttpClient,
/**
* HttpComponents (Apache HttpClient 5.x)
*/
HttpComponents,
Copy link

Copilot AI Dec 26, 2025

Choose a reason for hiding this comment

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

Channel Solon 插件的注释风格与 Spring Boot starter 一致,存在同样的问题。建议统一所有枚举值的注释详细程度。

Copilot uses AI. Check for mistakes.
Copy link
Contributor Author

Choose a reason for hiding this comment

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

已统一。所有 Channel 相关插件的枚举注释现在使用简洁一致的风格。提交: 154da92

binarywang and others added 4 commits December 27, 2025 16:40
Co-authored-by: Copilot <[email protected]>
…in/java/com/binarywang/spring/starter/wxjava/qidian/enums/HttpClientType.java

Co-authored-by: Copilot <[email protected]>
@binarywang
Copy link
Owner

@copilot apply changes based on the comments in this thread

- 修复文档中的版本号引用,使用通用版本描述
- 更正 CP 模块支持说明,明确其支持情况取决于具体 Starter 版本
- 添加 Multi-Starter 枚举命名格式说明
- 统一所有枚举类型的注释风格,使用简洁格式

Co-authored-by: binarywang <[email protected]>
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.

请问什么时候升级Httpclient,或者换成其他库,现在Httpclient4.x已经改成Httpclient5.x了

2 participants