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 209475
Collapse All | Expand All

(-)a/o.n.core/arch.xml (+10 lines)
Lines 482-487 Link Here
482
        <code>org.netbeans.core.Bundle</code>
482
        <code>org.netbeans.core.Bundle</code>
483
        to say <code>USE_Authentication=false</code>
483
        to say <code>USE_Authentication=false</code>
484
   </api>
484
   </api>
485
   <api name='StaticNonProxyHosts' 
486
        category='devel'
487
        type='export'
488
        group='branding'>
489
        Some applications may want to proxy connections to 
490
        localhost (which by default uses direct connection in NetBeans Platform).
491
        One can change the default by branding
492
        <code>org.netbeans.core.Bundle</code>
493
        specify something else than <code>StaticNonProxyHosts=localhost|127.0.0.1</code>.
494
   </api>
485
  </p>
495
  </p>
486
 </answer>
496
 </answer>
487
497
(-)a/o.n.core/src/org/netbeans/core/Bundle.properties (+3 lines)
Lines 185-187 Link Here
185
185
186
# NOI18N
186
# NOI18N
187
TimableEventQueue.install=true
187
TimableEventQueue.install=true
188
189
# NOI18N
190
StaticNonProxyHosts=localhost|127.0.0.1
(-)a/o.n.core/src/org/netbeans/core/GuiRunLevel.java (-1 / +1 lines)
Lines 92-98 Link Here
92
        Splash.getInstance().increment(10);
92
        Splash.getInstance().increment(10);
93
93
94
        // install java.net.ProxySelector
94
        // install java.net.ProxySelector
95
        java.net.ProxySelector.setDefault (new NbProxySelector ());
95
        NbProxySelector.register();
96
        
96
        
97
        if (CLIOptions.isGui()) {
97
        if (CLIOptions.isGui()) {
98
        //---------------------------------------------------------------------------------------------------------
98
        //---------------------------------------------------------------------------------------------------------
(-)a/o.n.core/src/org/netbeans/core/NbProxySelector.java (-8 / +17 lines)
Lines 71-88 Link Here
71
 */
71
 */
72
public final class NbProxySelector extends ProxySelector {
72
public final class NbProxySelector extends ProxySelector {
73
    
73
    
74
    private ProxySelector original = null;
74
    private final ProxySelector original;
75
    private static final Logger LOG = Logger.getLogger (NbProxySelector.class.getName ());
75
    private static final Logger LOG = Logger.getLogger (NbProxySelector.class.getName ());
76
    private static Object useSystemProxies;
76
    private static Object useSystemProxies;
77
        
77
        
78
    /** Creates a new instance of NbProxySelector */
78
    /** Creates a new instance of NbProxySelector */
79
    public NbProxySelector () {
79
    private NbProxySelector (ProxySelector delegate) {
80
        original = ProxySelector.getDefault ();
80
        original = delegate;
81
        if (original == null) {
82
            LOG.warning ("No default system ProxySelector was found thus NetBeans ProxySelector won't delegate on it");
83
        } else {
84
            LOG.fine ("Override the original ProxySelector: " + original);
85
        }
86
        LOG.fine ("java.net.useSystemProxies has been set to " + useSystemProxies ());
81
        LOG.fine ("java.net.useSystemProxies has been set to " + useSystemProxies ());
87
        LOG.fine ("In launcher was detected netbeans.system_http_proxy: " + System.getProperty ("netbeans.system_http_proxy", "N/A"));
82
        LOG.fine ("In launcher was detected netbeans.system_http_proxy: " + System.getProperty ("netbeans.system_http_proxy", "N/A"));
88
        LOG.fine ("In launcher was detected netbeans.system_socks_proxy: " + System.getProperty ("netbeans.system_socks_proxy", "N/A"));
83
        LOG.fine ("In launcher was detected netbeans.system_socks_proxy: " + System.getProperty ("netbeans.system_socks_proxy", "N/A"));
Lines 90-95 Link Here
90
        copySettingsToSystem ();
85
        copySettingsToSystem ();
91
    }
86
    }
92
    
87
    
88
    static ProxySelector create(ProxySelector delegate) {
89
        return new NbProxySelector(delegate);
90
    }
91
    
92
    static void register() {
93
        ProxySelector prev = ProxySelector.getDefault();
94
        if (prev == null) {
95
            LOG.warning("No default system ProxySelector was found thus NetBeans ProxySelector won't delegate on it");
96
        } else {
97
            LOG.log(Level.FINE, "Override the original ProxySelector: {0}", prev);
98
        }
99
        ProxySelector.setDefault(create(prev));
100
    }
101
    
93
    @Override
102
    @Override
94
    public List<Proxy> select(URI uri) {
103
    public List<Proxy> select(URI uri) {
95
        List<Proxy> res = new ArrayList<Proxy> ();
104
        List<Proxy> res = new ArrayList<Proxy> ();
(-)a/o.n.core/src/org/netbeans/core/ProxySettings.java (-1 / +23 lines)
Lines 352-364 Link Here
352
        return getModifiedNonProxyHosts (getSystemNonProxyHosts ());
352
        return getModifiedNonProxyHosts (getSystemNonProxyHosts ());
353
    }
353
    }
354
354
355
  
356
    private static String concatProxies(String... proxies) {
357
        StringBuilder sb = new StringBuilder();
358
        for (String n : proxies) {
359
            if (n == null) {
360
                continue;
361
            }
362
            n = n.trim();
363
            if (n.isEmpty()) {
364
                continue;
365
            }
366
            if (sb.length() > 0 && sb.charAt(sb.length() - 1) != '|') {
367
                if (!n.startsWith("|")) {
368
                    sb.append('|');
369
                }
370
            }
371
            sb.append(n);
372
        }
373
        return sb.toString();
374
    }
375
355
    private static String getModifiedNonProxyHosts (String systemPreset) {
376
    private static String getModifiedNonProxyHosts (String systemPreset) {
356
        String fromSystem = systemPreset.replaceAll (";", "|").replaceAll (",", "|"); //NOI18N
377
        String fromSystem = systemPreset.replaceAll (";", "|").replaceAll (",", "|"); //NOI18N
357
        String fromUser = getPresetNonProxyHosts () == null ? "" : getPresetNonProxyHosts ().replaceAll (";", "|").replaceAll (",", "|"); //NOI18N
378
        String fromUser = getPresetNonProxyHosts () == null ? "" : getPresetNonProxyHosts ().replaceAll (";", "|").replaceAll (",", "|"); //NOI18N
358
        if (Utilities.isWindows ()) {
379
        if (Utilities.isWindows ()) {
359
            fromSystem = addReguralToNonProxyHosts (fromSystem);
380
            fromSystem = addReguralToNonProxyHosts (fromSystem);
360
        }
381
        }
361
        String nonProxy = fromUser + (fromUser.length () == 0 ? "" : "|") + fromSystem + (fromSystem.length () == 0 ? "" : "|") + "localhost|127.0.0.1"; // NOI18N
382
        final String staticNonProxyHosts = NbBundle.getMessage(ProxySettings.class, "StaticNonProxyHosts"); // NOI18N
383
        String nonProxy = concatProxies(fromUser, fromSystem, staticNonProxyHosts); // NOI18N
362
        String localhost = ""; // NOI18N
384
        String localhost = ""; // NOI18N
363
        try {
385
        try {
364
            localhost = InetAddress.getLocalHost().getHostName();
386
            localhost = InetAddress.getLocalHost().getHostName();
(-)a/o.n.core/test/unit/src/org/netbeans/core/Bundle_te_ST.properties (+1 lines)
Lines 40-42 Link Here
40
40
41
# NOI18N
41
# NOI18N
42
TimableEventQueue.install=false
42
TimableEventQueue.install=false
43
StaticNonProxyHosts=
(-)e12ef8061554 (+113 lines)
Added Link Here
1
/*
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3
 *
4
 * Copyright 1997-2010 Oracle and/or its affiliates. All rights reserved.
5
 *
6
 * Oracle and Java are registered trademarks of Oracle and/or its affiliates.
7
 * Other names may be trademarks of their respective owners.
8
 *
9
 * The contents of this file are subject to the terms of either the GNU
10
 * General Public License Version 2 only ("GPL") or the Common
11
 * Development and Distribution License("CDDL") (collectively, the
12
 * "License"). You may not use this file except in compliance with the
13
 * License. You can obtain a copy of the License at
14
 * http://www.netbeans.org/cddl-gplv2.html
15
 * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
16
 * specific language governing permissions and limitations under the
17
 * License.  When distributing the software, include this License Header
18
 * Notice in each file and include the License file at
19
 * nbbuild/licenses/CDDL-GPL-2-CP.  Oracle designates this
20
 * particular file as subject to the "Classpath" exception as provided
21
 * by Oracle in the GPL Version 2 section of the License file that
22
 * accompanied this code. If applicable, add the following below the
23
 * License Header, with the fields enclosed by brackets [] replaced by
24
 * your own identifying information:
25
 * "Portions Copyrighted [year] [name of copyright owner]"
26
 *
27
 * Contributor(s):
28
 *
29
 * The Original Software is NetBeans. The Initial Developer of the Original
30
 * Software is Sun Microsystems, Inc. Portions Copyright 1997-2008 Sun
31
 * Microsystems, Inc. All Rights Reserved.
32
 *
33
 * If you wish your version of this file to be governed by only the CDDL
34
 * or only the GPL Version 2, indicate your decision by adding
35
 * "[Contributor] elects to include this software in this distribution
36
 * under the [CDDL or GPL Version 2] license." If you do not indicate a
37
 * single choice of license, a recipient has the option to distribute
38
 * your version of this file under either the CDDL, the GPL Version 2 or
39
 * to extend the choice of license to its licensees as provided above.
40
 * However, if you add GPL Version 2 code and therefore, elected the GPL
41
 * Version 2 license, then the option applies only if the new code is
42
 * made subject to such option by the copyright holder.
43
 */
44
45
package org.netbeans.core;
46
47
import java.io.IOException;
48
import java.net.InetAddress;
49
import java.net.InetSocketAddress;
50
import java.net.Proxy;
51
import java.net.ProxySelector;
52
import java.net.SocketAddress;
53
import java.net.URI;
54
import java.util.Collections;
55
import java.util.List;
56
import java.util.Locale;
57
import java.util.Locale;
58
import org.netbeans.junit.NbTestCase;
59
import org.openide.util.NetworkSettings;
60
import org.openide.util.lookup.ServiceProvider;
61
62
/** Check whether we can proxy to localhost.
63
 */
64
public class CanProxyToLocalhostTest extends NbTestCase {
65
    private static String USER_PROXY_HOST = "my.webcache";
66
    private static int USER_PROXY_PORT = 8080;
67
68
    private ProxySelector selector;
69
    private static URI TO_LOCALHOST;
70
    private static URI TO_NB;
71
    private MyPS myPS;
72
73
    public CanProxyToLocalhostTest (String name) {
74
        super (name);
75
    }
76
    
77
    @Override
78
    protected void setUp () throws Exception {
79
        myPS = new MyPS();
80
        selector = NbProxySelector.create(myPS);
81
        TO_LOCALHOST = new URI ("http://localhost");
82
        TO_NB = new URI ("http://netbeans.org");
83
    }
84
    
85
    public void testNoProxyForLocalhost() {
86
        Locale.setDefault(Locale.US);
87
        assertEquals ("Connect TO_LOCALHOST DIRECT.", "DIRECT", selector.select (TO_LOCALHOST).get(0).toString());
88
    }
89
    public void testProxyForLocalhost() {
90
        Locale.setDefault(new Locale("te", "ST"));
91
        assertEquals ("Connect TO_LOCALHOST provided by MyPS", "HTTP @ my.webcache:8080", selector.select (TO_LOCALHOST).get(0).toString());
92
        assertEquals("One call to my ps", 1, myPS.called);
93
    }
94
    public void testAlwaysProxyForNonLocalhost() {
95
        Locale.setDefault(Locale.US);
96
        assertEquals ("Connect TO_LOCALHOST DIRECT.", "HTTP @ my.webcache:8080", selector.select (TO_NB).get(0).toString());
97
        assertEquals("One call to my ps", 1, myPS.called);
98
    }
99
    
100
    private static class MyPS extends ProxySelector {
101
        int called;
102
        
103
        @Override
104
        public List<Proxy> select(URI uri) {
105
            called++;
106
            return Collections.singletonList(new Proxy(Proxy.Type.HTTP, new InetSocketAddress(USER_PROXY_HOST, USER_PROXY_PORT)));
107
        }
108
109
        @Override
110
        public void connectFailed(URI uri, SocketAddress sa, IOException ioe) {
111
        }
112
    }
113
}
(-)a/o.n.core/test/unit/src/org/netbeans/core/HttpSettingsTest.java (-1 / +1 lines)
Lines 98-104 Link Here
98
    protected void setUp () throws Exception {
98
    protected void setUp () throws Exception {
99
        super.setUp ();
99
        super.setUp ();
100
        System.setProperty ("http.nonProxyHosts", NETBEANS_ORG + ',' + NETBEANS_ORG);
100
        System.setProperty ("http.nonProxyHosts", NETBEANS_ORG + ',' + NETBEANS_ORG);
101
        ProxySelector.setDefault (new NbProxySelector ());
101
        NbProxySelector.register();
102
        proxyPreferences  = NbPreferences.root ().node ("/org/netbeans/core");
102
        proxyPreferences  = NbPreferences.root ().node ("/org/netbeans/core");
103
        proxyPreferences.addPreferenceChangeListener (new PreferenceChangeListener() {
103
        proxyPreferences.addPreferenceChangeListener (new PreferenceChangeListener() {
104
            public void preferenceChange(PreferenceChangeEvent arg0) {
104
            public void preferenceChange(PreferenceChangeEvent arg0) {
(-)a/o.n.core/test/unit/src/org/netbeans/core/NonProxyHostsTest.java (-1 / +1 lines)
Lines 90-96 Link Here
90
        System.setProperty ("netbeans.system_socks_proxy", SYSTEM_PROXY_HOST + ":" + SYSTEM_PROXY_PORT);
90
        System.setProperty ("netbeans.system_socks_proxy", SYSTEM_PROXY_HOST + ":" + SYSTEM_PROXY_PORT);
91
        System.setProperty ("netbeans.system_http_non_proxy_hosts", "*.other.org");
91
        System.setProperty ("netbeans.system_http_non_proxy_hosts", "*.other.org");
92
        System.setProperty ("http.nonProxyHosts", "*.netbeans.org");
92
        System.setProperty ("http.nonProxyHosts", "*.netbeans.org");
93
        ProxySelector.setDefault (new NbProxySelector ());
93
        NbProxySelector.register();
94
        selector = ProxySelector.getDefault ();
94
        selector = ProxySelector.getDefault ();
95
        proxyPreferences  = NbPreferences.root ().node ("/org/netbeans/core");
95
        proxyPreferences  = NbPreferences.root ().node ("/org/netbeans/core");
96
        proxyPreferences.addPreferenceChangeListener (new PreferenceChangeListener () {
96
        proxyPreferences.addPreferenceChangeListener (new PreferenceChangeListener () {

Return to bug 209475