Ignore:
Timestamp:
2017-07-24T21:45:30+12:00 (7 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.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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.