List of usage examples for org.apache.commons.httpclient.cookie CookiePolicy registerCookieSpec
public static void registerCookieSpec(String paramString, Class paramClass)
From source file:at.spardat.xma.boot.transport.HTTPTransport.java
/** * Initializes the underlaying http-protocol-provider from the given Propterties. * This sets the tcp-timeouts, the proxy-settings and ssl-settings. * @param prop containing properties for http and https protocol *//*from w w w. j a v a 2s . c o m*/ public static void init(Properties prop) { log_ = Logger.getLogger("boot.transport.http"); //$NON-NLS-1$ // proxy properties String strProxyEnable = prop.getProperty(Statics.CFG_PROP_PROXYENABLE); if (strProxyEnable != null && Boolean.valueOf(strProxyEnable).booleanValue()) { String strProxyServer = prop.getProperty(Statics.CFG_PROP_PROXYSERVER); String strProxyPort = prop.getProperty(Statics.CFG_PROP_PROXYPORT); if (strProxyServer != null && strProxyPort != null) { System.setProperty("proxySet", "true"); System.setProperty("http.proxyHost", strProxyServer); System.setProperty("http.proxyPort", strProxyPort); log_.log(LogLevel.FINE, "transport proxy is: {0}:{1}", new Object[] { strProxyServer, strProxyPort }); } String strSecureProxyServer = prop.getProperty(Statics.CFG_PROP_SECUREPROXYSERVER); String strSecureProxyPort = prop.getProperty(Statics.CFG_PROP_SECUREPROXYPORT); if (strSecureProxyPort != null && strSecureProxyServer != null) { System.setProperty("https.proxyHost", strSecureProxyServer); System.setProperty("https.proxyPort", strSecureProxyPort); log_.log(LogLevel.FINE, "secure transport proxy is: {0}:{1}", new Object[] { strSecureProxyServer, strSecureProxyPort }); } String strProxyOverride = prop.getProperty(Statics.CFG_PROP_PROXYOVERRIDE); if (strProxyOverride != null) { strProxyOverride = strProxyOverride.replace(';', '|'); // documented delimiter for IE strProxyOverride = strProxyOverride.replace(',', '|'); // IE supports ',' as delimiter, too strProxyOverride = strProxyOverride.replace(' ', '|'); // IE supports blank as delimiter, too strProxyOverride = strProxyOverride.replace('\t', '|'); // IE supports tab as delimiter, too strProxyOverride = strProxyOverride.replace('\r', '|'); // IE supports carriage return as delimiter, too strProxyOverride = strProxyOverride.replace('\n', '|'); // IE supports newline as delimiter, too strProxyOverride = strProxyOverride.replaceAll("<local>", "localhost|127.0.0.1"); System.setProperty("http.nonProxyHosts", strProxyOverride); log_.log(LogLevel.FINE, "proxy not used for: {0}", strProxyOverride); } } else { log_.log(LogLevel.FINE, "no transport proxy is used"); } // timeout properties String strConnectTimeout = prop.getProperty(Statics.CFG_PROP_CONNECTTIMEOUT); if (strConnectTimeout != null) { System.setProperty("sun.net.client.defaultConnectTimeout", strConnectTimeout); log_.log(LogLevel.FINE, "http connect timeout: " + strConnectTimeout + " milliseconds"); } String strReadTimeout = prop.getProperty(Statics.CFG_PROP_READTIMEOUT); if (strReadTimeout != null) { System.setProperty("sun.net.client.defaultReadTimeout", strReadTimeout); log_.log(LogLevel.FINE, "http read timeout: " + strReadTimeout + " milliseconds"); } // ssl properties String strTrustStore = prop.getProperty(Statics.CFG_PROP_SECURECERTS); if (strTrustStore != null) { log_.log(LogLevel.FINE, "using trusted certificates file " + strTrustStore); File trustFile = new File(strTrustStore); if (!trustFile.exists()) { log_.log(LogLevel.SEVERE, "trusted certificates file '" + trustFile.getAbsolutePath() + "' not found"); } System.setProperty("javax.net.ssl.trustStore", strTrustStore); } hostnameVerifier = new HostnameVerifierImpl(prop.getProperty(Statics.CFG_PROP_HOSTNAMEVERIFYIGNORE)); // cookie handling policy Class<?> cookiePolicyClass = null; String strCookiePolicy = prop.getProperty(Statics.CFG_PROP_COOKIEPOLICY); if (strCookiePolicy != null) { try { cookiePolicyClass = Class.forName(strCookiePolicy); } catch (ClassNotFoundException e) { log_.log(LogLevel.WARNING, "configured cookiePolicy '" + strCookiePolicy + "' not found, using default"); } } if (cookiePolicyClass == null) { cookiePolicyClass = CookieSpecBase.class; } log_.log(LogLevel.FINE, "using cookiePolicy " + cookiePolicyClass.getName()); CookiePolicy.registerCookieSpec(CookiePolicy.DEFAULT, cookiePolicyClass); cookieSpec = CookiePolicy.getDefaultSpec(); }