title: Java Jersey 2 client and proxies
body: <p>I use Jersey 2.11 to access the confluence REST API and get content from there.</p>
  
  <pre><code>import org.codehaus.jettison.json.JSONArray;
  import org.codehaus.jettison.json.JSONException;
  import org.codehaus.jettison.json.JSONObject;
  import org.glassfish.jersey.apache.connector.ApacheClientProperties;
  import org.glassfish.jersey.client.ClientConfig;
  import org.glassfish.jersey.client.ClientProperties;
  import org.glassfish.jersey.client.authentication.HttpAuthenticationFeature;
  import javax.net.ssl.HostnameVerifier;
  import javax.net.ssl.SSLSession;
  import javax.ws.rs.client.Client;
  import javax.ws.rs.client.ClientBuilder;
  import javax.ws.rs.client.Entity;
  import javax.ws.rs.client.WebTarget;
  import javax.ws.rs.core.MediaType;
  import javax.ws.rs.core.Response;
  </code></pre>
  
  <p>....</p>
  
  <pre><code>HttpAuthenticationFeature feature = HttpAuthenticationFeature.basic(
      "confluenceUsername", "confluencePassword"
  );
  
  ClientConfig cc = new ClientConfig();
  cc.property(ClientProperties.PROXY_URI, "xx.xx.xx.xx:xxxx");
  Client client = ClientBuilder.newClient(cc);
  
  client.register(feature);
  
  WebTarget target = client.target(credential.getUrl())
      .path("rest").path("api").path("content").path(id)
      .queryParam("expand", "space,body.storage,version,container,ancestors");
  
  Response response = target.request().get();
  </code></pre>
  
  <p>Is this the current right way to use proxy in Java with Jersey 2.11 ? I get always an exception</p>
  
  <pre><code>java.net.ConnectException: Connection refused: connect
  javax.ws.rs.ProcessingException: java.net.Connect Exception: Connection refused: connect
      at org.glassfish.jersey.client.HttpUrlConnector.apply(HttpUrlConnector.java:229)
  ...
  </code></pre>
  
  <p>The confluence site which I want to access use https. On a machine which don't need a proxy it work with</p>
  
  <pre><code>HttpAuthenticationFeature feature = HttpAuthenticationFeature.basic(
      "confluenceUsername", "confluencePassword");
  Client client = ClientBuilder.newClient();
  client.register(feature);
  </code></pre>
  
  <p>so Confluence isn't the problem. I think that is something wrong with proxy spefication but don't know what.</p>