use of com.helger.network.proxy.settings.IProxySettings 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.IProxySettings 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.IProxySettings 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;
}
use of com.helger.network.proxy.settings.IProxySettings in project ph-web by phax.
the class ProxyAutoConfigHelperTest method testGetProxyListForURL.
@Test
public void testGetProxyListForURL() throws ScriptException {
for (final String sFile : PAC_FILES) {
LOGGER.info("Reading " + sFile);
final IReadableResource aRes = new ClassPathResource("proxyautoconf/pacfiles/" + sFile);
assertTrue(aRes.exists());
final ProxyAutoConfigHelper aPACHelper = new ProxyAutoConfigHelper(aRes);
final ICommonsList<IProxySettings> aPC = aPACHelper.getProxyListForURL(URLHelper.getAsURI("http://www.orf.at/index.html"));
assertNotNull(sFile + " failed", aPC);
assertFalse(sFile + " failed", aPC.isEmpty());
LOGGER.info(" Found the following " + aPC.size() + " entries: " + aPC);
}
}
use of com.helger.network.proxy.settings.IProxySettings in project phoss-smp by phax.
the class SMPWebAppListener method initManagers.
@Override
protected void initManagers() {
{
LOGGER.info("Init of ConfigurationFileManager");
final ConfigurationFileManager aCFM = ConfigurationFileManager.getInstance();
aCFM.registerConfigurationFile(new ConfigurationFile(new ClassPathResource("log4j2.xml")).setDescription("Log4J2 configuration").setSyntaxHighlightLanguage(EConfigurationFileSyntax.XML));
aCFM.registerConfigurationFile(new ConfigurationFile(SMPWebAppConfiguration.getSettingsResource()).setDescription("SMP web application configuration").setSyntaxHighlightLanguage(EConfigurationFileSyntax.PROPERTIES));
final IReadableResource aConfigRes = SMPServerConfiguration.getConfigFile().getReadResource();
if (aConfigRes != null) {
aCFM.registerConfigurationFile(new ConfigurationFile(aConfigRes).setDescription("SMP server configuration").setSyntaxHighlightLanguage(EConfigurationFileSyntax.PROPERTIES));
}
aCFM.registerAll(PDClientConfiguration.getConfig());
}
{
LOGGER.info("Init of Directory client stuff");
// If the SMP settings change, the PD client must be re-created
SMPMetaManager.getSettingsMgr().callbacks().add(x -> PDClientProvider.getInstance().resetPDClient());
// Callback on BusinessCard manager - if something happens, notify PD
// server
final ISMPBusinessCardManager aBusinessCardMgr = SMPMetaManager.getBusinessCardMgr();
if (aBusinessCardMgr != null) {
aBusinessCardMgr.bcCallbacks().add(new ISMPBusinessCardCallback() {
public void onSMPBusinessCardCreatedOrUpdated(@Nonnull final ISMPBusinessCard aBusinessCard) {
final ISMPSettings aSettings = SMPMetaManager.getSettings();
if (aSettings.isDirectoryIntegrationEnabled() && aSettings.isDirectoryIntegrationAutoUpdate()) {
// Notify PD server: add
PDClientProvider.getInstance().getPDClient().addServiceGroupToIndex(aBusinessCard.getParticipantIdentifier());
}
}
public void onSMPBusinessCardDeleted(@Nonnull final ISMPBusinessCard aBusinessCard) {
final ISMPSettings aSettings = SMPMetaManager.getSettings();
if (aSettings.isDirectoryIntegrationEnabled() && aSettings.isDirectoryIntegrationAutoUpdate()) {
// Notify PD server: delete
PDClientProvider.getInstance().getPDClient().deleteServiceGroupFromIndex(aBusinessCard.getParticipantIdentifier());
}
}
});
// If a service information is create, updated or deleted, also update
// Business Card at PD
SMPMetaManager.getServiceInformationMgr().serviceInformationCallbacks().add(new ISMPServiceInformationCallback() {
@Override
public void onSMPServiceInformationCreated(@Nonnull final ISMPServiceInformation aServiceInformation) {
final ISMPSettings aSettings = SMPMetaManager.getSettings();
if (aSettings.isDirectoryIntegrationEnabled() && aSettings.isDirectoryIntegrationAutoUpdate()) {
// Only if a business card is present
if (aBusinessCardMgr.containsSMPBusinessCardOfServiceGroup(aServiceInformation.getServiceGroup())) {
// Notify PD server: update
PDClientProvider.getInstance().getPDClient().addServiceGroupToIndex(aServiceInformation.getServiceGroup().getParticipantIdentifier());
}
}
}
@Override
public void onSMPServiceInformationUpdated(@Nonnull final ISMPServiceInformation aServiceInformation) {
onSMPServiceInformationCreated(aServiceInformation);
}
@Override
public void onSMPServiceInformationDeleted(@Nonnull final ISMPServiceInformation aServiceInformation) {
onSMPServiceInformationCreated(aServiceInformation);
}
});
}
}
{
LOGGER.info("Init of HTTP and Proxy settings");
// Register global proxy servers
ProxySelectorProxySettingsManager.setAsDefault(true);
final IProxySettings aProxyHttp = SMPServerConfiguration.getAsHttpProxySettings();
if (aProxyHttp != null) {
// Register a handler that returns the "http" proxy, if an "http" URL is
// requested
ProxySettingsManager.registerProvider((sProtocol, sHost, nPort) -> "http".equals(sProtocol) ? new CommonsArrayList<>(aProxyHttp) : null);
}
final IProxySettings aProxyHttps = SMPServerConfiguration.getAsHttpsProxySettings();
if (aProxyHttps != null) {
// Register a handler that returns the "https" proxy, if an "https" URL
// is
// requested
ProxySettingsManager.registerProvider((sProtocol, sHost, nPort) -> "https".equals(sProtocol) ? new CommonsArrayList<>(aProxyHttps) : null);
}
}
// Special http client config
BasePageUtilsHttpClient.HttpClientConfigRegistry.register(new HttpClientConfig("directoryclient", "Directory client settings", PDHttpClientSettings::new));
LOGGER.info("Finished init of managers");
}
Aggregations