use of org.springframework.http.HttpStatus in project cuba by cuba-platform.
the class ServicesController method invokeServiceMethodGet.
@GetMapping("/{serviceName}/{methodName}")
public ResponseEntity<String> invokeServiceMethodGet(@PathVariable String serviceName, @PathVariable String methodName, @RequestParam(required = false) String modelVersion, @RequestParam Map<String, String> paramsMap) {
ServicesControllerManager.ServiceCallResult result = servicesControllerManager.invokeServiceMethodGet(serviceName, methodName, paramsMap, modelVersion);
HttpStatus status;
if (result == null) {
status = HttpStatus.NO_CONTENT;
result = new ServicesControllerManager.ServiceCallResult("", false);
} else {
status = HttpStatus.OK;
}
String contentType = result.isValidJson() ? "application/json;charset=UTF-8" : "text/plain;charset=UTF-8";
return ResponseEntity.status(status).header("Content-Type", contentType).body(result.getStringValue());
}
use of org.springframework.http.HttpStatus in project hub-alert by blackducksoftware.
the class LoginHandlerTest method authenticateUserWithIntegrationRestExceptionTest.
@Test
public void authenticateUserWithIntegrationRestExceptionTest() throws IntegrationException {
final LoginActions loginActions = Mockito.mock(LoginActions.class);
final LoginHandler loginHandler = new LoginHandler(objectTransformer, loginActions, csrfTokenRepository);
final HttpStatus responseCode = HttpStatus.BAD_GATEWAY;
Mockito.when(loginActions.authenticateUser(Mockito.any(), Mockito.any())).thenThrow(new IntegrationRestException(responseCode.value(), "", ""));
final ResponseEntity<String> response = loginHandler.authenticateUser(null, null, null);
assertEquals(responseCode, response.getStatusCode());
}
use of org.springframework.http.HttpStatus in project webofneeds by researchstudio-sat.
the class LinkedDataRestBridge method createRestTemplateForReadingLinkedData.
private RestTemplate createRestTemplateForReadingLinkedData(String webID) throws Exception {
RestTemplate template = CryptographyUtils.createSslRestTemplate(this.keyStoreService.getUnderlyingKeyStore(), this.keyStoreService.getPassword(), new PredefinedAliasPrivateKeyStrategy(keyPairAliasDerivationStrategy.getAliasForNeedUri(webID)), this.trustStoreService.getUnderlyingKeyStore(), this.trustStrategy, readTimeout, connectionTimeout, true);
// prevent the RestTemplate from throwing an exception when the server responds with 4xx or 5xx status
// because we want to hand the orginal response back to the original caller in BridgeForLinkedDataController
template.setErrorHandler(new DefaultResponseErrorHandler() {
@Override
protected boolean hasError(final HttpStatus statusCode) {
return false;
}
});
return template;
}
use of org.springframework.http.HttpStatus in project rpki-validator-3 by RIPE-NCC.
the class ApiErrorHandler method handleMethodArgumentNotValid.
@Override
protected ResponseEntity<Object> handleMethodArgumentNotValid(MethodArgumentNotValidException ex, HttpHeaders headers, HttpStatus status, WebRequest request) {
Locale locale = request.getLocale();
List<ApiError> errors = ex.getBindingResult().getFieldErrors().stream().map((fieldError) -> ApiError.builder().status(String.valueOf(HttpStatus.BAD_REQUEST.value())).code(fieldError.getCode()).title(messages.getMessage("title." + fieldError.getCode(), null, HttpStatus.BAD_REQUEST.getReasonPhrase(), locale)).detail(messages.getMessage(fieldError, locale)).source(ApiErrorSource.of(Optional.of("/" + fieldError.getField().replaceAll("[.\\[]", "/").replace("]", "")), Optional.empty())).build()).collect(Collectors.toList());
return ResponseEntity.badRequest().contentType(MediaType.valueOf(Api.API_MIME_TYPE)).body(ApiResponse.error(errors));
}
use of org.springframework.http.HttpStatus in project rpki-validator-3 by RIPE-NCC.
the class ApiErrorHandler method handleMethodArgumentNotValid.
@Override
protected ResponseEntity<Object> handleMethodArgumentNotValid(MethodArgumentNotValidException ex, HttpHeaders headers, HttpStatus status, WebRequest request) {
Locale locale = request.getLocale();
List<ApiError> errors = ex.getBindingResult().getFieldErrors().stream().map((fieldError) -> ApiError.builder().status(String.valueOf(HttpStatus.BAD_REQUEST.value())).code(fieldError.getCode()).title(messages.getMessage("title." + fieldError.getCode(), null, HttpStatus.BAD_REQUEST.getReasonPhrase(), locale)).detail(messages.getMessage(fieldError, locale)).source(ApiErrorSource.of(Optional.of("/" + fieldError.getField().replaceAll("[.\\[]", "/").replace("]", "")), Optional.empty())).build()).collect(Collectors.toList());
return ResponseEntity.badRequest().contentType(MediaType.valueOf(Api.API_MIME_TYPE)).body(ApiResponse.error(errors));
}
Aggregations