带有代理配置的 Quarkus / Restclient

问题描述

我正在使用 quarkus 1.10.5.Final 并且需要使用 Web 代理调用 Web 服务。 目前我的代码使用微配置客户端代理并在 application.properties 中放置以下配置

client/mp-rest/url=https://remote.com
client/mp-rest/scope=javax.inject.Dependent
client/mp-rest/trustStore=classpath:/meta-inf/resources/cacerts
client/mp-rest/connectTimeout=5000
client/mp-rest/readTimeout=5000
client/mp-rest/followRedirects=true
client/mp-rest/proxyAddress=http://proxy:8080

但仍然产生 RESTEASY004655: 无法调用请求: java.net.UnkNownHostException: No such host is kNown

我尝试使用 -Dhttp.proxyHost 和 -Dhttp.proxyPort 来测试代理并成功。 问题是我不能使用 -Dparams 因为它会中断其他服务调用

这个链接我得到了 mp-rest/proxyAddress 的配置 https://download.eclipse.org/microprofile/microprofile-rest-client-2.0-RC2/microprofile-rest-client-2.0-RC2.html 但它在 https://docs.jboss.org/resteasy/docs/4.1.1.Final/userguide/html/MicroProfile_Rest_Client.html 中没有提到 如果我看错了,请告诉我。

解决方法

2021 年 5 月更新

Quarkus 2.0 支持 MicroProfile Rest Client 2.0。有了它你可以使用你提到的配置,即

# A string value in the form of <proxyHost>:<proxyPort> that specifies the
# HTTP proxy server hostname (or IP address) and port for requests of
# this client to use.
client/mp-rest/proxyAddress=host:port

或者用编程方式设置

ProxiedClient client = RestClientBuilder.newBuilder()
                                        .baseUri(someUri)
                                        .proxyAddress("myproxy.mycompany.com",8080)
                                        .build(ProxiedClient.class);

原答案

您应该能够使用以下属性为 Quarkus Rest 客户端设置代理:

    org.jboss.resteasy.jaxrs.client.proxy.host
    org.jboss.resteasy.jaxrs.client.proxy.port
    org.jboss.resteasy.jaxrs.client.proxy.scheme
,

我刚刚遇到了同样的问题并发现了这个问题。

Upgrade to MP Rest Client 2.0 #10520

MP-Rest-Client 2.0 在 quarkus 1.10.5 中不可用。