Ignore:
Timestamp:
2017-08-14T22:23:04+12:00 (7 years ago)
Author:
ak19
Message:

All the changes that were required to set up multiple proxy servers, one for HTTP, one for HTTPS, one for FTP. Still need to test on Windows

File:
1 edited

Legend:

Unmodified
Added
Removed
  • main/trunk/gli/src/org/greenstone/gatherer/download/DownloadJob.java

    r31878 r31880  
    107107    private final String mode;
    108108   
    109     private String proxy_url; // only the main thread (where DownloadJob runs) modifies this, so no synching needed
     109    private Properties proxy_urls; // only the main thread (where DownloadJob runs) modifies this, so no synching needed
    110110   
    111111    /**
    112112     */
    113     public DownloadJob(Download download, String proxy_pass, String proxy_user, DownloadScrollPane mummy, String mode, String proxy_url) {
     113    public DownloadJob(Download download, String proxy_pass, String proxy_user, DownloadScrollPane mummy, String mode, Properties proxy_urls) {
    114114    URL url = null;
    115115    int folder_hash;
    116116
    117         this.proxy_url =  proxy_url;
     117        this.proxy_urls =  proxy_urls;
    118118   
    119119        download_option = downloadToHashMap(download);
     
    310310        Process prcs = null;
    311311
    312         if (proxy_url != null && !proxy_url.equals("")) {           
     312        if (proxy_urls.size() != 0) {
    313313        // Specify proxies as environment variables
    314314        // Need to manually specify GSDLHOME and GSDLOS also
     315        env = new String[4+proxy_urls.size()];
    315316       
    316         proxy_url = proxy_url.replaceAll("http://","");
    317        
    318         env = new String[7];
    319        
    320         env[0] = "http_proxy=http://"+proxy_url;
    321         env[1] = "https_proxy=http://"+proxy_url; // yes, HTTP protocol for https:// too
    322         // see also https://wiki.archlinux.org/index.php/proxy_settings
    323         env[2] = "ftp_proxy=ftp://"+proxy_url;
    324         env[3] = "GSDLHOME=" + Configuration.gsdl_path;
    325         env[4] = "GSDLOS=" + Gatherer.client_operating_system;
     317        env[0] = "GSDLHOME=" + Configuration.gsdl_path;
     318        env[1] = "GSDLOS=" + Gatherer.client_operating_system;
    326319        // teach it where the wgetrc file lives, in gs2build/bin/<os>:
    327         env[5] = "WGETRC=" + LocalGreenstone.getBinOSDirectoryPath(Gatherer.client_operating_system)+"wgetrc";
     320        env[2] = "WGETRC=" + LocalGreenstone.getBinOSDirectoryPath(Gatherer.client_operating_system)+"wgetrc";
    328321        // Issue discovered on Windows: If PATH is not made available to perl, so that wget or something else needed by
    329322        // WgetDownload.pm's open3()  call is not on the PATH, then the perl open() call to run wget fails.
    330323        // So make PATH available to get open3() working:
    331         env[6] = "PATH="+System.getenv("PATH");     
     324        env[3] = "PATH="+System.getenv("PATH");
     325
     326        int next_index = 4;
     327        String proxy_url = proxy_urls.getProperty("HTTP");
     328        if(proxy_url != null) {
     329            env[next_index] = "http_proxy="+proxy_url;
     330            next_index++;
     331        }
     332        proxy_url = proxy_urls.getProperty("HTTPS");
     333        if(proxy_url != null) {
     334            env[next_index] = "https_proxy="+proxy_url;
     335            next_index++;
     336        }
     337        proxy_url = proxy_urls.getProperty("FTP");
     338        if(proxy_url != null) {
     339            env[next_index] = "ftp_proxy="+proxy_url;
     340            next_index++;
     341        }               
    332342       
    333343        prcs = rt.exec(cmd, env);
     
    623633        String [] env = null;
    624634
    625         if (proxy_url != null && !proxy_url.equals("")) {           
     635        if (proxy_urls.size() != 0) {
    626636        // Specify proxies as environment variables
    627637        // Need to manually specify GSDLHOME and GSDLOS also
     638        env = new String[4+proxy_urls.size()];
    628639       
    629         proxy_url = proxy_url.replaceAll("http://","");
    630        
    631         env = new String[7];
    632        
    633         env[0] = "http_proxy=http://"+proxy_url;
    634         env[1] = "https_proxy=http://"+proxy_url; // yes, HTTP protocol for https:// too
    635         // see also https://wiki.archlinux.org/index.php/proxy_settings
    636         env[2] = "ftp_proxy=ftp://"+proxy_url;
    637         env[3] = "GSDLHOME=" + Configuration.gsdl_path;
    638         env[4] = "GSDLOS=" + Gatherer.client_operating_system;
     640        env[0] = "GSDLHOME=" + Configuration.gsdl_path;
     641        env[1] = "GSDLOS=" + Gatherer.client_operating_system;
    639642        // teach it where the wgetrc file lives, in gs2build/bin/<os>:
    640         env[5] = "WGETRC=" + LocalGreenstone.getBinOSDirectoryPath(Gatherer.client_operating_system)+"wgetrc";
     643        env[2] = "WGETRC=" + LocalGreenstone.getBinOSDirectoryPath(Gatherer.client_operating_system)+"wgetrc";
    641644        // Issue discovered on Windows: If PATH is not made available to perl, so that wget or something else needed by
    642645        // WgetDownload.pm's open3()  call is not on the PATH, then the perl open() call to run wget fails.
    643646        // So make PATH available to get open3() working:
    644         env[6] = "PATH="+System.getenv("PATH");     
     647        env[3] = "PATH="+System.getenv("PATH");
     648
     649        int next_index = 4;
     650        String proxy_url = proxy_urls.getProperty("HTTP");
     651        if(proxy_url != null) {
     652            env[next_index] = "http_proxy="+proxy_url;         
     653            next_index++;
     654        }
     655        proxy_url = proxy_urls.getProperty("HTTPS");
     656        if(proxy_url != null) {
     657            env[next_index] = "https_proxy="+proxy_url;
     658            next_index++;
     659        }
     660        proxy_url = proxy_urls.getProperty("FTP");
     661        if(proxy_url != null) {
     662            env[next_index] = "ftp_proxy="+proxy_url;
     663            next_index++;
     664        }               
    645665       
    646666        prcs = new SafeProcess(cmd, env, null);
    647         } 
     667        }
    648668        else if(Gatherer.isGsdlRemote && Gatherer.isDownloadEnabled && !Utility.isWindows()) {
    649669        // Not Windows, but running client with download panel
Note: See TracChangeset for help on using the changeset viewer.