Changeset 31820


Ignore:
Timestamp:
07/24/17 21:45:30 (3 years ago)
Author:
ak19
Message:

The changes necessary for GLI's Java code to work properly with a wget that can handle https. Next step is to compile up wget with open_ssl so that it supports https. So far tested against the system wget (which supports https) after copying this into the GS2 location in gs2build/bin/linux, since that's the location which GS uses to load wget from.

Location:
main/trunk/gli/src/org/greenstone/gatherer
Files:
3 edited

Legend:

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

    r31722 r31820  
    623623            // Specify proxies as environment variables
    624624            // Need to manually specify GSDLHOME and GSDLOS also
    625             env = new String[4];
     625            env = new String[5];
    626626                    proxy_url = proxy_url.replaceAll("http://","");
    627627            env[0] = "http_proxy=http://"+proxy_url;
    628             env[1] = "ftp_proxy=ftp://"+proxy_url;
    629             env[2] = "GSDLHOME=" + Configuration.gsdl_path;
    630             env[3] = "GSDLOS=" + Gatherer.client_operating_system;
     628            env[1] = "https_proxy=http://"+proxy_url; // HTTP protocol for https:// too
     629                        // see also https://wiki.archlinux.org/index.php/proxy_settings
     630            env[2] = "ftp_proxy=ftp://"+proxy_url;
     631            env[3] = "GSDLHOME=" + Configuration.gsdl_path;
     632            env[4] = "GSDLOS=" + Gatherer.client_operating_system;
    631633
    632634            prcs = new SafeProcess(cmd, env, null);
  • main/trunk/gli/src/org/greenstone/gatherer/download/ServerInfoDialog.java

    r31636 r31820  
    115115            // Specify proxies as environment variables
    116116            // Need to manually specify GSDLHOME and GSDLOS also
    117             env = new String[4];
     117            env = new String[5];
    118118                    proxy_url = proxy_url.replaceAll("http://","");
    119119            env[0] = "http_proxy=http://"+proxy_url;
    120             env[1] = "ftp_proxy=ftp://"+proxy_url;
    121             env[2] = "GSDLHOME=" + Configuration.gsdl_path;
    122             env[3] = "GSDLOS=" + Gatherer.client_operating_system;
     120            env[1] = "https_proxy=http://"+proxy_url; // yes, HTTP protocol for https:// too
     121                           // see also https://wiki.archlinux.org/index.php/proxy_settings
     122            env[2] = "ftp_proxy=ftp://"+proxy_url;
     123            env[3] = "GSDLHOME=" + Configuration.gsdl_path;
     124            env[4] = "GSDLOS=" + Gatherer.client_operating_system;
    123125            prcs = new SafeProcess(command, env, null);
    124126        }
  • main/trunk/gli/src/org/greenstone/gatherer/gui/DownloadPane.java

    r31816 r31820  
    9191    private TreePath previous_path;
    9292    private String proxy_url = "";
     93    private Proxy proxyObject = null;
    9394       
    9495    /** Main System code */
     
    604605     * @return the redirect url for the given url if any redirection is involved, or the
    605606     * url_str.
     607     *
     608     * Adding another useful URL on setting Java System Properties:
     609     * https://stackoverflow.com/questions/12181843/using-java-to-download-files-from-a-https-url
    606610     */
    607611    private String getRedirectURL(String url_str) {
     612    boolean noMoreRedirects = false;
     613   
     614    //System.err.println("@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@");
    608615    HttpURLConnection connection = null;
    609     if(url_str.startsWith("http:")) { // only test http urls
     616    if(url_str.startsWith("http:") || url_str.startsWith("https:")) { // only test http urls
    610617        try {
    611         URL url = new URL(url_str);
    612         connection = (HttpURLConnection)url.openConnection(); //new HttpURLConnection(url);
     618        URL url = new URL(url_str);
     619        if(this.proxyObject == null) {
     620            connection = (HttpURLConnection)url.openConnection(); //new HttpURLConnection(url);
     621        } else {
     622            connection = (HttpURLConnection)url.openConnection(proxyObject);
     623        }
    613624        // don't let it automatically follow redirects, since we want to
    614625        // find out whether we are dealing with redirects in the first place
     
    619630        // HTTP Codes 3xx are redirects, http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html
    620631        int responseCode = connection.getResponseCode();
     632        //System.err.println("@@@ response code was " + responseCode);
    621633        if(responseCode >= 300 && responseCode < 400) {
    622             String responseMsg = connection.getResponseMessage();
     634            //String responseMsg = connection.getResponseMessage();
     635            //System.err.println("@@@ response msg: " + responseMsg);
    623636
    624637            // Get the Location header since this specifies the new location of the resource
    625638            String location = connection.getHeaderField("Location");
    626            
     639
     640            //System.err.println("@@@ Old URL: |" + url_str + "|");
     641            //System.err.println("@@@ LOCATION: |" + location + "|");
    627642            // this becomes the url that wget should download from
    628643            url_str = location.trim();
    629         }
    630        
     644        } else {
     645           noMoreRedirects = true;
     646        }       
    631647        connection.disconnect();
    632648        } catch(Exception e) {
     
    639655    }
    640656
    641     return url_str;
     657    if(noMoreRedirects) {
     658        //System.err.println("@@@ Found url_str " + url_str);
     659        //System.err.println("@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@");
     660        return url_str;
     661    }
     662    else { // continue checking for whether the new URL redirects elsewhere again
     663        return getRedirectURL(url_str);
     664    }
    642665    }
    643666
     
    715738        }
    716739
     740        // https://askubuntu.com/questions/664777/systemwide-proxy-settings-in-ubuntu
     741        // http://www.rgagnon.com/javadetails/java-0085.html
     742        // how-do-i-make-httpurlconnection-use-a-proxy
     743        // https://stackoverflow.com/questions/8030908/how-to-check-if-proxy-is-working-in-java
     744        proxyObject = new Proxy(Proxy.Type.HTTP, new InetSocketAddress(proxy_host, Integer.parseInt(proxy_port)));
     745
    717746        if(user_pass.indexOf("@") != -1) {
    718747           
     
    773802            if (!checkProxy() || !checkURL(false) )return;
    774803
    775 
    776804        if(server_info != null) {
    777805        server_info.dispose();
    778806        }
    779 
    780        
     807       
    781808        Argument arg_url = current_download.getArgument("url");
    782809        String str_url = "";
    783 
    784810        if( arg_url!= null && arg_url.isAssigned()) {
    785811        str_url = arg_url.getValue();
    786812        }
    787813
    788            
     814        str_url = getRedirectURL(str_url); // work out the real URL
     815
    789816        server_info = new ServerInfoDialog(str_url ,proxy_url, mode,(Download)download_map.get(mode));
    790817       
Note: See TracChangeset for help on using the changeset viewer.