List of usage examples for org.apache.commons.httpclient.protocol DefaultProtocolSocketFactory DefaultProtocolSocketFactory
DefaultProtocolSocketFactory
From source file:ch.cyberduck.core.http.HTTP3Session.java
protected HostConfiguration getHostConfiguration(Host host) { int port = host.getPort(); final HostConfiguration configuration = new StickyHostConfiguration(); if ("https".equals(host.getProtocol().getScheme())) { if (-1 == port) { port = 443;/*from w ww.j a va 2s . c o m*/ } // Configuration with custom socket factory using the trust manager configuration.setHost(host.getHostname(), port, new org.apache.commons.httpclient.protocol.Protocol(host.getProtocol().getScheme(), new SSLSocketFactory(this.getTrustManager(host.getHostname())), port)); if (Preferences.instance().getBoolean("connection.proxy.enable")) { final Proxy proxy = ProxyFactory.instance(); if (proxy.isHTTPSProxyEnabled(host)) { configuration.setProxy(proxy.getHTTPSProxyHost(host), proxy.getHTTPSProxyPort(host)); } } } else if ("http".equals(host.getProtocol().getScheme())) { if (-1 == port) { port = 80; } configuration.setHost(host.getHostname(), port, new org.apache.commons.httpclient.protocol.Protocol( host.getProtocol().getScheme(), new DefaultProtocolSocketFactory(), port)); if (Preferences.instance().getBoolean("connection.proxy.enable")) { final Proxy proxy = ProxyFactory.instance(); if (proxy.isHTTPProxyEnabled(host)) { configuration.setProxy(proxy.getHTTPProxyHost(host), proxy.getHTTPProxyPort(host)); } } } final HostParams parameters = configuration.getParams(); parameters.setParameter(HttpMethodParams.USER_AGENT, this.getUserAgent()); parameters.setParameter(HttpMethodParams.PROTOCOL_VERSION, HttpVersion.HTTP_1_1); parameters.setParameter(HttpMethodParams.SO_TIMEOUT, this.timeout()); parameters.setParameter(HttpMethodParams.CREDENTIAL_CHARSET, "ISO-8859-1"); parameters.setParameter(HttpClientParams.MAX_REDIRECTS, 10); return configuration; }
From source file:org.apache.hadoop.fs.swift.http.SwiftRestClient.java
/** * This is something that needs to be looked at, as it is * setting the static state of the http client classes. *//*from w w w.jav a 2 s .c om*/ private void registerProtocols(Properties props) throws SwiftConfigurationException { Protocol.registerProtocol("http", new Protocol("http", new DefaultProtocolSocketFactory(), getIntOption(props, SWIFT_HTTP_PORT_PROPERTY, SWIFT_HTTP_PORT))); Protocol.registerProtocol("https", new Protocol("https", (ProtocolSocketFactory) new EasySSLProtocolSocketFactory(), getIntOption(props, SWIFT_HTTPS_PORT_PROPERTY, SWIFT_HTTPS_PORT))); }
From source file:org.cloudfoundry.identity.uaa.provider.saml.idp.SamlServiceProviderConfigurator.java
protected ExtendedMetadataDelegate configureURLMetadata(SamlServiceProvider provider) throws MetadataProviderException { ProtocolSocketFactory socketFactory = null; SamlServiceProviderDefinition def = provider.getConfig().clone(); if (def.getMetaDataLocation().startsWith("https")) { try {/*from w ww.j a v a 2 s . co m*/ socketFactory = new EasySSLProtocolSocketFactory(); } catch (GeneralSecurityException | IOException e) { throw new MetadataProviderException("Error instantiating SSL/TLS socket factory.", e); } } else { socketFactory = new DefaultProtocolSocketFactory(); } ExtendedMetadata extendedMetadata = new ExtendedMetadata(); extendedMetadata.setAlias(provider.getEntityId()); FixedHttpMetaDataProvider fixedHttpMetaDataProvider; try { fixedHttpMetaDataProvider = FixedHttpMetaDataProvider.buildProvider(dummyTimer, getClientParams(), adjustURIForPort(def.getMetaDataLocation()), new RestTemplate(UaaHttpRequestUtils.createRequestFactory(def.isSkipSslValidation())), this.contentCache ); } catch (URISyntaxException e) { throw new MetadataProviderException("Invalid metadata URI: " + def.getMetaDataLocation(), e); } fixedHttpMetaDataProvider.setSocketFactory(socketFactory); byte[] metadata = fixedHttpMetaDataProvider.fetchMetadata(); def.setMetaDataLocation(new String(metadata, StandardCharsets.UTF_8)); return configureXMLMetadata(provider); }
From source file:org.glite.slcs.caclient.impl.CMPClient.java
private HttpClient createHttpClient(String keystorePath, String keystorePassword, String truststorePath, URL caURL) throws SLCSException { Protocol protocol = null;// ww w .jav a2 s . co m int port = caURL.getPort(); if (caURL.getProtocol().equals("http")) { if (port == -1) { port = 80; } protocol = new Protocol("http", new DefaultProtocolSocketFactory(), port); } else if (caURL.getProtocol().equals("https")) { if (port == -1) { port = 443; } try { ExtendedProtocolSocketFactory psf = new ExtendedProtocolSocketFactory(keystorePath, keystorePassword, truststorePath); protocol = new Protocol("https", psf, port); } catch (Exception e) { throw new SLCSException("Error in generating the secure http client", e); } } else { throw new SLCSException("Protocol defined in CAClient.CAUrl is not supported! Use http or https."); } // create HTTP client MultiThreadedHttpConnectionManager connectionManager = new MultiThreadedHttpConnectionManager(); HttpClient client = new HttpClient(connectionManager); client.getHostConfiguration().setHost(caURL.getHost(), port, protocol); return client; }
From source file:org.rssowl.core.internal.connection.DefaultProtocolHandler.java
private synchronized void initFeedProtocol() { if (fgFeedProtocolInitialized) return;// w ww. j a v a 2 s . com Protocol feed = new Protocol(URIUtils.FEED_SCHEME, new DefaultProtocolSocketFactory(), 80); Protocol.registerProtocol(URIUtils.FEED_SCHEME, feed); fgFeedProtocolInitialized = true; }
From source file:org.scohen.juploadr.upload.HttpClientFactory.java
public static HttpClient getHttpClient(CommunityAccount account) { HttpClient client = new HttpClient(new MultiThreadedHttpConnectionManager()); Protocol http;//from w w w . ja v a 2 s . co m if (account.isBandwidthLimited()) { http = new Protocol(HTTP, new BandwidthLimitingProtocolSocketFactory(account.getBandwidth()), 80); } else { http = new Protocol(HTTP, new DefaultProtocolSocketFactory(), 80); } Protocol.registerProtocol(HTTP, http); NetActivator activator = NetActivator.getDefault(); IProxyService proxyService = activator.getProxyService(); String home = ((IConfigurationElement) account.getConfiguration().getParent()).getAttribute("home"); //$NON-NLS-1$ home = Core.furnishWebUrl(home); IProxyData proxyData = null; try { IProxyData[] select = proxyService.select(new URI(home)); if (select.length > 0) proxyData = select[0]; } catch (URISyntaxException e) { activator.logError(Messages.HttpClientFactory_bad_uri_for_proxy, e); } finally { activator.ungetProxyService(proxyService); } if (proxyData != null && proxyData.getHost() != null) { String proxyHost = proxyData.getHost(); String proxyPassword = proxyData.getPassword(); String proxyUsername = proxyData.getUserId(); int proxyPort = proxyData.getPort(); HostConfiguration hc = client.getHostConfiguration(); if (proxyPort < 0) hc.setHost(proxyHost); else hc.setProxy(proxyHost, proxyPort); if (proxyData.isRequiresAuthentication() && proxyUsername.length() > 0) { Credentials creds = new UsernamePasswordCredentials(proxyUsername, proxyPassword); client.getParams().setAuthenticationPreemptive(true); AuthScope scope = new AuthScope(proxyHost, proxyPort); client.getState().setProxyCredentials(scope, creds); } } client.getHttpConnectionManager().getParams().setConnectionTimeout(60000); client.getHttpConnectionManager().getParams().setSoTimeout(60000); client.getParams().setParameter(HttpMethodParams.RETRY_HANDLER, new DefaultHttpMethodRetryHandler(0, false)); return client; }