List of usage examples for org.apache.commons.httpclient.params HostParams setParameter
public void setParameter(String paramString, Object paramObject)
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 w w . ja v a 2 s. c om*/ } // 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.jetbrains.tfsIntegration.webservice.WebServiceHelper.java
private static void setCredentials(final @NotNull HttpClient httpClient, final @NotNull Credentials credentials, final @NotNull URI serverUri) { if (credentials.getType() == Credentials.Type.Alternate) { HostParams parameters = httpClient.getHostConfiguration().getParams(); Collection<Header> headers = (Collection<Header>) parameters.getParameter(HostParams.DEFAULT_HEADERS); if (headers == null) { headers = new ArrayList<Header>(); parameters.setParameter(HostParams.DEFAULT_HEADERS, headers); }//from w w w . j av a 2 s. c o m Header authHeader = ContainerUtil.find(headers, new Condition<Header>() { @Override public boolean value(Header header) { return header.getName().equals(HTTPConstants.HEADER_AUTHORIZATION); } }); if (authHeader == null) { authHeader = new Header(HTTPConstants.HEADER_AUTHORIZATION, ""); headers.add(authHeader); } authHeader.setValue(BasicScheme.authenticate( new UsernamePasswordCredentials(credentials.getUserName(), credentials.getPassword()), "UTF-8")); } else { final NTCredentials ntCreds = new NTCredentials(credentials.getUserName(), credentials.getPassword(), serverUri.getHost(), credentials.getDomain()); httpClient.getState().setCredentials(AuthScope.ANY, ntCreds); httpClient.getParams().setBooleanParameter(USE_NATIVE_CREDENTIALS, credentials.getType() == Credentials.Type.NtlmNative); } }