Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Proxy settings in a java program

Tags:

java

proxy

I am trying to connect to a web service with a client generated from wsdl through a java program in eclipse. I am passing my request through a proxy server. But it seems that request is not getting through. Same proxy settings are working fine on SoapUI. Please find below the system properties set by me.

Properties props= new Properties(System.getProperties()); 

props.put("http.proxySet", "true"); 

props.put("http.proxyHost", "10.x.x.x"); 

props.put("http.proxyPort", "80");

props.put("http.proxyUser","domainName\\xxx");

props.put("http.proxyPassword","xxx");

Properties newprops = new Properties(props);

Java program throws an exception as java.net.UnknownHostException:

What is it I am missing?

like image 989
Kunal Avatar asked Jan 10 '13 03:01

Kunal


People also ask

How do I find my Java proxy settings?

From the menu bar, click File > Settings (on macOS, click Android Studio > Preferences). In the left pane, click Appearance & Behavior > System Settings > HTTP Proxy. The HTTP Proxy page appears.

What is proxy service in Java?

Proxy servers act as intermediaries between client applications and other servers. In an enterprise setting, we often use them to help provide control over the content that users consume, usually across network boundaries. In this tutorial, we'll look at how to connect through proxy servers in Java.

How can I tell if Java is using a proxy?

After attaching to a Java process <PID> with strace , you'll see all addresses where the process connects to. If a proxy is used, there will be an address of the proxy.


2 Answers

I had the same problem. Just the following code works for me for setting proxy.

System.setProperty("java.net.useSystemProxies", "true");
like image 136
Marykhanzadi Avatar answered Oct 06 '22 11:10

Marykhanzadi


I use the following code (and it works):

    String host = "10.x.x.x";
    String port = "80";
    System.out.println("Using proxy: " + host + ":" + port);
    System.setProperty("http.proxyHost", host);
    System.setProperty("http.proxyPort", port);
    System.setProperty("http.nonProxyHosts", "localhost|127.0.0.1");
like image 28
Donato Szilagyi Avatar answered Oct 06 '22 11:10

Donato Szilagyi