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


Java HttpStatus.SERVICE_UNAVAILABLE屬性代碼示例

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


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

示例1: saveMedic

@PostMapping
public ResponseEntity<?> saveMedic(@RequestBody Medic medic, BindingResult result) {
	medicValidator.validate(medic, result);

	if (result.hasErrors()) {
		return new ResponseEntity<>(result.getAllErrors(), HttpStatus.NOT_ACCEPTABLE);
	}
	
	Medic newMedic = medicService.save(medic);

	if (newMedic != null) {
		final URI location = ServletUriComponentsBuilder.fromCurrentServletMapping().path("/v1/medics/{id}").build()
				.expand(newMedic.getId()).toUri();

		final HttpHeaders headers = new HttpHeaders();
		headers.setLocation(location);

		return new ResponseEntity<Void>(headers, HttpStatus.CREATED);
	}

	return new ResponseEntity<Void>(HttpStatus.SERVICE_UNAVAILABLE);
}
 
開發者ID:JUGIstanbul,項目名稱:second-opinion-api,代碼行數:22,代碼來源:MedicController.java

示例2: ready

@RequestMapping("/ready")
ResponseEntity<String> ready() {
	
	HttpHeaders responseHeaders = new HttpHeaders();
	HttpStatus httpStatus;
	String ret;
	if (ready)
	{
		httpStatus = HttpStatus.OK;
		ret = "ready";
	}
	else
	{
		httpStatus = HttpStatus.SERVICE_UNAVAILABLE;
		ret = "Service unavailable";
	}
	ResponseEntity<String> responseEntity = new ResponseEntity<String>(ret, responseHeaders, httpStatus);
	return responseEntity;
   }
 
開發者ID:SeldonIO,項目名稱:seldon-core,代碼行數:19,代碼來源:RestClientController.java

示例3: computeStatus

private HttpStatus computeStatus(Mode mode) {
    switch(mode) {
        case ALWAYS_OK:
            return HttpStatus.OK;
        case ALWAYS_WARNING:
            return HttpStatus.FOUND;
        case ALWAYS_CRITICAL:
            return HttpStatus.SERVICE_UNAVAILABLE;
        case DANGLING:
            Random random = new Random();
            int randomPos = random.nextInt() % Mode.values().length;
            if (randomPos < 0) {
                randomPos = randomPos * -1;
            }
            return computeStatus(Mode.values()[randomPos]);
        default:
            throw new IllegalArgumentException("Unable to manage mode " + mode);
    }

}
 
開發者ID:gilles-stragier,項目名稱:quickmon,代碼行數:20,代碼來源:DummyController.java

示例4: handleServerErrors

private static void handleServerErrors(HttpStatus statusCode) throws IOException {
    if (statusCode == HttpStatus.INTERNAL_SERVER_ERROR) {
        throw new InternalServerErrorException(TWITTER,
            "Something is broken at Twitter. Please see http://dev.twitter.com/pages/support to report the issue.");
    } else if (statusCode == HttpStatus.BAD_GATEWAY) {
        throw new ServerDownException(TWITTER, "Twitter is down or is being upgraded.");
    } else if (statusCode == HttpStatus.SERVICE_UNAVAILABLE) {
        throw new ServerOverloadedException(TWITTER, "Twitter is overloaded with requests. Try again later.");
    }
}
 
開發者ID:xm-online,項目名稱:xm-uaa,代碼行數:10,代碼來源:TwitterErrorHandler.java

示例5: getHealthCheck

@RequestMapping(value = "/healthCheck", method = RequestMethod.GET, produces = MediaType.TEXT_PLAIN_VALUE)
public ResponseEntity<String> getHealthCheck() {
    try {
        redirectorGateway.getApplications();
    } catch (Exception e) {
        LOGGER.error("", e);
        return new ResponseEntity<>(HttpStatus.SERVICE_UNAVAILABLE);
    }
    return new ResponseEntity<>("OK", HttpStatus.OK);
}
 
開發者ID:Comcast,項目名稱:redirector,代碼行數:10,代碼來源:DataServiceInfoController.java

示例6: invoke

@Override
@ActuatorGetMapping
protected Object invoke() {
    Map<String, Object> endpointProps = this.getDelegate().invoke();
    HttpStatus status = this.getDelegate().isPaused() ? HttpStatus.SERVICE_UNAVAILABLE : HttpStatus.OK;
    return new ResponseEntity<>(endpointProps, status);
}
 
開發者ID:jihor,項目名稱:hiatus-spring-boot,代碼行數:7,代碼來源:HiatusMvcEndpoint.java

示例7: getStatus

@RequestMapping(value = "/status")
public ResponseEntity getStatus() {
  try {
    if (new File(ConfigUtil.get("status.file.path")).exists()) {
      return new ResponseEntity(HttpStatus.OK);
    }
  } catch (Exception e) {
    xLog.warn("Error in checking the status of application:", e);
  }
  return new ResponseEntity(HttpStatus.SERVICE_UNAVAILABLE);
}
 
開發者ID:logistimo,項目名稱:logistimo-web-service,代碼行數:11,代碼來源:AppStatusController.java

示例8: logEvent

@RequestMapping(value = "/log/event", method = RequestMethod.POST, headers = "Accept=application/json")
@ResponseBody
public ResponseEntity<Void> logEvent(@RequestBody O2MSyncEventLog eventInfo) {
	try {
		if (eventInfo.getEventId() == null || eventInfo.getEventId().isEmpty()
				|| eventInfo.getEventFilters() == null || eventInfo.getEventFilters().isEmpty()) {
			return new ResponseEntity<Void>(HttpStatus.PARTIAL_CONTENT);
		}
		eventService.logEvent(eventInfo);
	} catch (Exception e) {
		return new ResponseEntity<Void>(HttpStatus.SERVICE_UNAVAILABLE);
	}
	return new ResponseEntity<Void>(HttpStatus.OK);
}
 
開發者ID:gagoyal01,項目名稱:mongodb-rdbms-sync,代碼行數:14,代碼來源:SyncEventController.java

示例9: fallbackResponse

/**
 * 降級處理HTTP響應。
 *
 * @return
 */
@Override
public ClientHttpResponse fallbackResponse() {

    return new ClientHttpResponse() {

        /**
         * 服務降級時返回503(SERVICE_UNAVAILABLE)狀態碼。
         * @return
         * @throws IOException
         */
        @Override
        public HttpStatus getStatusCode() throws IOException {
            return HttpStatus.SERVICE_UNAVAILABLE;
        }

        @Override
        public int getRawStatusCode() throws IOException {
            return this.getStatusCode().value();
        }

        @Override
        public String getStatusText() throws IOException {
            return this.getStatusCode().getReasonPhrase();
        }

        @Override
        public void close() {

        }

        /**
         * 服務降級時返回相應內容。
         * @return
         * @throws IOException
         */
        @Override
        public InputStream getBody() throws IOException {
            return new ByteArrayInputStream(FallbackInfo.instance().toString().getBytes());
        }

        /**
         *
         * @return
         */
        @Override
        public HttpHeaders getHeaders() {
            HttpHeaders headers = new HttpHeaders();
            MediaType mt = new MediaType("application", "json", Charset.forName("UTF-8"));
            headers.setContentType(mt);
            return headers;
        }
    };
}
 
開發者ID:kenly333,項目名稱:service-hive,代碼行數:58,代碼來源:BackendFallbackProvider.java


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