本文整理匯總了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;
}