Java 类org.apache.http.impl.nio.client.DefaultHttpAsyncClient 实例源码

项目:Mob-Platform    文件:ServiceCallManager_callServiceWith_UnitTests.java   
@SuppressWarnings("unchecked")
public ServiceCallManager_callServiceWith_UnitTests(String serviceCall, String data, String contentType, String serviceEndpoint, Map<String,String> tokenLookup, HttpResponse httpResponse, HttpResponse expectedResponse, boolean isDataTest) throws InterruptedException, ExecutionException
{
    this.serviceCall = serviceCall;
    this.expectedResponse = expectedResponse;
    this.data = data;
    this.contentType = contentType;
    this.isDataTest = isDataTest;

    this.context = mock(ServiceCallContext.class);
    when(this.context.getTokenLookup()).thenReturn(tokenLookup);

    IServiceContracts contract = mock(IServiceContracts.class);
    when(contract.getEndpointFromAlias(serviceCall, context)).thenReturn(serviceEndpoint);

    Future<HttpResponse> response = mock(Future.class);
    when(response.get()).thenReturn(httpResponse);

    this.client = mock(DefaultHttpAsyncClient.class);
    when(this.client.execute(any(HttpUriRequest.class), any(FutureCallback.class))).thenReturn(response);

    this.service.setHttpClient(client)
                .setServiceContracts(contract);
}
项目:debop4j    文件:AsyncLoadPage.java   
@Override
public void run() {
    // To change body of implemented methods use File | Settings | File Templates.if (log.isDebugEnabled())
    log.debug("URI=[{}] 의 웹 컨텐츠를 비동기 방식으로 다운로드 받아 캐시합니다.", url);

    try {

        String responseStr;
        HttpAsyncClient httpClient = new DefaultHttpAsyncClient();
        httpClient.start();
        HttpGet request = new HttpGet(url);
        Future<HttpResponse> future = httpClient.execute(request, null);

        HttpResponse response = future.get();
        responseStr = EntityUtils.toString(response.getEntity(), Charsets.UTF_8.toString());
        httpClient.shutdown();

        if (log.isDebugEnabled())
            log.debug("URI=[{}]로부터 웹 컨텐츠를 다운로드 받았습니다. responseStr=[{}]",
                      url, StringTool.ellipsisChar(responseStr, 255));

        ctx.getResponse().setCharacterEncoding("UTF-8");
        PrintWriter writer = ctx.getResponse().getWriter();
        writer.write(responseStr);
        writer.close();
        ctx.complete();
    } catch (Exception ignored) {
        throw new RuntimeException(ignored);
    }
}
项目:bsming    文件:HttpNIOClientUtil.java   
/**
   * 
   * @throws Exception .
   */
  private void init() throws IOReactorException {
HttpParams params = new SyncBasicHttpParams();  
HttpProtocolParams.setVersion(params, HttpVersion.HTTP_1_1);
HttpConnectionParams.setSocketBufferSize(params, 8192);

HttpConnectionParams.setConnectionTimeout(params, connectionTimeOut);       
HttpConnectionParams.setSoTimeout(params, 3000);

httpclient = new DefaultHttpAsyncClient(params);
httpclient.start();

  }
项目:Mob-Platform    文件:ServiceCallManager.java   
public ServiceCallManager setHttpClient(DefaultHttpAsyncClient value)
{
    this.httpClient = value;
    return this;
}
项目:Mob-Platform    文件:ServiceCallManager.java   
public DefaultHttpAsyncClient getHttpClient(){ return this.httpClient; }