7

I am using Jersey 2.4.1 for rest and want to make a GET or Post call via HTTP and HTTPS proxy. I am unable to do it. I have searched on internet and found many links but most of it are obsolete now. Some help will be really helpful as there are lot of changes from Jersey 1.X to 2.X

This is my code to make GET call(which is working fine). I want to modify it to make this call via HTTP and HTTPS proxy. Any pointers will be helpful.

javax.ws.rs.core.Response response = null;
Client client = ClientBuilder.newClient();
WebTarget target = client.target(url); //url is string
response = target.request().header("Authorization", header).accept(javax.ws.rs.core.MediaType.APPLICATION_JSON).get();
learner
  • 1,095
  • 2
  • 18
  • 41
  • [Try this](http://stackoverflow.com/a/18995077/2587435) – Paul Samsotha Apr 25 '15 at 09:13
  • I need to handle both http and https proxy. This does not handle this. Can you provide some solution in which I can handle both http and https proxies? – learner Apr 27 '15 at 12:25
  • This should have exactly what you need -- https://jersey.java.net/documentation/latest/client.html#d0e5070 – Gyan Apr 30 '15 at 06:04

2 Answers2

1

Try using the ClientConfiguration object, set whatever properties you want, and then set the configuration using ClientBuilder.withConfig(Configuration config). Then you can build it with the build() method. Have a look at this example:

ClientConfig cc = new ClientConfig();
cc.property(ClientProperties.PROXY_URI, "8.8.8.8:80");
Client client = JerseyClientBuilder.withConfig(cc).build();

This does however only work for http proxies. To set a https proxy you have to set the system properties like so:

System.setProperty("http.proxyHost", "some.proxy");
System.setProperty("http.proxyPort", "3476");
System.setProperty("https.proxyHost", "some.https.proxy");
System.setProperty("https.proxyPort", "6235");

Read this for further information.

Distjubo
  • 959
  • 6
  • 21
0

Proxy will drive crazy. I faced lot of issues with Proxy. I will do following checks in proxy env

Check #1:
Since this is GET request. Put the request URL directly in web browser or CURL. If you got the response. Then something to do with your code. Otherwise you need to fix the proxy settings in System Network settings.

Check #2:
If you are using Eclipse IDE, you need to fix the proxy setting with in the Eclipse.
http://www.mkyong.com/web-development/how-to-configure-proxy-settings-in-eclipse/

And you need to set ClientBuilder with Proxy URL.

https://gist.github.com/qerub/5877919 (Use proxy URL from properties file. )

Hope it work.

Arun G
  • 2,338
  • 1
  • 18
  • 22