binarywang/WxJava · error · IllegalArgumentException

不支持的http执行器类型:{requestType}

Error message

不支持的http执行器类型:{requestType}

What it means

ChannelMediaDownloadRequestExecutor.create only supports APACHE_HTTP and HTTP_COMPONENTS. JODD_HTTP and OK_HTTP hit the default branch and throw. Like the upload executor, the Channel module ships download implementations only for the Apache HttpClient families.

Source

Thrown at weixin-java-channel/src/main/java/me/chanjar/weixin/channel/executor/ChannelMediaDownloadRequestExecutor.java:45

  private static final Pattern PATTERN = Pattern.compile(".*filename=\"(.*)\"");

  public ChannelMediaDownloadRequestExecutor(RequestHttp<H, P> requestHttp, File tmpDirFile) {
    this.requestHttp = requestHttp;
    this.tmpDirFile = tmpDirFile;
  }

  @SuppressWarnings("unchecked")
  public static RequestExecutor<ChannelImageResponse, String> create(RequestHttp<?, ?> requestHttp, File tmpDirFile) {
    switch (requestHttp.getRequestType()) {
      case APACHE_HTTP:
        return new ApacheHttpChannelMediaDownloadRequestExecutor(
          (RequestHttp<org.apache.http.impl.client.CloseableHttpClient, org.apache.http.HttpHost>) requestHttp, tmpDirFile);
      case HTTP_COMPONENTS:
        return new HttpComponentsChannelMediaDownloadRequestExecutor(
          (RequestHttp<org.apache.hc.client5.http.impl.classic.CloseableHttpClient, org.apache.hc.core5.http.HttpHost>) requestHttp, tmpDirFile);
      default:
        throw new IllegalArgumentException("不支持的http执行器类型:" + requestHttp.getRequestType());
    }
  }

  /**
   * 创建临时文件
   *
   * @param inputStream 输入文件流
   * @param name        文件名
   * @param ext         扩展名
   * @param tmpDirFile  临时文件夹目录
   */
  public static File createTmpFile(InputStream inputStream, String name, String ext, File tmpDirFile)
    throws IOException {
    File resultFile = File.createTempFile(name, '.' + ext, tmpDirFile);
    resultFile.deleteOnExit();
    try (InputStream in = inputStream; OutputStream out = openOutputStream(resultFile)) {
      IOUtils.copy(in, out);
    }

View on GitHub (pinned to 1c43293a3c)

Solutions

  1. Configure the Channel service with Apache HttpClient 4.x (APACHE_HTTP) or 5.x (HTTP_COMPONENTS).
  2. Give the Channel service a dedicated Apache-based client rather than sharing a Jodd/OkHttp one.
  3. Guard at startup: assert requestHttp.getRequestType() is APACHE_HTTP or HTTP_COMPONENTS before any media download.

Example fix

// before
service.setWxHttpService(joddHttpService); // JODD_HTTP
File img = service.downloadMedia(...); // throws

// after
service.setWxHttpService(apacheHttpService); // APACHE_HTTP
File img = service.downloadMedia(...);
Defensive patterns

Strategy: validation

Validate before calling

Set<HttpClientType> supported = EnumSet.of(HttpClientType.APACHE_HTTP, HttpClientType.HTTP_COMPONENTS);
if (!supported.contains(requestHttp.getRequestType())) {
  throw new IllegalStateException("Channel media download requires Apache HttpClient, got " + requestHttp.getRequestType());
}

Type guard

private static boolean channelDownloadSupported(RequestHttp<?,?> http) {
  HttpClientType t = http.getRequestType();
  return t == HttpClientType.APACHE_HTTP || t == HttpClientType.HTTP_COMPONENTS;
}

Try / catch

try {
  service.downloadMedia(...);
} catch (IllegalArgumentException e) {
  if (e.getMessage().contains("不支持的http执行器类型")) {
    // reconfigure Channel service with Apache HttpClient
  }
  throw e;
}

Prevention

When it happens

Trigger: The Channel service is wired with an OkHttp or Jodd RequestHttp backend, and a media-download API (any method routed through ChannelMediaDownloadRequestExecutor) is called.

Common situations: Reusing a cross-module OkHttp/Jodd configuration for Channel media retrieval; migrating client backends without verifying download coverage.

Related errors


AI-assisted analysis of binarywang/WxJava@1c43293a3c (2026-08-14). Data as JSON: /api/errors/27c15379317b9a46. Report an issue: GitHub.