This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.

View | Details | Raw Unified | Return to bug 51843
Collapse All | Expand All

(-)autoupdate/src/org/netbeans/modules/autoupdate/Downloader.java (-5 / +79 lines)
Lines 15-21 Link Here
15
15
16
import java.io.*;
16
import java.io.*;
17
import java.net.URLConnection;
17
import java.net.URLConnection;
18
import java.net.UnknownHostException;
18
import java.text.MessageFormat;
19
import java.text.MessageFormat;
20
import java.util.Properties;
19
import java.util.jar.*;
21
import java.util.jar.*;
20
import java.util.Iterator;
22
import java.util.Iterator;
21
import java.util.List;
23
import java.util.List;
Lines 168-174 Link Here
168
170
169
                URLConnection distrConnection = null;
171
                URLConnection distrConnection = null;
170
                distrConnection = moduleUpdate.getDistribution().openConnection();
172
                distrConnection = moduleUpdate.getDistribution().openConnection();
171
                flen = distrConnection.getContentLength();
172
                moduleUpdate.setRemoteDistributionFilename(distrConnection);
173
                moduleUpdate.setRemoteDistributionFilename(distrConnection);
173
174
174
                if ( downloadCanceled )
175
                if ( downloadCanceled )
Lines 176-190 Link Here
176
177
177
                moduleDownloaded = 0;
178
                moduleDownloaded = 0;
178
179
179
                progressDialog.setGaugeBounds( ProgressDialog.PARTIAL_GAUGE, 0, flen / 1024 );
180
181
                moduleUpdate.setDownloadStarted( true );
180
                moduleUpdate.setDownloadStarted( true );
182
                
181
                
183
                destFile = getNBM( moduleUpdate );
182
                destFile = getNBM( moduleUpdate );
184
183
185
                BufferedInputStream bsrc = new BufferedInputStream( distrConnection.getInputStream() );
184
                BufferedInputStream bsrc = null;
186
                BufferedOutputStream bdest = new BufferedOutputStream( new FileOutputStream( destFile ) );
185
                BufferedOutputStream bdest = null;
186
                try {
187
                    bsrc = new BufferedInputStream( distrConnection.getInputStream() );
188
                    bdest = new BufferedOutputStream( new FileOutputStream( destFile ) );
189
                } catch (UnknownHostException uhe) { // thrown on jdk1.5
190
                    // connect via proxy fails, try system proxy
191
                    readSystemProxy ();
192
                    distrConnection = moduleUpdate.getDistribution().openConnection();
193
                    bsrc = new BufferedInputStream( distrConnection.getInputStream() );
194
                    bdest = new BufferedOutputStream( new FileOutputStream( destFile ) );
195
                } catch (IOException ioe) { // thrown on jdk1.4
196
                    // connect via proxy fails, try system proxy
197
                    readSystemProxy ();
198
                    distrConnection = moduleUpdate.getDistribution().openConnection();
199
                    bsrc = new BufferedInputStream( distrConnection.getInputStream() );
200
                    bdest = new BufferedOutputStream( new FileOutputStream( destFile ) );
201
                } finally {
202
                    // unset proxy back after download
203
                    unsetSystemProxy ();
204
                }
187
205
206
                flen = distrConnection.getContentLength();
207
                progressDialog.setGaugeBounds( ProgressDialog.PARTIAL_GAUGE, 0, flen / 1024 );
208
                
188
                int c;
209
                int c;
189
                int i = 0;
210
                int i = 0;
190
211
Lines 424-428 Link Here
424
445
425
    private String getBundle( String key ) {
446
    private String getBundle( String key ) {
426
        return NbBundle.getMessage( Downloader.class, key );
447
        return NbBundle.getMessage( Downloader.class, key );
448
    }
449
    
450
    static private String oldProxyHost = null;
451
    static private String oldProxyPort = null;
452
    static private boolean isSystemProxy = false;
453
    
454
    // helper method for handling system proxy
455
    static void readSystemProxy () {
456
        String systemProxy = System.getProperty("netbeans.system_http_proxy"); // NOI18N
457
        if (systemProxy == null) {
458
            return;
459
        }
460
461
        int i = systemProxy.indexOf(":"); // NOI18N
462
        if (i <= 0 || i >= systemProxy.length() - 1) {
463
            return;
464
        }
465
466
        String systemProxyHost= systemProxy.substring(0, i);
467
        String systemProxyPort = systemProxy.substring(i+1);
468
469
        oldProxyHost = System.getProperty("http.proxyHost"); // NOI18N
470
        oldProxyPort = System.getProperty("http.proxyPort"); // NOI18N
471
472
        System.setProperty("http.proxyHost", systemProxyHost); // NOI18N
473
        System.setProperty("http.proxyPort", systemProxyPort); // NOI18N
474
        
475
        isSystemProxy = true;
476
    }
477
    
478
    static void unsetSystemProxy () {
479
        if (isSystemProxy) {
480
            isSystemProxy = false;
481
        } else {
482
            // no system proxy set => no job
483
            return ;
484
        }
485
        
486
        Properties props = System.getProperties();
487
488
        if (oldProxyHost == null) {
489
            props.remove("http.proxyHost"); // NOI18N
490
        } else {
491
            props.put("http.proxyHost", oldProxyHost); // NOI18N
492
        }
493
494
        if (oldProxyPort == null) {
495
            props.remove("http.proxyPort"); // NOI18N
496
        } else {
497
            props.put("http.proxyPort", oldProxyPort); // NOI18N
498
        }
499
500
        System.setProperties(props);
427
    }
501
    }
428
}
502
}
(-)autoupdate/src/org/netbeans/modules/autoupdate/XMLUpdates.java (-63 / +50 lines)
Lines 14-24 Link Here
14
package org.netbeans.modules.autoupdate;
14
package org.netbeans.modules.autoupdate;
15
15
16
import java.io.File;
16
import java.io.File;
17
import java.io.IOException;
17
import java.net.URL;
18
import java.net.URL;
18
import java.util.ArrayList;
19
import java.util.ArrayList;
19
import java.util.Collection;
20
import java.util.Collection;
20
import java.util.Date;
21
import java.util.Date;
21
import java.util.Properties;
22
import java.text.SimpleDateFormat;
22
import java.text.SimpleDateFormat;
23
import java.text.ParsePosition;
23
import java.text.ParsePosition;
24
import java.util.HashMap;
24
import java.util.HashMap;
Lines 28-35 Link Here
28
28
29
import org.w3c.dom.*;
29
import org.w3c.dom.*;
30
import org.xml.sax.*;
30
import org.xml.sax.*;
31
31
import org.xml.sax.SAXException;
32
import org.openide.util.*;
33
32
34
33
35
/** Serves for building an UpdateCache from XML Document
34
/** Serves for building an UpdateCache from XML Document
Lines 321-393 Link Here
321
        if ( showStr != null && Boolean.valueOf( showStr ).booleanValue() )
320
        if ( showStr != null && Boolean.valueOf( showStr ).booleanValue() )
322
            System.out.println("URL : " + xmlURL ); // NOI18N
321
            System.out.println("URL : " + xmlURL ); // NOI18N
323
322
324
        parseDocumentImpl();
325
        
326
        if ( checkCanceled )
327
            return;
328
329
        if (pError != NO_NETWORK)
330
            return;
331
        
332
        String proxyHost = System.getProperty("http.proxyHost"); // NOI18N
333
        if (proxyHost != null)
334
            return;
335
            
336
        String systemProxy = System.getProperty("netbeans.system_http_proxy"); // NOI18N
337
        if (systemProxy == null)
338
            return;
339
340
        int i = systemProxy.indexOf(":"); // NOI18N
341
        if (i <= 0 || i >= systemProxy.length() - 1)
342
            return;
343
344
        String systemProxyHost= systemProxy.substring(0, i);
345
        String systemProxyPort = systemProxy.substring(i+1);
346
        
347
        String proxyPort = System.getProperty("http.proxyPort"); // NOI18N
348
349
        try {
323
        try {
350
            pError = NO_ERROR;
351
            
352
            System.setProperty("http.proxyHost", systemProxyHost); // NOI18N
353
            System.setProperty("http.proxyPort", systemProxyPort); // NOI18N
354
            
355
            parseDocumentImpl();
324
            parseDocumentImpl();
356
        } finally {
325
        } catch ( SAXException e ) {
357
            Properties props = System.getProperties();
326
            pError = PARSE_ERROR;
327
            showParseError(e);
328
        } catch ( IOException e ) {
329
            pError = NO_NETWORK;
358
            
330
            
359
            if (proxyHost == null)
331
            try {
360
                props.remove("http.proxyHost"); // NOI18N
361
            else
362
                props.put("http.proxyHost", proxyHost); // NOI18N
363
364
            if (proxyPort == null)
365
                props.remove("http.proxyPort"); // NOI18N
366
            else
367
                props.put("http.proxyPort", proxyPort); // NOI18N
368
332
369
            System.setProperties(props);
333
                if (checkCanceled) {
334
                    return;
335
                }
336
337
                if (pError != NO_NETWORK) {
338
                    return;
339
                }
340
341
                String proxyHost = System.getProperty ("http.proxyHost");
342
                if (proxyHost != null && proxyHost.trim ().length () > 0) { // NOI18N
343
                    // proxy host already set => don't read the system proxy
344
                    return;
345
                }
346
                
347
                Downloader.readSystemProxy ();
348
                
349
                pError = NO_ERROR;
350
        
351
                try {
352
                    parseDocumentImpl();
353
                } catch (SAXException saxe) {
354
                    showParseError (saxe);
355
                } catch (IOException ioe) {
356
                    // ok, also this connet fails -> will be shown the first IOException
357
                }
358
                
359
            } finally {
360
                Downloader.unsetSystemProxy ();
361
                
362
                // show caught IOException
363
                if (NO_ERROR != pError) {
364
                    pError = NO_NETWORK;
365
                    showParseError(e);
366
                }
367
            }
370
        }
368
        }
371
    }
369
    }
372
370
373
    private void parseDocumentImpl() {
371
    private void parseDocumentImpl() throws SAXException, IOException {
374
        try {
372
        java.net.HttpURLConnection.setFollowRedirects( true );
375
            java.net.HttpURLConnection.setFollowRedirects( true );
373
376
            //document = XMLDataObject.parse( xmlURL, new ErrorCatcher() );
374
        xmlInputSource = new InputSource( xmlURL.toExternalForm() );
377
            
375
        if ( checkCanceled )
378
            xmlInputSource = new InputSource( xmlURL.toExternalForm() );
376
            return;
379
            if ( checkCanceled )
377
        document = org.netbeans.updater.XMLUtil.parse( xmlInputSource, false, false, new ErrorCatcher(), org.netbeans.updater.XMLUtil.createAUResolver () );            
380
                return;
381
            document = org.netbeans.updater.XMLUtil.parse( xmlInputSource, false, false, new ErrorCatcher(), org.netbeans.updater.XMLUtil.createAUResolver () );            
382
        }
383
        catch ( SAXException e ) {
384
            pError = PARSE_ERROR;
385
            showParseError(e);
386
        }
387
        catch ( java.io.IOException e ) {
388
            pError = NO_NETWORK;
389
            showParseError(e);
390
        }
391
    }
378
    }
392
    
379
    
393
    private void showParseError(Throwable t) {
380
    private void showParseError(Throwable t) {

Return to bug 51843