Search code examples
javaproxyjavafx-2socks

JavaFX2.2 (stable) ignores set properties for "socksProxyHost" and "socksProxyPort"?


First, I would like to mention that I also had this problem when 2.2 was still beta (forced me to revert back to 2.1.1).

Installed JavaSE 7u6 today (comes bundled with JavaFX 2.2 stable). NetBeans was able to automatically detect the Default JavaFX Platform.

Created a new JavaFX Application project (tried the FXML derivative with the same result as well). Tried this piece of code:

package javafxapplication;


import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.URL;
import java.net.URLConnection;
import javafx.application.Application;
import javafx.stage.Stage;



public class JavaFXApplication extends Application 
{

    public static void main(String[] args) 
    {
        launch(args);
    }

    @Override
    public void start(Stage primaryStage) 
    {
        System.setProperty("socksProxyHost", "127.0.0.1");
        System.setProperty("socksProxyPort", "9050");

        try
        {
            URLConnection conn = new URL("http://www.wikipedia.org").openConnection();
            BufferedReader br = new BufferedReader(new InputStreamReader(conn.getInputStream()));

            String line;

            while ((line = br.readLine()) != null)
            {
                System.out.println(line);
            }
        }
        catch (Exception e) { e.printStackTrace(); }

        System.exit(0);
    }
}

And it works. Without spewing an error that no connection could be made due to bad socks proxy settings (there is nothing running on that port on my machine). These properties are silently ignored and the connection occurs directly. Is this a bug? I've tested this on 2 machines running Win7 x64. Does not happen on 2.1.1.


Solution

  • JavaFX 2.2 introduced support for system proxy (see http://javafx-jira.kenai.com/browse/RT-21705).

    It may interfere with socks proxy settings. You can try remove your system proxy or try to add next to JVM options: -Djavafx.autoproxy.disable=true