當前位置: 首頁>>代碼示例>>Java>>正文


Java Response.getStatusCode方法代碼示例

本文整理匯總了Java中com.ning.http.client.Response.getStatusCode方法的典型用法代碼示例。如果您正苦於以下問題:Java Response.getStatusCode方法的具體用法?Java Response.getStatusCode怎麽用?Java Response.getStatusCode使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在com.ning.http.client.Response的用法示例。


在下文中一共展示了Response.getStatusCode方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: browse

import com.ning.http.client.Response; //導入方法依賴的package包/類
public Collection<MesosFileObject> browse(String slaveHostname, String fullPath) throws SlaveNotFoundException {
  try {
    Response response = asyncHttpClient.prepareGet(String.format("http://%s:5051/files/browse.json", slaveHostname))
        .addQueryParameter("path", fullPath)
        .execute().get();

    if (response.getStatusCode() == 404) {
      return Collections.emptyList();
    }

    if (response.getStatusCode() != 200) {
      throw new RuntimeException(String.format("Got HTTP %s from Mesos slave", response.getStatusCode()));
    }

    return objectMapper.readValue(response.getResponseBodyAsStream(), MESOS_FILE_OBJECTS);
  } catch (ConnectException ce) {
    throw new SlaveNotFoundException(ce);
  } catch (Exception e) {
    if (e.getCause().getClass() == ConnectException.class) {
      throw new SlaveNotFoundException(e);
    } else {
      throw Throwables.propagate(e);
    }
  }
}
 
開發者ID:PacktPublishing,項目名稱:Mastering-Mesos,代碼行數:26,代碼來源:SandboxManager.java

示例2: get

import com.ning.http.client.Response; //導入方法依賴的package包/類
@Override
public BrokerResponse get(long timeout, TimeUnit unit)
    throws InterruptedException, ExecutionException, TimeoutException {
  try {
    LOGGER.debug("Sending query {} to {}", _query, _url);

    Response httpResponse = _response.get(timeout, unit);

    LOGGER.debug("Completed query, HTTP status is {}", httpResponse.getStatusCode());

    if (httpResponse.getStatusCode() != 200) {
      throw new PinotClientException("Pinot returned HTTP status " + httpResponse.getStatusCode() +
          ", expected 200");
    }

    String responseBody = httpResponse.getResponseBody();
    return BrokerResponse.fromJson(new JSONObject(responseBody));
  } catch (Exception e) {
    throw new ExecutionException(e);
  }
}
 
開發者ID:Hanmourang,項目名稱:Pinot,代碼行數:22,代碼來源:JsonAsyncHttpPinotClientTransport.java

示例3: onCompleted

import com.ning.http.client.Response; //導入方法依賴的package包/類
@Override
public Response onCompleted(final Response response) throws Exception {
	final long duration = System.currentTimeMillis() - startTime;
	Boolean sameStatus = null;
	try {
		sameStatus = Integer.parseInt(originalData.getStatusCode()) == response.getStatusCode();
	} catch (NumberFormatException e) {
		LOG.warn("Unable to parse original status code to int: {}", originalData.getStatusCode());
	}
	resultDataLogger.logResultDataLine(originalData, response, sameStatus, duration, startTime);
	LOG.info("Status={} OriginalStatus={} SameStatus={} Duration={} OriginalDuration={} Difference={} Request={}", response.getStatusCode(), originalData.getStatusCode(),
			sameStatus, duration,
			originalData.getDuration(),
			duration - originalData.getDuration(), response.getUri().toASCIIString());
	return response;
}
 
開發者ID:paulwellnerbou,項目名稱:chronicreplay,代碼行數:17,代碼來源:LoggingAsyncCompletionHandler.java

示例4: getContents

import com.ning.http.client.Response; //導入方法依賴的package包/類
public Optional<String> getContents(String user, String repo, String path, Optional<String> ref) {
  try {
    final BoundRequestBuilder builder = asyncHttpClient.prepareGet(String.format("%s/repos/%s/%s/contents/%s", baseUrl, user, repo, path))
        .addHeader("Accept", "application/vnd.github.v3.raw");

    if (ref.isPresent()) {
      builder.addQueryParameter("ref", ref.get());
    }

    if (accessToken.isPresent()) {
      builder.addQueryParameter("access_token", accessToken.get());
    }

    final Response response = builder.execute().get();

    if (response.getStatusCode() == 200) {
      return Optional.of(response.getResponseBody());
    } else if (response.getStatusCode() == 404) {
      return Optional.absent();
    } else {
      throw new RuntimeException(response.getResponseBody());  // TODO: better exception
    }
  } catch (Exception e) {
    throw Throwables.propagate(e);
  }
}
 
開發者ID:HubSpot,項目名稱:Nebula,代碼行數:27,代碼來源:GitHubClient.java

示例5: read

import com.ning.http.client.Response; //導入方法依賴的package包/類
@SuppressWarnings("deprecation")
public Optional<MesosFileChunkObject> read(String slaveHostname, String fullPath, Optional<Long> offset, Optional<Long> length) throws SlaveNotFoundException {
  try {
    final AsyncHttpClient.BoundRequestBuilder builder = asyncHttpClient.prepareGet(String.format("http://%s:5051/files/read.json", slaveHostname))
        .addQueryParameter("path", fullPath);

    PerRequestConfig timeoutConfig = new PerRequestConfig();
    timeoutConfig.setRequestTimeoutInMs((int) configuration.getSandboxHttpTimeoutMillis());
    builder.setPerRequestConfig(timeoutConfig);

    if (offset.isPresent()) {
      builder.addQueryParameter("offset", offset.get().toString());
    }

    if (length.isPresent()) {
      builder.addQueryParameter("length", length.get().toString());
    }

    final Response response = builder.execute().get();

    if (response.getStatusCode() == 404) {
      return Optional.absent();
    }

    if (response.getStatusCode() != 200) {
      throw new RuntimeException(String.format("Got HTTP %s from Mesos slave", response.getStatusCode()));
    }

    return Optional.of(objectMapper.readValue(response.getResponseBodyAsStream(), MesosFileChunkObject.class));
  } catch (ConnectException ce) {
    throw new SlaveNotFoundException(ce);
  } catch (Exception e) {
    if ((e.getCause() != null) && (e.getCause().getClass() == ConnectException.class)) {
      throw new SlaveNotFoundException(e);
    } else {
      throw Throwables.propagate(e);
    }
  }
}
 
開發者ID:PacktPublishing,項目名稱:Mastering-Mesos,代碼行數:40,代碼來源:SandboxManager.java

示例6: sendRequest

import com.ning.http.client.Response; //導入方法依賴的package包/類
private LoadBalancerUpdateHolder sendRequest(LoadBalancerRequestId loadBalancerRequestId, Request request, BaragonRequestState onFailure) {
  try {
    LOG.trace("Sending LB {} request for {} to {}", request.getMethod(), loadBalancerRequestId, request.getUrl());

    ListenableFuture<Response> future = httpClient.executeRequest(request);

    Response response = future.get(loadBalancerTimeoutMillis, TimeUnit.MILLISECONDS);

    LOG.trace("LB {} request {} returned with code {}", request.getMethod(), loadBalancerRequestId, response.getStatusCode());

    if (response.getStatusCode() == 504) {
      return new LoadBalancerUpdateHolder(BaragonRequestState.UNKNOWN, Optional.of(String.format("LB %s request %s timed out", request.getMethod(), loadBalancerRequestId)));
    } else if (!JavaUtils.isHttpSuccess(response.getStatusCode())) {
      return new LoadBalancerUpdateHolder(onFailure, Optional.of(String.format("Response status code %s", response.getStatusCode())));
    }

    BaragonResponse lbResponse = readResponse(response);

    return new LoadBalancerUpdateHolder(lbResponse.getLoadBalancerState(), lbResponse.getMessage());
  } catch (TimeoutException te) {
    LOG.trace("LB {} request {} timed out after waiting {}", request.getMethod(), loadBalancerRequestId, JavaUtils.durationFromMillis(loadBalancerTimeoutMillis));
    return new LoadBalancerUpdateHolder(BaragonRequestState.UNKNOWN, Optional.of(String.format("Timed out after %s", JavaUtils.durationFromMillis(loadBalancerTimeoutMillis))));
  } catch (Throwable t) {
    LOG.error("LB {} request {} to {} threw error", request.getMethod(), loadBalancerRequestId, request.getUrl(), t);
    return new LoadBalancerUpdateHolder(BaragonRequestState.UNKNOWN, Optional.of(String.format("Exception %s - %s", t.getClass().getSimpleName(), t.getMessage())));
  }
}
 
開發者ID:PacktPublishing,項目名稱:Mastering-Mesos,代碼行數:28,代碼來源:LoadBalancerClientImpl.java

示例7: onCompleted

import com.ning.http.client.Response; //導入方法依賴的package包/類
@Override
public T onCompleted(Response response) throws Exception {
    if (expectedStatusCodes.contains(response.getStatusCode())) {
        if (response.hasResponseBody()) {
            if (tClass == String.class) {
                return tClass.cast(response.getResponseBody());
            } else {
                return objectMapper.readValue(response.getResponseBody(), tClass);
            }
        }
        return null;
    } else {
        throw new HTTPException(response.getStatusCode());
    }
}
 
開發者ID:yahoo,項目名稱:parsec-libraries,代碼行數:16,代碼來源:DefaultAsyncCompletionHandler.java

示例8: onCompleted

import com.ning.http.client.Response; //導入方法依賴的package包/類
@Override
public Void onCompleted(final Response response) throws Exception {
    final URI requestUri = response.getUri();
    try {
        if (!response.hasResponseStatus()) {
            sendError(response, "the response didn't have a response status");
            return null;
        }

        final int httpStatusCode = response.getStatusCode();
        if (httpStatusCode != HttpStatus.SC_OK) {
            return handleFailureHttpStatus(response, requestUri, httpStatusCode);
        } else {
            if(returnType.equals(Void.class)){
                httpResponseHandler.sendMessage(Message.obtain(httpResponseHandler, HttpRequestTask.SUCCESS, 0, 0));
            } else {
                if (checkResponseBody(response)) return null;
                final String responseValue = response.getResponseBody(request.getBodyEncoding());
                Logger.getInstance().d("ResponseBody: " + responseValue);

                Object result;
                if(returnType.equals(String.class)) {
                    result = responseValue;
                } else if(returnType.equals(Character.class)) {
                    result = responseValue.charAt(0);
                } else {
                    result = new ObjectMapper().readValue(responseValue, returnType);
                }
                httpResponseHandler.sendMessage(Message.obtain(httpResponseHandler, HttpRequestTask.SUCCESS, 0, 0, result));
            }
            return null;
        }
    } catch (Exception e) {
        sendError(response, e.toString());
        return null;
    }
}
 
開發者ID:yongbeam,項目名稱:Android-kakaologin-gradle-sample,代碼行數:38,代碼來源:KakaoAsyncHandler.java

示例9: onCompleted

import com.ning.http.client.Response; //導入方法依賴的package包/類
@Override
public Response onCompleted(Response response) throws Exception {
    if (response.getStatusCode() < 200 || response.getStatusCode() > 206)
        throw new RuntimeException("Unexpected Buttercoin API response: " + response.getStatusCode() + " " + response.getStatusText() + " " + response.getResponseBody("UTF-8"));

    return response;
}
 
開發者ID:buttercoin,項目名稱:buttercoin-java,代碼行數:8,代碼來源:ThrowOnHttpFailure.java

示例10: apply

import com.ning.http.client.Response; //導入方法依賴的package包/類
@Override
public URL apply(Response response) {
    if (response.getStatusCode() != 202)
        throw new RuntimeException("Not a 202 Created response: " + response.getStatusCode() + " " + response.getStatusText());

    try {
        return new URL(response.getHeader("Location"));
    }
    catch (MalformedURLException e) {
        throw new RuntimeException(e);
    }
}
 
開發者ID:buttercoin,項目名稱:buttercoin-java,代碼行數:13,代碼來源:Status202ExtractLocation.java

示例11: onCompleted

import com.ning.http.client.Response; //導入方法依賴的package包/類
@Override
public Response onCompleted(Response response) throws Exception {
    if (response.getStatusCode() != 200) {
        LOG.info(" <- '{}'", response.getStatusCode());
    }
    return response;
}
 
開發者ID:elastisys,項目名稱:scale.commons,代碼行數:8,代碼來源:BurstingApacheLogReplayer.java

示例12: onCompleted

import com.ning.http.client.Response; //導入方法依賴的package包/類
@Override
public Response onCompleted(Response response) throws Exception{

    // TODO: Handle status codes other than 200...
    int httpStatus = response.getStatusCode();

    if (deferredResult.isSetOrExpired()) {
        log.logAlreadyExpiredNonBlocking();

    } else {
        boolean deferredStatus = deferredResult.setResult(response.getResponseBody());
        log.logEndNonBlocking(httpStatus, deferredStatus);
    }
    return response;
}
 
開發者ID:callistaenterprise,項目名稱:blog-non-blocking-rest-service-with-spring-mvc,代碼行數:16,代碼來源:RouterCallback.java

示例13: onResult

import com.ning.http.client.Response; //導入方法依賴的package包/類
public void onResult(int id, Response response) {

        try {
            // TODO: Handle status codes other than 200...
            int httpStatus = response.getStatusCode();
            log.logEndProcessingStepNonBlocking(id, httpStatus);

            // If many requests completes at the same time the following code must be executed in sequence for one thread at a time
            // Since we don't have any Actor-like mechanism to rely on (for the time being...) we simply ensure that the code block is executed by one thread at a time by an old school synchronized block
            // Since the processing in the block is very limited it will not cause a bottleneck.
            synchronized (result) {
                // Count down, aggregate answer and return if all answers (also cancel timer)...
                int noOfRes = noOfResults.incrementAndGet();

                // Perform the aggregation...
                log.logMessage("Safely adding response #" + id);
                result += response.getResponseBody() + '\n';

                if (noOfRes >= noOfCalls) {
                    onAllCompleted();
                }
            }



        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }
 
開發者ID:callistaenterprise,項目名稱:blog-non-blocking-rest-service-with-spring-mvc,代碼行數:30,代碼來源:AggregatorEventHandler.java

示例14: onComplete

import com.ning.http.client.Response; //導入方法依賴的package包/類
public MyResponse onComplete(Response response) {

		cancelCancellable();
		try {

			String statusCode = response.getStatusCode() + " " + response.getStatusText();
			
			reply(response.getResponseBody(), false, null, null, statusCode);
		} catch (IOException e) {
			e.printStackTrace();
		}

		return null;
	}
 
開發者ID:eBay,項目名稱:restcommander,代碼行數:15,代碼來源:HttpWorker.java

示例15: setResponse

import com.ning.http.client.Response; //導入方法依賴的package包/類
public void setResponse(String endpoint, Response response) throws IOException {

        Integer statusCode = response.getStatusCode();
        String httpResponse = response.getResponseBody();
        List<Cookie> cookies = response.getCookies();
        this.response = new HttpResponse(statusCode, httpResponse, cookies);
    }
 
開發者ID:Stratio,項目名稱:bdt,代碼行數:8,代碼來源:CommonG.java


注:本文中的com.ning.http.client.Response.getStatusCode方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。