Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I found an odd behavior experimenting with the suggested code here. </p> <p>It appears that, after a default ProxySelector has been set, regular socket code (e.g. creating a new Socket) does not work anymore, because it tries to use a socks server (not sure why it would do this, but for me it does). </p> <p>So if you, when calling</p> <pre><code>Socket socket = new Socket(host, port); </code></pre> <p>you receive such a SocketException:</p> <pre><code>java.net.SocketException: Malformed reply from SOCKS server at java.net.SocksSocketImpl.readSocksReply(Unknown Source) at java.net.SocksSocketImpl.connect(Unknown Source) at java.net.Socket.connect(Unknown Source) at java.net.Socket.connect(Unknown Source) at java.net.Socket.&lt;init&gt;(Unknown Source) at java.net.Socket.&lt;init&gt;(Unknown Source) </code></pre> <p>then try setting the default ProxySelector back to null:</p> <pre><code>ProxySelector.setDefault(null); </code></pre> <p>For me this resulted in the following small Java class which I now use to simply retrieve the systems proxy settings without having it affect the further usage of Sockets() of the application, yet configuring the system properly to use the proxy:</p> <pre><code>public class ProxyConfig { private static String host; private static int port; public static void init() { System.setProperty("java.net.useSystemProxies", "true"); Proxy proxy = getProxy(); if (proxy != null) { InetSocketAddress addr = (InetSocketAddress) proxy.address(); host = addr.getHostName(); port = addr.getPort(); System.setProperty("java.net.useSystemProxies", "false"); System.setProperty("http.proxyHost", host); System.setProperty("http.proxyPort", ""+port); } System.setProperty("java.net.useSystemProxies", "false"); } public static String getHost() { return host; } public static int getPort() { return port; } private static Proxy getProxy() { List&lt;Proxy&gt; l = null; try { ProxySelector def = ProxySelector.getDefault(); l = def.select(new URI("http://foo/bar")); ProxySelector.setDefault(null); } catch (Exception e) { e.printStackTrace(); } if (l != null) { for (Iterator&lt;Proxy&gt; iter = l.iterator(); iter.hasNext();) { java.net.Proxy proxy = iter.next(); return proxy; } } return null; } } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload