List of usage examples for org.apache.http.params HttpConnectionParamBean HttpConnectionParamBean
public HttpConnectionParamBean(HttpParams httpParams)
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 ww w . ja va2 s. c om } 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.piraso.ui.base.manager.HttpUpdateManager.java
public static HttpUpdateManager create() { ThreadSafeClientConnManager manager = new ThreadSafeClientConnManager(); manager.setDefaultMaxPerRoute(1);// w w w .j a v a2 s .c o m manager.setMaxTotal(1); HttpParams params = new BasicHttpParams(); // set timeout HttpConnectionParamBean connParamBean = new HttpConnectionParamBean(params); connParamBean.setConnectionTimeout(3000); connParamBean.setSoTimeout(1000 * 60 * 120); HttpClient client = new DefaultHttpClient(manager, params); HttpContext context = new BasicHttpContext(); return new HttpUpdateManager(client, context); }
From source file:com.alu.e3.gateway.loadbalancer.HttpLoadBalancerProducer.java
protected HttpRequestBase createMethod(Exchange exchange) throws URISyntaxException, CamelExchangeException { HttpRequestBase httpRequest = super.createMethod(exchange); HttpParams params = httpRequest.getParams(); Integer connectionTimeout = exchange.getProperty(ExchangeConstantKeys.E3_HTTP_CONNECTION_TIMEOUT.toString(), E3Constant.DEFAULT_HTTP_CONNECTION_TIMETOUT, Integer.class); Integer socketTimeout = exchange.getProperty(ExchangeConstantKeys.E3_HTTP_SOCKET_TIMEOUT.toString(), E3Constant.DEFAULT_HTTP_SOCKET_TIMEOUT, Integer.class); HttpConnectionParamBean httpConnectionParamBean = new HttpConnectionParamBean(params); httpConnectionParamBean.setConnectionTimeout(connectionTimeout); httpConnectionParamBean.setSoTimeout(socketTimeout); exchange.getIn().setHeader(HttpHeaders.HOST, httpRequest.getURI().getHost()); return httpRequest; }
From source file:org.piraso.io.impl.HttpEntrySource.java
private void initReader() { alive = false;/*from w w w . ja v a2 s . c o m*/ ThreadSafeClientConnManager manager = new ThreadSafeClientConnManager(); manager.setDefaultMaxPerRoute(2); manager.setMaxTotal(2); HttpParams params = new BasicHttpParams(); // set timeout HttpConnectionParamBean connParamBean = new HttpConnectionParamBean(params); connParamBean.setConnectionTimeout(3000); connParamBean.setSoTimeout(1000 * 60 * 120); HttpClient client = new DefaultHttpClient(manager, params); HttpContext context = new BasicHttpContext(); this.reader = new HttpPirasoEntryReader(client, context); reader.setUri(uri); reader.getStartHandler().setPreferences(preferences); if (watchedAddr != null) { reader.getStartHandler().setWatchedAddr(watchedAddr); } }
From source file:com.alu.e3.gateway.loadbalancer.E3HttpClientConfigurer.java
@Override public void configureHttpClient(HttpClient httpClient) { ClientConnectionManager clientConnectionManager = httpClient.getConnectionManager(); HttpParams params = httpClient.getParams(); // set Connection Pool Manager if (clientConnectionManager instanceof ThreadSafeClientConnManager) { setThreadSafeConnectionManager(clientConnectionManager); } else {//from ww w . j a v a2 s . com LOGGER.error( "The given settings for the HttpClient connection pool will be ignored: Unsupported implementation"); } // set HttpClient global setting HttpConnectionParamBean httpConnectionParamBean = new HttpConnectionParamBean(params); if (getSocketTimeOut() != null) { httpConnectionParamBean.setSoTimeout(getSocketTimeOut()); } // set HttpClient global connection timeout if (getConnectionTimeOut() != null) { httpConnectionParamBean.setConnectionTimeout(getConnectionTimeOut()); } // set HttpClient Proxy settings if (getForwardProxy() != null) { setForwardProxy(httpClient, params); } }
From source file:org.xmlsh.internal.commands.http.java
private void setOptions(DefaultHttpClient client, HttpHost host, Options opts) throws KeyManagementException, NoSuchAlgorithmException, UnrecoverableKeyException, CertificateException, FileNotFoundException, KeyStoreException, IOException { HttpParams params = client.getParams(); HttpConnectionParamBean connection = new HttpConnectionParamBean(params); if (opts.hasOpt("connectTimeout")) connection.setConnectionTimeout((int) (opts.getOptDouble("connectTimeout", 0) * 1000.)); if (opts.hasOpt("readTimeout")) connection.setSoTimeout((int) (opts.getOptDouble("readTimeout", 0) * 1000.)); /*// w w w. j a v a 2 s. c om * if( opts.hasOpt("useCaches")) * client.setUseCaches( opts.getOpt("useCaches").getFlag()); * * * if( opts.hasOpt("followRedirects")) * * client.setInstanceFollowRedirects( * opts.getOpt("followRedirects").getFlag()); * * * * * * * String disableTrustProto = opts.getOptString("disableTrust", null); * * String keyStore = opts.getOptString("keystore", null); * String keyPass = opts.getOptString("keypass", null); * String sslProto = opts.getOptString("sslProto", "SSLv3"); * * if(disableTrustProto != null && client instanceof HttpsURLConnection ) * disableTrust( (HttpsURLConnection) client , disableTrustProto ); * * else * if( keyStore != null ) * setClient( (HttpsURLConnection) client , keyStore , keyPass , sslProto ); * */ String disableTrustProto = opts.getOptString("disableTrust", null); if (disableTrustProto != null) disableTrust(client, disableTrustProto); String user = opts.getOptString("user", null); String pass = opts.getOptString("password", null); if (user != null && pass != null) { UsernamePasswordCredentials creds = new UsernamePasswordCredentials(user, pass); client.getCredentialsProvider().setCredentials(AuthScope.ANY, creds); /* * // Create AuthCache instance * AuthCache authCache = new BasicAuthCache(); * // Generate DIGEST scheme object, initialize it and add it to the local * // auth cache * DigestScheme digestAuth = new DigestScheme(); * // Suppose we already know the realm name * digestAuth.overrideParamter("realm", "some realm"); * // Suppose we already know the expected nonce value * digestAuth.overrideParamter("nonce", "whatever"); * authCache.put(host, digestAuth); * * // Add AuthCache to the execution context * BasicHttpContext localcontext = new BasicHttpContext(); * localcontext.setAttribute(ClientContext.AUTH_CACHE, authCache); */ } }
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; }