Skip to content

恢复默认 HTTP 客户端兼容性#4067

Open
binarywang wants to merge 1 commit into
developfrom
codex/fix-default-httpclient-compat
Open

恢复默认 HTTP 客户端兼容性#4067
binarywang wants to merge 1 commit into
developfrom
codex/fix-default-httpclient-compat

Conversation

@binarywang

@binarywang binarywang commented Jul 7, 2026

Copy link
Copy Markdown
Owner

变更说明

修复 Gitee issue IJYMVW提到的 4.8.4+ 默认引入/默认使用 HttpClient5 导致非 Starter 手动集成场景依赖树变重、排除 HC5 后可能缺类的问题。

本次调整:

  • 将非 Starter 的默认 *ServiceImpl 恢复为 Apache HttpClient 4 实现,显式的 *HttpComponentsImpl 仍保留给需要 HttpClient5 的用户和 Starter 配置使用。
  • weixin-java-common 以及相关业务模块中的 HC4 依赖恢复为 compile 传递依赖,httpclient5 调整为 provided。
  • 补充 miniapp/pay 默认实现类型断言,防止默认类再次回退到 HC5。

影响

手动 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 compile
  • mvn -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=compile
  • 使用 JShell 验证 WxMaServiceImpl 默认 APACHE_HTTPWxMaServiceHttpComponentsImpl 仍为 HTTP_COMPONENTSWxPayServiceImpl 默认继承 WxPayServiceApacheHttpImpl

说明:项目根 POM 中 surefire 配置了 <skip>true</skip>,Maven 定向测试命令会显示 Tests are skipped,因此额外用 JShell 执行了新增断言对应的运行时验证。

@binarywang binarywang marked this pull request as ready for review July 7, 2026 09:41
Copilot AI review requested due to automatic review settings July 7, 2026 09:41

Copilot AI left a comment

Copy link
Copy Markdown

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 各业务模块在“非 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 依赖定位的注释说明(强调显式使用时才需要)。

@augmentcode

augmentcode Bot commented Jul 7, 2026

Copy link
Copy Markdown
🤖 Augment PR Summary

Summary: 本 PR 旨在恢复 4.8.4+ 之前的默认 HTTP 客户端兼容性,避免非 Starter 手动集成时因默认引入 HttpClient5 导致依赖树变重/排除后缺类。

Changes:

  • 将多模块默认 *ServiceImpl 从 HC5 的 *HttpComponentsImpl 回退为 HC4 实现(*HttpClientImpl/*ApacheHttpImpl
  • 调整 Maven 依赖:HttpClient4 相关依赖恢复为 compile 传递;HttpClient5 调整为 provided(显式使用时再引入)
  • 新增 miniapp/pay 的断言型测试,防止默认实现再次回退到 HC5
Notes: 需要 HC5 的用户仍可显式使用 *HttpComponentsImpl 或通过 Starter 配置选择。

🤖 Was this summary useful? React with 👍 or 👎

@augmentcode augmentcode Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Review completed. 2 suggestions posted.

Fix All in Augment

Comment augment review to trigger a new review at any time.

@@ -45,7 +45,6 @@
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpmime</artifactId>

@augmentcode augmentcode Bot Jul 7, 2026

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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:34
  • weixin-java-channel/pom.xml:38
  • weixin-java-miniapp/pom.xml:36
  • weixin-java-miniapp/pom.xml:40
  • weixin-java-mp/pom.xml:36
  • weixin-java-mp/pom.xml:40
  • weixin-java-open/pom.xml:53
  • weixin-java-open/pom.xml:57
  • weixin-java-cp/pom.xml:35
  • weixin-java-qidian/pom.xml:36

Fix This in Augment

🤖 Was this useful? React with 👍 or 👎, or 🚀 if it prevented an incident/outage.

Comment thread pom.xml
<!-- HttpClient 5.x - 可选依赖,显式使用 HttpComponents 实现时需要 -->
<dependency>
<groupId>org.apache.httpcomponents.client5</groupId>
<artifactId>httpclient5</artifactId>

@augmentcode augmentcode Bot Jul 7, 2026

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

pom.xml:168 这里在 dependencyManagement 中声明的 httpclient5 没有统一管理成 provided/optional,虽然注释写“可选”,但某些模块若未显式写 scope 会把 HC5 以 compile 传递给使用方(例如 weixin-java-aispeech 当前就是无 <scope> 声明)。考虑在这里统一约束 scope 以避免依赖树意外变重。

Severity: medium

Fix This in Augment

🤖 Was this useful? React with 👍 or 👎, or 🚀 if it prevented an incident/outage.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 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>

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge 保留 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 {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge 修正 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 {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge 修正 Qidian Spring Starter 的 HttpComponents 分支

Spring Boot Qidian Starter 的 WxQidianProperties 默认 HttpComponents,但 WxQidianServiceAutoConfiguration 没有 case HttpComponents,会落到 new WxQidianServiceImpl();这行改为继承 HC4 后,默认配置或显式选择 HttpComponents 的 Spring 用户都会得到 HttpClient 实现。需要补上 WxQidianServiceHttpComponentsImpl 分支,或同步调整默认配置。

Useful? React with 👍 / 👎.

Comment thread weixin-java-mp/pom.xml
Comment on lines 35 to 36
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge 排除重新传递的 commons-logging

这些业务模块把 httpclientprovided 改成传递依赖时,没有保留 weixin-java-commoncommons-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 👍 / 👎.

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