3 Replies Latest reply on Jul 19, 2013 9:53 AM by user1985256

    Proxy settings causing unwanted use of SOCKS

    843790
      I have a Java app that, among other things, has to connect to a web server and get a response. Pretty simple stuff. I needed to be able to support proxy servers out of the box. So I looked around and discovered the ProxySelector and the java.net.useSystemProxies=true property. I read that it would auto-magically detect proxy settings for the platform. I added the code to detect and use the proxy if present and it worked without a hitch in testing.

      I was contacted by a customer stating that they weren't able to communicate to the internet. I looked at my logs and saw that I was detecting their HTTP proxy server and port correctly. I spoke to their proxy server administrator and confirmed everything. Then, I saw this in the logs:
      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.<init>(Unknown Source)
           at java.net.Socket.<init>(Unknown Source)
      They were not using a SOCKS proxy, only a standard HTTP proxy. The customer's IE could connect to the site without issue. I then asked them to describe their IE connection settings to me. They said they simply checked "Use a proxy server for your LAN" and entered the proxy address and port. I asked them to check the "Advanced" proxy settings and they had "Use the same proxy server for all protocols" checked, and that's it. They mentioned that they had never clicked "Advanced" when setting it up.

      I setup my machine's config to match theirs and I got the issue to occur. I then un-checked "Use the same proxy server for all protocols" and everything worked fine. No SOCKS sockets were used.

      Hopefully you're still with me here...

      Why does Java assume that it should use SOCKS for the socket and IE does not when "Use the same proxy server for all protocols" is checked? How can I prevent this from happening?

      Specs: WinXP, Java 6, IE 7

      Edited: Changed title...
        • 1. Re: Proxy settings causing unwanted use of SOCKS
          843790
          Hello rhimo�
          I�m torturing my self for 3 day with a similar problem.
          At first a thought it was a Java version problem, so I installed the latest 6u3.
          After a lot of testing and googling, now I�m sure that it�s some kind of a bug.
          So, I�m using one public web address as a test:
          http://www.dailyfx.com/charts/Chart.html


          I set the java proxy settings to �USE BROWSER SETTINGS�
          I set the IE 7 PROXY with the exact server using port 8080.
          In ADVANCED SETTINGS, I Copy/Paste the same server/port to all the rest of the fields (HTTP, SECURE, FTP, SOCKS)
          So the �USE THE SAME PROXY SERVER FOR ALL PROTOCOLS� is unchecked.

          When I start the web site, everything is working OK, the �daily graph� comes out, and the java console log looks like this:

          Dec 25, 2007 2:54:09 PM com.netdania.ui.applet.c init
          INFO: Finance Chart 2.1.3
          Applet Browser: sun.plugin
          Dec 25, 2007 2:54:16 PM com.netdania.ui.applet.c init
          INFO: ... Loading complete.
          In connect() -> Switched to polling!, attemps: 1


          As you can see, the page loads after the 1st attempt.
          Java is using the SOCKS protocol with the defined server.


          Now, the problem comes when I select the �USE THE SAME PROXY SERVER FOR ALL PROTOCOLS�.
          First strange thing is that all fields becoming gray (which is OK) but the SOCKS field becomes blank and gray.
          Whit these settings I�m unable to open the �daily graph� and I receive this java console messages:


          Dec 25, 2007 3:02:07 PM com.netdania.ui.applet.c init
          INFO: Finance Chart 2.1.3
          Applet Browser: sun.plugin
          Dec 25, 2007 3:02:14 PM com.netdania.ui.applet.c init
          INFO: ... Loading complete.
          In connect() -> null, attemps: 1
          In connect() -> null, attemps: 2
          In connect() -> null, attemps: 3
          *.*
          *.*
          And so on�

          I assuming that the java is tying to connect using the same SOCKS protocol as before, but now, the server is undefined.

          I�ve try testing the same scenario with Firefox but there I find more bugs:
          http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6504564

          So, if you decide to do the same tests, I recommend using IE7 and latest Java 6u3.
          I think that this is one more Microsoft issue, and the solution will come as sooner as possible.
          Please reply me with eventual solution.
          Thanks.
          • 2. Re: Proxy settings causing unwanted use of SOCKS
            843790
            I know the question was asked some time ago ... maybe someone can use this information anyway.

            I don't know why the problem happens but here's what I did for a workaround:
            I created an new ProxySelector subclass that delegates all methods to the default proxy selector - except ...
            In the "select" method when the URI's scheme ist "socket", I compare the hostname of the uri to the hostname of the proxies returned by the default proxy selector. If equal I remove the proxy from the list. Works for me.
            • 3. Re: Proxy settings causing unwanted use of SOCKS
              user1985256

              This problem still exist in 1.6, 1.7