Example usage for org.apache.commons.httpclient.cookie CookiePolicy DEFAULT

List of usage examples for org.apache.commons.httpclient.cookie CookiePolicy DEFAULT

Introduction

In this page you can find the example usage for org.apache.commons.httpclient.cookie CookiePolicy DEFAULT.

Prototype

String DEFAULT

To view the source code for org.apache.commons.httpclient.cookie CookiePolicy DEFAULT.

Click Source Link

Usage

From source file:com.agiletec.plugins.jpcasclient.aps.system.services.controller.control.CasClientTicketValidationUtil.java

/**
 * ticket validation /*w w w .  j av  a  2  s .  c  om*/
 * */
public Assertion validateTicket(String service, String ticket_key) throws ApsSystemException {
    Assertion assertion = null;
    MultiThreadedHttpConnectionManager connectionManager = new MultiThreadedHttpConnectionManager();
    _client = new HttpClient(connectionManager);
    GetMethod authget = new GetMethod();
    Map<String, String> params = new HashMap<String, String>();
    params.put("service", service);
    params.put("ticket", ticket_key);
    authget.getParams().setCookiePolicy(CookiePolicy.DEFAULT);
    String responseBodyValidation = null;
    String responseAssertion = null;
    String responseUser = null;
    responseBodyValidation = this.CASgetMethod(authget, _client, this._urlCasValidate, params);
    try {
        //    controllo della risposta sulla richiesta validazione ticket
        if (null != responseBodyValidation && responseBodyValidation.length() > 0) {
            InputStreamReader reader;
            reader = new InputStreamReader(authget.getResponseBodyAsStream());
            BufferedReader bufferedReader = new BufferedReader(reader);
            responseAssertion = bufferedReader.readLine();
            if (responseAssertion.equals(_positiveResponse)) {
                responseUser = bufferedReader.readLine();
            }
            ApsSystemUtils.getLogger().info("CasClientTicketValidationUtil - Assertion: " + responseAssertion
                    + " user: " + responseUser);
        }
    } catch (Throwable t) {
        _logger.error("Error in CasClientTicketValidationUtil - validateTicket", t);
        throw new ApsSystemException("Error in CasClientTicketValidationUtil - validateTicket", t);
    }
    if (null != responseAssertion && null != responseUser
            && responseAssertion.equalsIgnoreCase(_positiveResponse) && responseUser.length() > 0) {
        assertion = new AssertionImpl(responseUser);
    }
    return assertion;
}

From source file:ie.pars.nlp.sketchengine.interactions.SKEInteractionsBase.java

/**
 * Create a session id to communicate with the server
 *
 * @return//from  ww  w  .j a va2s  . co  m
 */
protected HttpClient getSessionID() {
    String cookie_policy = CookiePolicy.DEFAULT; //use CookiePolicy.BROWSER_COMPATIBILITY in case cookie handling does not work
    HttpClient client = new HttpClient();
    try {
        Protocol.registerProtocol("https",
                new Protocol("https", (ProtocolSocketFactory) new EasySSLProtocolSocketFactory(), 443));
        client.getHostConfiguration().setHost(rootURL, 80, "http");
        client.getParams().setCookiePolicy(cookie_policy);
    } catch (java.security.GeneralSecurityException | IOException e) {
        e.printStackTrace();
    }
    client.getParams().setCookiePolicy(cookie_policy);
    // retrieve session id
    GetMethod authget = new GetMethod("/login/");
    try {
        int code = client.executeMethod(authget);
    } catch (IOException ex) {
        System.err.println("Error: couldn't retrieve session ID from Sketch Engine server.");
        System.exit(1);
    }
    authget.releaseConnection();
    return client;

}

From source file:flex.messaging.services.http.HTTPConnectionManagerSettings.java

/**
 * Creates a default <code>HTTPConnectionManagerSettings</code> instance.
 *//*from   w ww  .  j  a v a  2  s.c om*/
public HTTPConnectionManagerSettings() {
    cookiePolicy = CookiePolicy.DEFAULT;
    defaultMaxConnectionsPerHost = DEFAULT_MAX_CONNECTIONS_HOST;
    maxTotalConnections = DEFAULT_MAX_TOTAL_CONNECTIONS;
    linger = -1;
    staleCheckingEnabled = true;
    tcpNoDelay = true;
}

From source file:com.compomics.mslims.util.mascot.MascotWebConnector.MascotAuthenticatedConnection.java

/**
 * create a web client, execute the command and set cookies
 * @param method//w w w.  j a va  2  s. co m
 * @throws org.apache.commons.httpclient.HttpException
 * @throws java.io.IOException
 */
public int executeMethod(PostMethod method) throws IOException {
    if (lConnectionProperties.contains("mascotserverport")) {
        client.getHostConfiguration().setHost(lConnectionProperties.getProperty("mascotserverlocation"),
                Integer.parseInt(lConnectionProperties.getProperty("mascotserverport")));
    } else {
        client.getHostConfiguration().setHost(lConnectionProperties.getProperty("mascotserverlocation"));
    }
    client.getParams().setCookiePolicy(CookiePolicy.DEFAULT);
    client.getParams().setConnectionManagerTimeout(0);
    int status = client.executeMethod(method);
    method.releaseConnection();

    return status;
}

From source file:de.mpg.escidoc.services.framework.AdminHelper.java

public static void logoutUser(String userHandle)
        throws HttpException, IOException, ServiceException, URISyntaxException {
    String frameworkUrl = ServiceLocator.getLoginUrl();

    int delim1 = frameworkUrl.indexOf("//");
    int delim2 = frameworkUrl.indexOf(":", delim1);

    String host;/*from w  ww  .j  a  v  a2  s  .  c o m*/
    int port;

    if (delim2 > 0) {
        host = frameworkUrl.substring(delim1 + 2, delim2);
        port = Integer.parseInt(frameworkUrl.substring(delim2 + 1));
    } else {
        host = frameworkUrl.substring(delim1 + 2);
        port = 80;
    }
    HttpClient client = new HttpClient();

    client.getParams().setCookiePolicy(CookiePolicy.DEFAULT);

    GetMethod getMethod = new GetMethod(frameworkUrl + "/aa/logout");
    client.getState().addCookie(new Cookie(host, "escidocCookie", userHandle, "/", null, false));
    //client.getState().addCookie(sessionCookie);
    ProxyHelper.executeMethod(client, getMethod);

    if (HttpServletResponse.SC_OK != getMethod.getStatusCode()) {
        throw new HttpException("Wrong status code: " + getMethod.getStatusCode());
    }

}

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  ww  .  j a va2 s.c  om
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();
}

From source file:flex.messaging.services.http.HTTPProxyAdapter.java

/**
 * Initializes the <code>HTTPProxyAdapter</code> with the properties.
 *
 * <pre>//from w  ww  .  java  2 s. c o  m
 * &lt;connection-manager&gt;
 *     &lt;cookie-policy&gt;rfc2109&lt;/cookie-policy&gt;
 *     &lt;max-total-connections&gt;100&lt;/max-total-connections&gt;
 *     &lt;default-max-connections-per-host&gt;2&lt;/default-max-connections-per-host&gt;
 *     &lt;connection-timeout&gt;0&lt;/connection-timeout&gt;
 *     &lt;socket-timeout&gt;&lt;/socket-timeout&gt;
 *     &lt;stale-checking-enabled&gt;&lt;/stale-checking-enabled&gt;
 *     &lt;send-buffer-size&gt;&lt;/send-buffer-size&gt;
 *     &lt;receive-buffer-size&gt;&lt;/receive-buffer-size&gt;
 *     &lt;tcp-no-delay&gt;true&lt;/tcp-no-delay&gt;
 *     &lt;linger&gt;-1&lt;/linger&gt;
 *     &lt;max-per-host&gt;
 *           &lt;host&gt;...&lt;/host&gt;
 *           &lt;port&gt;80&lt;/port&gt;
 *           &lt;protocol&gt;http&lt;/protocol&gt;
 *           &lt;protocol-factory class="flex.messaging.services.http.ProtocolFactory"&gt;
 *               &lt;properties&gt;...&lt;/properties&gt;
 *           &lt;/protocol-factory&gt;
 *           &lt;max-connections&gt;2&lt;/max-connections&gt;
 *           &lt;proxy&gt;
 *               &lt;host&gt;...&lt;/host&gt;
 *               &lt;port&gt;80&lt;/port&gt;
 *           &lt;/proxy&gt;
 *           &lt;local-address&gt;...&lt;/local-address&gt;
 *           &lt;virtual-host&gt;...&lt;/virtual-host&gt;
 *     &lt;/max-per-host&gt;
 *  &lt;/connection-manager&gt;
 *  &lt;cookie-limit&gt;200&lt;/cookie-limit&gt;
 *  &lt;allow-lax-ssl&gt;false&lt;/allow-lax-ssl&gt;
 *  &lt;content-chunked&gt;false&lt;/content-chunked&gt;
 *  &lt;external-proxy&gt;
 *      &lt;server&gt;...&lt;/server&gt;
 *      &lt;port&gt;80&lt;/port&gt;
 *      &lt;nt-domain&gt;...&lt;/nt-domain&gt;
 *      &lt;username&gt;...&lt;/username&gt;
 *      &lt;password&gt;...&lt;/password&gt;
 *  &lt;/external-proxy&gt;
 *  </pre>
 *
 * @param id         The id of the destination.
 * @param properties Properties for the <code>Destination</code>.
 */
public void initialize(String id, ConfigMap properties) {
    super.initialize(id, properties);

    if (properties == null || properties.size() == 0)
        return;

    // Connection Manager
    ConfigMap conn = properties.getPropertyAsMap(HTTPConnectionManagerSettings.CONNECTION_MANAGER, null);
    if (conn != null) {
        // Cookie policy.
        if (conn.getProperty(HTTPConnectionManagerSettings.COOKIE_POLICY) != null) {
            connectionManagerSettings.setCookiePolicy(conn
                    .getPropertyAsString(HTTPConnectionManagerSettings.COOKIE_POLICY, CookiePolicy.DEFAULT));
        }

        // Max Connections Total
        if (conn.getProperty(HTTPConnectionManagerSettings.MAX_TOTAL_CONNECTIONS) != null) {
            int maxTotal = conn.getPropertyAsInt(HTTPConnectionManagerSettings.MAX_TOTAL_CONNECTIONS,
                    MultiThreadedHttpConnectionManager.DEFAULT_MAX_TOTAL_CONNECTIONS);
            connectionManagerSettings.setMaxTotalConnections(maxTotal);
        }

        // Default Max Connections Per Host
        int defaultMaxConnsPerHost = MultiThreadedHttpConnectionManager.DEFAULT_MAX_HOST_CONNECTIONS;
        if (conn.getProperty(HTTPConnectionManagerSettings.DEFAULT_MAX_CONNECTIONS_PER_HOST) != null) {
            defaultMaxConnsPerHost = conn.getPropertyAsInt(
                    HTTPConnectionManagerSettings.DEFAULT_MAX_CONNECTIONS_PER_HOST,
                    MultiThreadedHttpConnectionManager.DEFAULT_MAX_HOST_CONNECTIONS);
            connectionManagerSettings.setDefaultMaxConnectionsPerHost(defaultMaxConnsPerHost);
        }

        // Connection Timeout
        if (conn.getProperty(HTTPConnectionManagerSettings.CONNECTION_TIMEOUT) != null) {
            int timeout = conn.getPropertyAsInt(HTTPConnectionManagerSettings.CONNECTION_TIMEOUT, 0);
            if (timeout >= 0)
                connectionManagerSettings.setConnectionTimeout(timeout);
        }

        // Socket Timeout
        if (conn.getProperty(HTTPConnectionManagerSettings.SOCKET_TIMEOUT) != null) {
            int timeout = conn.getPropertyAsInt(HTTPConnectionManagerSettings.SOCKET_TIMEOUT, 0);
            if (timeout >= 0)
                connectionManagerSettings.setSocketTimeout(timeout);
        }

        // Stale Checking
        if (conn.getProperty(HTTPConnectionManagerSettings.STALE_CHECKING_ENABLED) != null) {
            boolean staleCheck = conn.getPropertyAsBoolean(HTTPConnectionManagerSettings.STALE_CHECKING_ENABLED,
                    true);
            connectionManagerSettings.setStaleCheckingEnabled(staleCheck);
        }

        // Send Buffer Size
        if (conn.getProperty(HTTPConnectionManagerSettings.SEND_BUFFER_SIZE) != null) {
            int bufferSize = conn.getPropertyAsInt(HTTPConnectionManagerSettings.SEND_BUFFER_SIZE, 0);
            if (bufferSize > 0)
                connectionManagerSettings.setSendBufferSize(bufferSize);
        }

        // Send Receive Size
        if (conn.getProperty(HTTPConnectionManagerSettings.RECEIVE_BUFFER_SIZE) != null) {
            int bufferSize = conn.getPropertyAsInt(HTTPConnectionManagerSettings.RECEIVE_BUFFER_SIZE, 0);
            if (bufferSize > 0)
                connectionManagerSettings.setReceiveBufferSize(bufferSize);
        }

        // TCP No Delay (Nagel's Algorithm)
        if (conn.getProperty(HTTPConnectionManagerSettings.TCP_NO_DELAY) != null) {
            boolean noNagel = conn.getPropertyAsBoolean(HTTPConnectionManagerSettings.TCP_NO_DELAY, true);
            connectionManagerSettings.setTcpNoDelay(noNagel);
        }

        // Linger
        if (conn.getProperty(HTTPConnectionManagerSettings.LINGER) != null) {
            int linger = conn.getPropertyAsInt(HTTPConnectionManagerSettings.LINGER, -1);
            connectionManagerSettings.setLinger(linger);
        }

        // Max Connections Per Host
        List hosts = conn.getPropertyAsList(HTTPConnectionManagerSettings.MAX_PER_HOST, null);
        if (hosts != null) {
            List hostSettings = new ArrayList();
            Iterator it = hosts.iterator();
            while (it.hasNext()) {
                ConfigMap maxPerHost = (ConfigMap) it.next();
                HostConfigurationSettings hostConfig = new HostConfigurationSettings();

                // max-connections
                if (maxPerHost.getProperty(HostConfigurationSettings.MAX_CONNECTIONS) != null) {
                    int maxConn = maxPerHost.getPropertyAsInt(HostConfigurationSettings.MAX_CONNECTIONS,
                            defaultMaxConnsPerHost);
                    hostConfig.setMaximumConnections(maxConn);
                }

                // host
                if (maxPerHost.getProperty(HostConfigurationSettings.HOST) != null) {
                    String host = maxPerHost.getPropertyAsString(HostConfigurationSettings.HOST, null);
                    hostConfig.setHost(host);
                    if (host != null) {
                        // port
                        int port = maxPerHost.getPropertyAsInt(HostConfigurationSettings.PORT, 0);
                        hostConfig.setPort(port);

                        // protocol-factory
                        ConfigMap factoryMap = maxPerHost
                                .getPropertyAsMap(HostConfigurationSettings.PROTOCOL_FACFORY, null);
                        if (factoryMap != null) {
                            String className = factoryMap.getPropertyAsString(CLASS, null);
                            if (className != null) {
                                Class factoryClass = ClassUtil.createClass(className);
                                ProtocolFactory protocolFactory = (ProtocolFactory) ClassUtil
                                        .createDefaultInstance(factoryClass, ProtocolFactory.class);
                                String factoryId = factoryMap.getPropertyAsString(ID,
                                        host + "_protocol_factory");
                                ConfigMap protocolProperties = factoryMap.getPropertyAsMap(PROPERTIES, null);
                                protocolFactory.initialize(factoryId, protocolProperties);
                            }
                        }
                        // protocol
                        else {
                            String protocol = maxPerHost.getPropertyAsString(HostConfigurationSettings.PROTOCOL,
                                    null);
                            hostConfig.setProtocol(protocol);
                        }
                    }
                }

                // proxy
                ConfigMap proxy = maxPerHost.getPropertyAsMap(HostConfigurationSettings.PROXY, null);
                if (proxy != null) {
                    // host
                    String proxyHost = proxy.getPropertyAsString(HostConfigurationSettings.HOST, null);
                    hostConfig.setProxyHost(proxyHost);
                    if (proxyHost != null) {
                        // port
                        int port = proxy.getPropertyAsInt(HostConfigurationSettings.PORT, 0);
                        hostConfig.setProxyPort(port);
                    }
                }

                // local-address
                if (maxPerHost.getProperty(HostConfigurationSettings.LOCAL_ADDRESS) != null) {
                    String localAddress = maxPerHost
                            .getPropertyAsString(HostConfigurationSettings.LOCAL_ADDRESS, null);
                    hostConfig.setLocalAddress(localAddress);
                }

                // virtual-host
                if (maxPerHost.getProperty(HostConfigurationSettings.VIRTUAL_HOST) != null) {
                    String virtualHost = maxPerHost.getPropertyAsString(HostConfigurationSettings.VIRTUAL_HOST,
                            null);
                    hostConfig.setVirtualHost(virtualHost);
                }
                hostSettings.add(hostConfig);
            }

            if (hostSettings.size() > 0)
                connectionManagerSettings.setMaxConnectionsPerHost(hostSettings);
        }
        setConnectionManagerSettings(connectionManagerSettings);
    }

    // Cookie Limit
    if (properties.getProperty(COOKIE_LIMIT) != null) {
        int cl = properties.getPropertyAsInt(COOKIE_LIMIT, DEFAULT_COOKIE_LIMIT);
        setCookieLimit(cl);
    }

    // Allow Lax SSL
    if (properties.getProperty(ALLOW_LAX_SSL) != null) {
        boolean lax = properties.getPropertyAsBoolean(ALLOW_LAX_SSL, false);
        setAllowLaxSSL(lax);
    }

    // Content Chunked
    if (properties.getProperty(CONTENT_CHUNKED) != null) {
        boolean ch = properties.getPropertyAsBoolean(CONTENT_CHUNKED, false);
        setContentChunked(ch);
    }

    // External Proxy
    ConfigMap extern = properties.getPropertyAsMap(ExternalProxySettings.EXTERNAL_PROXY, null);
    if (extern != null) {
        ExternalProxySettings proxy = new ExternalProxySettings();

        String proxyServer = extern.getPropertyAsString(ExternalProxySettings.SERVER, null);
        proxy.setProxyServer(proxyServer);
        int proxyPort = extern.getPropertyAsInt(ExternalProxySettings.PORT,
                ExternalProxySettings.DEFAULT_PROXY_PORT);
        proxy.setProxyPort(proxyPort);
        String ntdomain = extern.getPropertyAsString(ExternalProxySettings.NT_DOMAIN, null);
        proxy.setNTDomain(ntdomain);
        String username = extern.getPropertyAsString(ExternalProxySettings.USERNAME, null);
        proxy.setUsername(username);
        String password = extern.getPropertyAsString(ExternalProxySettings.PASSWORD, null);
        proxy.setPassword(password);

        setExternalProxySettings(proxy);
    }
}

From source file:flex.messaging.services.http.HTTPProxyAdapter.java

private void initHttpConnectionManagerParams(HTTPConnectionManagerSettings settings) {
    connectionParams = new HttpConnectionManagerParams();
    connectionParams.setMaxTotalConnections(settings.getMaxTotalConnections());
    connectionParams.setDefaultMaxConnectionsPerHost(settings.getDefaultMaxConnectionsPerHost());

    if (!settings.getCookiePolicy().equals(CookiePolicy.DEFAULT)) {
        HttpClientParams httpClientParams = (HttpClientParams) connectionParams.getDefaults();
        httpClientParams.setCookiePolicy(settings.getCookiePolicy());
    }/* w w w . java 2s .  c  o  m*/

    if (settings.getConnectionTimeout() >= 0)
        connectionParams.setConnectionTimeout(settings.getConnectionTimeout());

    if (settings.getSocketTimeout() >= 0)
        connectionParams.setSoTimeout(settings.getSocketTimeout());

    connectionParams.setStaleCheckingEnabled(settings.isStaleCheckingEnabled());

    if (settings.getSendBufferSize() > 0)
        connectionParams.setSendBufferSize(settings.getSendBufferSize());

    if (settings.getReceiveBufferSize() > 0)
        connectionParams.setReceiveBufferSize(settings.getReceiveBufferSize());

    connectionParams.setTcpNoDelay(settings.isTcpNoDelay());
    connectionParams.setLinger(settings.getLinger());

    if (settings.getMaxConnectionsPerHost() != null) {
        Iterator it = settings.getMaxConnectionsPerHost().iterator();
        while (it.hasNext()) {
            HostConfigurationSettings hcs = (HostConfigurationSettings) it.next();
            HostConfiguration hostConfig = new HostConfiguration();

            if (hcs.getProtocol() != null) {
                Protocol protocol = Protocol.getProtocol(hcs.getProtocol());
                hostConfig.setHost(hcs.getHost(), hcs.getPort(), protocol);
            } else if (hcs.getProtocolFactory() != null) {
                Protocol protocol = hcs.getProtocolFactory().getProtocol();
                if (hcs.getPort() > 0)
                    hostConfig.setHost(hcs.getHost(), hcs.getPort(), protocol);
                else
                    hostConfig.setHost(hcs.getHost(), protocol.getDefaultPort(), protocol);
            } else {
                if (hcs.getPort() > 0)
                    hostConfig.setHost(hcs.getHost(), hcs.getPort());
                else
                    hostConfig.setHost(hcs.getHost());
            }

            if (hcs.getVirtualHost() != null) {
                HostParams params = hostConfig.getParams();
                if (params != null)
                    params.setVirtualHost(hcs.getVirtualHost());
            }

            if (hcs.getProxyHost() != null) {
                hostConfig.setProxy(hcs.getProxyHost(), hcs.getProxyPort());
            }

            try {
                InetAddress addr = InetAddress.getByName(hcs.getLocalAddress());
                hostConfig.setLocalAddress(addr);
            } catch (UnknownHostException ex) {
            }
            connectionParams.setMaxConnectionsPerHost(hostConfig, hcs.getMaximumConnections());
        }
    }
}