public static <T> T execute(HttpRequestBase request, HttpResponseCallbackHandler<T> responseHandler)
            throws Exception {

        CloseableHttpResponse httpclientResponse = null;

        try {

            if (LOGGER.isDebugEnabled()) {
                Header[] headers = request.getAllHeaders();
                for (Header header : headers) {
                    LOGGER.debug("request: " + header.getName() + "\t" + header.getValue());
                }
            }

            httpclientResponse = httpclient.execute(request);

            if (LOGGER.isDebugEnabled()) {
                for (Header header : httpclientResponse.getAllHeaders()) {
                    LOGGER.debug("response header: {}\t{}", header.getName(), header.getValue());
                }
            }

            // 填充状态码
            int statusCode = httpclientResponse.getStatusLine().getStatusCode();

            String requestBody = null;
            if (request instanceof HttpEntityEnclosingRequestBase) {
                HttpEntity requestEntity = ((HttpEntityEnclosingRequestBase) request).getEntity();
                if (requestEntity != null) {
                    requestBody = EntityUtils.toString(requestEntity);
                }
            }

            LOGGER.info("execute http request [{}], status code [{}]", requestBody, statusCode);

            if (statusCode != 200) {
                throw new Exception("execute  request failed [" + requestBody + "], statusCode [" + statusCode
                        + "]");
            }

            // 处理响应体
            HttpEntity entity = httpclientResponse.getEntity();
            if (entity != null && responseHandler != null) {
                return responseHandler.handleResponse(requestBody, entity);
            } else {
                LOGGER.info("execute response [{}], response empty", requestBody);
            }

            return null;

        } catch (Exception e) {
            throw e;
        } finally {
            if (httpclientResponse != null) {
                try {
                    httpclientResponse.close();
                } catch (IOException e) {
                }
            }
        }
    }
public static < T > T execute ( HttpRequestBase request , HttpResponseCallbackHandler < T > responseHandler ) throws Exception { CloseableHttpResponse httpclientResponse = null ; try { if ( LOGGER . isDebugEnabled ( ) ) { Header [ ] headers = request . getAllHeaders ( ) ; for ( Header header : headers ) { LOGGER . debug ( "request: " + header . getName ( ) + "\t" + header . getValue ( ) ) ; } } httpclientResponse = httpclient . execute ( request ) ; if ( LOGGER . isDebugEnabled ( ) ) { for ( Header header : httpclientResponse . getAllHeaders ( ) ) { LOGGER . debug ( "response header: {}\t{}" , header . getName ( ) , header . getValue ( ) ) ; } } int statusCode = httpclientResponse . getStatusLine ( ) . getStatusCode ( ) ; String requestBody = null ; if ( request instanceof HttpEntityEnclosingRequestBase ) { HttpEntity requestEntity = ( ( HttpEntityEnclosingRequestBase ) request ) . getEntity ( ) ; if ( requestEntity != null ) { requestBody = EntityUtils . toString ( requestEntity ) ; } } LOGGER . info ( "execute http request [{}], status code [{}]" , requestBody , statusCode ) ; if ( statusCode != 200 ) { throw new Exception ( "execute  request failed [" + requestBody + "], statusCode [" + statusCode + "]" ) ; } HttpEntity entity = httpclientResponse . getEntity ( ) ; if ( entity != null && responseHandler != null ) { return responseHandler . handleResponse ( requestBody , entity ) ; } else { LOGGER . info ( "execute response [{}], response empty" , requestBody ) ; } return null ; } catch ( Exception e ) { throw e ; } finally { if ( httpclientResponse != null ) { try { httpclientResponse . close ( ) ; } catch ( IOException e ) { } } } }
处理具体代理请求执行, 入口方法

@throws Exception