I use Jersey 2.11 to access the confluence REST API and get content from there.
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;
....
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();
Is this the current right way to use proxy in Java with Jersey 2.11 ? I get always an exception
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)
...
The confluence site which I want to access use https. On a machine which don't need a proxy it work with
HttpAuthenticationFeature feature = HttpAuthenticationFeature.basic(
"confluenceUsername", "confluencePassword");
Client client = ClientBuilder.newClient();
client.register(feature);
so Confluence isn't the problem. I think that is something wrong with proxy spefication but don't know what.