添加枚举HttpType

This commit is contained in:
ecoolper 2017-05-03 20:55:49 +08:00
parent a8dfccc210
commit 2384b4b863
2 changed files with 29 additions and 20 deletions

View File

@ -17,26 +17,29 @@ import okhttp3.ConnectionPool;
public abstract class AbstractRequestExecutor<T, E> implements RequestExecutor<T, E> { public abstract class AbstractRequestExecutor<T, E> implements RequestExecutor<T, E> {
@Override @Override
public T execute(RequestHttp requestHttp, String uri, E data) throws WxErrorException, IOException{ public T execute(RequestHttp requestHttp, String uri, E data) throws WxErrorException, IOException {
if (requestHttp.getRequestHttpClient() instanceof CloseableHttpClient) { switch (requestHttp.getRequestType()) {
//apache-http请求 case apacheHttp: {
CloseableHttpClient httpClient = (CloseableHttpClient) requestHttp.getRequestHttpClient(); //apache-http请求
HttpHost httpProxy = (HttpHost) requestHttp.getRequestHttpProxy(); CloseableHttpClient httpClient = (CloseableHttpClient) requestHttp.getRequestHttpClient();
return executeApache(httpClient, httpProxy, uri, data); HttpHost httpProxy = (HttpHost) requestHttp.getRequestHttpProxy();
} return executeApache(httpClient, httpProxy, uri, data);
if (requestHttp.getRequestHttpClient() instanceof HttpConnectionProvider) { }
//jodd-http请求 case joddHttp: {
HttpConnectionProvider provider = (HttpConnectionProvider) requestHttp.getRequestHttpClient(); //jodd-http请求
ProxyInfo proxyInfo = (ProxyInfo) requestHttp.getRequestHttpProxy(); HttpConnectionProvider provider = (HttpConnectionProvider) requestHttp.getRequestHttpClient();
return executeJodd(provider, proxyInfo, uri, data); ProxyInfo proxyInfo = (ProxyInfo) requestHttp.getRequestHttpProxy();
} else if (requestHttp.getRequestHttpClient() instanceof ConnectionPool) { return executeJodd(provider, proxyInfo, uri, data);
//okhttp请求 }
ConnectionPool pool = (ConnectionPool) requestHttp.getRequestHttpClient(); case okHttp: {
OkhttpProxyInfo proxyInfo = (OkhttpProxyInfo) requestHttp.getRequestHttpProxy(); //okhttp请求
return executeOkhttp(pool, proxyInfo, uri, data); ConnectionPool pool = (ConnectionPool) requestHttp.getRequestHttpClient();
} else { OkhttpProxyInfo proxyInfo = (OkhttpProxyInfo) requestHttp.getRequestHttpProxy();
//TODO 这里需要抛出异常需要优化 return executeOkhttp(pool, proxyInfo, uri, data);
return null; }
default:
//TODO 这里需要抛出异常需要优化
return null;
} }
} }

View File

@ -17,4 +17,10 @@ public interface RequestHttp<H,P> {
*/ */
P getRequestHttpProxy(); P getRequestHttpProxy();
/**
*
* @return
*/
HttpType getRequestType();
} }