Changeset 31882
- Timestamp:
- 2017-08-15T18:48:47+12:00 (6 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
main/trunk/gli/src/org/greenstone/gatherer/Gatherer.java
r31880 r31882 127 127 static public boolean isLocalLibrary = false; 128 128 129 // for storing the original proxy settings on GLI startup 130 private static Properties startup_proxy_settings = new Properties(); 131 129 132 /* TODO: If we're using local GLI, collections are built locally. If we're using client-GLI 130 133 * and it contains a gs2build folder in it, then localBuild will also be true (if this is not … … 161 164 162 165 static private URL default_gliserver_url=null; 163 166 164 167 public Gatherer(String[] args) 165 168 { … … 344 347 open_collection_file_path = null; 345 348 } 349 350 351 // Before calling setProxy, store anything already present 352 // Downloading happens on the machine where GLI is running from, even with clientgli 353 // For downloading with wget, we use ftp/http(s)_proxy env vars, so check if they're 354 // already set 355 if(System.getenv("http_proxy") != null) System.err.println("http_proxy already set"); 356 if(System.getenv("https_proxy") != null) System.err.println("https_proxy already set"); 357 if(System.getenv("ftp_proxy") != null) System.err.println("ftp_proxy already set"); 358 346 359 347 360 // Finally, we're ready to find out the version of the remote Greenstone server … … 660 673 } 661 674 662 675 663 676 /** Returns the correct version of the (local or remote) Greenstone server if init() has already been called. */ 664 677 public static int serverVersionNumber() { … … 1452 1465 static public void setProxy() { 1453 1466 try {// Can throw several exceptions 1454 if(Configuration.get("general.use_proxy", true)) { 1455 // These are Java properties, therefore see 1456 // https://docs.oracle.com/javase/7/docs/api/java/net/doc-files/net-properties.html 1457 // https://docs.oracle.com/javase/8/docs/technotes/guides/net/proxies.html 1458 // https://stackoverflow.com/questions/14243590/proxy-settings-in-java 1459 1460 // Not sure what proxyType is. And proxySet ceased to exist since JDK 6 or before 1461 System.setProperty("http.proxyType", "4"); 1462 System.setProperty("http.proxyHost", Configuration.getString("general.HTTP_proxy_host", true)); 1463 System.setProperty("http.proxyPort", Configuration.getString("general.HTTP_proxy_port", true)); 1464 //System.setProperty("http.proxySet", "true"); 1465 1466 System.setProperty("https.proxyHost", Configuration.getString("general.HTTPS_proxy_host", true)); 1467 System.setProperty("https.proxyPort", Configuration.getString("general.HTTPS_proxy_port", true)); 1468 1469 System.setProperty("ftp.proxyHost", Configuration.getString("general.FTP_proxy_host", true)); 1470 System.setProperty("ftp.proxyPort", Configuration.getString("general.FTP_proxy_port", true)); 1471 1472 } else { 1473 System.setProperty("http.proxyHost", ""); 1474 System.setProperty("http.proxyPort", ""); 1475 //System.setProperty("http.proxySet", "false"); 1476 System.setProperty("https.proxyHost", ""); 1477 System.setProperty("https.proxyPort", ""); 1478 System.setProperty("ftp.proxyHost", ""); 1479 System.setProperty("ftp.proxyPort", ""); 1480 } 1467 boolean use_proxy = Configuration.get("general.use_proxy", true); 1468 1469 setProxyForProtocol("http", use_proxy); 1470 setProxyForProtocol("https", use_proxy); 1471 setProxyForProtocol("ftp", use_proxy); 1472 1481 1473 } catch (Exception error) { 1482 1474 DebugStream.println("Error in Gatherer.initProxy(): " + error); … … 1485 1477 } 1486 1478 1479 private static void setProxyForProtocol(String protocol, boolean use_proxy) throws Exception { 1480 // These are Java properties, therefore see 1481 // https://docs.oracle.com/javase/7/docs/api/java/net/doc-files/net-properties.html 1482 // https://docs.oracle.com/javase/8/docs/technotes/guides/net/proxies.html 1483 // https://stackoverflow.com/questions/14243590/proxy-settings-in-java 1484 1485 if(use_proxy) { 1486 if(System.getenv(protocol+"_proxy") != null) { 1487 System.err.println("Overriding original "+protocol+" proxy settings"); 1488 1489 // first store the original settings, but only if we haven't already stored them for this protocol 1490 if(startup_proxy_settings.getProperty(protocol+".proxyHost") == null) { 1491 ///System.err.println("@@@ Overriding with: " + System.getProperty(protocol+".proxyHost", "")); 1492 startup_proxy_settings.setProperty(protocol+".proxyHost", System.getProperty(protocol+".proxyHost", "")); 1493 startup_proxy_settings.setProperty(protocol+".proxyPort", System.getProperty(protocol+".proxyPort", "")); 1494 1495 //if(protocol.equals("http")) { 1496 //startup_proxy_settings.setProperty(protocol+".proxyType", System.getProperty(protocol+".proxyType", "")); 1497 //startup_proxy_settings.setProperty(protocol+".proxySet", System.getProperty(protocol+".proxySet", "")); 1498 //} 1499 } 1500 } 1501 1502 // finally can now set the custom proxy defined through GLI for this protocol 1503 System.setProperty(protocol+".proxyHost", Configuration.getString("general."+protocol.toUpperCase()+"_proxy_host", true)); 1504 System.setProperty(protocol+".proxyPort", Configuration.getString("general."+protocol.toUpperCase()+"_proxy_port", true)); 1505 1506 // Not sure what proxyType is. And proxySet ceased to exist since JDK 6 or before. See links above. 1507 // But we used to set them both for HTTP before, so still doing so for proxyType which may or may not exist 1508 // but proxySet doesn't exist anymore, so not continuing with that. 1509 if(protocol.equals("http")) { 1510 System.setProperty(protocol+".proxyType", "4"); 1511 //System.setProperty(protocol+".proxySet", "true"); 1512 } 1513 1514 } 1515 1516 else { // use_proxy=false, not using proxy defined through GLI, so 1517 // either unset proxy vars for this protocol, or restore any original settings for them 1518 1519 if(System.getenv(protocol+"_proxy") != null) { 1520 System.err.println("Restoring original "+protocol+" proxy settings"); 1521 System.setProperty(protocol+".proxyHost", startup_proxy_settings.getProperty(protocol+".proxyHost")); 1522 System.setProperty(protocol+".proxyPort", startup_proxy_settings.getProperty(protocol+".proxyPort")); 1523 1524 //if(protocol.equals("http")) { 1525 //System.setProperty(protocol+".proxyHost", startup_proxy_settings.getProperty(protocol+".proxyType")); 1526 //System.setProperty(protocol+".proxyPort", startup_proxy_settings.getProperty(protocol+".proxySet")); 1527 //} 1528 } 1529 1530 } 1531 } 1532 1487 1533 1488 1534 /** This private class contains an instance of an external application running within a JVM shell. It is important that this process sits in its own thread, but its more important that when we exit the Gatherer we don't actually System.exit(0) the Gatherer object until the user has voluntarily ended all of these child processes. Otherwise when we quit the Gatherer any changes the users may have made in external programs will be lost and the child processes are automatically deallocated. */
Note:
See TracChangeset
for help on using the changeset viewer.