Revision 30340
branches/v2_0_0_prep/applications/appCatalog/src/org/gvsig/catalog/DiscoveryServiceClient.java | ||
---|---|---|
1 | 1 |
package org.gvsig.catalog; |
2 | 2 |
|
3 | 3 |
import java.io.IOException; |
4 |
import java.net.Authenticator; |
|
5 |
import java.net.PasswordAuthentication; |
|
4 | 6 |
import java.net.Socket; |
5 | 7 |
import java.net.URI; |
6 | 8 |
import java.net.URISyntaxException; |
7 | 9 |
import java.net.UnknownHostException; |
10 |
import java.util.Properties; |
|
8 | 11 |
|
12 |
import org.apache.commons.httpclient.HttpConnection; |
|
9 | 13 |
import org.gvsig.catalog.drivers.DiscoveryServiceCapabilities; |
10 | 14 |
import org.gvsig.catalog.drivers.IDiscoveryServiceDriver; |
11 | 15 |
import org.gvsig.catalog.exceptions.NotSupportedProtocolException; |
... | ... | |
132 | 136 |
* false --> server is not ready |
133 | 137 |
*/ |
134 | 138 |
public boolean serverIsReady() throws ServerIsNotReadyException { |
135 |
Socket sock = null; |
|
136 |
try { |
|
137 |
sock = new Socket(getUri().getHost(), |
|
138 |
getUri().getPort()); |
|
139 |
} catch (UnknownHostException e) { |
|
140 |
throw new ServerIsNotReadyException(e); |
|
141 |
} catch (IOException e) { |
|
142 |
throw new ServerIsNotReadyException(e); |
|
143 |
} |
|
144 |
return (sock != null); |
|
139 |
Properties systemSettings = System.getProperties(); |
|
140 |
|
|
141 |
|
|
142 |
Object isProxyEnabled = systemSettings.get("http.proxySet"); |
|
143 |
if ((isProxyEnabled == null) || (isProxyEnabled.equals("false"))){ |
|
144 |
Socket sock; |
|
145 |
try{ |
|
146 |
sock = new Socket(getUri().getHost(), |
|
147 |
getUri().getPort()); |
|
148 |
} catch (UnknownHostException e) { |
|
149 |
throw new ServerIsNotReadyException(e); |
|
150 |
} catch (IOException e) { |
|
151 |
throw new ServerIsNotReadyException(e); |
|
152 |
} |
|
153 |
return (sock != null); |
|
154 |
}else{ |
|
155 |
Object host = systemSettings.get("http.proxyHost"); |
|
156 |
Object port = systemSettings.get("http.proxyPort"); |
|
157 |
Object user = systemSettings.get("http.proxyUserName"); |
|
158 |
Object password = systemSettings.get("http.proxyPassword"); |
|
159 |
if ((host != null) && (port != null)){ |
|
160 |
int iPort = 80; |
|
161 |
try{ |
|
162 |
iPort = Integer.parseInt((String)port); |
|
163 |
}catch (Exception e) { |
|
164 |
//Use 80 |
|
165 |
} |
|
166 |
HttpConnection connection = new HttpConnection(getUri().getHost(), |
|
167 |
getUri().getPort()); |
|
168 |
connection.setProxyHost((String)host); |
|
169 |
connection.setProxyPort(iPort); |
|
170 |
Authenticator.setDefault(new SimpleAuthenticator( |
|
171 |
user,password)); |
|
172 |
|
|
173 |
try { |
|
174 |
connection.open(); |
|
175 |
connection.close(); |
|
176 |
} catch (IOException e) { |
|
177 |
throw new ServerIsNotReadyException(e); |
|
178 |
} |
|
179 |
} |
|
180 |
} |
|
181 |
return true; |
|
145 | 182 |
} |
146 | 183 |
|
147 | 184 |
/** |
... | ... | |
196 | 233 |
return driver.createQuery(); |
197 | 234 |
} |
198 | 235 |
|
199 |
/** |
|
200 |
* @return if the protocol always works with the |
|
201 |
* same server |
|
202 |
*/ |
|
203 |
public ServerData getOneServer(){ |
|
204 |
return driver.getOneServer(); |
|
205 |
} |
|
236 |
private class SimpleAuthenticator |
|
237 |
extends Authenticator |
|
238 |
{ |
|
239 |
private String username, |
|
240 |
password; |
|
241 |
|
|
242 |
public SimpleAuthenticator(Object username, Object password) |
|
243 |
{ |
|
244 |
if (username != null){ |
|
245 |
this.username = (String)username; |
|
246 |
} |
|
247 |
if (password != null){ |
|
248 |
this.password = (String)password; |
|
249 |
} |
|
250 |
} |
|
251 |
|
|
252 |
protected PasswordAuthentication getPasswordAuthentication() |
|
253 |
{ |
|
254 |
return new PasswordAuthentication( |
|
255 |
username,password.toCharArray()); |
|
256 |
} |
|
257 |
} |
|
206 | 258 |
} |
Also available in: Unified diff