gpt4 book ai didi

java - 使用 Apache CXF 3 和 JAX-RS 2.0 添加客户端代理

转载 作者:行者123 更新时间:2023-11-29 03:02:03 35 4
gpt4 key购买 nike

我尝试向我的 Apache CXF 3 客户端 API 添加代理。

ClientBuilder.newClient().target(serverUri)
.request()
.post();

对于 Jersey 实现,我使用 ClientConfig :

ClientConfig config = new ClientConfig();
config.connectorProvider(new ApacheConnectorProvider());
config.property(ClientProperties.PROXY_URI, proxyAddress);
ClientBuilder.newClient(config) ...

我想用 CXF 3 做同样的事情而不使用他们的特定客户端(我使用 JAX-RS 客户端实现)并且不在 JVM 上设置代理。

任何帮助都会得到帮助 ;)

编辑:

解决方案的开始可以是:

client.property("http.proxy.server.uri", proxyUri); 
client.property("http.proxy.server.port",proxyPort);

但是我没有找到代理认证的属性。

最佳答案

您不使用 JAX-RS 客户端,它只是一个接口(interface),请参阅 JAX-RS API .实现是 Apache CXF 客户端,参见 JAX-RS 2.0 Client API :

CXF 3.0.0 implements JAX-RS 2.0 Client API. Internally it is implemented in terms of CXF specific WebClient.

您可以使用 Apache CXF 客户端配置,请参阅 Apache CXF API :

Represents the configuration of the current proxy or WebClient. Given an instance with the name 'client', one can access its configuration using a WebClient.getConfig(client) call.

例子:

Client client = ClientBuilder.newClient();
HTTPConduit conduit = WebClient.getConfig(client).getHttpConduit();

HTTPClientPolicy policy = new HTTPClientPolicy();
policy.setProxyServer("my.proxy.domain");
policy.setProxyServerPort(80);
conduit.setClient(policy);

ProxyAuthorizationPolicy policy = new ProxyAuthorizationPolicy();
policy.setAuthorizationType("Basic");
policy.setUserName(PROXY_USER);
policy.setPassword(PROXY_PWD);
conduit.setProxyAuthorization(policy);

关于java - 使用 Apache CXF 3 和 JAX-RS 2.0 添加客户端代理,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34200388/

35 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com