2
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
4
* Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
6
* The contents of this file are subject to the terms of either the GNU
7
* General Public License Version 2 only ("GPL") or the Common
8
* Development and Distribution License("CDDL") (collectively, the
9
* "License"). You may not use this file except in compliance with the
10
* License. You can obtain a copy of the License at
11
* http://www.netbeans.org/cddl-gplv2.html
12
* or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
13
* specific language governing permissions and limitations under the
14
* License. When distributing the software, include this License Header
15
* Notice in each file and include the License file at
16
* nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
17
* particular file as subject to the "Classpath" exception as provided
18
* by Sun in the GPL Version 2 section of the License file that
19
* accompanied this code. If applicable, add the following below the
20
* License Header, with the fields enclosed by brackets [] replaced by
21
* your own identifying information:
22
* "Portions Copyrighted [year] [name of copyright owner]"
26
* The Original Software is NetBeans. The Initial Developer of the Original
27
* Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
28
* Microsystems, Inc. All Rights Reserved.
30
* If you wish your version of this file to be governed by only the CDDL
31
* or only the GPL Version 2, indicate your decision by adding
32
* "[Contributor] elects to include this software in this distribution
33
* under the [CDDL or GPL Version 2] license." If you do not indicate a
34
* single choice of license, a recipient has the option to distribute
35
* your version of this file under either the CDDL, the GPL Version 2 or
36
* to extend the choice of license to its licensees as provided above.
37
* However, if you add GPL Version 2 code and therefore, elected the GPL
38
* Version 2 license, then the option applies only if the new code is
39
* made subject to such option by the copyright holder.
42
package org.netbeans.modules.proxy;
44
import java.net.InetSocketAddress;
47
* This data object encapsulates parameters that are needed to establish connection to an arbitrary remote IP address.
48
* There are basically 2 types of connectivity:
50
* <li>direct connection (without any firewall or proxy, or with a transparent proxy)
51
* <li>mediated connection that routes via a firewall or proxy
53
* If this object represents a direct connection type, no further parameters are required. If this object
54
* represents a proxy connection, it also hold the proxy type, address, and port. Other optional parameters
55
* include proxy username and password.
57
* @author Maros Sandor
59
public class ConnectivitySettings {
61
* Connection type constant for a direct connection.
63
public static final int CONNECTION_DIRECT = 0;
66
* Connection type constant for connection via SOCKS proxies.
68
public static final int CONNECTION_VIA_SOCKS = 1;
71
* Connection type constant for connection via HTTP proxies.
73
public static final int CONNECTION_VIA_HTTPS = 2;
75
private static final int CONNECTION_TYPE_MIN = CONNECTION_DIRECT;
76
private static final int CONNECTION_TYPE_MAX = CONNECTION_VIA_HTTPS;
78
private int mConnectionType;
79
private String mProxyHost;
80
private int mProxyPort;
81
private String mProxyUsername;
82
private char[] mProxyPassword;
83
private int mKeepAliveIntervalSeconds;
85
public String toString() {
86
return "Type: " + mConnectionType + " Proxy: " + mProxyUsername + "@" + mProxyHost + ":" + mProxyPort;
90
* Constructs connectivity settings with the default connection setting (direct connection).
92
public ConnectivitySettings() {
93
mConnectionType = CONNECTION_DIRECT;
94
mKeepAliveIntervalSeconds = 60;
98
* Changes configuration of this connectivity settings.
100
* @param type one of the connection type constants
101
* @param host proxy hostname, must not be null for proxy configurations, is ignored for direct connectivity.
102
* @param port proxy port, must be in range 1-65535 for proxy configurations, is ignored for direct connectivity.
103
* @param username a username to supply to proxy when it request user authentication, may be null if the proxy
104
* does not require authentication or we use direct connection
105
* @param proxyPassword password to supply to proxy when it request user authentication, may be null if the proxy
106
* does not require authentication or we use direct connection
107
* @throws java.lang.IllegalArgumentException
108
* if the connection type constant is illegal, the proxy number is out of range or
109
* the proxy host is empty or null (for non-direct connections)
111
public void setProxy(int type, String host, int port, String username, char[] proxyPassword) {
112
if (type < CONNECTION_TYPE_MIN || type > CONNECTION_TYPE_MAX) throw new IllegalArgumentException("Illegal connection type");
114
if (type != CONNECTION_DIRECT) {
115
if (port < 1 || port > 65535) throw new IllegalArgumentException("Illegal proxy port number: " + port);
116
if (host == null || (host = host.trim()).length() == 0) throw new IllegalArgumentException("A proxy host must be specified");
119
mConnectionType = type;
122
mProxyUsername = username;
123
mProxyPassword = proxyPassword;
126
public int getKeepAliveIntervalSeconds() {
127
return mKeepAliveIntervalSeconds;
130
public void setKeepAliveIntervalSeconds(int keepAliveIntervalSeconds) {
131
mKeepAliveIntervalSeconds = keepAliveIntervalSeconds;
134
public int getConnectionType() {
135
return mConnectionType;
138
public void setConnectionType(int connectionType) {
139
mConnectionType = connectionType;
142
public String getProxyHost() {
146
public void setProxyHost(String proxyHost) {
147
mProxyHost = proxyHost;
150
public int getProxyPort() {
154
public void setProxyPort(int proxyPort) {
155
mProxyPort = proxyPort;
158
public String getProxyUsername() {
159
return mProxyUsername;
162
public void setProxyUsername(String proxyUsername) {
163
mProxyUsername = proxyUsername;
166
public char[] getProxyPassword() {
167
return mProxyPassword;
170
public void setProxyPassword(char[] proxyPassword) {
171
mProxyPassword = proxyPassword;