[英]Add client proxy with Apache CXF 3 and JAX-RS 2.0
I try to add a proxy to my Apache CXF 3 client API. 我尝试将代理添加到我的Apache CXF 3客户端API。
ClientBuilder.newClient().target(serverUri)
.request()
.post();
With Jersey implementation I use ClientConfig : 在Jersey实现中,我使用ClientConfig:
ClientConfig config = new ClientConfig();
config.connectorProvider(new ApacheConnectorProvider());
config.property(ClientProperties.PROXY_URI, proxyAddress);
ClientBuilder.newClient(config) ...
And i would like to do the same thing with CXF 3 without using their specific client (I use JAX-RS client implementation) and not setting the proxy on the JVM. 我想对CXF 3做同样的事情,而不使用它们的特定客户端(我使用JAX-RS客户端实现),并且不在JVM上设置代理。
Any help will be apriciated ;) 任何帮助将不胜感激;)
EDIT : 编辑:
A start of solution can be : 解决方案的开始可以是:
client.property("http.proxy.server.uri", proxyUri);
client.property("http.proxy.server.port",proxyPort);
But i didn't found properties for proxy authentification. 但是我没有找到代理身份验证的属性。
You don't use JAX-RS client, it is just an interface, see JAX-RS API . 您不使用JAX-RS客户端,它只是一个接口,请参见JAX-RS API 。 The implementation is Apache CXF client, see JAX-RS 2.0 Client API :
该实现是Apache CXF客户端,请参阅JAX-RS 2.0客户端API :
CXF 3.0.0 implements JAX-RS 2.0 Client API.
CXF 3.0.0实现了JAX-RS 2.0客户端API。 Internally it is implemented in terms of CXF specific WebClient.
在内部,它是根据CXF特定的WebClient实施的。
You can use Apache CXF client configuration, see Apache CXF API : 您可以使用Apache CXF客户端配置,请参阅Apache CXF API :
Represents the configuration of the current proxy or WebClient.
表示当前代理或WebClient的配置。 Given an instance with the name 'client', one can access its configuration using a WebClient.getConfig(client) call.
给定一个名为“客户端”的实例,可以使用WebClient.getConfig(client)调用访问其配置。
Example: 例:
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);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.