欧美性猛交XXXX免费看蜜桃,成人网18免费韩国,亚洲国产成人精品区综合,欧美日韩一区二区三区高清不卡,亚洲综合一区二区精品久久

打開(kāi)APP
userphoto
未登錄

開(kāi)通VIP,暢享免費電子書(shū)等14項超值服

開(kāi)通VIP
HttpClient-aaaaa
package com.paic.padlife.common;

import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.lang.reflect.ParameterizedType;
import java.lang.reflect.Type;
import java.util.List;
import java.util.concurrent.TimeUnit;

import org.apache.http.HttpEntity;
import org.apache.http.StatusLine;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.client.methods.HttpUriRequest;
import org.apache.http.conn.ConnectionPoolTimeoutException;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.message.BasicNameValuePair;
import org.apache.http.util.EntityUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.alibaba.fastjson.JSON;
import com.paic.padlife.biz.product.common.utils.PrintLog;

/**
 * @author ex-chenkefeng001
 * HttpClient工具類(lèi)
 */
public class PafaHttpClient {

private static final Logger logger = LoggerFactory.getLogger(PafaHttpClient.class);
private static PafaHttpManager manager;
/**
* 發(fā)送GET請求
* @param url
*            請求地址
* @param callback
*            請求結束之后回調
* @param params
*            請求參數
*/
public static <T, K, V> void doGet(String url, ParamDTO<K, V> params,
InvokeHandleCallback<T> callback) {
// 獲取httpGet
PrintLog.info(logger, "[{}] doGet start... and params is [{}]", url, params);
HttpGet get;
if(params != null && params.isNotEmpty()){
get = new HttpGet(String.format("%s?%s", url, params.toUrlParams("utf-8")));
}else{
get = new HttpGet(url);
}
processAndExecuteRequest(get,callback);
}


/**
* 發(fā)送GET請求
* @param url
*            請求地址
* @param callback
*            請求結束之后回調
*/
public static <T> void doGet(String url, InvokeHandleCallback<T> callback) {
doGet(url, null, callback);
}

/**
* 發(fā)送POST請求
* @param url
*            請求地址
* @param params
*            請求參數
* @param callback
*            請求結束之后回調
*/
public static <T, K, V> void doPost(String url, ParamDTO<K, V> params,
InvokeHandleCallback<T> callback) {
PrintLog.info(logger, "[{}] doPost start... and params is [{}]", url, params);
HttpPost post = new HttpPost(url);
List<BasicNameValuePair> list = null;
if(params != null){
list = params.preparePostData();
}
try {
UrlEncodedFormEntity entity = new UrlEncodedFormEntity(list);
post.setEntity(entity);
processAndExecuteRequest(post, callback);
} catch (UnsupportedEncodingException e) {
PrintLog.info(logger, "UrlEncodedFormEntity..init error...", e);
if(callback != null){
callback.onError(e);
}
}
}

/**
* 發(fā)送POST請求
* @param url
*            請求地址
* @param body
*            請求體
* @param callback
*            請求結束之后回調
*/
public static <T> void doPost(String url, String body,
InvokeHandleCallback<T> callback) {
PrintLog.info(logger, "[{}] doPost start... and params is [{}]", url, body);
HttpPost post = new HttpPost(url);
if(body != null){
try {
post.setEntity(new StringEntity(body, "utf-8"));
} catch (UnsupportedEncodingException e) {
PrintLog.info(logger, "UrlEncodedFormEntity..init error...", e);
if(callback != null){
callback.onError(e);
}
}
}
processAndExecuteRequest(post, callback);
}
@SuppressWarnings("unchecked")
private static <T> void processAndExecuteRequest(HttpUriRequest req,InvokeHandleCallback<T> callback){
if(manager == null){
manager = PafaHttpManager.getDefault();
}
PrintLog.info(logger, "pool manager available client number is <池中活動(dòng)的client數目> [{}]," +
"leased number is <池中針對該地址連接的最大連接數目> [{}]," +
"pending number is <當前正在等待的連接數> [{}]," +
"max allow number <服務(wù)器允許最大的并發(fā)client數 > is [{}]", 
manager.getAvailable(),manager.getLeased(),manager.getPending(),manager.getMax());
CloseableHttpClient httpClient = manager.getHttpClient();
CloseableHttpResponse httpResp = null;
HttpEntity entity = null;
try {
httpResp = httpClient.execute(req);
StatusLine statusLine = httpResp.getStatusLine();
if(statusLine.getStatusCode() == 200){
entity = httpResp.getEntity();
String respDat a= EntityUtils.toString(entity, "utf-8");
PrintLog.info(logger, "remote server response dat ais [{}]", respData);
if(callback != null){
callback.onSuccess(JSON.parseObject(respData, (Class<T>)callback.getClazz()));
}
}else{
PrintLog.info(logger, "remote server response code is [{}]..", statusLine.getStatusCode());
if(callback != null){
callback.onRemoteError(statusLine);
}
}
} catch (ClientProtocolException e) {
//e.printStackTrace();
PrintLog.info(logger, "", e);
if(callback != null){
callback.onError(e);
}
} catch (IOException e) {
if(e instanceof ConnectionPoolTimeoutException){
}else{
PrintLog.info(logger, "", e);
///e.printStackTrace();
}
if(callback != null){
callback.onError(e);
}
} finally {
try {
if(entity != null){
entity.getContent().close();
}
if (httpResp != null) {
httpResp.close();
}
//httpClient.close();
} catch (Exception e2) {
// do not handle..
}
}
}
/**
* @author ex-chenkefeng001
* 請求結果回調處理
* @param <T>
*/
public abstract static class InvokeHandleCallback<T> {

/**
* 發(fā)生錯誤時(shí)回調,例如:超時(shí)等
* @param e
*/
public void onError(Exception e) {
manager.release();
}

/**
* 遠程服務(wù)器錯誤
* @param e
*/
public void onRemoteError(StatusLine status) {
manager.release();
}

public void onSuccess(T resp){
manager.release();
};

@SuppressWarnings("unchecked")
public Class<?> getClazz() {
Type type = this.getClass().getGenericSuperclass();
if (type instanceof ParameterizedType) {
ParameterizedType ptype = (ParameterizedType) type;
Type[] types = ptype.getActualTypeArguments();
if (types.length > 0) {
return (Class<T>) types[0];
}
}
return Object.class;
}

}
public static void main(String[] args) {
for(;;){
new Thread(){
public void run() {
doGet("http://localhost:7001/padlife/do/product/queryAllAddress?productId=1", new InvokeHandleCallback<String>() {
@Override
public void onSuccess(String resp) {
super.onSuccess(resp);
//System.out.println(resp);
}
public void onError(Exception e) {
System.out.println(e.getMessage());
};
});
};
@Override
protected void finalize() throws Throwable {
super.finalize();
System.out.println("thread 對象銷(xiāo)毀啦。。。");
}
}.start();
try {
TimeUnit.MILLISECONDS.sleep(50);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
}

本站僅提供存儲服務(wù),所有內容均由用戶(hù)發(fā)布,如發(fā)現有害或侵權內容,請點(diǎn)擊舉報。
打開(kāi)APP,閱讀全文并永久保存 查看更多類(lèi)似文章
猜你喜歡
類(lèi)似文章
使用Gzip加速網(wǎng)頁(yè)的傳輸
spring集成httpclient連接池配置
Android封裝的http請求實(shí)用工具類(lèi)
HTTP
CXF方式發(fā)布WebService全步驟
zookeeper下的分布式鎖
更多類(lèi)似文章 >>
生活服務(wù)
分享 收藏 導長(cháng)圖 關(guān)注 下載文章
綁定賬號成功
后續可登錄賬號暢享VIP特權!
如果VIP功能使用有故障,
可點(diǎn)擊這里聯(lián)系客服!

聯(lián)系客服

欧美性猛交XXXX免费看蜜桃,成人网18免费韩国,亚洲国产成人精品区综合,欧美日韩一区二区三区高清不卡,亚洲综合一区二区精品久久