Ejemplo n.º 1
0
 private static void setupProxies() {
   String proxyHostArgument = System.getProperty(PROXY_HOST); // System properties, not user pref
   String proxyPortArgument = System.getProperty(PROXY_PORT);
   if (proxyHostArgument == null)
     proxyHostArgument =
         System.getProperty(HTTP_PROXYHOST); // in case it was set by -D we also check this
   if (proxyPortArgument == null) proxyPortArgument = System.getProperty(HTTP_PROXYPORT);
   // arguments should override and set user preferences
   // host
   String proxyHost = null;
   if (proxyHostArgument != null && proxyHostArgument.trim().length() > 0)
     proxyHost = proxyHostArgument;
   // port
   String proxyPort = null;
   if (proxyPortArgument != null && proxyPortArgument.trim().length() > 0) {
     try {
       Integer.parseInt(proxyPortArgument);
       proxyPort = proxyPortArgument;
     } catch (final NumberFormatException nfe) {
       nfe.printStackTrace();
     }
   }
   if (proxyHost != null || proxyPort != null)
     setProxy(proxyHost, proxyPort, ProxyChoice.USE_USER_PREFERENCES);
   final Preferences pref = Preferences.userNodeForPackage(GameRunner2.class);
   final ProxyChoice choice =
       ProxyChoice.valueOf(pref.get(PROXY_CHOICE, ProxyChoice.NONE.toString()));
   if (choice == ProxyChoice.USE_SYSTEM_SETTINGS) setToUseSystemProxies();
   else if (choice == ProxyChoice.USE_USER_PREFERENCES) {
     final String host = pref.get(GameRunner2.PROXY_HOST, "");
     final String port = pref.get(GameRunner2.PROXY_PORT, "");
     if (host.trim().length() > 0) System.setProperty(HTTP_PROXYHOST, host);
     if (port.trim().length() > 0) System.setProperty(HTTP_PROXYPORT, port);
   }
 }
Ejemplo n.º 2
0
 public static void setProxy(
     final String proxyHost, final String proxyPort, final ProxyChoice proxyChoice) {
   final Preferences pref = Preferences.userNodeForPackage(GameRunner2.class);
   final ProxyChoice choice;
   if (proxyChoice != null) {
     choice = proxyChoice;
     pref.put(PROXY_CHOICE, proxyChoice.toString());
   } else {
     choice = ProxyChoice.valueOf(pref.get(PROXY_CHOICE, ProxyChoice.NONE.toString()));
   }
   if (proxyHost != null && proxyHost.trim().length() > 0) {
     pref.put(PROXY_HOST, proxyHost); // user pref, not system properties
     if (choice == ProxyChoice.USE_USER_PREFERENCES) System.setProperty(HTTP_PROXYHOST, proxyHost);
   }
   if (proxyPort != null && proxyPort.trim().length() > 0) {
     try {
       Integer.parseInt(proxyPort);
       pref.put(PROXY_PORT, proxyPort); // user pref, not system properties
       if (choice == ProxyChoice.USE_USER_PREFERENCES)
         System.setProperty(HTTP_PROXYPORT, proxyPort);
     } catch (final NumberFormatException nfe) {
       nfe.printStackTrace();
     }
   }
   if (choice == ProxyChoice.NONE) {
     System.clearProperty(HTTP_PROXYHOST);
     System.clearProperty(HTTP_PROXYPORT);
   } else if (choice == ProxyChoice.USE_SYSTEM_SETTINGS) {
     setToUseSystemProxies();
   }
   if (proxyHost != null || proxyPort != null || proxyChoice != null) {
     try {
       pref.flush();
       pref.sync();
     } catch (final BackingStoreException e) {
       e.printStackTrace();
     }
   }
   /*System.out.println(System.getProperty(HTTP_PROXYHOST));
   System.out.println(System.getProperty(HTTP_PROXYPORT));*/
 }