use of org.springframework.http.HttpStatus in project open-kilda by telstra.
the class HealthCheckController method getHealthCheck.
/**
* Gets the health-check status.
*
* @param correlationId request correlation id
* @return health-check model entity
*/
@ApiOperation(value = "Gets health-check status", response = HealthCheck.class)
@ApiResponses(value = { @ApiResponse(code = 200, response = HealthCheck.class, message = "Operation is successful"), @ApiResponse(code = 401, response = MessageError.class, message = "Unauthorized"), @ApiResponse(code = 403, response = MessageError.class, message = "Forbidden"), @ApiResponse(code = 404, response = MessageError.class, message = "Not found"), @ApiResponse(code = 503, response = MessageError.class, message = "Service unavailable") })
@RequestMapping(value = "/health-check", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
public ResponseEntity<HealthCheck> getHealthCheck(@RequestHeader(value = CORRELATION_ID, defaultValue = DEFAULT_CORRELATION_ID) String correlationId) {
logger.debug("getHealthCheck");
HealthCheck healthCheck = healthCheckService.getHealthCheck(correlationId);
HttpStatus status = healthCheck.hasNonOperational() ? HttpStatus.GATEWAY_TIMEOUT : HttpStatus.OK;
return new ResponseEntity<>(healthCheck, new HttpHeaders(), status);
}
use of org.springframework.http.HttpStatus in project open-kilda by telstra.
the class NorthboundExceptionHandler method handleMessageException.
/**
* Handles NorthboundException exception.
*
* @param exception the NorthboundException instance
* @param request the WebRequest caused exception
* @return the ResponseEntity object instance
*/
@ExceptionHandler(MessageException.class)
protected ResponseEntity<Object> handleMessageException(MessageException exception, WebRequest request) {
HttpStatus status;
switch(exception.getErrorType()) {
case NOT_FOUND:
status = HttpStatus.NOT_FOUND;
break;
case DATA_INVALID:
case PARAMETERS_INVALID:
status = HttpStatus.BAD_REQUEST;
break;
case ALREADY_EXISTS:
status = HttpStatus.CONFLICT;
break;
case AUTH_FAILED:
status = HttpStatus.UNAUTHORIZED;
break;
case OPERATION_TIMED_OUT:
case INTERNAL_ERROR:
default:
status = HttpStatus.INTERNAL_SERVER_ERROR;
break;
}
MessageError error = new MessageError(request.getHeader(CORRELATION_ID), exception.getTimestamp(), exception.getErrorType().toString(), exception.getMessage(), exception.getErrorDescription());
logger.warn(format("Error %s caught.", error), exception);
return super.handleExceptionInternal(exception, error, new HttpHeaders(), status, request);
}
use of org.springframework.http.HttpStatus in project dhis2-core by dhis2.
the class SmsGateway method send.
public HttpStatus send(String urlTemplate, HttpEntity<?> request, Class<?> klass) {
ResponseEntity<?> response;
HttpStatus statusCode = null;
try {
response = restTemplate.exchange(urlTemplate, HttpMethod.POST, request, klass);
statusCode = response.getStatusCode();
} catch (HttpClientErrorException ex) {
log.error("Client error", ex);
statusCode = ex.getStatusCode();
} catch (HttpServerErrorException ex) {
log.error("Server error", ex);
statusCode = ex.getStatusCode();
} catch (Exception ex) {
log.error("Error", ex);
statusCode = HttpStatus.INTERNAL_SERVER_ERROR;
}
log.info("Response status code: " + statusCode);
return statusCode;
}
use of org.springframework.http.HttpStatus in project metacat by Netflix.
the class MetacatErrorController method error.
/**
* Mapping for error handling.
* @param request http request
* @return error response
*/
@RequestMapping
@ResponseBody
public ResponseEntity<Map<String, Object>> error(final HttpServletRequest request) {
final Map<String, Object> body = getErrorAttributes(request, isIncludeStackTrace(request));
final HttpStatus status = getStatus(request);
return new ResponseEntity<>(body, status);
}
use of org.springframework.http.HttpStatus in project ORCID-Source by ORCID.
the class OauthGenericCallsController method obtainOauth2TokenPost.
@RequestMapping(value = "/oauth/token", consumes = MediaType.APPLICATION_FORM_URLENCODED, produces = MediaType.APPLICATION_JSON)
public ResponseEntity<?> obtainOauth2TokenPost(HttpServletRequest request) {
String authorization = request.getHeader("Authorization");
Enumeration<String> paramNames = request.getParameterNames();
MultivaluedMap<String, String> formParams = new MultivaluedMapImpl();
while (paramNames.hasMoreElements()) {
String paramName = paramNames.nextElement();
formParams.add(paramName, request.getParameter(paramName));
}
try {
Response response = orcidClientCredentialEndPointDelegator.obtainOauth2Token(authorization, formParams);
return ResponseEntity.status(response.getStatus()).body(response.getEntity());
} catch (Exception e) {
OAuthError error = OAuthErrorUtils.getOAuthError(e);
HttpStatus status = HttpStatus.valueOf(error.getResponseStatus().getStatusCode());
return ResponseEntity.status(status).body(error);
}
}
Aggregations