本文整理汇总了Java中org.apache.http.params.CoreConnectionPNames类的典型用法代码示例。如果您正苦于以下问题:Java CoreConnectionPNames类的具体用法?Java CoreConnectionPNames怎么用?Java CoreConnectionPNames使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
CoreConnectionPNames类属于org.apache.http.params包,在下文中一共展示了CoreConnectionPNames类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: postUrl
import org.apache.http.params.CoreConnectionPNames; //导入依赖的package包/类
public static String postUrl(String url, String body) {
HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost(url);
httppost.getParams().setParameter(HttpProtocolParams.HTTP_CONTENT_CHARSET, "UTF-8");
//请求超时 ,连接超时
httpclient.getParams().setParameter(CoreConnectionPNames.CONNECTION_TIMEOUT, CONNECTION_TIMEOUT);
//读取超时
httpclient.getParams().setParameter(CoreConnectionPNames.SO_TIMEOUT, SO_TIMEOUT);
try {
StringEntity entity = new StringEntity(body, "UTF-8");
httppost.setEntity(entity);
System.out.println(entity.toString());
HttpResponse response = httpclient.execute(httppost);
if (response.getStatusLine().getStatusCode() == HttpStatus.SC_OK) {
String charsetName = EntityUtils.getContentCharSet(response.getEntity());
//System.out.println(charsetName + "<<<<<<<<<<<<<<<<<");
String rs = EntityUtils.toString(response.getEntity());
//System.out.println( ">>>>>>" + rs);
return rs;
} else {
//System.out.println("Eorr occus");
}
} catch (Exception e) {
e.printStackTrace();
} finally {
httpclient.getConnectionManager().shutdown();
}
return "";
}
示例2: initSubtitleResource
import org.apache.http.params.CoreConnectionPNames; //导入依赖的package包/类
public void initSubtitleResource(final String url) {
new Thread(new Runnable() {
@Override
public void run() {
try {
HttpClient client = new DefaultHttpClient();
client.getParams().setParameter(
CoreConnectionPNames.CONNECTION_TIMEOUT, 5000);
HttpGet httpGet = new HttpGet(url);
HttpResponse response = client.execute(httpGet);
HttpEntity entity = response.getEntity();
String results = EntityUtils.toString(entity, "utf-8");
parseSubtitleStr(results);
} catch (Exception e) {
Log.e("CCVideoViewDemo", "" + e.getMessage());
}
}
}).start();
}
示例3: testConnection
import org.apache.http.params.CoreConnectionPNames; //导入依赖的package包/类
public boolean testConnection() throws ConnectionTestException {
// store the old timeouts
Integer oldTimeout = getIntClientParameter(CoreConnectionPNames.CONNECTION_TIMEOUT);
Integer oldSocketTimeout = getIntClientParameter(CoreConnectionPNames.SO_TIMEOUT);
boolean isValid = false;
try {
int tempTime = HCPMoverProperties.CONNECTION_TEST_TIMEOUT_OVERRIDE_MS.getAsInt();
setIntClientParameter(tempTime, CoreConnectionPNames.CONNECTION_TIMEOUT);
setIntClientParameter(tempTime, CoreConnectionPNames.SO_TIMEOUT);
isValid = doTestConnection();
} finally {
// restore the old timeouts
setIntClientParameter(oldTimeout, CoreConnectionPNames.CONNECTION_TIMEOUT);
setIntClientParameter(oldSocketTimeout, CoreConnectionPNames.SO_TIMEOUT);
}
return isValid;
}
示例4: init
import org.apache.http.params.CoreConnectionPNames; //导入依赖的package包/类
/**
* Initializes this session input buffer.
*
* @param instream the source input stream.
* @param buffersize the size of the internal buffer.
* @param params HTTP parameters.
*/
protected void init(final InputStream instream, int buffersize, final HttpParams params) {
if (instream == null) {
throw new IllegalArgumentException("Input stream may not be null");
}
if (buffersize <= 0) {
throw new IllegalArgumentException("Buffer size may not be negative or zero");
}
if (params == null) {
throw new IllegalArgumentException("HTTP parameters may not be null");
}
this.instream = instream;
this.buffer = new byte[buffersize];
this.bufferpos = 0;
this.bufferlen = 0;
this.linebuffer = new ByteArrayBuffer(buffersize);
this.charset = Charset.forName(HttpProtocolParams.getHttpElementCharset(params));
this.ascii = this.charset.equals(ASCII);
this.decoder = null;
this.maxLineLen = params.getIntParameter(CoreConnectionPNames.MAX_LINE_LENGTH, -1);
this.minChunkLimit = params.getIntParameter(CoreConnectionPNames.MIN_CHUNK_LIMIT, 512);
this.metrics = createTransportMetrics();
this.onMalformedInputAction = HttpProtocolParams.getMalformedInputAction(params);
this.onUnMappableInputAction = HttpProtocolParams.getUnmappableInputAction(params);
}
示例5: init
import org.apache.http.params.CoreConnectionPNames; //导入依赖的package包/类
/**
* Initializes this session output buffer.
*
* @param outstream the destination output stream.
* @param buffersize the size of the internal buffer.
* @param params HTTP parameters.
*/
protected void init(final OutputStream outstream, int buffersize, final HttpParams params) {
if (outstream == null) {
throw new IllegalArgumentException("Input stream may not be null");
}
if (buffersize <= 0) {
throw new IllegalArgumentException("Buffer size may not be negative or zero");
}
if (params == null) {
throw new IllegalArgumentException("HTTP parameters may not be null");
}
this.outstream = outstream;
this.buffer = new ByteArrayBuffer(buffersize);
this.charset = Charset.forName(HttpProtocolParams.getHttpElementCharset(params));
this.ascii = this.charset.equals(ASCII);
this.encoder = null;
this.minChunkLimit = params.getIntParameter(CoreConnectionPNames.MIN_CHUNK_LIMIT, 512);
this.metrics = createTransportMetrics();
this.onMalformedInputAction = HttpProtocolParams.getMalformedInputAction(params);
this.onUnMappableInputAction = HttpProtocolParams.getUnmappableInputAction(params);
}
示例6: AbstractMessageParser
import org.apache.http.params.CoreConnectionPNames; //导入依赖的package包/类
/**
* Creates an instance of this class.
*
* @param buffer the session input buffer.
* @param parser the line parser.
* @param params HTTP parameters.
*/
public AbstractMessageParser(
final SessionInputBuffer buffer,
final LineParser parser,
final HttpParams params) {
super();
if (buffer == null) {
throw new IllegalArgumentException("Session input buffer may not be null");
}
if (params == null) {
throw new IllegalArgumentException("HTTP parameters may not be null");
}
this.sessionBuffer = buffer;
this.maxHeaderCount = params.getIntParameter(
CoreConnectionPNames.MAX_HEADER_COUNT, -1);
this.maxLineLen = params.getIntParameter(
CoreConnectionPNames.MAX_LINE_LENGTH, -1);
this.lineParser = (parser != null) ? parser : BasicLineParser.DEFAULT;
this.headerLines = new ArrayList<CharArrayBuffer>();
this.state = HEAD_LINE;
}
示例7: httpGet
import org.apache.http.params.CoreConnectionPNames; //导入依赖的package包/类
/**
* HTTP GET
* @param host
* @param path
* @param connectTimeout
* @param headers
* @param querys
* @param signHeaderPrefixList
* @param appKey
* @param appSecret
* @return
* @throws Exception
*/
public static Response httpGet(String host, String path, int connectTimeout, Map<String, String> headers, Map<String, String> querys, List<String> signHeaderPrefixList, String appKey, String appSecret)
throws Exception {
headers = initialBasicHeader(HttpMethod.GET, path, headers, querys, null, signHeaderPrefixList, appKey, appSecret);
HttpClient httpClient = wrapClient(host);
httpClient.getParams().setParameter(CoreConnectionPNames.CONNECTION_TIMEOUT, getTimeout(connectTimeout));
HttpGet get = new HttpGet(initUrl(host, path, querys));
for (Map.Entry<String, String> e : headers.entrySet()) {
get.addHeader(e.getKey(), MessageDigestUtil.utf8ToIso88591(e.getValue()));
}
return convert(httpClient.execute(get));
}
示例8: httpPost
import org.apache.http.params.CoreConnectionPNames; //导入依赖的package包/类
/**
* HTTP POST表单
* @param host
* @param path
* @param connectTimeout
* @param headers
* @param querys
* @param bodys
* @param signHeaderPrefixList
* @param appKey
* @param appSecret
* @return
* @throws Exception
*/
public static Response httpPost(String host, String path, int connectTimeout, Map<String, String> headers, Map<String, String> querys, Map<String, String> bodys, List<String> signHeaderPrefixList, String appKey, String appSecret)
throws Exception {
if (headers == null) {
headers = new HashMap<String, String>();
}
headers.put(HttpHeader.HTTP_HEADER_CONTENT_TYPE, ContentType.CONTENT_TYPE_FORM);
headers = initialBasicHeader(HttpMethod.POST, path, headers, querys, bodys, signHeaderPrefixList, appKey, appSecret);
HttpClient httpClient = wrapClient(host);
httpClient.getParams().setParameter(CoreConnectionPNames.CONNECTION_TIMEOUT, getTimeout(connectTimeout));
HttpPost post = new HttpPost(initUrl(host, path, querys));
for (Map.Entry<String, String> e : headers.entrySet()) {
post.addHeader(e.getKey(), MessageDigestUtil.utf8ToIso88591(e.getValue()));
}
UrlEncodedFormEntity formEntity = buildFormEntity(bodys);
if (formEntity != null) {
post.setEntity(formEntity);
}
return convert(httpClient.execute(post));
}
示例9: httpPut
import org.apache.http.params.CoreConnectionPNames; //导入依赖的package包/类
/**
* HTTP PUT 字符串
* @param host
* @param path
* @param connectTimeout
* @param headers
* @param querys
* @param body
* @param signHeaderPrefixList
* @param appKey
* @param appSecret
* @return
* @throws Exception
*/
public static Response httpPut(String host, String path, int connectTimeout, Map<String, String> headers, Map<String, String> querys, String body, List<String> signHeaderPrefixList, String appKey, String appSecret)
throws Exception {
headers = initialBasicHeader(HttpMethod.PUT, path, headers, querys, null, signHeaderPrefixList, appKey, appSecret);
HttpClient httpClient = wrapClient(host);
httpClient.getParams().setParameter(CoreConnectionPNames.CONNECTION_TIMEOUT, getTimeout(connectTimeout));
HttpPut put = new HttpPut(initUrl(host, path, querys));
for (Map.Entry<String, String> e : headers.entrySet()) {
put.addHeader(e.getKey(), MessageDigestUtil.utf8ToIso88591(e.getValue()));
}
if (StringUtils.isNotBlank(body)) {
put.setEntity(new StringEntity(body, Constants.ENCODING));
}
return convert(httpClient.execute(put));
}
示例10: QSystemHtmlInstance
import org.apache.http.params.CoreConnectionPNames; //导入依赖的package包/类
private QSystemHtmlInstance() {
this.params.setIntParameter(CoreConnectionPNames.SO_TIMEOUT, 5000).
setIntParameter(CoreConnectionPNames.SOCKET_BUFFER_SIZE, 8 * 1024).
setBooleanParameter(CoreConnectionPNames.STALE_CONNECTION_CHECK, false).
setBooleanParameter(CoreConnectionPNames.TCP_NODELAY, true).
setParameter(CoreProtocolPNames.ORIGIN_SERVER, "QSystemReportHttpServer/1.1");
// Set up the HTTP protocol processor
final BasicHttpProcessor httpproc = new BasicHttpProcessor();
httpproc.addInterceptor(new ResponseDate());
httpproc.addInterceptor(new ResponseServer());
httpproc.addInterceptor(new ResponseContent());
httpproc.addInterceptor(new ResponseConnControl());
// Set up request handlers
final HttpRequestHandlerRegistry reqistry = new HttpRequestHandlerRegistry();
reqistry.register("*", new HttpQSystemReportsHandler());
// Set up the HTTP service
this.httpService = new HttpService(
httpproc,
new DefaultConnectionReuseStrategy(),
new DefaultHttpResponseFactory(), reqistry, this.params);
}
示例11: RequestListenerThread
import org.apache.http.params.CoreConnectionPNames; //导入依赖的package包/类
public RequestListenerThread(Context context) throws IOException, BindException {
serversocket = new ServerSocket(PORT);
params = new BasicHttpParams();
params.setIntParameter(CoreConnectionPNames.SO_TIMEOUT, 5000).setIntParameter(CoreConnectionPNames.SOCKET_BUFFER_SIZE, 8 * 1024)
.setBooleanParameter(CoreConnectionPNames.STALE_CONNECTION_CHECK, false)
.setBooleanParameter(CoreConnectionPNames.TCP_NODELAY, true).setParameter(CoreProtocolPNames.ORIGIN_SERVER, "HttpComponents/1.1");
// Set up the HTTP protocol processor
BasicHttpProcessor httpProcessor = new BasicHttpProcessor();
httpProcessor.addInterceptor(new ResponseDate());
httpProcessor.addInterceptor(new ResponseServer());
httpProcessor.addInterceptor(new ResponseContent());
httpProcessor.addInterceptor(new ResponseConnControl());
// Set up the HTTP service
this.httpService = new YaaccHttpService(httpProcessor, new DefaultConnectionReuseStrategy(), new DefaultHttpResponseFactory(), context);
}
示例12: get
import org.apache.http.params.CoreConnectionPNames; //导入依赖的package包/类
public void get() throws IOException {
String requesturl = "http://www.tuling123.com/openapi/api";
// 声明httpclient 每一个会话有一个独立的httpclient
CloseableHttpClient httpclient = HttpClients.createDefault();
CloseableHttpResponse response = null;
StringBuilder params = new StringBuilder();
params.append(requesturl + "?");
params.append("key=" + URLEncoder.encode("4b441cb500f431adc6cc0cb650b4a5d0", REQUEST_CHARSET)).append("&");
params.append("info=" + URLEncoder.encode("4b441cb500f431adc6cc0cb650b4a5d0", REQUEST_CHARSET));
try {
httpclient.getParams().setParameter(CoreConnectionPNames.CONNECTION_TIMEOUT, 10000); // 请求超时
httpclient.getParams().setParameter(CoreConnectionPNames.SO_TIMEOUT, 10000); // 读取超时
HttpGet httpGet = new HttpGet(params.toString());
response = httpclient.execute(httpGet);
HttpEntity entity = response.getEntity();
String content = EntityUtils.toString(entity, "utf-8");
log.info(content);
EntityUtils.consume(entity);
} catch (Exception e) {
log.error("" + e);
} finally {
if (response != null)
response.close();
}
}
示例13: getHttpParams
import org.apache.http.params.CoreConnectionPNames; //导入依赖的package包/类
/**
* 此处解释下MaxtTotal和DefaultMaxPerRoute的区别:
* 1、MaxtTotal是整个池子的大小;
* 2、DefaultMaxPerRoute是根据连接到的主机对MaxTotal的一个细分;比如:
* MaxtTotal=400 DefaultMaxPerRoute=200
* 而我只连接到http://sishuok.com时,到这个主机的并发最多只有200;而不是400;
* 而我连接到http://sishuok.com 和 http://qq.com时,到每个主机的并发最多只有200;即加起来是400(但不能超过400);所以起作用的设置是DefaultMaxPerRoute。
*/
public HttpParams getHttpParams() {
HttpParams params = new BasicHttpParams();
// 设置连接超时时间
Integer CONNECTION_TIMEOUT = 2 * 1000; // 设置请求超时2秒钟 根据业务调整
Integer SO_TIMEOUT = 2 * 1000; // 设置等待数据超时时间2秒钟 根据业务调整
// 定义了当从ClientConnectionManager中检索ManagedClientConnection实例时使用的毫秒级的超时时间
// 这个参数期望得到一个java.lang.Long类型的值。如果这个参数没有被设置,默认等于CONNECTION_TIMEOUT,因此一定要设置
Long CONN_MANAGER_TIMEOUT = 500L; // 该值就是连接不够用的时候等待超时时间,一定要设置,而且不能太大 ()
params.setIntParameter(CoreConnectionPNames.CONNECTION_TIMEOUT, CONNECTION_TIMEOUT);
params.setIntParameter(CoreConnectionPNames.SO_TIMEOUT, SO_TIMEOUT);
params.setLongParameter(ClientPNames.CONN_MANAGER_TIMEOUT, CONN_MANAGER_TIMEOUT);
// 在提交请求之前 测试连接是否可用
params.setBooleanParameter(CoreConnectionPNames.STALE_CONNECTION_CHECK, true);
return params;
}
示例14: initHttpClient
import org.apache.http.params.CoreConnectionPNames; //导入依赖的package包/类
/**
* 微信自定义信任管理器X509TrustManager
* @param httpclient
* @return
*/
private static HttpClient initHttpClient(HttpClient httpclient) {
try {
TrustManager[] tm = { new MyX509TrustManager() };
// 取得SSL的SSLContext实例
SSLContext sslContext = SSLContext.getInstance("SSL", "SunJSSE");
// 初始化SSLContext
sslContext.init(null, tm, new java.security.SecureRandom());
// 从上述SSLContext对象中得到SSLSocketFactory对象
SocketFactory ssf = (SocketFactory) sslContext.getSocketFactory();
ClientConnectionManager ccm = new DefaultHttpClient().getConnectionManager();
SchemeRegistry sr = ccm.getSchemeRegistry();
sr.register(new Scheme("https", ssf, 8443));
HttpParams params = new BasicHttpParams();
params.setParameter(ConnManagerPNames.MAX_TOTAL_CONNECTIONS, 30);
params.setParameter(ConnManagerPNames.MAX_CONNECTIONS_PER_ROUTE, new ConnPerRouteBean(30));
params.setParameter(HttpProtocolParams.USE_EXPECT_CONTINUE, false);
HttpProtocolParams.setVersion(params, HttpVersion.HTTP_1_1);
params.setParameter(CoreConnectionPNames.CONNECTION_TIMEOUT, 1000);
params.setParameter(CoreConnectionPNames.SO_TIMEOUT, 5000);
httpclient = new DefaultHttpClient(ccm, params);
} catch (Exception ex) {
Exceptions.printException(ex);
}
return httpclient;
}
示例15: start
import org.apache.http.params.CoreConnectionPNames; //导入依赖的package包/类
public void start() throws IOException {
log.info("Starting sample Axis2 server");
//To set the socket can be bound even though a previous connection is still in a timeout state.
if (System.getProperty(CoreConnectionPNames.SO_REUSEADDR) == null) {
System.setProperty(CoreConnectionPNames.SO_REUSEADDR, "true");
}
listenerManager = new ListenerManager();
listenerManager.init(cfgCtx);
listenerManager.start();
try {
Thread.sleep(2000);
} catch (InterruptedException ignored) {
}
started = true;
}