Please wait. This can take some minutes ...
Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance.
Project price only 1 $
You can buy this project and download/modify it how often you want.
org.frameworkset.spi.remote.http.HttpRequestProxy Maven / Gradle / Ivy
package org.frameworkset.spi.remote.http;
import com.frameworkset.util.SimpleStringUtil;
import org.apache.http.*;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.HttpClient;
import org.apache.http.client.ResponseHandler;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.*;
import org.apache.http.conn.ConnectTimeoutException;
import org.apache.http.conn.ConnectionPoolTimeoutException;
import org.apache.http.conn.HttpHostConnectException;
import org.apache.http.entity.ContentType;
import org.apache.http.entity.StringEntity;
import org.apache.http.entity.mime.MultipartEntityBuilder;
import org.apache.http.entity.mime.content.FileBody;
import org.apache.http.impl.io.EmptyInputStream;
import org.apache.http.message.BasicNameValuePair;
import org.apache.http.params.BasicHttpParams;
import org.apache.http.params.HttpParams;
import org.apache.http.util.EntityUtils;
import org.frameworkset.spi.remote.http.proxy.*;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.net.NoRouteToHostException;
import java.net.SocketTimeoutException;
import java.net.UnknownHostException;
import java.nio.charset.Charset;
import java.util.*;
import java.util.Map.Entry;
import static org.frameworkset.spi.remote.http.HttpRequestUtil.object2json;
/**
* @author yinbp
* @Date:2016-11-20 11:39:59
*/
public class HttpRequestProxy {
private static Logger logger = LoggerFactory.getLogger(HttpRequestProxy.class);
public static void startHttpPools(String configFile){
HttpRequestUtil.startHttpPools(configFile);
}
public static void startHttpPools(Map configs){
HttpRequestUtil.startHttpPools(configs);
}
public static void startHttpPoolsFromApollo(String namespaces){
HttpRequestUtil.startHttpPoolsFromApollo(namespaces);
}
public static void startHttpPoolsFromApollo(String namespaces,String configChangeListener){
HttpRequestUtil.startHttpPoolsFromApollo(namespaces,configChangeListener);
}
public static void startHttpPoolsFromApolloAwaredChange(String namespaces){
HttpRequestUtil.startHttpPoolsFromApolloAwaredChange(namespaces);
}
public static String httpGetforString(String url) throws HttpProxyRequestException {
return httpGetforString(url, (String) null, (String) null, (Map) null);
}
public static T httpGetforObject(String url,final Class resultType) throws HttpProxyRequestException {
return httpGetforString("default",url, (String) null, (String) null, (Map) null, new BaseURLResponseHandler() {
@Override
public T handleResponse(final HttpResponse response)
throws ClientProtocolException, IOException {
return HttpRequestProxy.handleResponse(url, response, resultType);
}
});
}
public static String httpGetforString(String poolname, String url) throws HttpProxyRequestException {
return httpGetforString(poolname, url, (String) null, (String) null, (Map) null);
}
public static T httpGetforObject(String poolname, String url,final Class resultType) throws HttpProxyRequestException {
return httpGetforString(poolname, url, (String) null, (String) null, (Map) null, new BaseURLResponseHandler() {
@Override
public T handleResponse(final HttpResponse response)
throws ClientProtocolException, IOException {
return HttpRequestProxy.handleResponse( url,response, resultType);
}
});
}
public static List httpGetforList(String url,final Class resultType) throws HttpProxyRequestException {
return httpGetforString("default",url, (String) null, (String) null, (Map) null, new BaseURLResponseHandler>() {
@Override
public List handleResponse(final HttpResponse response)
throws ClientProtocolException, IOException {
return HttpRequestProxy.handleListResponse( url,response, resultType);
}
});
}
public static Map httpGetforMap(String url,final Class keyType,final Class resultType) throws HttpProxyRequestException {
return httpGetforString("default",url, (String) null, (String) null, (Map) null, new BaseURLResponseHandler >() {
@Override
public Map handleResponse(final HttpResponse response)
throws ClientProtocolException, IOException {
return HttpRequestProxy.handleMapResponse( url,response,keyType, resultType);
}
});
}
public static Set httpGetforSet(String url,final Class resultType) throws HttpProxyRequestException {
return httpGetforString("default",url, (String) null, (String) null, (Map) null, new BaseURLResponseHandler>() {
@Override
public Set handleResponse(final HttpResponse response)
throws ClientProtocolException, IOException {
return HttpRequestProxy.handleSetResponse(url, response, resultType);
}
});
}
public static List httpGetforList(String poolName,String url,final Class resultType) throws HttpProxyRequestException {
return httpGetforString( poolName,url, (String) null, (String) null, (Map) null, new BaseURLResponseHandler>() {
@Override
public List handleResponse(final HttpResponse response)
throws ClientProtocolException, IOException {
return HttpRequestProxy.handleListResponse( url, response, resultType);
}
});
}
public static D httpGetforTypeObject(String url,final Class containType,final Class resultType) throws HttpProxyRequestException {
return httpGetforTypeObject("default", url, containType, resultType);
}
public static D httpGetforTypeObject(String poolName,String url,final Class containType,final Class resultType) throws HttpProxyRequestException {
return httpGetforString( poolName,url, (String) null, (String) null, (Map) null, new BaseURLResponseHandler() {
@Override
public D handleResponse(final HttpResponse response)
throws ClientProtocolException, IOException {
return HttpRequestProxy.handleResponse( url, response,containType, resultType);
}
});
}
public static Map httpGetforMap(String poolName,String url,final Class keyType,final Class resultType) throws HttpProxyRequestException {
return httpGetforString( poolName,url, (String) null, (String) null, (Map) null, new BaseURLResponseHandler >() {
@Override
public Map handleResponse(final HttpResponse response)
throws ClientProtocolException, IOException {
return HttpRequestProxy.handleMapResponse( url, response,keyType, resultType);
}
});
}
public static Set httpGetforSet(String poolName,String url,final Class resultType) throws HttpProxyRequestException {
return httpGetforString( poolName,url, (String) null, (String) null, (Map) null, new BaseURLResponseHandler>() {
@Override
public Set handleResponse(final HttpResponse response)
throws ClientProtocolException, IOException {
return HttpRequestProxy.handleSetResponse( url, response, resultType);
}
});
}
public static T httpGet(String poolname, String url,ResponseHandler responseHandler) throws HttpProxyRequestException {
return httpGetforString(poolname, url, (String) null, (String) null, (Map) null,responseHandler);
}
public static T httpGet(String poolname, String url,Map headers,ResponseHandler responseHandler) throws HttpProxyRequestException {
return httpGetforString(poolname, url, (String) null, (String) null, headers,responseHandler);
}
public static T httpGet(String url,Map headers,ResponseHandler responseHandler) throws HttpProxyRequestException {
return httpGetforString("default", url, (String) null, (String) null, headers,responseHandler);
}
public static String httpGetforString(String url, Map headers) throws HttpProxyRequestException {
return httpGetforString(url, (String) null, (String) null, headers);
}
public static String httpGetforString(String poolname, String url, Map headers) throws HttpProxyRequestException {
return httpGetforString(poolname, url, (String) null, (String) null, headers);
}
public static T httpGetforString(String poolname, String url, Map headers,ResponseHandler responseHandler) throws HttpProxyRequestException {
return httpGetforString(poolname, url, (String) null, (String) null, headers,responseHandler);
}
public static T httpGetforString( String url, Map headers,ResponseHandler responseHandler) throws HttpProxyRequestException {
return httpGetforString("default", url, (String) null, (String) null, headers,responseHandler);
}
public static String httpGetforString(String url, String cookie, String userAgent, Map headers) throws HttpProxyRequestException {
return httpGetforString("default", url, cookie, userAgent, headers);
}
public static String httpGetforString(String poolname, String url, String cookie, String userAgent, Map headers) throws HttpProxyRequestException{
return httpGetforString(poolname, url, cookie, userAgent, headers,new StringResponseHandler()) ;
}
/**
* get请求URL
*
* @param url
* @throws HttpProxyRequestException
*/
public static T httpGetforString(String poolname, String url, String cookie, String userAgent, Map headers,ResponseHandler responseHandler) throws HttpProxyRequestException {
return httpGet( poolname, url, cookie, userAgent, headers, responseHandler);
}
private static Exception getException(ResponseHandler responseHandler,HttpServiceHosts httpServiceHosts ){
// assertCheck( httpServiceHosts );
ExceptionWare exceptionWare = httpServiceHosts.getExceptionWare();
if(exceptionWare != null) {
return exceptionWare.getExceptionFromResponse(responseHandler);
}
return null;
}
/**
* get请求URL
*
* @param url
* @throws HttpProxyRequestException
*/
public static T httpGet(String poolname, String url, final String cookie,final String userAgent,final Map headers,final ResponseHandler responseHandler) throws HttpProxyRequestException {
// String cookie = getCookie();
// String userAgent = getUserAgent();
return _handleRequest( poolname, url ,
responseHandler,new ExecuteRequest(){
@Override
public Object execute(ClientConfiguration config, HttpClient httpClient,String url, int triesCount) throws Exception {
HttpGet httpGet = null;
try {
httpGet = HttpRequestUtil.getHttpGet(config, url, cookie, userAgent, headers);
Object responseBody = httpClient.execute(httpGet, responseHandler);
return responseBody;
}
finally {
// 释放连接
if (httpGet != null)
httpGet.releaseConnection();
}
}
} );
/**
HttpClient httpClient = null;
HttpGet httpGet = null;
T responseBody = null;
// int time = 0;
ClientConfiguration config = ClientConfiguration.getClientConfiguration(poolname);
// int RETRY_TIME = config.getRetryTime();
// do {
String endpoint = null;
Throwable e = null;
int triesCount = 0;
if(!url.startsWith("http://") && !url.startsWith("https://")) {
endpoint = url;
HttpAddress httpAddress = null;
HttpServiceHosts httpServiceHosts = config.getHttpServiceHosts();
assertCheck( httpServiceHosts );
do {
try {
httpAddress = httpServiceHosts.getHttpAddress();
url = SimpleStringUtil.getPath(httpAddress.getAddress(), endpoint);
if(logger.isDebugEnabled()){
logger.debug("Get call {}",url);
}
httpClient = HttpRequestUtil.getHttpClient(config);
httpGet = HttpRequestUtil.getHttpGet(config, url, cookie, userAgent, headers);
if(responseHandler != null && responseHandler instanceof URLResponseHandler){
((URLResponseHandler)responseHandler).setUrl(url);
}
responseBody = httpClient.execute(httpGet, responseHandler);
httpAddress.recover();
e = getException( responseHandler,httpServiceHosts );
break;
} catch (HttpHostConnectException ex) {
httpAddress.setStatus(1);
e = new NoHttpServerException(ex);
if (!httpServiceHosts.reachEnd(triesCount )) {//失败尝试下一个地址
triesCount++;
continue;
} else {
break;
}
} catch (UnknownHostException ex) {
httpAddress.setStatus(1);
e = new NoHttpServerException(ex);
if (!httpServiceHosts.reachEnd(triesCount )) {//失败尝试下一个地址
triesCount++;
continue;
} else {
break;
}
}
catch (NoRouteToHostException ex) {
httpAddress.setStatus(1);
e = new NoHttpServerException(ex);
if (!httpServiceHosts.reachEnd(triesCount )) {//失败尝试下一个地址
triesCount++;
continue;
} else {
break;
}
}
catch (NoHttpResponseException ex) {
httpAddress.setStatus(1);
e = new NoHttpServerException(ex);
if (!httpServiceHosts.reachEnd(triesCount )) {//失败尝试下一个地址
triesCount++;
continue;
} else {
break;
}
}
catch (ConnectionPoolTimeoutException ex){//连接池获取connection超时,直接抛出
e = handleConnectionPoolTimeOutException( poolname,url,config,ex);
break;
}
catch (ConnectTimeoutException connectTimeoutException){
httpAddress.setStatus(1);
e = handleConnectionTimeOutException(poolname,url,config,connectTimeoutException);
if (!httpServiceHosts.reachEnd(triesCount )) {//失败尝试下一个地址
triesCount++;
continue;
} else {
break;
}
}
catch (SocketTimeoutException ex) {
e = handleSocketTimeoutException(poolname,url,config, ex);
break;
}
catch (NoHttpServerException ex){
e = ex;
break;
}
catch (ClientProtocolException ex){
throw new HttpProxyRequestException(new StringBuilder().append("Get Request[").append(url)
.append("] handle failed: must use http/https protocol port such as 9200,do not use other transport such as 9300.").toString(),ex);
}
catch (Exception ex) {
e = ex;
break;
}
catch (Throwable ex) {
e = ex;
break;
} finally {
// 释放连接
if (httpGet != null)
httpGet.releaseConnection();
httpClient = null;
}
} while (true);
}
else{
try {
if(logger.isDebugEnabled()){
logger.debug("Get call {}",url);
}
httpClient = HttpRequestUtil.getHttpClient(config);
httpGet = HttpRequestUtil.getHttpGet(config, url, cookie, userAgent, headers);
if(responseHandler != null && responseHandler instanceof URLResponseHandler){
((URLResponseHandler)responseHandler).setUrl(url);
}
responseBody = httpClient.execute(httpGet, responseHandler);
} catch (Exception ex) {
e = ex;
} finally {
// 释放连接
if (httpGet != null)
httpGet.releaseConnection();
httpClient = null;
}
}
if (e != null){
if(e instanceof HttpProxyRequestException)
throw (HttpProxyRequestException)e;
throw new HttpProxyRequestException("Get request url:"+url,e);
}
return responseBody;
*/
}
/**
* head请求URL
*
* @param url
* @throws HttpProxyRequestException
*/
public static T httpHead(String poolname, String url,ResponseHandler responseHandler) throws HttpProxyRequestException {
return httpHead( poolname, url, null, null, (Map) null,responseHandler);
}
/**
* get请求URL
*
* @param url
* @throws HttpProxyRequestException
*/
public static T httpHead(String url,ResponseHandler responseHandler) throws HttpProxyRequestException {
return httpHead( "default", url, null, null, (Map) null,responseHandler);
}
/**
* head请求URL
*
* @param url
* @throws HttpProxyRequestException
*/
public static T httpHead(String poolname, String url,Map params,Map headers,ResponseHandler responseHandler) throws HttpProxyRequestException {
return httpHead( poolname, url, null, null,params, (Map) headers,responseHandler);
}
/**
* get请求URL
* ,Map params,Map headers,
* @param url
* @throws HttpProxyRequestException
*/
public static T httpHead(String poolname, String url, String cookie, String userAgent, Map headers,ResponseHandler responseHandler) throws HttpProxyRequestException {
return httpHead( poolname, url, cookie, userAgent,(Map )null, headers,responseHandler);
}
/**
* get请求URL
* ,Map params,Map headers,
* @param url
* @throws HttpProxyRequestException
*/
public static T httpHead(String poolname, String url, final String cookie, final String userAgent,final Map params, final Map headers,
final ResponseHandler responseHandler) throws HttpProxyRequestException {
// String cookie = getCookie();
// String userAgent = getUserAgent();
return _handleRequest( poolname, url ,
responseHandler,new ExecuteRequest(){
@Override
public Object execute(ClientConfiguration config, HttpClient httpClient,String url, int triesCount) throws Exception {
HttpHead httpHead = null;
try {
httpHead = HttpRequestUtil.getHttpHead(config, url, cookie, userAgent, headers);
HttpParams httpParams = null;
if (params != null && params.size() > 0) {
httpParams = new BasicHttpParams();
Iterator> it = params.entrySet().iterator();
NameValuePair paramPair_ = null;
for (int i = 0; it.hasNext(); i++) {
Entry entry = it.next();
httpParams.setParameter(entry.getKey(), entry.getValue());
}
httpHead.setParams(httpParams);
}
Object responseBody = httpClient.execute(httpHead, responseHandler);
return responseBody;
}
finally {
// 释放连接
if (httpHead != null)
httpHead.releaseConnection();
}
}
} );
/**
HttpClient httpClient = null;
HttpHead httpHead = null;
T responseBody = null;
// int time = 0;
ClientConfiguration config = ClientConfiguration.getClientConfiguration(poolname);
String endpoint = null;
Throwable e = null;
int triesCount = 0;
if(!url.startsWith("http://") && !url.startsWith("https://")) {
endpoint = url;
HttpAddress httpAddress = null;
HttpServiceHosts httpServiceHosts = config.getHttpServiceHosts();
assertCheck( httpServiceHosts );
do {
try {
httpAddress = httpServiceHosts.getHttpAddress();
url = SimpleStringUtil.getPath(httpAddress.getAddress(), endpoint);
if(logger.isDebugEnabled()){
logger.debug("Head call {}",url);
}
httpClient = HttpRequestUtil.getHttpClient(config);
httpHead = HttpRequestUtil.getHttpHead(config, url, cookie, userAgent, headers);
HttpParams httpParams = null;
if (params != null && params.size() > 0) {
httpParams = new BasicHttpParams();
Iterator> it = params.entrySet().iterator();
NameValuePair paramPair_ = null;
for (int i = 0; it.hasNext(); i++) {
Entry entry = it.next();
httpParams.setParameter(entry.getKey(), entry.getValue());
}
httpHead.setParams(httpParams);
}
if(responseHandler != null && responseHandler instanceof URLResponseHandler){
((URLResponseHandler)responseHandler).setUrl(url);
}
responseBody = httpClient.execute(httpHead, responseHandler);
httpAddress.recover();
e = getException( responseHandler,httpServiceHosts );
break;
} catch (HttpHostConnectException ex) {
httpAddress.setStatus(1);
e = new NoHttpServerException(ex);
if (!httpServiceHosts.reachEnd(triesCount )) {//失败尝试下一个地址
triesCount++;
continue;
} else {
break;
}
} catch (UnknownHostException ex) {
httpAddress.setStatus(1);
e = new NoHttpServerException(ex);
if (!httpServiceHosts.reachEnd(triesCount )) {//失败尝试下一个地址
triesCount++;
continue;
} else {
break;
}
}
catch (NoRouteToHostException ex) {
httpAddress.setStatus(1);
e = new NoHttpServerException(ex);
if (!httpServiceHosts.reachEnd(triesCount )) {//失败尝试下一个地址
triesCount++;
continue;
} else {
break;
}
}
catch (NoHttpResponseException ex) {
httpAddress.setStatus(1);
e = new NoHttpServerException(ex);
if (!httpServiceHosts.reachEnd(triesCount )) {//失败尝试下一个地址
triesCount++;
continue;
} else {
break;
}
}
catch (ConnectionPoolTimeoutException ex){//连接池获取connection超时,直接抛出
e = handleConnectionPoolTimeOutException( poolname,url,config,ex);
break;
}
catch (ConnectTimeoutException connectTimeoutException){
httpAddress.setStatus(1);
e = handleConnectionTimeOutException(poolname,url,config,connectTimeoutException);
if (!httpServiceHosts.reachEnd(triesCount )) {//失败尝试下一个地址
triesCount++;
continue;
} else {
break;
}
}
catch (SocketTimeoutException ex) {
e = handleSocketTimeoutException(poolname,url,config, ex);
break;
}
catch (NoHttpServerException ex){
e = ex;
break;
}
catch (ClientProtocolException ex){
httpAddress.setStatus(1);
e = ex;
if(logger.isErrorEnabled())
logger.error(new StringBuilder().append("Head Request[").append(url)
.append("] handle failed: must use http/https protocol port such as 9200,do not use other transport such as 9300.").toString(),ex);
if (!httpServiceHosts.reachEnd(triesCount )) {//失败尝试下一个地址
triesCount++;
continue;
} else {
break;
}
}
catch (Exception ex) {
e = ex;
break;
}
catch (Throwable ex) {
e = ex;
break;
} finally {
// 释放连接
if (httpHead != null)
httpHead.releaseConnection();
httpClient = null;
}
} while (true);
}
else{
try {
if(logger.isDebugEnabled()){
logger.debug("Head call {}",url);
}
httpClient = HttpRequestUtil.getHttpClient(config);
httpHead = HttpRequestUtil.getHttpHead(config, url, cookie, userAgent, headers);
HttpParams httpParams = null;
if (params != null && params.size() > 0) {
httpParams = new BasicHttpParams();
Iterator> it = params.entrySet().iterator();
NameValuePair paramPair_ = null;
for (int i = 0; it.hasNext(); i++) {
Entry entry = it.next();
httpParams.setParameter(entry.getKey(), entry.getValue());
}
httpHead.setParams(httpParams);
}
if(responseHandler != null && responseHandler instanceof URLResponseHandler){
((URLResponseHandler)responseHandler).setUrl(url);
}
responseBody = httpClient.execute(httpHead, responseHandler);
} catch (Exception ex) {
e = ex;
} finally {
// 释放连接
if (httpHead != null)
httpHead.releaseConnection();
httpClient = null;
}
}
if (e != null){
if(e instanceof HttpProxyRequestException)
throw (HttpProxyRequestException)e;
throw new HttpProxyRequestException("Head request url:"+url,e);
}
return responseBody;
*/
}
/**
* 公用post方法
*
* @param url
* @param params
* @param files
* @throws HttpProxyRequestException
*/
public static String httpPostFileforString(String url, Map params, Map files)
throws HttpProxyRequestException {
return httpPostFileforString("default", url, (String) null, (String) null, params, files);
}
public static String httpPostFileforString(String poolname, String url, Map params, Map files)
throws HttpProxyRequestException {
return httpPostFileforString(poolname, url, (String) null, (String) null, params, files);
}
public static String httpPostforString(String url, Map params) throws HttpProxyRequestException {
return httpPostforString(url, params, (Map) null);
}
public static T httpPost(String url, Map params,ResponseHandler responseHandler) throws HttpProxyRequestException {
return httpPostforString(url, params, (Map) null, responseHandler);
}
public static T httpPostForObject(String url, Map params, final Class resultType) throws HttpProxyRequestException {
return httpPostforString(url, params, (Map) null, new BaseURLResponseHandler() {
@Override
public T handleResponse(HttpResponse response) throws ClientProtocolException, IOException {
return HttpRequestProxy.handleResponse(url,response,resultType);
}
});
}
public static List httpPostForList(String url, Map params, final Class resultType) throws HttpProxyRequestException {
return httpPostforString(url, params, (Map) null, new BaseURLResponseHandler>() {
@Override
public List handleResponse(HttpResponse response) throws ClientProtocolException, IOException {
return HttpRequestProxy.handleListResponse(url,response,resultType);
}
});
}
public static Set httpPostForSet(String url, Map params, final Class resultType) throws HttpProxyRequestException {
return httpPostforString(url, params, (Map) null, new BaseURLResponseHandler>() {
@Override
public Set handleResponse(HttpResponse response) throws ClientProtocolException, IOException {
return HttpRequestProxy.handleSetResponse(url,response,resultType);
}
});
}
public static Map httpPostForMap(String url, Map params, final Class keyType, final Class resultType) throws HttpProxyRequestException {
return httpPostforString(url, params, (Map) null, new BaseURLResponseHandler>() {
@Override
public Map handleResponse(HttpResponse response) throws ClientProtocolException, IOException {
return HttpRequestProxy.handleMapResponse(url,response,keyType,resultType);
}
});
}
public static T httpPostForObject(String poolName,String url, Map params, final Class resultType) throws HttpProxyRequestException {
HttpOption httpOption = new HttpOption();
httpOption.params = params;
return httpPost( poolName, url, httpOption, new BaseURLResponseHandler() {
@Override
public T handleResponse(HttpResponse response) throws ClientProtocolException, IOException {
return HttpRequestProxy.handleResponse(url,response,resultType);
}
});
// return httpPostforString( poolName,url, params, (Map) null);
}
public static T httpPostForObject(String poolName,String url, Map params, final Class resultType,DataSerialType dataSerialType) throws HttpProxyRequestException {
HttpOption httpOption = new HttpOption();
httpOption.params = params;
httpOption.dataSerialType = dataSerialType;
return httpPost( poolName, url, httpOption, new BaseURLResponseHandler() {
@Override
public T handleResponse(HttpResponse response) throws ClientProtocolException, IOException {
return HttpRequestProxy.handleResponse(url,response,resultType);
}
});
// return httpPostforString( poolName,url, params, (Map) null);
}
public static List httpPostForList(String poolName,String url, Map params, final Class resultType,DataSerialType dataSerialType) throws HttpProxyRequestException {
HttpOption httpOption = new HttpOption();
httpOption.params = params;
httpOption.dataSerialType = dataSerialType;
return httpPost( poolName, url, httpOption, new BaseURLResponseHandler>() {
@Override
public List handleResponse(HttpResponse response) throws ClientProtocolException, IOException {
return HttpRequestProxy.handleListResponse(url,response,resultType);
}
});
}
public static Set httpPostForSet(String poolName,String url, Map params, final Class resultType,DataSerialType dataSerialType) throws HttpProxyRequestException {
HttpOption httpOption = new HttpOption();
httpOption.params = params;
httpOption.dataSerialType = dataSerialType;
return httpPost( poolName, url, httpOption, new BaseURLResponseHandler>() {
@Override
public Set handleResponse(HttpResponse response) throws ClientProtocolException, IOException {
return HttpRequestProxy.handleSetResponse(url,response,resultType);
}
});
// return httpPostforString( poolName,url, params, (Map) null, new ResponseHandler>() {
// @Override
// public Set handleResponse(HttpResponse response) throws ClientProtocolException, IOException {
// return HttpRequestProxy.handleSetResponse(response,resultType);
// }
// });
}
public static Map httpPostForMap(String poolName,String url, Map params, final Class keyType, final Class resultType,DataSerialType dataSerialType) throws HttpProxyRequestException {
HttpOption httpOption = new HttpOption();
httpOption.params = params;
httpOption.dataSerialType = dataSerialType;
return httpPost( poolName, url, httpOption,new BaseURLResponseHandler>() {
@Override
public Map handleResponse(HttpResponse response) throws ClientProtocolException, IOException {
return HttpRequestProxy.handleMapResponse(url,response,keyType,resultType);
}
});
// return httpPostforString(poolName,url, params, (Map) null, new ResponseHandler>() {
// @Override
// public Map handleResponse(HttpResponse response) throws ClientProtocolException, IOException {
// return HttpRequestProxy.handleMapResponse(response,keyType,resultType);
// }
// });
}
public static List httpPostForList(String poolName,String url, Map params, final Class resultType) throws HttpProxyRequestException {
return httpPostforString( poolName,url, params, (Map) null, new BaseURLResponseHandler>() {
@Override
public List handleResponse(HttpResponse response) throws ClientProtocolException, IOException {
return HttpRequestProxy.handleListResponse(url,response,resultType);
}
});
}
public static List httpPostForList(String poolName,String url , final Class resultType) throws HttpProxyRequestException {
return httpPostforString( poolName,url, (Map) null, (Map) null, new BaseURLResponseHandler>() {
@Override
public List handleResponse(HttpResponse response) throws ClientProtocolException, IOException {
return HttpRequestProxy.handleListResponse(url,response,resultType);
}
});
}
public static List httpPostForList(String url , final Class resultType) throws HttpProxyRequestException {
return httpPostforString( (String)null,url, (Map) null, (Map) null, new BaseURLResponseHandler>() {
@Override
public List handleResponse(HttpResponse response) throws ClientProtocolException, IOException {
return HttpRequestProxy.handleListResponse(url,response,resultType);
}
});
}
public static Set httpPostForSet(String poolName,String url, Map params, final Class resultType) throws HttpProxyRequestException {
return httpPostforString( poolName,url, params, (Map) null, new BaseURLResponseHandler>() {
@Override
public Set handleResponse(HttpResponse response) throws ClientProtocolException, IOException {
return HttpRequestProxy.handleSetResponse(url,response,resultType);
}
});
}
public static Map httpPostForMap(String poolName,String url, Map params, final Class keyType, final Class resultType) throws HttpProxyRequestException {
return httpPostforString(poolName,url, params, (Map) null, new BaseURLResponseHandler>() {
@Override
public Map handleResponse(HttpResponse response) throws ClientProtocolException, IOException {
return HttpRequestProxy.handleMapResponse(url,response,keyType,resultType);
}
});
}
/**
* 公用post方法
*
* @param url
* @param params
* @param headers
* @throws HttpProxyRequestException
*/
public static String httpPostforString(String url, Map params, Map headers) throws HttpProxyRequestException {
return httpPostFileforString("default", url, (String) null, (String) null, params, (Map) null, headers);
}
/**
* 公用post方法
*
* @param url
* @param params
* @param headers
* @throws HttpProxyRequestException
*/
public static String httpPostforString(String poolName,String url, Map params, Map headers) throws HttpProxyRequestException {
return httpPostFileforString(poolName, url, (String) null, (String) null, params, (Map) null, headers);
}
/**
* 公用post方法
*
* @param url
* @param params
* @param headers
* @throws HttpProxyRequestException
*/
public static T httpPost(String url, Map params, Map headers,ResponseHandler responseHandler) throws HttpProxyRequestException {
return httpPost("default", url, (String) null, (String) null, params, (Map) null, headers, responseHandler);
}
/**
* 公用post方法
*
* @param url
* @param params
* @param headers
* @throws HttpProxyRequestException
*/
public static T httpPostforString(String url, Map params, Map headers,ResponseHandler responseHandler) throws HttpProxyRequestException {
return httpPost("default", url, (String) null, (String) null, params, (Map) null, headers,responseHandler);
}
/**
* 公用post方法
*
* @param url
* @param params
* @param headers
* @throws HttpProxyRequestException
*/
public static T httpPostforString(String poolName,String url, Map params, Map headers,ResponseHandler responseHandler) throws HttpProxyRequestException {
return httpPost(poolName, url, (String) null, (String) null, params, (Map) null, headers,responseHandler);
}
public static String httpPostforString(String poolname, String url, Map params) throws HttpProxyRequestException {
HttpOption httpOption = new HttpOption();
httpOption.params = params;
return httpPost( poolname, url, httpOption,new StringResponseHandler());
// return httpPostFileforString(poolname, url, (String) null, (String) null, params, (Map) null);
}
public static String httpPostforString(String poolname, String url, Map params,DataSerialType dataSerialType) throws HttpProxyRequestException {
HttpOption httpOption = new HttpOption();
httpOption.params = params;
httpOption.dataSerialType = dataSerialType;
return httpPost( poolname, url, httpOption,new StringResponseHandler());
// return httpPostFileforString(poolname, url, (String) null, (String) null, params, (Map) null);
}
public static String httpPostforString(String url) throws HttpProxyRequestException {
return httpPostforString("default", url);
}
public static T httpPost(String url,ResponseHandler responseHandler) throws HttpProxyRequestException {
return httpPost("default", url, responseHandler);
}
/**
* 公用post方法
*
* @param poolname
* @param url
* @throws HttpProxyRequestException
*/
public static String httpPostforString(String poolname, String url) throws HttpProxyRequestException {
return httpPostFileforString(poolname, url, (String) null, (String) null, (Map) null,
(Map) null);
}
/**
* 公用post方法
*
* @param poolname
* @param url
* @throws HttpProxyRequestException
*/
public static T httpPost(String poolname, String url,ResponseHandler responseHandler) throws HttpProxyRequestException {
return httpPost( poolname, url, (String) null, (String) null, (Map