當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。