Example usage for org.apache.http.conn.params ConnManagerParamBean ConnManagerParamBean

List of usage examples for org.apache.http.conn.params ConnManagerParamBean ConnManagerParamBean

Introduction

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

Prototype

public ConnManagerParamBean(final HttpParams params) 

Source Link

Usage

From source file:org.apache.droids.examples.cli.SimpleRuntime.java

public static void main(String[] args) throws Exception {

    if (args.length < 1) {
        System.out.println("Please specify a URL to crawl");
        System.exit(-1);//from  www. j  a  va  2s . co  m
    }
    String targetURL = args[0];

    // Create parser factory. Support basic HTML markup only
    ParserFactory parserFactory = new ParserFactory();
    TikaDocumentParser tikaParser = new TikaDocumentParser();
    parserFactory.getMap().put("text/html", tikaParser);

    // Create protocol factory. Support HTTP/S only.
    ProtocolFactory protocolFactory = new ProtocolFactory();

    // Create and configure HTTP client
    HttpParams params = new BasicHttpParams();
    HttpProtocolParamBean hppb = new HttpProtocolParamBean(params);
    HttpConnectionParamBean hcpb = new HttpConnectionParamBean(params);
    ConnManagerParamBean cmpb = new ConnManagerParamBean(params);

    // Set protocol parametes
    hppb.setVersion(HttpVersion.HTTP_1_1);
    hppb.setContentCharset(HTTP.ISO_8859_1);
    hppb.setUseExpectContinue(true);
    // Set connection parameters
    hcpb.setStaleCheckingEnabled(false);
    // Set connection manager parameters
    ConnPerRouteBean connPerRouteBean = new ConnPerRouteBean();
    connPerRouteBean.setDefaultMaxPerRoute(2);
    cmpb.setConnectionsPerRoute(connPerRouteBean);

    DroidsHttpClient httpclient = new DroidsHttpClient(params);

    HttpProtocol httpProtocol = new HttpProtocol(httpclient);
    protocolFactory.getMap().put("http", httpProtocol);
    protocolFactory.getMap().put("https", httpProtocol);

    // Create URL filter factory.
    URLFiltersFactory filtersFactory = new URLFiltersFactory();
    RegexURLFilter defaultURLFilter = new RegexURLFilter();
    defaultURLFilter.setFile("classpath:/regex-urlfilter.txt");
    filtersFactory.getMap().put("default", defaultURLFilter);

    // Create handler factory. Provide sysout handler only.
    HandlerFactory handlerFactory = new HandlerFactory();
    SysoutHandler defaultHandler = new SysoutHandler();
    handlerFactory.getMap().put("default", defaultHandler);

    // Create droid factory. Leave it empty for now.
    DroidFactory<Link> droidFactory = new DroidFactory<Link>();

    // Create default droid
    SimpleDelayTimer simpleDelayTimer = new SimpleDelayTimer();
    simpleDelayTimer.setDelayMillis(100);

    Queue<Link> simpleQueue = new LinkedList<Link>();

    SequentialTaskMaster<Link> taskMaster = new SequentialTaskMaster<Link>();
    taskMaster.setDelayTimer(simpleDelayTimer);
    taskMaster.setExceptionHandler(new DefaultTaskExceptionHandler());

    CrawlingDroid helloCrawler = new SysoutCrawlingDroid(simpleQueue, taskMaster);
    helloCrawler.setFiltersFactory(filtersFactory);
    helloCrawler.setParserFactory(parserFactory);
    helloCrawler.setProtocolFactory(protocolFactory);

    Collection<String> initialLocations = new ArrayList<String>();
    initialLocations.add(targetURL);
    helloCrawler.setInitialLocations(initialLocations);

    // Initialize and start the crawler
    helloCrawler.init();
    helloCrawler.start();

    // Await termination
    helloCrawler.getTaskMaster().awaitTermination(0, TimeUnit.MILLISECONDS);
    // Shut down the HTTP connection manager
    httpclient.getConnectionManager().shutdown();
}

From source file:org.apache.camel.component.http4.HttpComponent.java

protected ClientConnectionManager createConnectionManager() {
    SchemeRegistry schemeRegistry = new SchemeRegistry();

    // configure additional configurations
    HttpParams params = new BasicHttpParams();
    ConnManagerParamBean param = new ConnManagerParamBean(params);
    if (getMaxTotalConnections() > 0) {
        param.setMaxTotalConnections(getMaxTotalConnections());
    }//  w ww.  j  a v  a  2 s.  c om
    if (getConnectionsPerRoute() > 0) {
        param.setConnectionsPerRoute(new ConnPerRouteBean(getConnectionsPerRoute()));
    }

    ThreadSafeClientConnManager answer = new ThreadSafeClientConnManager(params, schemeRegistry);
    LOG.info("Created ClientConnectionManager " + answer);

    return answer;
}

From source file:org.apache.camel.component.http4.HttpComponent.java

protected HttpParams configureHttpParams(Map<String, Object> parameters) throws Exception {
    HttpParams clientParams = new BasicHttpParams();

    AuthParamBean authParamBean = new AuthParamBean(clientParams);
    IntrospectionSupport.setProperties(authParamBean, parameters, "httpClient.");

    ClientParamBean clientParamBean = new ClientParamBean(clientParams);
    IntrospectionSupport.setProperties(clientParamBean, parameters, "httpClient.");

    ConnConnectionParamBean connConnectionParamBean = new ConnConnectionParamBean(clientParams);
    IntrospectionSupport.setProperties(connConnectionParamBean, parameters, "httpClient.");

    ConnManagerParamBean connManagerParamBean = new ConnManagerParamBean(clientParams);
    IntrospectionSupport.setProperties(connManagerParamBean, parameters, "httpClient.");

    ConnRouteParamBean connRouteParamBean = new ConnRouteParamBean(clientParams);
    IntrospectionSupport.setProperties(connRouteParamBean, parameters, "httpClient.");

    CookieSpecParamBean cookieSpecParamBean = new CookieSpecParamBean(clientParams);
    IntrospectionSupport.setProperties(cookieSpecParamBean, parameters, "httpClient.");

    HttpConnectionParamBean httpConnectionParamBean = new HttpConnectionParamBean(clientParams);
    IntrospectionSupport.setProperties(httpConnectionParamBean, parameters, "httpClient.");

    HttpProtocolParamBean httpProtocolParamBean = new HttpProtocolParamBean(clientParams);
    IntrospectionSupport.setProperties(httpProtocolParamBean, parameters, "httpClient.");

    return clientParams;
}