当前位置: 首页>>代码示例>>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;未经允许,请勿转载。