use of com.helger.network.proxy.settings.ProxySettings in project ph-web by phax.
the class AuthenticatorProxySettingsManagerTest method testProxyMultipleMixed.
@Test
public void testProxyMultipleMixed() {
ProxySettingsManager.registerProvider((sProtocol, sHostName, nPort) -> new CommonsArrayList<>(new ProxySettings(Proxy.Type.HTTP, "http://proxysrv", 8080), new ProxySettings(Proxy.Type.HTTP, "http://proxysrv2", 8080, "user", "pw")));
final PasswordAuthentication aPA = Authenticator.requestPasswordAuthentication("orf.at", null, 80, "http", "bla", null, null, RequestorType.PROXY);
assertNotNull(aPA);
assertEquals("user", aPA.getUserName());
assertEquals("pw", new String(aPA.getPassword()));
}
use of com.helger.network.proxy.settings.ProxySettings in project ph-web by phax.
the class ProxySelectorProxySettingsManagerTest method testDifferentHost.
@Test
public void testDifferentHost() {
ProxySettingsManager.registerProvider((sProtocol, sHostName, nPort) -> new CommonsArrayList<>(sHostName.contains(".orf.at") ? ProxySettings.createNoProxySettings() : new ProxySettings(Proxy.Type.HTTP, "http://proxysrv", 8080)));
// Will choose the http proxy
List<Proxy> aProxies = ProxySelector.getDefault().select(URLHelper.getAsURI("http://www.helger.com/blafoo"));
assertNotNull(aProxies);
assertEquals(1, aProxies.size());
assertNotNull(aProxies.get(0));
assertEquals(Proxy.Type.HTTP, aProxies.get(0).type());
assertEquals("http://proxysrv", ((InetSocketAddress) aProxies.get(0).address()).getHostString());
assertEquals(8080, ((InetSocketAddress) aProxies.get(0).address()).getPort());
// Will choose the no proxy
aProxies = ProxySelector.getDefault().select(URLHelper.getAsURI("http://anyserver.orf.at/blafoo"));
assertNotNull(aProxies);
assertEquals(1, aProxies.size());
assertNotNull(aProxies.get(0));
assertEquals(Proxy.Type.DIRECT, aProxies.get(0).type());
}
use of com.helger.network.proxy.settings.ProxySettings in project phoss-smp by phax.
the class SMPServerConfiguration method getAsHttpsProxySettings.
/**
* @return A single object for all https (but not http) proxy settings. May be
* <code>null</code>.
* @see #getAsHttpProxySettings()
* @since 5.0.7
*/
@Nullable
public static IProxySettings getAsHttpsProxySettings() {
final String sHostname = getHttpsProxyHost();
final int nPort = getHttpsProxyPort();
if (sHostname != null && nPort > 0)
return new ProxySettings(Proxy.Type.HTTP, sHostname, nPort, getProxyUsername(), getProxyPassword());
return null;
}
use of com.helger.network.proxy.settings.ProxySettings in project phoss-smp by phax.
the class SMPServerConfiguration method getAsHttpProxySettings.
/**
* @return A single object for all http (but not https) proxy settings. May be
* <code>null</code>.
* @see #getAsHttpsProxySettings()
* @since 5.0.7
*/
@Nullable
public static IProxySettings getAsHttpProxySettings() {
final String sHostname = getHttpProxyHost();
final int nPort = getHttpProxyPort();
if (sHostname != null && nPort > 0)
return new ProxySettings(Proxy.Type.HTTP, sHostname, nPort, getProxyUsername(), getProxyPassword());
return null;
}
use of com.helger.network.proxy.settings.ProxySettings in project ph-web by phax.
the class ProxyAutoConfigHelper method getProxyListForURL.
@Nonnull
public ICommonsList<IProxySettings> getProxyListForURL(@Nonnull final String sURL, @Nonnull final String sHost) throws ScriptException {
final ICommonsList<IProxySettings> ret = new CommonsArrayList<>();
String sProxyCode = findProxyForURL(sURL, sHost);
if (sProxyCode != null) {
// parse result of PAC call
sProxyCode = sProxyCode.trim();
if (sProxyCode.length() > 0) {
for (String sDirective : StringHelper.getExploded(';', sProxyCode)) {
boolean bError = true;
sDirective = sDirective.trim();
if (sDirective.equals("DIRECT")) {
ret.add(ProxySettings.createNoProxySettings());
bError = false;
} else if (sDirective.startsWith("PROXY")) {
String[] aParts = StringHelper.getExplodedArray(' ', sDirective, 2);
if (aParts.length == 2) {
aParts = StringHelper.getExplodedArray(':', aParts[1], 2);
if (aParts.length == 2) {
final String sProxyHost = aParts[0];
final String sProxyPort = aParts[1];
final int nProxyPort = StringParser.parseInt(sProxyPort, -1);
ret.add(new ProxySettings(Proxy.Type.HTTP, sProxyHost, nProxyPort));
bError = false;
}
}
} else if (sDirective.startsWith("SOCKS")) {
String[] aParts = StringHelper.getExplodedArray(' ', sDirective, 2);
if (aParts.length == 2) {
aParts = StringHelper.getExplodedArray(':', aParts[1], 2);
if (aParts.length == 2) {
final String sProxyHost = aParts[0];
final String sProxyPort = aParts[1];
final int nProxyPort = StringParser.parseInt(sProxyPort, SocksProxyConfig.DEFAULT_SOCKS_PROXY_PORT);
ret.add(new ProxySettings(Proxy.Type.SOCKS, sProxyHost, nProxyPort));
bError = false;
}
}
}
if (bError)
if (LOGGER.isWarnEnabled())
LOGGER.warn("Found unknown proxy directive '" + sDirective + "'");
}
}
}
return ret;
}
Aggregations