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


Java HttpStatus.SC_SERVICE_UNAVAILABLE属性代码示例

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


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

示例1: sendConnectionErrorMessage

public static void sendConnectionErrorMessage(IDiscordClient client, IChannel channel, String command, @Nullable String message, @NotNull HttpStatusException httpe) throws RateLimitException, DiscordException, MissingPermissionsException {
    @NotNull String problem = message != null ? message + "\n" : "";
    if (httpe.getStatusCode() == HttpStatus.SC_SERVICE_UNAVAILABLE) {
        problem += "Service unavailable, please try again latter.";
    } else if (httpe.getStatusCode() == HttpStatus.SC_FORBIDDEN) {
        problem += "Acess dennied.";
    } else if (httpe.getStatusCode() == HttpStatus.SC_NOT_FOUND) {
        problem += "Not Found";
    } else {
        problem += httpe.getStatusCode() + SPACE + httpe.getMessage();
    }

    new MessageBuilder(client)
            .appendContent("Error during HTTP Connection ", MessageBuilder.Styles.BOLD)
            .appendContent("\n")
            .appendContent(EventManager.MAIN_COMMAND_NAME, MessageBuilder.Styles.BOLD)
            .appendContent(SPACE)
            .appendContent(command, MessageBuilder.Styles.BOLD)
            .appendContent("\n")
            .appendContent(problem, MessageBuilder.Styles.BOLD)
            .withChannel(channel)
            .send();
}
 
开发者ID:ViniciusArnhold,项目名称:ProjectAltaria,代码行数:23,代码来源:EventUtils.java

示例2: testServiceUnavailableFailure

@Test(expectedExceptions = DatarouterHttpResponseException.class)
public void testServiceUnavailableFailure() throws DatarouterHttpException{
	try{
		int status = HttpStatus.SC_SERVICE_UNAVAILABLE;
		String expectedResponse = UUID.randomUUID().toString();
		server.setResponse(status, expectedResponse);
		DatarouterHttpClient client = new DatarouterHttpClientBuilder().build();
		DatarouterHttpRequest request = new DatarouterHttpRequest(HttpRequestMethod.GET, URL, false);
		client.executeChecked(request);
	}catch(DatarouterHttpResponseException e){
		Assert.assertTrue(e.isServerError());
		DatarouterHttpResponse response = e.getResponse();
		Assert.assertNotNull(response);
		Assert.assertEquals(response.getStatusCode(), HttpStatus.SC_SERVICE_UNAVAILABLE);
		throw e;
	}
}
 
开发者ID:hotpads,项目名称:datarouter,代码行数:17,代码来源:DatarouterHttpClientIntegrationTests.java

示例3: toResponse

@Override
public Response toResponse(Exception e) {
  // Don't catch this as filter forward on 404
  // (ServletContainer.FEATURE_FILTER_FORWARD_ON_404)
  // won't work and the web UI won't work!
  if (e instanceof com.sun.jersey.api.NotFoundException) {
    return ((com.sun.jersey.api.NotFoundException) e).getResponse();
  }
  // clear content type
  response.setContentType(null);

  // Map response status
  String logPrefix = "Http request failed due to: ";
  final int statusCode;
  if (e instanceof NotFoundException) {
    LOGGER.logInfo(e, logPrefix + "Not Found");
    statusCode = HttpStatus.SC_NOT_FOUND;
  } else if (e instanceof BadRequestException ||
      e instanceof JsonProcessingException ||
      e instanceof WebApplicationException) {
    LOGGER.logInfo(e, logPrefix + "Bad Request");
    statusCode = HttpStatus.SC_BAD_REQUEST;
  } else if (e instanceof ThrottledRequestException) {
    LOGGER.logInfo(e, logPrefix + "Throttled Request");
    statusCode = WebCommon.SC_TOO_MANY_REQUESTS;
  } else {
    LOGGER.logWarning(e, logPrefix + "Service Unavailable");
    statusCode = HttpStatus.SC_SERVICE_UNAVAILABLE;
  }

  // let jaxb handle marshalling data out in the same format requested
  RemoteExceptionData exception = new RemoteExceptionData(
      e.getClass().getSimpleName(),
      StringUtils.stringifyException(e),
      e.getClass().getName());

  return Response.status(statusCode).entity(exception)
      .build();
}
 
开发者ID:Microsoft,项目名称:pai,代码行数:39,代码来源:LauncherExceptionHandler.java

示例4: shouldRetryCommon

private Boolean shouldRetryCommon(WebClientOutput output) {
  if (output.getStatusCode() == HttpStatus.SC_REQUEST_TIMEOUT ||
      output.getStatusCode() == HttpStatus.SC_SERVICE_UNAVAILABLE ||
      output.getStatusCode() == WebCommon.SC_TOO_MANY_REQUESTS) {
    // Must be Transient Failure
    return true;
  } else if (output.getStatusCode() == HttpStatus.SC_BAD_REQUEST) {
    // Must be NON_TRANSIENT Failure
    return false;
  } else {
    // UNKNOWN Failure
    return null;
  }
}
 
开发者ID:Microsoft,项目名称:pai,代码行数:14,代码来源:LauncherClientInternal.java

示例5: map

public BackgroundException map(final Throwable failure, final StringBuilder buffer, final int statusCode) {
    switch(statusCode) {
        case HttpStatus.SC_UNAUTHORIZED:
            return new LoginFailureException(buffer.toString(), failure);
        case HttpStatus.SC_PROXY_AUTHENTICATION_REQUIRED:
            return new ProxyLoginFailureException(buffer.toString(), failure);
        case HttpStatus.SC_FORBIDDEN:
        case HttpStatus.SC_NOT_ACCEPTABLE:
            return new AccessDeniedException(buffer.toString(), failure);
        case HttpStatus.SC_CONFLICT:
            return new ConflictException(buffer.toString(), failure);
        case HttpStatus.SC_NOT_FOUND:
        case HttpStatus.SC_GONE:
        case HttpStatus.SC_REQUESTED_RANGE_NOT_SATISFIABLE:
            return new NotfoundException(buffer.toString(), failure);
        case HttpStatus.SC_INSUFFICIENT_SPACE_ON_RESOURCE:
        case HttpStatus.SC_INSUFFICIENT_STORAGE:
        case HttpStatus.SC_PAYMENT_REQUIRED:
            return new QuotaException(buffer.toString(), failure);
        case HttpStatus.SC_UNPROCESSABLE_ENTITY:
        case HttpStatus.SC_BAD_REQUEST:
        case HttpStatus.SC_REQUEST_URI_TOO_LONG:
        case HttpStatus.SC_METHOD_NOT_ALLOWED:
        case HttpStatus.SC_NOT_IMPLEMENTED:
            return new InteroperabilityException(buffer.toString(), failure);
        case HttpStatus.SC_REQUEST_TIMEOUT:
        case HttpStatus.SC_GATEWAY_TIMEOUT:
        case HttpStatus.SC_BAD_GATEWAY:
            return new ConnectionTimeoutException(buffer.toString(), failure);
        case HttpStatus.SC_INTERNAL_SERVER_ERROR:
        case HttpStatus.SC_SERVICE_UNAVAILABLE:
        case 429:
            // Too Many Requests. Rate limiting
        case 509:
            // Bandwidth Limit Exceeded
            return new RetriableAccessDeniedException(buffer.toString(), failure);
        default:
            return new InteroperabilityException(buffer.toString(), failure);
    }
}
 
开发者ID:iterate-ch,项目名称:cyberduck,代码行数:40,代码来源:HttpResponseExceptionMappingService.java

示例6: getAuthorizationResult

public void getAuthorizationResult(String url) throws IOException, ScriptException {

        URL cloudFlareUrl = new URL(url);

        try {

            int retries = 5;
            Response response = getResponse(url,null);

            while (response.httpStatus == HttpStatus.SC_SERVICE_UNAVAILABLE && retries-- > 0) {

                int answer = getJsAnswer(cloudFlareUrl,response.responseText);
                String jschl_vc = new PatternStreamer(jsChallenge).results(response.responseText).findFirst().get();
                String pass =  new PatternStreamer(password).results(response.responseText).findFirst().get();

                String authUrl = String.format("https://%s/cdn-cgi/l/chk_jschl?jschl_vc=%s&pass=%s&jschl_answer=%d",
                        cloudFlareUrl.getHost(),jschl_vc,pass,answer);

                Thread.sleep(5000);
                response = getResponse(authUrl, url);
            }

            if (response.httpStatus != HttpStatus.SC_OK) {
                log.error("Failed to perform Cloudflare DDoS authorization, got status {}", response.httpStatus);
                return;
            }

        }catch(InterruptedException ie){
            log.error("Interrupted whilst waiting to perform CloudFlare authorization",ie);
            return;
        }

        Optional<Cookie> cfClearanceCookie = httpClientContext.getCookieStore().getCookies()
                .stream()
                .filter(cookie -> cookie.getName().equals("cf_clearance"))
                .findFirst();

        if(cfClearanceCookie.isPresent()) {
            log.info("Cloudflare DDos authorization success, cf_clearance: {}",
                    cfClearanceCookie.get().getValue());
        }else{
            log.info("Cloudflare DDoS is not currently active");
        }
    }
 
开发者ID:CCob,项目名称:bittrex4j,代码行数:44,代码来源:CloudFlareAuthorizer.java

示例7: retryRequest

public boolean retryRequest(final HttpResponse response, int executionCount, final HttpContext context) {
    return executionCount <= maxRetries &&
        response.getStatusLine().getStatusCode() == HttpStatus.SC_SERVICE_UNAVAILABLE;
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:4,代码来源:DefaultServiceUnavailableRetryStrategy.java

示例8: shouldBackoff

public boolean shouldBackoff(HttpResponse resp) {
    return (resp.getStatusLine().getStatusCode() == HttpStatus.SC_SERVICE_UNAVAILABLE);
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:3,代码来源:DefaultBackoffStrategy.java

示例9: process

public void process(final HttpResponse response, final HttpContext context)
        throws HttpException, IOException {
    if (response == null) {
        throw new IllegalArgumentException("HTTP response may not be null");
    }
    if (context == null) {
        throw new IllegalArgumentException("HTTP context may not be null");
    }
    // Always drop connection after certain type of responses
    int status = response.getStatusLine().getStatusCode();
    if (status == HttpStatus.SC_BAD_REQUEST ||
            status == HttpStatus.SC_REQUEST_TIMEOUT ||
            status == HttpStatus.SC_LENGTH_REQUIRED ||
            status == HttpStatus.SC_REQUEST_TOO_LONG ||
            status == HttpStatus.SC_REQUEST_URI_TOO_LONG ||
            status == HttpStatus.SC_SERVICE_UNAVAILABLE ||
            status == HttpStatus.SC_NOT_IMPLEMENTED) {
        response.setHeader(HTTP.CONN_DIRECTIVE, HTTP.CONN_CLOSE);
        return;
    }
    Header explicit = response.getFirstHeader(HTTP.CONN_DIRECTIVE);
    if (explicit != null && HTTP.CONN_CLOSE.equalsIgnoreCase(explicit.getValue())) {
        // Connection persistence explicitly disabled
        return;
    }
    // Always drop connection for HTTP/1.0 responses and below
    // if the content body cannot be correctly delimited
    HttpEntity entity = response.getEntity();
    if (entity != null) {
        ProtocolVersion ver = response.getStatusLine().getProtocolVersion();
        if (entity.getContentLength() < 0 &&
                (!entity.isChunked() || ver.lessEquals(HttpVersion.HTTP_1_0))) {
            response.setHeader(HTTP.CONN_DIRECTIVE, HTTP.CONN_CLOSE);
            return;
        }
    }
    // Drop connection if requested by the client or request was <= 1.0
    HttpRequest request = (HttpRequest)
        context.getAttribute(ExecutionContext.HTTP_REQUEST);
    if (request != null) {
        Header header = request.getFirstHeader(HTTP.CONN_DIRECTIVE);
        if (header != null) {
            response.setHeader(HTTP.CONN_DIRECTIVE, header.getValue());
        } else if (request.getProtocolVersion().lessEquals(HttpVersion.HTTP_1_0)) {
            response.setHeader(HTTP.CONN_DIRECTIVE, HTTP.CONN_CLOSE);
        }
    }
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:48,代码来源:ResponseConnControl.java

示例10: RemoteIdentityServerException

public RemoteIdentityServerException(String error) {
    super(HttpStatus.SC_SERVICE_UNAVAILABLE, "M_REMOTE_IS_ERROR", "Error from remote server: " + error);
}
 
开发者ID:kamax-io,项目名称:mxisd,代码行数:3,代码来源:RemoteIdentityServerException.java

示例11: RemoteHomeServerException

public RemoteHomeServerException(String error) {
    super(HttpStatus.SC_SERVICE_UNAVAILABLE, "M_REMOTE_HS_ERROR", "Error from remote server: " + error);
}
 
开发者ID:kamax-io,项目名称:mxisd,代码行数:3,代码来源:RemoteHomeServerException.java


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