使用 Apache CXF 3 和 JAX-RS 2.0 添加客户端代理
Add client proxy with Apache CXF 3 and JAX-RS 2.0
我尝试向我的 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 客户端,它只是一个接口,请参阅 JAX-RS API. The implementation is Apache CXF client, see 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);
我尝试向我的 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 客户端,它只是一个接口,请参阅 JAX-RS API. The implementation is Apache CXF client, see 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);