1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31 package edu.internet2.middleware.grouperClientExt.org.apache.commons.httpclient;
32
33 import edu.internet2.middleware.grouperClientExt.org.apache.commons.httpclient.protocol.Protocol;
34 import edu.internet2.middleware.grouperClientExt.org.apache.commons.httpclient.util.LangUtils;
35
36
37
38
39
40
41
42
43
44
45
46
47 public class HttpHost implements Cloneable {
48
49
50 private String hostname = null;
51
52
53 private int port = -1;
54
55
56 private Protocol protocol = null;
57
58
59
60
61
62
63
64
65 public HttpHost(final String hostname, int port, final Protocol protocol) {
66 super();
67 if (hostname == null) {
68 throw new IllegalArgumentException("Host name may not be null");
69 }
70 if (protocol == null) {
71 throw new IllegalArgumentException("Protocol may not be null");
72 }
73 this.hostname = hostname;
74 this.protocol = protocol;
75 if (port >= 0) {
76 this.port = port;
77 } else {
78 this.port = this.protocol.getDefaultPort();
79 }
80 }
81
82
83
84
85
86
87
88 public HttpHost(final String hostname, int port) {
89 this(hostname, port, Protocol.getProtocol("http"));
90 }
91
92
93
94
95
96
97 public HttpHost(final String hostname) {
98 this(hostname, -1, Protocol.getProtocol("http"));
99 }
100
101
102
103
104
105
106 public HttpHost(final URI uri) throws URIException {
107 this(uri.getHost(), uri.getPort(), Protocol.getProtocol(uri.getScheme()));
108 }
109
110
111
112
113
114
115 public HttpHost2/middleware/grouperClientExt/org/apache/commons/httpclient/HttpHost.html#HttpHost">HttpHost (final HttpHost httphost) {
116 super();
117 init(httphost);
118 }
119
120 private void init(final HttpHost httphost) {
121 this.hostname = httphost.hostname;
122 this.port = httphost.port;
123 this.protocol = httphost.protocol;
124 }
125
126
127
128
129
130 public Object clone() throws CloneNotSupportedException {
131 HttpHost../../../../../../../../edu/internet2/middleware/grouperClientExt/org/apache/commons/httpclient/HttpHost.html#HttpHost">HttpHost copy = (HttpHost) super.clone();
132 copy.init(this);
133 return copy;
134 }
135
136
137
138
139
140
141 public String getHostName() {
142 return this.hostname;
143 }
144
145
146
147
148
149
150 public int getPort() {
151 return this.port;
152 }
153
154
155
156
157
158 public Protocol getProtocol() {
159 return this.protocol;
160 }
161
162
163
164
165
166
167 public String toURI() {
168 StringBuffer buffer = new StringBuffer(50);
169 buffer.append(this.protocol.getScheme());
170 buffer.append("://");
171 buffer.append(this.hostname);
172 if (this.port != this.protocol.getDefaultPort()) {
173 buffer.append(':');
174 buffer.append(this.port);
175 }
176 return buffer.toString();
177 }
178
179
180
181
182 public String toString() {
183 StringBuffer buffer = new StringBuffer(50);
184 buffer.append(toURI());
185 return buffer.toString();
186 }
187
188
189
190
191 public boolean equals(final Object o) {
192
193 if (o instanceof HttpHost) {
194
195 if (o == this) {
196 return true;
197 }
198 HttpHost../../../../../../../../edu/internet2/middleware/grouperClientExt/org/apache/commons/httpclient/HttpHost.html#HttpHost">HttpHost that = (HttpHost) o;
199 if (!this.hostname.equalsIgnoreCase(that.hostname)) {
200 return false;
201 }
202 if (this.port != that.port) {
203 return false;
204 }
205 if (!this.protocol.equals(that.protocol)) {
206 return false;
207 }
208
209 return true;
210 } else {
211 return false;
212 }
213 }
214
215
216
217
218 public int hashCode() {
219 int hash = LangUtils.HASH_SEED;
220 hash = LangUtils.hashCode(hash, this.hostname);
221 hash = LangUtils.hashCode(hash, this.port);
222 hash = LangUtils.hashCode(hash, this.protocol);
223 return hash;
224 }
225
226 }