Index: autoupdate/src/org/netbeans/modules/autoupdate/Downloader.java =================================================================== RCS file: /cvs/autoupdate/src/org/netbeans/modules/autoupdate/Downloader.java,v retrieving revision 1.36 diff -u -r1.36 Downloader.java --- autoupdate/src/org/netbeans/modules/autoupdate/Downloader.java 2 Jul 2004 09:31:51 -0000 1.36 +++ autoupdate/src/org/netbeans/modules/autoupdate/Downloader.java 25 Nov 2004 16:32:15 -0000 @@ -15,7 +15,9 @@ import java.io.*; import java.net.URLConnection; +import java.net.UnknownHostException; import java.text.MessageFormat; +import java.util.Properties; import java.util.jar.*; import java.util.Iterator; import java.util.List; @@ -168,7 +170,6 @@ URLConnection distrConnection = null; distrConnection = moduleUpdate.getDistribution().openConnection(); - flen = distrConnection.getContentLength(); moduleUpdate.setRemoteDistributionFilename(distrConnection); if ( downloadCanceled ) @@ -176,15 +177,35 @@ moduleDownloaded = 0; - progressDialog.setGaugeBounds( ProgressDialog.PARTIAL_GAUGE, 0, flen / 1024 ); - moduleUpdate.setDownloadStarted( true ); destFile = getNBM( moduleUpdate ); - BufferedInputStream bsrc = new BufferedInputStream( distrConnection.getInputStream() ); - BufferedOutputStream bdest = new BufferedOutputStream( new FileOutputStream( destFile ) ); + BufferedInputStream bsrc = null; + BufferedOutputStream bdest = null; + try { + bsrc = new BufferedInputStream( distrConnection.getInputStream() ); + bdest = new BufferedOutputStream( new FileOutputStream( destFile ) ); + } catch (UnknownHostException uhe) { // thrown on jdk1.5 + // connect via proxy fails, try system proxy + readSystemProxy (); + distrConnection = moduleUpdate.getDistribution().openConnection(); + bsrc = new BufferedInputStream( distrConnection.getInputStream() ); + bdest = new BufferedOutputStream( new FileOutputStream( destFile ) ); + } catch (IOException ioe) { // thrown on jdk1.4 + // connect via proxy fails, try system proxy + readSystemProxy (); + distrConnection = moduleUpdate.getDistribution().openConnection(); + bsrc = new BufferedInputStream( distrConnection.getInputStream() ); + bdest = new BufferedOutputStream( new FileOutputStream( destFile ) ); + } finally { + // unset proxy back after download + unsetSystemProxy (); + } + flen = distrConnection.getContentLength(); + progressDialog.setGaugeBounds( ProgressDialog.PARTIAL_GAUGE, 0, flen / 1024 ); + int c; int i = 0; @@ -424,5 +445,58 @@ private String getBundle( String key ) { return NbBundle.getMessage( Downloader.class, key ); + } + + static private String oldProxyHost = null; + static private String oldProxyPort = null; + static private boolean isSystemProxy = false; + + // helper method for handling system proxy + static void readSystemProxy () { + String systemProxy = System.getProperty("netbeans.system_http_proxy"); // NOI18N + if (systemProxy == null) { + return; + } + + int i = systemProxy.indexOf(":"); // NOI18N + if (i <= 0 || i >= systemProxy.length() - 1) { + return; + } + + String systemProxyHost= systemProxy.substring(0, i); + String systemProxyPort = systemProxy.substring(i+1); + + oldProxyHost = System.getProperty("http.proxyHost"); // NOI18N + oldProxyPort = System.getProperty("http.proxyPort"); // NOI18N + + System.setProperty("http.proxyHost", systemProxyHost); // NOI18N + System.setProperty("http.proxyPort", systemProxyPort); // NOI18N + + isSystemProxy = true; + } + + static void unsetSystemProxy () { + if (isSystemProxy) { + isSystemProxy = false; + } else { + // no system proxy set => no job + return ; + } + + Properties props = System.getProperties(); + + if (oldProxyHost == null) { + props.remove("http.proxyHost"); // NOI18N + } else { + props.put("http.proxyHost", oldProxyHost); // NOI18N + } + + if (oldProxyPort == null) { + props.remove("http.proxyPort"); // NOI18N + } else { + props.put("http.proxyPort", oldProxyPort); // NOI18N + } + + System.setProperties(props); } } Index: autoupdate/src/org/netbeans/modules/autoupdate/XMLUpdates.java =================================================================== RCS file: /cvs/autoupdate/src/org/netbeans/modules/autoupdate/XMLUpdates.java,v retrieving revision 1.24 diff -u -r1.24 XMLUpdates.java --- autoupdate/src/org/netbeans/modules/autoupdate/XMLUpdates.java 10 Sep 2004 15:16:01 -0000 1.24 +++ autoupdate/src/org/netbeans/modules/autoupdate/XMLUpdates.java 25 Nov 2004 16:32:15 -0000 @@ -14,11 +14,11 @@ package org.netbeans.modules.autoupdate; import java.io.File; +import java.io.IOException; import java.net.URL; import java.util.ArrayList; import java.util.Collection; import java.util.Date; -import java.util.Properties; import java.text.SimpleDateFormat; import java.text.ParsePosition; import java.util.HashMap; @@ -28,8 +28,7 @@ import org.w3c.dom.*; import org.xml.sax.*; - -import org.openide.util.*; +import org.xml.sax.SAXException; /** Serves for building an UpdateCache from XML Document @@ -321,73 +320,61 @@ if ( showStr != null && Boolean.valueOf( showStr ).booleanValue() ) System.out.println("URL : " + xmlURL ); // NOI18N - parseDocumentImpl(); - - if ( checkCanceled ) - return; - - if (pError != NO_NETWORK) - return; - - String proxyHost = System.getProperty("http.proxyHost"); // NOI18N - if (proxyHost != null) - return; - - String systemProxy = System.getProperty("netbeans.system_http_proxy"); // NOI18N - if (systemProxy == null) - return; - - int i = systemProxy.indexOf(":"); // NOI18N - if (i <= 0 || i >= systemProxy.length() - 1) - return; - - String systemProxyHost= systemProxy.substring(0, i); - String systemProxyPort = systemProxy.substring(i+1); - - String proxyPort = System.getProperty("http.proxyPort"); // NOI18N - try { - pError = NO_ERROR; - - System.setProperty("http.proxyHost", systemProxyHost); // NOI18N - System.setProperty("http.proxyPort", systemProxyPort); // NOI18N - parseDocumentImpl(); - } finally { - Properties props = System.getProperties(); + } catch ( SAXException e ) { + pError = PARSE_ERROR; + showParseError(e); + } catch ( IOException e ) { + pError = NO_NETWORK; - if (proxyHost == null) - props.remove("http.proxyHost"); // NOI18N - else - props.put("http.proxyHost", proxyHost); // NOI18N - - if (proxyPort == null) - props.remove("http.proxyPort"); // NOI18N - else - props.put("http.proxyPort", proxyPort); // NOI18N + try { - System.setProperties(props); + if (checkCanceled) { + return; + } + + if (pError != NO_NETWORK) { + return; + } + + String proxyHost = System.getProperty ("http.proxyHost"); + if (proxyHost != null && proxyHost.trim ().length () > 0) { // NOI18N + // proxy host already set => don't read the system proxy + return; + } + + Downloader.readSystemProxy (); + + pError = NO_ERROR; + + try { + parseDocumentImpl(); + } catch (SAXException saxe) { + showParseError (saxe); + } catch (IOException ioe) { + // ok, also this connet fails -> will be shown the first IOException + } + + } finally { + Downloader.unsetSystemProxy (); + + // show caught IOException + if (NO_ERROR != pError) { + pError = NO_NETWORK; + showParseError(e); + } + } } } - private void parseDocumentImpl() { - try { - java.net.HttpURLConnection.setFollowRedirects( true ); - //document = XMLDataObject.parse( xmlURL, new ErrorCatcher() ); - - xmlInputSource = new InputSource( xmlURL.toExternalForm() ); - if ( checkCanceled ) - return; - document = org.netbeans.updater.XMLUtil.parse( xmlInputSource, false, false, new ErrorCatcher(), org.netbeans.updater.XMLUtil.createAUResolver () ); - } - catch ( SAXException e ) { - pError = PARSE_ERROR; - showParseError(e); - } - catch ( java.io.IOException e ) { - pError = NO_NETWORK; - showParseError(e); - } + private void parseDocumentImpl() throws SAXException, IOException { + java.net.HttpURLConnection.setFollowRedirects( true ); + + xmlInputSource = new InputSource( xmlURL.toExternalForm() ); + if ( checkCanceled ) + return; + document = org.netbeans.updater.XMLUtil.parse( xmlInputSource, false, false, new ErrorCatcher(), org.netbeans.updater.XMLUtil.createAUResolver () ); } private void showParseError(Throwable t) {