当前位置: 首页>>代码示例>>Java>>正文


Java HttpRequestBase.abort方法代码示例

本文整理汇总了Java中org.apache.http.client.methods.HttpRequestBase.abort方法的典型用法代码示例。如果您正苦于以下问题:Java HttpRequestBase.abort方法的具体用法?Java HttpRequestBase.abort怎么用?Java HttpRequestBase.abort使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.apache.http.client.methods.HttpRequestBase的用法示例。


在下文中一共展示了HttpRequestBase.abort方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: createCancellableConnection

import org.apache.http.client.methods.HttpRequestBase; //导入方法依赖的package包/类
@Nullable
@Override
public CancellableConnection createCancellableConnection() {
  final HttpRequestBase request = apiRequest("user.whoami", Collections.emptyList());
  return new CancellableConnection() {
    @Override
    protected void doTest() throws Exception {
      try {
        HttpResponse response = getHttpClient().execute(request);
        WhoamiResponse res = deserializeApiResponse(response, WhoamiResponse.class);
        res.checkOk();
      }
      catch (IOException e) {
        if (!request.isAborted()) {
          throw e;
        }
      }
    }

    @Override
    public void cancel() {
      request.abort();
    }
  };
}
 
开发者ID:mmm444,项目名称:ijphab,代码行数:26,代码来源:PhabricatorRepository.java

示例2: query

import org.apache.http.client.methods.HttpRequestBase; //导入方法依赖的package包/类
/**
 * Execute Http request and response code
 * @param request - HTTP Request
 * @param expectedCode - expected response code
 * @return - response in JSONObject
 */
public JSON query(HttpRequestBase request, int expectedCode) throws IOException {
    log.info("Requesting: " + request);
    addRequiredHeader(request);

    HttpParams requestParams = request.getParams();
    requestParams.setIntParameter(CoreConnectionPNames.SO_TIMEOUT, TIMEOUT * 1000);
    requestParams.setIntParameter(CoreConnectionPNames.CONNECTION_TIMEOUT, TIMEOUT * 1000);

    synchronized (httpClient) {
        String response;
        try {
            HttpResponse result = httpClient.execute(request);

            int statusCode = result.getStatusLine().getStatusCode();

            response = getResponseEntity(result);

            if (statusCode != expectedCode) {

                notifier.notifyAbout("Response with code " + statusCode + ": " + extractErrorMessage(response));
                throw new IOException("API responded with wrong status code: " + statusCode);
            } else {
                log.debug("Response: " + response);
            }
        } finally {
            request.abort();
        }

        if (response == null || response.isEmpty()) {
            return JSONNull.getInstance();
        } else {
            return JSONSerializer.toJSON(response, new JsonConfig());
        }
    }
}
 
开发者ID:Blazemeter,项目名称:jmeter-bzm-plugins,代码行数:42,代码来源:HttpUtils.java

示例3: forceAbortRequestUnchecked

import org.apache.http.client.methods.HttpRequestBase; //导入方法依赖的package包/类
private static void forceAbortRequestUnchecked(HttpRequestBase internalHttpRequest){
	try{
		internalHttpRequest.abort();
	}catch(Exception e){
		logger.error("aborting internal http request failed", e);
	}
}
 
开发者ID:hotpads,项目名称:datarouter,代码行数:8,代码来源:DatarouterHttpClient.java

示例4: prepareRequest

import org.apache.http.client.methods.HttpRequestBase; //导入方法依赖的package包/类
@Override
public AbortableCallable<SdkHttpFullResponse> prepareRequest(SdkHttpFullRequest request, SdkRequestContext context) {
    final HttpRequestBase apacheRequest = toApacheRequest(request);
    return new AbortableCallable<SdkHttpFullResponse>() {
        @Override
        public SdkHttpFullResponse call() throws Exception {
            return execute(apacheRequest);
        }

        @Override
        public void abort() {
            apacheRequest.abort();
        }
    };
}
 
开发者ID:aws,项目名称:aws-sdk-java-v2,代码行数:16,代码来源:ApacheHttpClient.java

示例5: executeRequest

import org.apache.http.client.methods.HttpRequestBase; //导入方法依赖的package包/类
private Response executeRequest(HttpRequestBase httpMethod, HttpContext httpContext) throws RestException {
    try (CloseableHttpResponse httpResponse = client.execute(httpMethod, httpContext)) {
        return new Response(httpResponse.getStatusLine().getStatusCode(), HTTPCUtil.getHeaders(httpResponse), HTTPCUtil.handleResponse(httpResponse));
    
    } catch (Exception e) {
        httpMethod.abort();
        throw new RestException(e, e.getMessage());
    }
}
 
开发者ID:mercadolibre,项目名称:java-restclient,代码行数:10,代码来源:HTTPCClient.java

示例6: executeDownload

import org.apache.http.client.methods.HttpRequestBase; //导入方法依赖的package包/类
private Response executeDownload(HttpRequestBase method, HttpContext context, Request request) throws RestException {
    try (CloseableHttpResponse response = client.execute(method, context)) {
    	EmptyResponse emptyResponse = new EmptyResponse(response.getStatusLine().getStatusCode(), HTTPCUtil.getHeaders(response));
    	
        request.populateOutputStream(response.getEntity().getContent(), emptyResponse.getHeaders().getHeader("Content-Encoding"));
        
        EntityUtils.consume(response.getEntity());

        return emptyResponse;
        
    } catch (IOException e) {
        method.abort();
        throw new RestException(e, e.getMessage());
    }
}
 
开发者ID:mercadolibre,项目名称:java-restclient,代码行数:16,代码来源:HTTPCClient.java


注:本文中的org.apache.http.client.methods.HttpRequestBase.abort方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。