• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Java SimpleHttpConnectionManager类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Java中org.apache.commons.httpclient.SimpleHttpConnectionManager的典型用法代码示例。如果您正苦于以下问题:Java SimpleHttpConnectionManager类的具体用法?Java SimpleHttpConnectionManager怎么用?Java SimpleHttpConnectionManager使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



SimpleHttpConnectionManager类属于org.apache.commons.httpclient包,在下文中一共展示了SimpleHttpConnectionManager类的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: HttpClient

import org.apache.commons.httpclient.SimpleHttpConnectionManager; //导入依赖的package包/类
public HttpClient(int maxConPerHost, int conTimeOutMs, int soTimeOutMs,
			int maxSize) {
		
//		MultiThreadedHttpConnectionManager connectionManager = new MultiThreadedHttpConnectionManager();
		SimpleHttpConnectionManager connectionManager = new SimpleHttpConnectionManager(true);
		HttpConnectionManagerParams params = connectionManager.getParams();
		params.setDefaultMaxConnectionsPerHost(maxConPerHost);
		params.setConnectionTimeout(conTimeOutMs);
		params.setSoTimeout(soTimeOutMs);

		HttpClientParams clientParams = new HttpClientParams();
		clientParams.setCookiePolicy(CookiePolicy.IGNORE_COOKIES);
		client = new org.apache.commons.httpclient.HttpClient(clientParams,
				connectionManager);
		Protocol myhttps = new Protocol("https", new MySSLSocketFactory(), 443);
		Protocol.registerProtocol("https", myhttps);
	}
 
开发者ID:dehuinet,项目名称:minxing_java_sdk,代码行数:18,代码来源:HttpClient.java


示例2: shutdown

import org.apache.commons.httpclient.SimpleHttpConnectionManager; //导入依赖的package包/类
private void shutdown(HttpMethodBase method) {
    if (method != null) {
        method.releaseConnection();
    }
    if (!externalConnectionManager) {
        ((SimpleHttpConnectionManager) httpConnectionManager).shutdown();
    }
}
 
开发者ID:bingoohuang,项目名称:javacode-demo,代码行数:9,代码来源:HttpReq.java


示例3: initHttpClient

import org.apache.commons.httpclient.SimpleHttpConnectionManager; //导入依赖的package包/类
private void initHttpClient() {
    HostConfiguration hostConfiguration = new HostConfiguration();

    SimpleHttpConnectionManager connectionManager = new SimpleHttpConnectionManager();
    connectionManager.closeIdleConnections(5000L);

    HttpConnectionManagerParams params = new HttpConnectionManagerParams();
    params.setStaleCheckingEnabled(diamondConfigure.isConnectionStaleCheckingEnabled());
    params.setConnectionTimeout(diamondConfigure.getConnectionTimeout());
    connectionManager.setParams(params);

    configHttpClient = new HttpClient(connectionManager);
    configHttpClient.setHostConfiguration(hostConfiguration);
}
 
开发者ID:lysu,项目名称:diamond,代码行数:15,代码来源:ServerAddressProcessor.java


示例4: interrupt

import org.apache.commons.httpclient.SimpleHttpConnectionManager; //导入依赖的package包/类
/** {@inheritDoc} */
@Override
public boolean interrupt() {
    HttpClient client = savedClient;
    if (client != null) {
        savedClient = null;
        // TODO - not sure this is the best method
        final HttpConnectionManager httpConnectionManager = client.getHttpConnectionManager();
        if (httpConnectionManager instanceof SimpleHttpConnectionManager) {// Should be true
            ((SimpleHttpConnectionManager)httpConnectionManager).shutdown();
        }
    }
    return client != null;
}
 
开发者ID:johrstrom,项目名称:cloud-meter,代码行数:15,代码来源:HTTPHC3Impl.java


示例5: start

import org.apache.commons.httpclient.SimpleHttpConnectionManager; //导入依赖的package包/类
/**
 * {@inheritDoc}
 */
@Override
public void start() throws HomematicClientException {
	logger.info("Starting {}", CcuClient.class.getSimpleName());
	super.start();

	tclregaScripts = loadTclRegaScripts();

	httpClient = new HttpClient(new SimpleHttpConnectionManager(true));
	HttpClientParams params = httpClient.getParams();
	Long timeout = context.getConfig().getTimeout() * 1000L;
	params.setConnectionManagerTimeout(timeout);
	params.setSoTimeout(timeout.intValue());
	params.setContentCharset("ISO-8859-1");
}
 
开发者ID:andrey-desman,项目名称:openhab-hdl,代码行数:18,代码来源:CcuClient.java


示例6: start

import org.apache.commons.httpclient.SimpleHttpConnectionManager; //导入依赖的package包/类
/**
 * {@inheritDoc}
 */
@Override
public void start() throws HomematicClientException {
    logger.info("Starting {}", CcuClient.class.getSimpleName());
    super.start();

    tclregaScripts = loadTclRegaScripts();

    httpClient = new HttpClient(new SimpleHttpConnectionManager(true));
    HttpClientParams params = httpClient.getParams();
    Long timeout = context.getConfig().getTimeout() * 1000L;
    params.setConnectionManagerTimeout(timeout);
    params.setSoTimeout(timeout.intValue());
    params.setContentCharset("ISO-8859-1");
}
 
开发者ID:openhab,项目名称:openhab1-addons,代码行数:18,代码来源:CcuClient.java


示例7: initHttpClient

import org.apache.commons.httpclient.SimpleHttpConnectionManager; //导入依赖的package包/类
private void initHttpClient() {
	HostConfiguration hostConfiguration = new HostConfiguration();

	SimpleHttpConnectionManager connectionManager = new SimpleHttpConnectionManager();
	connectionManager.closeIdleConnections(5000L);

	HttpConnectionManagerParams params = new HttpConnectionManagerParams();
	params.setStaleCheckingEnabled(diamondConfigure
			.isConnectionStaleCheckingEnabled());
	params.setConnectionTimeout(diamondConfigure.getConnectionTimeout());
	connectionManager.setParams(params);

	configHttpClient = new HttpClient(connectionManager);
	configHttpClient.setHostConfiguration(hostConfiguration);
}
 
开发者ID:weijiahao001,项目名称:tb_diamond,代码行数:16,代码来源:ServerAddressProcessor.java


示例8: testFailConnection

import org.apache.commons.httpclient.SimpleHttpConnectionManager; //导入依赖的package包/类
@Test(expected=IOException.class)
public void testFailConnection() throws Exception {
  SimpleHttpConnectionManager simple = new SimpleHttpConnectionManager();
  HttpClient http = new HttpClient(simple);
  ReviewboardConnection bad =
      new ReviewboardConnection(System.getProperty("reviewboard.url", "https://reviewboard.eng.vmware.com/"),
          System.getProperty("reviewboard.user"), "foobar");
  try {
    ReviewboardOps.ensureAuthentication(bad, http);
  } finally {
    simple.shutdown();
  }

}
 
开发者ID:vmware,项目名称:jenkins-reviewbot,代码行数:15,代码来源:ConnectionTest.java


示例9: isGovCloud

import org.apache.commons.httpclient.SimpleHttpConnectionManager; //导入依赖的package包/类
private static boolean isGovCloud()
/*     */   {
/* 486 */     if (ec2MetaDataAz != null) {
/* 487 */       return ec2MetaDataAz.startsWith("us-gov-west-1");
/*     */     }
/*     */ 
/* 492 */     String hostname = getHostName();
/* 493 */     int timeout = hostname.startsWith("ip-") ? 30000 : 5000;
/* 494 */     GetMethod getMethod = new GetMethod("http://169.254.169.254/latest/meta-data/placement/availability-zone");
/*     */     try {
/* 496 */       HttpConnectionManager manager = new SimpleHttpConnectionManager();
/* 497 */       HttpConnectionManagerParams params = manager.getParams();
/*     */ 
/* 499 */       params.setConnectionTimeout(timeout);
/*     */ 
/* 501 */       params.setSoTimeout(timeout);
/* 502 */       HttpClient httpClient = new HttpClient(manager);
/* 503 */       int status = httpClient.executeMethod(getMethod);
/* 504 */       if ((status < 200) || (status > 299)) {
/* 505 */         LOG.info("error status code" + status + " GET " + "http://169.254.169.254/latest/meta-data/placement/availability-zone");
/*     */       } else {
/* 507 */         ec2MetaDataAz = getMethod.getResponseBodyAsString().trim();
/* 508 */         LOG.info("GET http://169.254.169.254/latest/meta-data/placement/availability-zone result: " + ec2MetaDataAz);
/* 509 */         return ec2MetaDataAz.startsWith("us-gov-west-1");
/*     */       }
/*     */     } catch (Exception e) {
/* 512 */       LOG.info("GET http://169.254.169.254/latest/meta-data/placement/availability-zone exception ", e);
/*     */     } finally {
/* 514 */       getMethod.releaseConnection();
/*     */     }
/* 516 */     return false;
/*     */   }
 
开发者ID:libin,项目名称:s3distcp,代码行数:33,代码来源:S3DistCp.java


示例10: initDownloadThread

import org.apache.commons.httpclient.SimpleHttpConnectionManager; //导入依赖的package包/类
private void initDownloadThread() {
    client.getHTTPClient().setHttpConnectionManager(new SimpleHttpConnectionManager());
    client.getHTTPClient().getHttpConnectionManager().closeIdleConnections(0);
}
 
开发者ID:jhkst,项目名称:dlface,代码行数:5,代码来源:FrdHttpFileDownloadTask.java


示例11: doPost

import org.apache.commons.httpclient.SimpleHttpConnectionManager; //导入依赖的package包/类
/**
 * 通过http的post方式请求数据  connectionTimeOut:建立连接的超时时间,soTimeOut:等待返回结果的超时时间
 * @param urlString
 * @param params
 * @param encode
 * @param connectionTimeOut
 * @param soTimeOut
 * @return
 * @throws IOException 
 * @throws HttpException 
 * @throws Exception
 * @Author YHJ create at 2014年5月14日 下午4:36:02
 */
public static String doPost(String urlString, Map<String, String> params) throws HttpException, IOException {
	PostMethod method = new PostMethod(urlString);
	HttpClient client = null;
	try {
		Set<String> keys = params.keySet();
		NameValuePair[] values = new NameValuePair[keys.size()];
		int i = 0;
		for (String key : keys) {
			NameValuePair v = new NameValuePair();
			v.setName(key);
			v.setValue(params.get(key));
			values[i] = v;
			i++;
		}
		
		client = new HttpClient();
		client.getHostConfiguration().setHost(urlString, 80, "http");
		client.getHttpConnectionManager().getParams().setConnectionTimeout(30000);// 建立连接的超时时间
		client.getHttpConnectionManager().getParams().setSoTimeout(30000);// 等待请求结果的超时时间
		if (StringUtils.isNotBlank(encode))
			client.getParams().setParameter(
					HttpMethodParams.HTTP_CONTENT_CHARSET, encode);
		method.setRequestBody(values); // 使用 POST 方式提交数据
		int state = client.executeMethod(method);   //返回的状态 
		if(state != HttpStatus.SC_OK){
			throw new RuntimeException("HttpStatus is "+state);
		} 
		return inputStreamToString(method.getResponseBodyAsStream(), encode);
	} finally {
		//releaseConnection方法不能关闭socket连接
           //使用SimpleHttpConnectionManager的shutdown方法强制关闭
		method.releaseConnection();
		if (client != null ) {
            HttpConnectionManager manager = client.getHttpConnectionManager();
            if (manager instanceof SimpleHttpConnectionManager) {
                SimpleHttpConnectionManager tmp = (SimpleHttpConnectionManager)manager;
                tmp.shutdown();
            }
		}
	}
}
 
开发者ID:shuqin,项目名称:ALLIN,代码行数:55,代码来源:HttpUtil.java


示例12: execute

import org.apache.commons.httpclient.SimpleHttpConnectionManager; //导入依赖的package包/类
/**
 * This method performs the proxying of the request to the target address.
 *
 * @param target     The target address. Has to be a fully qualified address. The request is send as-is to this address.
 * @param hsRequest  The request data which should be send to the
 * @param hsResponse The response data which will contain the data returned by the proxied request to target.
 * @throws java.io.IOException Passed on from the connection logic.
 */
public static void execute(final String target, final HttpServletRequest hsRequest, final HttpServletResponse hsResponse) throws IOException {
    if ( log.isInfoEnabled() ) {
        log.info("execute, target is " + target);
        log.info("response commit state: " + hsResponse.isCommitted());
    }

    if (StringUtils.isBlank(target)) {
        log.error("The target address is not given. Please provide a target address.");
        return;
    }

    log.info("checking url");
    final URL url;
    try {
        url = new URL(target);
    } catch (MalformedURLException e) {
        log.error("The provided target url is not valid.", e);
        return;
    }

    log.info("seting up the host configuration");

    final HostConfiguration config = new HostConfiguration();

    ProxyHost proxyHost = getUseProxyServer((String) hsRequest.getAttribute("use-proxy"));
    if (proxyHost != null) config.setProxyHost(proxyHost);

    final int port = url.getPort() != -1 ? url.getPort() : url.getDefaultPort();
    config.setHost(url.getHost(), port, url.getProtocol());

    if ( log.isInfoEnabled() ) log.info("config is " + config.toString());

    final HttpMethod targetRequest = setupProxyRequest(hsRequest, url);
    if (targetRequest == null) {
        log.error("Unsupported request method found: " + hsRequest.getMethod());
        return;
    }

    //perform the reqeust to the target server
    final HttpClient client = new HttpClient(new SimpleHttpConnectionManager());
    if (log.isInfoEnabled()) {
        log.info("client state" + client.getState());
        log.info("client params" + client.getParams().toString());
        log.info("executeMethod / fetching data ...");
    }

    final int result;
    if (targetRequest instanceof EntityEnclosingMethod) {
        final RequestProxyCustomRequestEntity requestEntity = new RequestProxyCustomRequestEntity(
                hsRequest.getInputStream(), hsRequest.getContentLength(), hsRequest.getContentType());
        final EntityEnclosingMethod entityEnclosingMethod = (EntityEnclosingMethod) targetRequest;
        entityEnclosingMethod.setRequestEntity(requestEntity);
        result = client.executeMethod(config, entityEnclosingMethod);

    } else {
        result = client.executeMethod(config, targetRequest);
    }

    //copy the target response headers to our response
    setupResponseHeaders(targetRequest, hsResponse);

    InputStream originalResponseStream = targetRequest.getResponseBodyAsStream();
    //the body might be null, i.e. for responses with cache-headers which leave out the body
    if (originalResponseStream != null) {
        OutputStream responseStream = hsResponse.getOutputStream();
        copyStream(originalResponseStream, responseStream);
    }

    log.info("set up response, result code was " + result);
}
 
开发者ID:paultuckey,项目名称:urlrewritefilter,代码行数:79,代码来源:RequestProxy.java



注:本文中的org.apache.commons.httpclient.SimpleHttpConnectionManager类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java IHAListener类代码示例发布时间:2022-05-21
下一篇:
Java StoredProcedureQuery类代码示例发布时间:2022-05-21
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap