Changeset 31820
- Timestamp:
- 2017-07-24T21:45:30+12:00 (7 years ago)
- 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 623 623 // Specify proxies as environment variables 624 624 // Need to manually specify GSDLHOME and GSDLOS also 625 env = new String[ 4];625 env = new String[5]; 626 626 proxy_url = proxy_url.replaceAll("http://",""); 627 627 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; 631 633 632 634 prcs = new SafeProcess(cmd, env, null); -
main/trunk/gli/src/org/greenstone/gatherer/download/ServerInfoDialog.java
r31636 r31820 115 115 // Specify proxies as environment variables 116 116 // Need to manually specify GSDLHOME and GSDLOS also 117 env = new String[ 4];117 env = new String[5]; 118 118 proxy_url = proxy_url.replaceAll("http://",""); 119 119 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; 123 125 prcs = new SafeProcess(command, env, null); 124 126 } -
main/trunk/gli/src/org/greenstone/gatherer/gui/DownloadPane.java
r31816 r31820 91 91 private TreePath previous_path; 92 92 private String proxy_url = ""; 93 private Proxy proxyObject = null; 93 94 94 95 /** Main System code */ … … 604 605 * @return the redirect url for the given url if any redirection is involved, or the 605 606 * 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 606 610 */ 607 611 private String getRedirectURL(String url_str) { 612 boolean noMoreRedirects = false; 613 614 //System.err.println("@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@"); 608 615 HttpURLConnection connection = null; 609 if(url_str.startsWith("http:") ) { // only test http urls616 if(url_str.startsWith("http:") || url_str.startsWith("https:")) { // only test http urls 610 617 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 } 613 624 // don't let it automatically follow redirects, since we want to 614 625 // find out whether we are dealing with redirects in the first place … … 619 630 // HTTP Codes 3xx are redirects, http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html 620 631 int responseCode = connection.getResponseCode(); 632 //System.err.println("@@@ response code was " + responseCode); 621 633 if(responseCode >= 300 && responseCode < 400) { 622 String responseMsg = connection.getResponseMessage(); 634 //String responseMsg = connection.getResponseMessage(); 635 //System.err.println("@@@ response msg: " + responseMsg); 623 636 624 637 // Get the Location header since this specifies the new location of the resource 625 638 String location = connection.getHeaderField("Location"); 626 639 640 //System.err.println("@@@ Old URL: |" + url_str + "|"); 641 //System.err.println("@@@ LOCATION: |" + location + "|"); 627 642 // this becomes the url that wget should download from 628 643 url_str = location.trim(); 629 } 630 644 } else { 645 noMoreRedirects = true; 646 } 631 647 connection.disconnect(); 632 648 } catch(Exception e) { … … 639 655 } 640 656 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 } 642 665 } 643 666 … … 715 738 } 716 739 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 717 746 if(user_pass.indexOf("@") != -1) { 718 747 … … 773 802 if (!checkProxy() || !checkURL(false) )return; 774 803 775 776 804 if(server_info != null) { 777 805 server_info.dispose(); 778 806 } 779 780 807 781 808 Argument arg_url = current_download.getArgument("url"); 782 809 String str_url = ""; 783 784 810 if( arg_url!= null && arg_url.isAssigned()) { 785 811 str_url = arg_url.getValue(); 786 812 } 787 813 788 814 str_url = getRedirectURL(str_url); // work out the real URL 815 789 816 server_info = new ServerInfoDialog(str_url ,proxy_url, mode,(Download)download_map.get(mode)); 790 817
Note:
See TracChangeset
for help on using the changeset viewer.