Example usage for org.apache.http.params BasicHttpParams setBooleanParameter

List of usage examples for org.apache.http.params BasicHttpParams setBooleanParameter

Introduction

In this page you can find the example usage for org.apache.http.params BasicHttpParams setBooleanParameter.

Prototype

public HttpParams setBooleanParameter(String str, boolean z) 

Source Link

Usage

From source file:org.zaizi.sensefy.auth.user.acl.ManifoldACLRequester.java

@PostConstruct
public void init() {
    socketTimeOut = 300000;/*  w  w  w.  j a va2  s  .  c o  m*/
    poolSize = 50;

    // Initialize the connection pool
    httpConnectionManager = new PoolingClientConnectionManager();
    httpConnectionManager.setMaxTotal(poolSize);
    httpConnectionManager.setDefaultMaxPerRoute(poolSize);
    BasicHttpParams params = new BasicHttpParams();
    params.setBooleanParameter(CoreConnectionPNames.TCP_NODELAY, true);
    params.setBooleanParameter(CoreConnectionPNames.STALE_CONNECTION_CHECK, false);
    params.setIntParameter(CoreConnectionPNames.SO_TIMEOUT, socketTimeOut);
    DefaultHttpClient clientAux = new DefaultHttpClient(httpConnectionManager, params);
    clientAux.setRedirectStrategy(new DefaultRedirectStrategy());
    client = clientAux;
}

From source file:com.iflytek.cssp.SwiftAPI.SwiftClient.java

public SwiftClientResponse HeadContainer(String url, String Container, String accesskey, String secretkey)
        throws IOException, CSSPException {
    Map<String, String> headers = new LinkedHashMap<String, String>();
    BasicHttpParams httpParameters = new BasicHttpParams();
    HttpConnectionParams.setConnectionTimeout(httpParameters, connectionTimeout);
    HttpConnectionParams.setSoTimeout(httpParameters, soTimeout);
    //default enable auto redirect
    httpParameters.setBooleanParameter(ClientPNames.HANDLE_REDIRECTS, Boolean.TRUE);
    HttpClient httpClient = new DefaultHttpClient(httpParameters);
    HttpHead httphead = new HttpHead(url + "/" + encode(Container));

    CSSPSignature signature = new CSSPSignature("HEAD", null, "/" + Container, null, null);
    signature.getDate();//from w ww .ja  v  a2s  . c om
    String auth = signature.getSinature();
    String signa = signature.HmacSHA1Encrypt(auth, secretkey);
    httphead.addHeader(DATE, signature.Date);
    httphead.addHeader(AUTH, CSSP + accesskey + ":" + signa);

    //httphead.addHeader(AUTH_TOKEN,  token);
    HttpResponse response = httpClient.execute(httphead);
    Header[] Headers = response.getAllHeaders();
    for (Header Header : Headers) {
        headers.put(Header.getName(), Header.getValue());
    }
    if (isMatch_2XX(response.getStatusLine().getStatusCode()))//2xx 401
    {
        return new SwiftClientResponse(headers, response.getStatusLine().getStatusCode(),
                response.getStatusLine(), null, null);
    } else {
        logger.error("[get metadata for Container: error,  StatusCode is ]"
                + response.getStatusLine().getStatusCode());
        return new ExceptionHandle().ContainerExceptionHandle(response, headers);
    }
}

From source file:org.apache.manifoldcf.crawler.connectors.meridio.meridiowrapper.MeridioWrapper.java

/** The Meridio Wrapper constructor that calls the Meridio login method
*
*@param log                                     a handle to a Log4j logger
*@param meridioDmwsUrl          the URL to the Meridio Document Management Web Service
*@param meridioRmwsUrl          the URL to the Meridio Records Management Web Service
*@param dmwsProxyHost           the proxy for DMWS, or null if none
*@param dmwsProxyPort           the proxy port for DMWS, or -1 if default
*@param rmwsProxyHost           the proxy for RMWS, or null if none
*@param rmwsProxyPort           the proxy port for RMWS, or -1 if default
*@param userName                        the username of the user to log in as, must include the Windows, e.g. domain\\user
*@param password                        the password of the user who is logging in
*@param clientWorkstation       an identifier for the client workstation, could be the IP address, for auditing purposes
*@param protocolFactory         the protocol factory object to use for https communication
*@param engineConfigurationFile the engine configuration object to use to communicate with the web services
*
*@throws RemoteException        if an error is encountered logging into Meridio
*//*  w ww  . j a  va2  s  .c  o m*/
public MeridioWrapper(Logger log, URL meridioDmwsUrl, URL meridioRmwsUrl, URL meridioManifoldCFWSUrl,
        String dmwsProxyHost, String dmwsProxyPort, String rmwsProxyHost, String rmwsProxyPort,
        String mcwsProxyHost, String mcwsProxyPort, String userName, String password, String clientWorkstation,
        javax.net.ssl.SSLSocketFactory mySSLFactory, Class resourceClass, String engineConfigurationFile)
        throws RemoteException, NumberFormatException {
    // Initialize local instance variables
    oLog = log;
    this.engineConfiguration = new ResourceProvider(resourceClass, engineConfigurationFile);
    this.clientWorkstation = clientWorkstation;

    // Set up the pool.
    // We have a choice: We can either have one httpclient instance, which gets reinitialized for every service
    // it connects with (because each one has a potentially different proxy setup), OR we can have a different
    // httpclient for each service.  The latter approach is obviously the more efficient, so I've chosen to do it
    // that way.
    PoolingClientConnectionManager localConnectionManager = new PoolingClientConnectionManager();
    localConnectionManager.setMaxTotal(1);
    if (mySSLFactory != null) {
        SSLSocketFactory myFactory = new SSLSocketFactory(mySSLFactory, new BrowserCompatHostnameVerifier());
        Scheme myHttpsProtocol = new Scheme("https", 443, myFactory);
        localConnectionManager.getSchemeRegistry().register(myHttpsProtocol);
    }
    connectionManager = localConnectionManager;

    // Parse the user and password values
    int index = userName.indexOf("\\");
    String domainUser;
    String domain;
    if (index != -1) {
        domainUser = userName.substring(index + 1);
        domain = userName.substring(0, index);
        if (oLog != null && oLog.isDebugEnabled())
            oLog.debug("Meridio: User is '" + domainUser + "', domain is '" + domain + "'");
    } else {
        domain = null;
        domainUser = userName;
        if (oLog != null && oLog.isDebugEnabled())
            oLog.debug("Meridio: User is '" + domainUser + "'; there is no domain specified");
    }

    if (oLog != null && oLog.isDebugEnabled()) {
        if (password != null && password.length() > 0)
            oLog.debug("Meridio: Password exists");
        else
            oLog.debug("Meridio: Password is null");
    }

    // Initialize the three httpclient objects

    // dmws first
    BasicHttpParams dmwsParams = new BasicHttpParams();
    dmwsParams.setBooleanParameter(CoreConnectionPNames.TCP_NODELAY, true);
    dmwsParams.setBooleanParameter(CoreConnectionPNames.STALE_CONNECTION_CHECK, false);
    dmwsParams.setIntParameter(CoreConnectionPNames.CONNECTION_TIMEOUT, 60000);
    dmwsParams.setIntParameter(CoreConnectionPNames.SO_TIMEOUT, 900000);
    dmwsParams.setBooleanParameter(ClientPNames.ALLOW_CIRCULAR_REDIRECTS, true);
    DefaultHttpClient localDmwsHttpClient = new DefaultHttpClient(connectionManager, dmwsParams);
    // No retries
    localDmwsHttpClient.setHttpRequestRetryHandler(new HttpRequestRetryHandler() {
        public boolean retryRequest(IOException exception, int executionCount, HttpContext context) {
            return false;
        }

    });

    localDmwsHttpClient.setRedirectStrategy(new DefaultRedirectStrategy());
    if (domainUser != null) {
        localDmwsHttpClient.getCredentialsProvider().setCredentials(
                new AuthScope(meridioDmwsUrl.getHost(), meridioDmwsUrl.getPort()),
                new NTCredentials(domainUser, password, currentHost, domain));
    }
    // Initialize proxy
    if (dmwsProxyHost != null && dmwsProxyHost.length() > 0) {
        int port = (dmwsProxyPort == null || dmwsProxyPort.length() == 0) ? 8080
                : Integer.parseInt(dmwsProxyPort);
        // Configure proxy authentication
        if (domainUser != null && domainUser.length() > 0) {
            localDmwsHttpClient.getCredentialsProvider().setCredentials(new AuthScope(dmwsProxyHost, port),
                    new NTCredentials(domainUser, password, currentHost, domain));
        }

        HttpHost proxy = new HttpHost(dmwsProxyHost, port);
        localDmwsHttpClient.getParams().setParameter(ConnRoutePNames.DEFAULT_PROXY, proxy);
    }
    dmwsHttpClient = localDmwsHttpClient;

    // rmws
    BasicHttpParams rmwsParams = new BasicHttpParams();
    rmwsParams.setBooleanParameter(CoreConnectionPNames.TCP_NODELAY, true);
    rmwsParams.setBooleanParameter(CoreConnectionPNames.STALE_CONNECTION_CHECK, false);
    rmwsParams.setIntParameter(CoreConnectionPNames.CONNECTION_TIMEOUT, 60000);
    rmwsParams.setIntParameter(CoreConnectionPNames.SO_TIMEOUT, 900000);
    rmwsParams.setBooleanParameter(ClientPNames.ALLOW_CIRCULAR_REDIRECTS, true);
    DefaultHttpClient localRmwsHttpClient = new DefaultHttpClient(connectionManager, rmwsParams);
    // No retries
    localRmwsHttpClient.setHttpRequestRetryHandler(new HttpRequestRetryHandler() {
        public boolean retryRequest(IOException exception, int executionCount, HttpContext context) {
            return false;
        }

    });

    localRmwsHttpClient.setRedirectStrategy(new DefaultRedirectStrategy());
    if (domainUser != null) {
        localRmwsHttpClient.getCredentialsProvider().setCredentials(
                new AuthScope(meridioRmwsUrl.getHost(), meridioRmwsUrl.getPort()),
                new NTCredentials(domainUser, password, currentHost, domain));
    }
    // Initialize proxy
    if (rmwsProxyHost != null && rmwsProxyHost.length() > 0) {
        int port = (rmwsProxyPort == null || rmwsProxyPort.length() == 0) ? 8080
                : Integer.parseInt(rmwsProxyPort);
        // Configure proxy authentication
        if (domainUser != null && domainUser.length() > 0) {
            localRmwsHttpClient.getCredentialsProvider().setCredentials(new AuthScope(rmwsProxyHost, port),
                    new NTCredentials(domainUser, password, currentHost, domain));
        }

        HttpHost proxy = new HttpHost(rmwsProxyHost, port);
        localRmwsHttpClient.getParams().setParameter(ConnRoutePNames.DEFAULT_PROXY, proxy);
    }
    rmwsHttpClient = localRmwsHttpClient;

    // mcws
    if (meridioManifoldCFWSUrl != null) {
        BasicHttpParams mcwsParams = new BasicHttpParams();
        mcwsParams.setBooleanParameter(CoreConnectionPNames.TCP_NODELAY, true);
        mcwsParams.setBooleanParameter(CoreConnectionPNames.STALE_CONNECTION_CHECK, false);
        mcwsParams.setIntParameter(CoreConnectionPNames.CONNECTION_TIMEOUT, 60000);
        mcwsParams.setIntParameter(CoreConnectionPNames.SO_TIMEOUT, 900000);
        mcwsParams.setBooleanParameter(ClientPNames.ALLOW_CIRCULAR_REDIRECTS, true);
        DefaultHttpClient localMcwsHttpClient = new DefaultHttpClient(connectionManager, mcwsParams);
        // No retries
        localMcwsHttpClient.setHttpRequestRetryHandler(new HttpRequestRetryHandler() {
            public boolean retryRequest(IOException exception, int executionCount, HttpContext context) {
                return false;
            }

        });

        localMcwsHttpClient.setRedirectStrategy(new DefaultRedirectStrategy());
        if (domainUser != null) {
            localMcwsHttpClient.getCredentialsProvider().setCredentials(
                    new AuthScope(meridioManifoldCFWSUrl.getHost(), meridioManifoldCFWSUrl.getPort()),
                    new NTCredentials(domainUser, password, currentHost, domain));
        }
        // Initialize proxy
        if (mcwsProxyHost != null && mcwsProxyHost.length() > 0) {
            int port = (mcwsProxyPort == null || mcwsProxyPort.length() == 0) ? 8080
                    : Integer.parseInt(mcwsProxyPort);
            // Configure proxy authentication
            if (domainUser != null && domainUser.length() > 0) {
                localMcwsHttpClient.getCredentialsProvider().setCredentials(new AuthScope(mcwsProxyHost, port),
                        new NTCredentials(domainUser, password, currentHost, domain));
            }

            HttpHost proxy = new HttpHost(mcwsProxyHost, port);
            localMcwsHttpClient.getParams().setParameter(ConnRoutePNames.DEFAULT_PROXY, proxy);
        }
        mcwsHttpClient = localMcwsHttpClient;
    } else
        mcwsHttpClient = null;

    // Set up the stub handles
    /*=================================================================
    * Get a handle to the DMWS
    *================================================================*/
    MeridioDMLocator meridioDMLocator = new MeridioDMLocator(engineConfiguration);
    MeridioDMSoapStub meridioDMWebService = new MeridioDMSoapStub(meridioDmwsUrl, meridioDMLocator);

    meridioDMWebService.setPortName(meridioDMLocator.getMeridioDMSoapWSDDServiceName());
    meridioDMWebService.setUsername(userName);
    meridioDMWebService.setPassword(password);
    meridioDMWebService._setProperty(HTTPCLIENT_PROPERTY, dmwsHttpClient);

    meridioDMWebService_ = meridioDMWebService;

    /*=================================================================
    * Get a handle to the RMWS
    *================================================================*/
    MeridioRMLocator meridioRMLocator = new MeridioRMLocator(engineConfiguration);
    MeridioRMSoapStub meridioRMWebService = new MeridioRMSoapStub(meridioRmwsUrl, meridioRMLocator);

    meridioRMWebService.setPortName(meridioRMLocator.getMeridioRMSoapWSDDServiceName());
    meridioRMWebService.setUsername(userName);
    meridioRMWebService.setPassword(password);
    meridioRMWebService._setProperty(HTTPCLIENT_PROPERTY, rmwsHttpClient);

    meridioRMWebService_ = meridioRMWebService;

    /*=================================================================
    * Get a handle to the MeridioMetaCarta Web Service
    *================================================================*/
    if (meridioManifoldCFWSUrl != null) {
        MetaCartaLocator meridioMCWS = new MetaCartaLocator(engineConfiguration);
        Service McWsService = null;
        MetaCartaSoapStub meridioMetaCartaWebService = new MetaCartaSoapStub(meridioManifoldCFWSUrl,
                McWsService);

        meridioMetaCartaWebService.setPortName(meridioMCWS.getMetaCartaSoapWSDDServiceName());
        meridioMetaCartaWebService.setUsername(userName);
        meridioMetaCartaWebService.setPassword(password);
        meridioMetaCartaWebService._setProperty(HTTPCLIENT_PROPERTY, mcwsHttpClient);

        meridioMCWS_ = meridioMetaCartaWebService;
    }

    this.loginUnified();
}