Example usage for org.apache.http.conn.params ConnRouteParamBean setDefaultProxy

List of usage examples for org.apache.http.conn.params ConnRouteParamBean setDefaultProxy

Introduction

In this page you can find the example usage for org.apache.http.conn.params ConnRouteParamBean setDefaultProxy.

Prototype

public void setDefaultProxy(final HttpHost defaultProxy) 

Source Link

Usage

From source file:com.alu.e3.gateway.loadbalancer.E3HttpClientConfigurer.java

/**
 * Sets global PROXY for HttpClient/*  w  w  w  .j a  v a 2s.  c  o  m*/
 * @param client HttpClient
 * @param params of the PROXY
 */
private void setForwardProxy(HttpClient client, HttpParams params) {

    if (forwardProxy != null) {

        if (client instanceof DefaultHttpClient) {

            String host = forwardProxy.getProxyHost();
            Integer port = new Integer(forwardProxy.getProxyPort());

            if (host != null && port != null) {

                HttpHost httpHost = new HttpHost(host, port);

                ConnRouteParamBean connRouteParamBean = new ConnRouteParamBean(params);
                connRouteParamBean.setDefaultProxy(httpHost);

                String user = forwardProxy.getProxyUser();
                String pass = forwardProxy.getProxyPass();

                if (user != null && pass != null) {

                    Credentials credentials = null;

                    String ntdomain = null; //targetHost.getForwardProxy().getProxyNtDomain;
                    String ntworkstation = null; //targetHost.getForwardProxy().getProxyNtWorkstation();

                    if (ntdomain != null || ntworkstation != null) {
                        credentials = new NTCredentials(user, pass, ntworkstation, ntdomain);
                    } else {
                        credentials = new UsernamePasswordCredentials(user, pass);
                    }

                    AuthScope authscope = new AuthScope(host, port);

                    DefaultHttpClient defaultHttpClient = (DefaultHttpClient) client;
                    defaultHttpClient.getCredentialsProvider().setCredentials(authscope, credentials);

                } else {
                    if (LOGGER.isDebugEnabled()) {
                        LOGGER.debug("The proxy is set with no user or password information");
                    }
                }

            } else {
                LOGGER.error("Unable to set proxy settings: Host or Port are NULL");
            }

        } else {
            LOGGER.error("Unable to set proxy settings: Unsupported HttpClient implementation");
        }
    }
}