use of aQute.bnd.service.url.URLConnectionHandler in project bnd by bndtools.
the class HttpClient method getProxiedAndConfiguredConnection.
private URLConnection getProxiedAndConfiguredConnection(URL url, ProxySetup proxy) throws IOException, Exception {
final URLConnection urlc = proxy != null ? url.openConnection(proxy.proxy) : url.openConnection();
URLConnectionHandler matching = findMatchingHandler(url);
if (matching == null)
return urlc;
matching.handle(urlc);
return urlc;
}
use of aQute.bnd.service.url.URLConnectionHandler in project bnd by bndtools.
the class ConnectionSettings method createUrlConnectionHandler.
public URLConnectionHandler createUrlConnectionHandler(ServerDTO serverDTO) {
final Glob match = new Glob(serverDTO.match == null ? serverDTO.id : serverDTO.match);
final BasicAuthentication basic = getBasicAuthentication(serverDTO.username, serverDTO.password);
final HttpsVerification https = new HttpsVerification(serverDTO.trust, serverDTO.verify, getParent());
return new URLConnectionHandler() {
@Override
public boolean matches(URL url) {
String scheme = url.getProtocol().toLowerCase();
StringBuilder address = new StringBuilder();
address.append(scheme).append("://").append(url.getHost());
if (url.getPort() > 0 && url.getPort() != url.getDefaultPort())
address.append(":").append(url.getPort());
return match.matcher(address).matches();
}
@Override
public void handle(URLConnection connection) throws Exception {
if (basic != null)
basic.handle(connection);
if (isHttps(connection) && https != null) {
https.handle(connection);
}
}
boolean isHttps(URLConnection connection) {
return "https".equalsIgnoreCase(connection.getURL().getProtocol());
}
public String toString() {
return "Server [ match=" + match + ", basic=" + basic + ", https=" + https + "]";
}
};
}
Aggregations