Thomas
Thomas

Reputation: 1140

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.

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

With Jersey implementation I use 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.

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.

Upvotes: 1

Views: 4363

Answers (1)

dur
dur

Reputation: 16979

You don't use JAX-RS client, it is just an interface, see 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.

You can use Apache CXF client configuration, see 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.

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);

Upvotes: 7

Related Questions