title: how to test proxy internet connection using java?
body: <p>i have some code to test if the proxy server and port is working ,some of the code like this:</p>
  
  <pre><code>System.getProperties().put("proxySet", "true");
  System.getProperties().put("https.proxyHost", "localhost");
  System.getProperties().put("https.proxyPort", "1234");
  System.getProperties().put("http.proxyHost", "localhost");
  System.getProperties().put("http.proxyPort", "1234");
  HttpURLConnection conn = (HttpURLConnection) new URL("https://www.google.com").openConnection();
  conn.getContent();
  conn.disconnect();
  </code></pre>
  
  <p><strong>it seems that openConnection() method will do thing like this:<br/></strong></p>
  
  <ol>
  <li>try to connect given URL using proxy.</li>
  <li>if it fails to use proxy,it will connect URL <strong>directly without proxy</strong>.</li>
  </ol>
  
  <p>that's the problem,i meant to test if the proxy is working,but this code won't stop if the proxy can not connect. </p>
  
  <p><strong>i also tried to use isReachable() method of InetAddress class,but i get the same result.</strong></p>
  
  <p>so how could i stop this connection if the proxy doesn't work ,in order to test if the proxy is reachable ?</p>