title: Read system proxy in Java
body: <p>Surprisingly I couldn't find a working solution for such a trivial question.</p>
  
  <p>In a Java servlet I need to connect to external web site and in doGet method I'm using</p>
  
  <pre><code>URL website = new URL(websiteUrl);
  </code></pre>
  
  <p>for this.</p>
  
  <p>This code works on my PC but fails to connect when running on production Linux application server.</p>
  
  <p>I checked Firefox network settings on the server and it is set to use system proxy.
  Using <code>echo $http_proxy</code> command in Linux terminal I read the proxy settings and changed my code to:</p>
  
  <pre><code>URL website = new URL("http", proxy, Integer.parseInt(proxyPort), websiteUrl);
  </code></pre>
  
  <p>setting proxy settings hard coded.</p>
  
  <p>Now it works but obviously I wouldn't like to hard-code the proxy settings but to read it dynamically.</p>
  
  <p>That is where I stumbled as none of the methods I found on the Internet worked for me.</p>
  
  <pre><code>System.getProperty("http.proxyHost")
  System.getProperty("http_proxy")
  </code></pre>
  
  <p><a href="http://www.tutorialspoint.com/javaexamples/net_poxy.htm" rel="nofollow">ProxySelector methods</a> or adding </p>
  
  <pre><code>System.setProperty("java.net.useSystemProxies", "true");
  </code></pre>
  
  <p>brought no result.</p>
  
  <p>Is there a working solution?
  Any idea why those common solutions do not work in my case?</p>
  
  <p>I'm running WebLogic 10.3.5/JRockit on RHEL 6.
  Thanks.</p>