java - 带代理配置的 Quarkus/Restclient

标签 java quarkus microprofile quarkus-rest-client

我正在使用 quarkus 1.10.5.Final,需要使用 Web 代理调用 Web 服务。 目前我的代码使用 microprofile 客户端代理并将以下配置放在 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:没有这样的主机已知

我尝试使用 -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.htmlhttps://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

关于java - 带代理配置的 Quarkus/Restclient,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65686908/

相关文章:

tomcat - Apache Tomee 7.0.2 - 微服务的 Maven 编译错误

java - 如何使用不同的java包名称创建perforce分支?

java - 为 GWT 应用程序启用 Google 身份验证的最简单方法? (非 GAE 托管)

java - 使用 TextAction 实现带有 actionPerformed 的 JMenu

hibernate - 本地镜像构建过程在Quarkus中被卡住

docker - Quarkus:测试容器内置的原生镜像

java - 微文件客户端返回null

java - 使用 OpenCV 检测简单的几何形状 [Java]

RESTEASY003145 : Unable to find a MessageBodyReader of content-type application/xml

quarkus - 如何在quarkus microprofile案例中配置rest client