binarywang/WxJava · error · IllegalArgumentException

不支持的http执行器类型:

Error message

不支持的http执行器类型:

What it means

OcrDiscernRequestExecutor.create only supports APACHE_HTTP and HTTP_COMPONENTS (Apache HttpClient 4.x and 5.x). JODD_HTTP and OK_HTTP fall through to the default branch and throw. The OCR feature ships no Jodd/OkHttp implementations, so those clients cannot perform OCR requests.

Source

Thrown at weixin-java-common/src/main/java/me/chanjar/weixin/common/requestexecuter/ocr/OcrDiscernRequestExecutor.java:42

    this.requestHttp = requestHttp;
  }

  @Override
  public void execute(String uri, File data, ResponseHandler<String> handler, WxType wxType) throws WxErrorException, IOException {
    handler.handle(this.execute(uri, data, wxType));
  }

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

View on GitHub (pinned to 1c43293a3c)

Solutions

  1. Configure the OCR-capable service with Apache HttpClient 4.x (APACHE_HTTP) or 5.x (HTTP_COMPONENTS).
  2. Give the OCR service a dedicated Apache-based client.
  3. Assert requestHttp.getRequestType() is APACHE_HTTP or HTTP_COMPONENTS at startup before any OCR call.

Example fix

// before
mpService.setWxHttpService(okHttpService); // OK_HTTP
String text = ocrService.discern(imgFile); // throws

// after
mpService.setWxHttpService(apacheHttpService); // APACHE_HTTP
String text = ocrService.discern(imgFile);
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("OCR requires Apache HttpClient, got " + requestHttp.getRequestType());
}

Type guard

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

Try / catch

try {
  ocrService.discern(imgFile);
} catch (IllegalArgumentException e) {
  if (e.getMessage().contains("不支持的http执行器类型")) {
    // reconfigure the OCR-capable service with Apache HttpClient
  }
  throw e;
}

Prevention

When it happens

Trigger: The service (MP/Channel) is configured with an OkHttp or Jodd RequestHttp backend, and an OCR (image recognition) API routed through OcrDiscernRequestExecutor is called.

Common situations: Migrating to OkHttp globally without checking OCR coverage; sharing a Jodd/OkHttp client config with the OCR-capable service.

Related errors


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