How to redirect a javax.ws.rs.client.WebTarget Post request via a Proxy

1.6k Views Asked by At

I have an a server that is trying to make a POST call to an external IP, unfortunately if I make the call directly it is blocked by an internal firewall.

However we do have a proxy that allowed outbound http traffic, if I redirect the POST call via this proxy first, then it should succeed.

The client making the call is using a javax.ws.rs.client.WebTarget object to create/direct the POST in the call format:

WebTarget.path("URL_HERE").request().post(ENTITY_HERE).readEntity(RETURN_TYPE_HERE.class);

However I can see no way in the javax ws documentaton to redirect this call via the proxy (for instance via host = proxy_domain, and port = 1).

Secondly is there a way to scope the proxy redirection? For instance I can see some similar documentation online regarding updating a wsdl for global settings - but I only wish for this to happen for this single POST call.

EDIT: This Q is the same as an earlier one regarding the proxy call, though the answer to that one did not suffice - I have added a note to the comments here on the addition of the ApacheConnectorProvider that was required to get the 'via' call instantiated.

The solution as mentioned there was to create config as per:

ClientConfig config = new ClientConfig().connectorProvider(new ApacheConnectorProvider()) .property(ClientProperties.PROXY_URI, "http://PROXY_ADDRESS:PROXY_PORT");

Using Jersey 2.27.

1

There are 1 best solutions below

0
On

Answer was as per

Proxy setting not working in Jersey ClientConfig

I have added the code segment I needed to the end of my original question.