恢复默认 HTTP 客户端兼容性#4067
Conversation
There was a problem hiding this comment.
Pull request overview
该 PR 旨在恢复 WxJava 各业务模块在“非 Starter 手动集成”场景下的默认 HTTP 客户端兼容性:默认 *ServiceImpl 回退为 Apache HttpClient 4(HC4)实现路径,同时将 HttpClient5(HC5)调整为可选/显式使用时才需要的 provided 依赖,以避免默认依赖树变重及排除 HC5 后的缺类问题。
Changes:
- 将多个模块的默认
*ServiceImpl从*HttpComponentsImpl(HC5)切换为*HttpClientImpl / *ApacheHttpClientImpl(HC4)。 - 将 HC4 相关依赖(
httpclient/httpmime)在 common 与各业务模块中恢复为 compile 传递依赖;将httpclient5调整为 provided。 - 补充 miniapp / pay 的默认实现断言测试,锁定默认实现类型,防止后续回归。
Reviewed changes
Copilot reviewed 16 out of 16 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| weixin-java-common/pom.xml | 将 httpclient5 标记为 provided,并恢复 HC4 依赖为默认传递依赖,作为全局基础依赖策略调整。 |
| weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/api/impl/WxMaServiceImpl.java | miniapp 默认实现切换为 HC4 的 WxMaServiceHttpClientImpl。 |
| weixin-java-miniapp/src/test/java/cn/binarywang/wx/miniapp/api/impl/WxMaServiceImplTest.java | 新增默认 getRequestType() 断言,区分默认 HC4 与显式 HC5 实现。 |
| weixin-java-miniapp/pom.xml | miniapp:恢复 HC4 依赖为 compile 传递,并将 httpclient5 设为 provided。 |
| weixin-java-pay/src/main/java/com/github/binarywang/wxpay/service/impl/WxPayServiceImpl.java | pay 默认实现切换为 WxPayServiceApacheHttpImpl(HC4)。 |
| weixin-java-pay/src/test/java/com/github/binarywang/wxpay/service/impl/BaseWxPayServiceImplTest.java | 新增默认实现类型断言,锁定 WxPayServiceImpl 的继承实现为 HC4。 |
| weixin-java-pay/pom.xml | pay:将 httpclient5 设为 provided,并保持 HC4 为默认传递依赖。 |
| weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/impl/WxMpServiceImpl.java | mp 默认实现切换为 WxMpServiceHttpClientImpl(HC4)。 |
| weixin-java-mp/pom.xml | mp:恢复 HC4 依赖为 compile 传递,并将 httpclient5 设为 provided。 |
| weixin-java-open/src/main/java/me/chanjar/weixin/open/api/impl/WxOpenServiceImpl.java | open 默认实现切换为 WxOpenServiceApacheHttpClientImpl(HC4)。 |
| weixin-java-open/pom.xml | open:恢复 HC4(含 httpmime)为 compile 传递,并将 httpclient5 设为 provided。 |
| weixin-java-channel/src/main/java/me/chanjar/weixin/channel/api/impl/WxChannelServiceImpl.java | channel 默认实现切换为 WxChannelServiceHttpClientImpl(HC4)。 |
| weixin-java-channel/pom.xml | channel:恢复 HC4 依赖为 compile 传递,并将 httpclient5 设为 provided。 |
| weixin-java-qidian/src/main/java/me/chanjar/weixin/qidian/api/impl/WxQidianServiceImpl.java | qidian 默认实现切换为 WxQidianServiceHttpClientImpl(HC4)。 |
| weixin-java-qidian/pom.xml | qidian:恢复 HC4 依赖为 compile 传递,并将 httpclient5 设为 provided。 |
| weixin-java-cp/pom.xml | cp:恢复 HC4 依赖为 compile 传递,并将 httpclient5 设为 provided。 |
| pom.xml | 更新根 POM 中对 HC5 依赖定位的注释说明(强调显式使用时才需要)。 |
🤖 Augment PR SummarySummary: 本 PR 旨在恢复 4.8.4+ 之前的默认 HTTP 客户端兼容性,避免非 Starter 手动集成时因默认引入 HttpClient5 导致依赖树变重/排除后缺类。
*HttpComponentsImpl 或通过 Starter 配置选择。
🤖 Was this summary useful? React with 👍 or 👎 |
| @@ -45,7 +45,6 @@ | |||
| <dependency> | |||
| <groupId>org.apache.httpcomponents</groupId> | |||
| <artifactId>httpmime</artifactId> | |||
There was a problem hiding this comment.
weixin-java-common/pom.xml:47 目前只在 httpclient 依赖上排除了 commons-logging,但 httpmime 变为 compile 依赖后可能通过传递依赖把 commons-logging 再引入,进而与本模块的 jcl-over-slf4j 产生桥接失效/类冲突风险;建议确认所有引入路径都已排除。
Severity: medium
Other Locations
weixin-java-channel/pom.xml:34weixin-java-channel/pom.xml:38weixin-java-miniapp/pom.xml:36weixin-java-miniapp/pom.xml:40weixin-java-mp/pom.xml:36weixin-java-mp/pom.xml:40weixin-java-open/pom.xml:53weixin-java-open/pom.xml:57weixin-java-cp/pom.xml:35weixin-java-qidian/pom.xml:36
🤖 Was this useful? React with 👍 or 👎, or 🚀 if it prevented an incident/outage.
| <!-- HttpClient 5.x - 可选依赖,显式使用 HttpComponents 实现时需要 --> | ||
| <dependency> | ||
| <groupId>org.apache.httpcomponents.client5</groupId> | ||
| <artifactId>httpclient5</artifactId> |
There was a problem hiding this comment.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: f139e6d357
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| <dependency> | ||
| <groupId>org.apache.httpcomponents.client5</groupId> | ||
| <artifactId>httpclient5</artifactId> | ||
| <scope>provided</scope> |
There was a problem hiding this comment.
保留 Starter 的 HttpClient5 运行时依赖
这里把 httpclient5 改成 provided 后,依赖 weixin-java-common 的 Starter 不再向用户应用传递 HC5;但多个 Starter 仍会默认或在 HttpComponents 分支创建 *HttpComponentsImpl(例如 Spring MiniApp 的 WxMaProperties 默认 HttpComponents,AutoConfiguration 创建 WxMaServiceHttpComponentsImpl,而该 Starter POM 没有直接声明 httpclient5)。用户只引入 Starter 并使用默认配置时,setConfig/initHttp 加载 HC5 实现会因缺少 org.apache.hc.* 类失败;需要在这些 Starter 直接声明 httpclient5,或不要从 common 的传递依赖中移除它。
Useful? React with 👍 / 👎.
| */ | ||
| @Slf4j | ||
| public class WxChannelServiceImpl extends WxChannelServiceHttpComponentsImpl { | ||
| public class WxChannelServiceImpl extends WxChannelServiceHttpClientImpl { |
There was a problem hiding this comment.
修正 Channel Starter 的 HttpComponents 默认实现
单应用 Channel 的 Spring 和 Solon AutoConfiguration 都始终 new WxChannelServiceImpl(),同时各自的 WxChannelProperties 默认 httpClientType = HttpComponents;这行把默认类改成 HC4 后,使用 Starter 默认配置的应用会静默得到 APACHE_HTTP,不再符合 Starter 的默认 HttpComponents 语义。需要同步改 AutoConfiguration 按配置创建 WxChannelServiceHttpComponentsImpl,或调整 Starter 默认值。
Useful? React with 👍 / 👎.
| * @author <a href="https://github.com/binarywang">Binary Wang</a> | ||
| */ | ||
| public class WxQidianServiceImpl extends WxQidianServiceHttpComponentsImpl { | ||
| public class WxQidianServiceImpl extends WxQidianServiceHttpClientImpl { |
There was a problem hiding this comment.
修正 Qidian Spring Starter 的 HttpComponents 分支
Spring Boot Qidian Starter 的 WxQidianProperties 默认 HttpComponents,但 WxQidianServiceAutoConfiguration 没有 case HttpComponents,会落到 new WxQidianServiceImpl();这行改为继承 HC4 后,默认配置或显式选择 HttpComponents 的 Spring 用户都会得到 HttpClient 实现。需要补上 WxQidianServiceHttpComponentsImpl 分支,或同步调整默认配置。
Useful? React with 👍 / 👎.
| <groupId>org.apache.httpcomponents</groupId> | ||
| <artifactId>httpclient</artifactId> |
There was a problem hiding this comment.
这些业务模块把 httpclient 从 provided 改成传递依赖时,没有保留 weixin-java-common 对 commons-logging 的排除;因此依赖 weixin-java-mp(miniapp/channel/open/cp/qidian 也类似)的下游会同时拿到 commons-logging 和 common 里的 jcl-over-slf4j,两者提供同一组 org.apache.commons.logging 类,运行时类路径顺序可能让日志桥接失效。建议在这些新传递的 httpclient 依赖上加同样的 exclusion,或直接依赖 common 的已排除版本。
Useful? React with 👍 / 👎.
变更说明
修复 Gitee issue IJYMVW提到的 4.8.4+ 默认引入/默认使用 HttpClient5 导致非 Starter 手动集成场景依赖树变重、排除 HC5 后可能缺类的问题。
本次调整:
*ServiceImpl恢复为 Apache HttpClient 4 实现,显式的*HttpComponentsImpl仍保留给需要 HttpClient5 的用户和 Starter 配置使用。weixin-java-common以及相关业务模块中的 HC4 依赖恢复为 compile 传递依赖,httpclient5调整为 provided。影响
手动
new WxMaServiceImpl()、new WxPayServiceImpl()以及 mp/channel/qidian/open/cp 默认实现时,默认依赖树回到 HC4 兼容路径。需要 HC5 的用户仍可显式使用*HttpComponentsImpl或通过 Starter 的HttpComponents配置选择。验证
mvn -pl weixin-java-common,weixin-java-miniapp,weixin-java-pay,weixin-java-mp,weixin-java-channel,weixin-java-qidian,weixin-java-open,weixin-java-cp -am -DskipTests compilemvn -pl weixin-java-miniapp,weixin-java-mp,weixin-java-channel,weixin-java-qidian,weixin-java-open,weixin-java-cp dependency:tree -Dincludes=org.apache.httpcomponents.client5:httpclient5,org.apache.httpcomponents:httpclient,org.apache.httpcomponents:httpmime -Dscope=compileWxMaServiceImpl默认APACHE_HTTP、WxMaServiceHttpComponentsImpl仍为HTTP_COMPONENTS、WxPayServiceImpl默认继承WxPayServiceApacheHttpImpl。说明:项目根 POM 中 surefire 配置了
<skip>true</skip>,Maven 定向测试命令会显示Tests are skipped,因此额外用 JShell 执行了新增断言对应的运行时验证。