本文整理汇总了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);
}
示例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;
}
示例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);
}
}
示例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.");
}
}
示例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);
}
示例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);
}
示例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);
}
示例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);
}
示例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;
}
};
}