/** * Opens a connection with appropriate proxy and credentials, if required. * * @param url The URL to open. * @return The opened connection. * @throws IOException If an error occurs establishing the connection. */ public URLConnection openConnection(URL url) throws IOException { Proxy proxy = getProxyFor(url); URLConnection conn = null; if (proxy != null) { conn = url.openConnection(proxy.getProxy()); proxy.authenticate(conn); } else { conn = url.openConnection(); } return conn; }
public void authenticate(URLConnection conn) { if (this.username == null && this.password == null) { return; } String authz = "Basic " + getCredentialsBase64(); conn.addRequestProperty("Proxy-Authorization", authz); } }
static void parseProxy(final XmlPullParser reader, MavenSettings mavenSettings) throws XmlPullParserException, IOException { int eventType; Proxy proxy = new Proxy(); while ((eventType = reader.nextTag()) != END_DOCUMENT) { if (eventType == START_TAG) { switch (reader.getName()) { case "id": { proxy.setId(reader.nextText()); break; proxy.setActive(Boolean.parseBoolean(reader.nextText())); break; proxy.setProtocol(reader.nextText()); break; proxy.setHost(reader.nextText()); break; proxy.setPort(Integer.parseInt(reader.nextText())); break; proxy.setUsername(reader.nextText()); break; proxy.setPassword(reader.nextText()); break; proxy.setNonProxyHosts(reader.nextText()); break;
static void parseProxy(final XmlPullParser reader, MavenSettings mavenSettings) throws XmlPullParserException, IOException { int eventType; Proxy proxy = new Proxy(); while ((eventType = reader.nextTag()) != END_DOCUMENT) { if (eventType == START_TAG) { switch (reader.getName()) { case "id": { proxy.setId(reader.nextText()); break; proxy.setActive(Boolean.parseBoolean(reader.nextText())); break; proxy.setProtocol(reader.nextText()); break; proxy.setHost(reader.nextText()); break; proxy.setPort(Integer.parseInt(reader.nextText())); break; proxy.setUsername(reader.nextText()); break; proxy.setPassword(reader.nextText()); break; proxy.setNonProxyHosts(reader.nextText()); break;
/** * Opens a connection with appropriate proxy and credentials, if required. * * @param url The URL to open. * @return The opened connection. * @throws IOException If an error occurs establishing the connection. */ public URLConnection openConnection(URL url) throws IOException { Proxy proxy = getProxyFor(url); URLConnection conn = null; if (proxy != null) { conn = url.openConnection(proxy.getProxy()); proxy.authenticate(conn); } else { conn = url.openConnection(); } return conn; }
public Proxy getProxyFor(URL url) { for (Proxy proxy : this.proxies) { if (proxy.canProxyFor(url)) { return proxy; } } return null; }
public void authenticate(URLConnection conn) { if (this.username == null && this.password == null) { return; } String authz = "Basic " + getCredentialsBase64(); conn.addRequestProperty("Proxy-Authorization", authz); } }
public Proxy getProxyFor(URL url) { for (Proxy proxy : this.proxies) { if (proxy.canProxyFor(url)) { return proxy; } } return null; }