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, getErrorAttributeOptions(request));
final HttpStatus status = getStatus(request);
return new ResponseEntity<>(body, status);
}
use of org.springframework.http.HttpStatus in project open-kilda by telstra.
the class HealthCheckController method getHealthCheck.
/**
* Gets the health-check status.
*
* @return health-check model entity
*/
@ApiOperation(value = "Gets health-check status", response = HealthCheck.class)
@GetMapping(value = "/health-check")
public ResponseEntity<HealthCheck> getHealthCheck() {
logger.debug("getHealthCheck");
HealthCheck healthCheck = healthCheckService.getHealthCheck();
HttpStatus status = healthCheck.hasNonOperational() ? HttpStatus.SERVICE_UNAVAILABLE : 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:
status = HttpStatus.BAD_REQUEST;
break;
case PARAMETERS_INVALID:
status = HttpStatus.BAD_REQUEST;
break;
case REQUEST_INVALID:
status = HttpStatus.BAD_REQUEST;
break;
case OPERATION_TIMED_OUT:
status = HttpStatus.REQUEST_TIMEOUT;
break;
case ALREADY_EXISTS:
status = HttpStatus.CONFLICT;
break;
case AUTH_FAILED:
status = HttpStatus.UNAUTHORIZED;
break;
case UNPROCESSABLE_REQUEST:
status = HttpStatus.UNPROCESSABLE_ENTITY;
break;
case INTERNAL_ERROR:
status = HttpStatus.INTERNAL_SERVER_ERROR;
break;
case NOT_PERMITTED:
status = HttpStatus.FORBIDDEN;
break;
case NOT_IMPLEMENTED:
status = HttpStatus.NOT_IMPLEMENTED;
break;
default:
status = HttpStatus.INTERNAL_SERVER_ERROR;
break;
}
MessageError error = new MessageError(exception.getCorrelationId(), exception.getTimestamp(), exception.getErrorType().toString(), exception.getMessage(), exception.getErrorDescription());
try (MDCCloseable mdcCloseable = MDC.putCloseable(CORRELATION_ID, exception.getCorrelationId())) {
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 spring-security-oauth by spring-projects.
the class AuthorizationCodeGrantTests method testTokenAcquisitionWithCorrectContext.
@Test
public void testTokenAcquisitionWithCorrectContext() throws Exception {
ResponseEntity<String> page = serverRunning.getForString("/tonr2/login.jsp");
String cookie = page.getHeaders().getFirst("Set-Cookie");
HttpHeaders headers = new HttpHeaders();
headers.set("Cookie", cookie);
Matcher matcher = Pattern.compile("(?s).*name=\"_csrf\".*?value=\"([^\"]+).*").matcher(page.getBody());
MultiValueMap<String, String> form;
form = new LinkedMultiValueMap<String, String>();
form.add("username", "marissa");
form.add("password", "wombat");
if (matcher.matches()) {
form.add("_csrf", matcher.group(1));
}
ResponseEntity<Void> response = serverRunning.postForStatus("/tonr2/login", headers, form);
cookie = response.getHeaders().getFirst("Set-Cookie");
headers = new HttpHeaders();
headers.set("Cookie", cookie);
// headers.setAccept(Collections.singletonList(MediaType.ALL));
headers.setAccept(MediaType.parseMediaTypes("image/png,image/*;q=0.8,*/*;q=0.5"));
String location = serverRunning.getForRedirect("/tonr2/sparklr/photos/1", headers);
location = authenticateAndApprove(location);
assertTrue("Redirect location should be to the original photo URL: " + location, location.contains("photos/1"));
HttpStatus status = serverRunning.getStatusCode(location, headers);
assertEquals(HttpStatus.OK, status);
}
use of org.springframework.http.HttpStatus in project spring-security-oauth by spring-projects.
the class OAuth2RestTemplateTests method open.
@Before
public void open() throws Exception {
resource = new BaseOAuth2ProtectedResourceDetails();
// Facebook and older specs:
resource.setTokenName("bearer_token");
restTemplate = new OAuth2RestTemplate(resource);
restTemplate.setAccessTokenProvider(accessTokenProvider);
request = Mockito.mock(ClientHttpRequest.class);
headers = new HttpHeaders();
Mockito.when(request.getHeaders()).thenReturn(headers);
ClientHttpResponse response = Mockito.mock(ClientHttpResponse.class);
HttpStatus statusCode = HttpStatus.OK;
Mockito.when(response.getStatusCode()).thenReturn(statusCode);
Mockito.when(request.execute()).thenReturn(response);
}
Aggregations