Java Code Examples for org.springframework.http.ResponseEntity#status()
The following examples show how to use
org.springframework.http.ResponseEntity#status() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ExceptionTranslator.java From jhipster-microservices-example with Apache License 2.0 | 6 votes |
@ExceptionHandler(Exception.class) public ResponseEntity<ErrorVM> processException(Exception ex) { if (log.isDebugEnabled()) { log.debug("An unexpected error occured: {}", ex.getMessage(), ex); } else { log.error("An unexpected error occured: {}", ex.getMessage()); } BodyBuilder builder; ErrorVM errorVM; ResponseStatus responseStatus = AnnotationUtils.findAnnotation(ex.getClass(), ResponseStatus.class); if (responseStatus != null) { builder = ResponseEntity.status(responseStatus.value()); errorVM = new ErrorVM("error." + responseStatus.value().value(), responseStatus.reason()); } else { builder = ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR); errorVM = new ErrorVM(ErrorConstants.ERR_INTERNAL_SERVER_ERROR, "Internal server error"); } return builder.body(errorVM); }
Example 2
Source File: ExceptionTranslator.java From jhipster-microservices-example with Apache License 2.0 | 6 votes |
@ExceptionHandler(Exception.class) public ResponseEntity<ErrorVM> processException(Exception ex) { if (log.isDebugEnabled()) { log.debug("An unexpected error occured: {}", ex.getMessage(), ex); } else { log.error("An unexpected error occured: {}", ex.getMessage()); } BodyBuilder builder; ErrorVM errorVM; ResponseStatus responseStatus = AnnotationUtils.findAnnotation(ex.getClass(), ResponseStatus.class); if (responseStatus != null) { builder = ResponseEntity.status(responseStatus.value()); errorVM = new ErrorVM("error." + responseStatus.value().value(), responseStatus.reason()); } else { builder = ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR); errorVM = new ErrorVM(ErrorConstants.ERR_INTERNAL_SERVER_ERROR, "Internal server error"); } return builder.body(errorVM); }
Example 3
Source File: PlatformsController.java From hesperides with GNU General Public License v3.0 | 6 votes |
@ApiOperation("Update a platform") @PutMapping("/{application_name}/platforms") public ResponseEntity<PlatformIO> updatePlatform(Authentication authentication, @PathVariable("application_name") final String applicationName, @ApiParam(value = "Copie les propriétés du module déployé de la plateforme source avec l'ID correspondant. " + "Si ce module ne contient pas de propriétés, à défaut on utilise les propriétés du module avec le même properties_path.") @RequestParam(value = "copyPropertiesForUpgradedModules", required = false) final Boolean copyPropertiesForUpgradedModules, @Valid @RequestBody final PlatformIO platformInput) { Platform.Key platformKey = new Platform.Key(applicationName, platformInput.getPlatformName()); platformUseCases.updatePlatform(platformKey, platformInput.toDomainInstance(), Boolean.TRUE.equals(copyPropertiesForUpgradedModules), // on traite le cas `null` new User(authentication) ); final ResponseEntity.BodyBuilder response = ResponseEntity.status(HttpStatus.OK); PlatformView platformView = platformUseCases.getPlatform(platformKey); return response.body(new PlatformIO(platformView)); }
Example 4
Source File: ExceptionTranslator.java From klask-io with GNU General Public License v3.0 | 6 votes |
@ExceptionHandler(Exception.class) public ResponseEntity<ErrorDTO> processRuntimeException(Exception ex) throws Exception { BodyBuilder builder; ErrorDTO errorDTO; ResponseStatus responseStatus = AnnotationUtils.findAnnotation(ex.getClass(), ResponseStatus.class); if (responseStatus != null) { builder = ResponseEntity.status(responseStatus.value()); errorDTO = new ErrorDTO("error." + responseStatus.value().value(), responseStatus.reason()); } else { builder = ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR); errorDTO = new ErrorDTO(ErrorConstants.ERR_INTERNAL_SERVER_ERROR, "Internal server error"); } log.error("Exception in rest call", ex); errorDTO.add("error", "error", ex.getMessage()); return builder.body(errorDTO); }
Example 5
Source File: ExceptionTranslator.java From jhipster-ribbon-hystrix with GNU General Public License v3.0 | 5 votes |
@ExceptionHandler(Exception.class) public ResponseEntity<ErrorDTO> processRuntimeException(Exception ex) throws Exception { BodyBuilder builder; ErrorDTO errorDTO; ResponseStatus responseStatus = AnnotationUtils.findAnnotation(ex.getClass(), ResponseStatus.class); if (responseStatus != null) { builder = ResponseEntity.status(responseStatus.value()); errorDTO = new ErrorDTO("error." + responseStatus.value().value(), responseStatus.reason()); } else { builder = ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR); errorDTO = new ErrorDTO(ErrorConstants.ERR_INTERNAL_SERVER_ERROR, "Internal server error"); } return builder.body(errorDTO); }
Example 6
Source File: ExceptionTranslator.java From tutorials with MIT License | 5 votes |
@ExceptionHandler(Exception.class) public ResponseEntity<ErrorVM> processRuntimeException(Exception ex) { BodyBuilder builder; ErrorVM errorVM; ResponseStatus responseStatus = AnnotationUtils.findAnnotation(ex.getClass(), ResponseStatus.class); if (responseStatus != null) { builder = ResponseEntity.status(responseStatus.value()); errorVM = new ErrorVM("error." + responseStatus.value().value(), responseStatus.reason()); } else { builder = ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR); errorVM = new ErrorVM(ErrorConstants.ERR_INTERNAL_SERVER_ERROR, "Internal server error"); } return builder.body(errorVM); }
Example 7
Source File: ExceptionTranslator.java From tutorials with MIT License | 5 votes |
@ExceptionHandler(Exception.class) public ResponseEntity<ErrorVM> processRuntimeException(Exception ex) { BodyBuilder builder; ErrorVM errorVM; ResponseStatus responseStatus = AnnotationUtils.findAnnotation(ex.getClass(), ResponseStatus.class); if (responseStatus != null) { builder = ResponseEntity.status(responseStatus.value()); errorVM = new ErrorVM("error." + responseStatus.value().value(), responseStatus.reason()); } else { builder = ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR); errorVM = new ErrorVM(ErrorConstants.ERR_INTERNAL_SERVER_ERROR, "Internal server error"); } return builder.body(errorVM); }
Example 8
Source File: ExceptionTranslator.java From tutorials with MIT License | 5 votes |
@ExceptionHandler(Exception.class) public ResponseEntity<ErrorVM> processRuntimeException(Exception ex) { BodyBuilder builder; ErrorVM errorVM; ResponseStatus responseStatus = AnnotationUtils.findAnnotation(ex.getClass(), ResponseStatus.class); if (responseStatus != null) { builder = ResponseEntity.status(responseStatus.value()); errorVM = new ErrorVM("error." + responseStatus.value().value(), responseStatus.reason()); } else { builder = ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR); errorVM = new ErrorVM(ErrorConstants.ERR_INTERNAL_SERVER_ERROR, "Internal server error"); } return builder.body(errorVM); }
Example 9
Source File: ExceptionTranslator.java From tutorials with MIT License | 5 votes |
@ExceptionHandler(Exception.class) public ResponseEntity<ErrorVM> processRuntimeException(Exception ex) { BodyBuilder builder; ErrorVM errorVM; ResponseStatus responseStatus = AnnotationUtils.findAnnotation(ex.getClass(), ResponseStatus.class); if (responseStatus != null) { builder = ResponseEntity.status(responseStatus.value()); errorVM = new ErrorVM("error." + responseStatus.value().value(), responseStatus.reason()); } else { builder = ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR); errorVM = new ErrorVM(ErrorConstants.ERR_INTERNAL_SERVER_ERROR, "Internal server error"); } return builder.body(errorVM); }
Example 10
Source File: ExceptionTranslator.java From OpenIoE with Apache License 2.0 | 5 votes |
@ExceptionHandler(Exception.class) public ResponseEntity<ErrorDTO> processRuntimeException(Exception ex) throws Exception { BodyBuilder builder; ErrorDTO errorDTO; ResponseStatus responseStatus = AnnotationUtils.findAnnotation(ex.getClass(), ResponseStatus.class); if (responseStatus != null) { builder = ResponseEntity.status(responseStatus.value()); errorDTO = new ErrorDTO("error." + responseStatus.value().value(), responseStatus.reason()); } else { builder = ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR); errorDTO = new ErrorDTO(ErrorConstants.ERR_INTERNAL_SERVER_ERROR, "Internal server error"); } return builder.body(errorDTO); }
Example 11
Source File: ExceptionTranslator.java From gpmr with Apache License 2.0 | 5 votes |
@ExceptionHandler(Exception.class) public ResponseEntity<ErrorDTO> processRuntimeException(Exception ex) throws Exception { BodyBuilder builder; ErrorDTO errorDTO; ResponseStatus responseStatus = AnnotationUtils.findAnnotation(ex.getClass(), ResponseStatus.class); if (responseStatus != null) { builder = ResponseEntity.status(responseStatus.value()); errorDTO = new ErrorDTO("error." + responseStatus.value().value(), responseStatus.reason()); } else { builder = ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR); errorDTO = new ErrorDTO(ErrorConstants.ERR_INTERNAL_SERVER_ERROR, "Internal server error"); } return builder.body(errorDTO); }
Example 12
Source File: ExceptionTranslator.java From jhipster-ribbon-hystrix with GNU General Public License v3.0 | 5 votes |
@ExceptionHandler(Exception.class) public ResponseEntity<ErrorDTO> processRuntimeException(Exception ex) throws Exception { BodyBuilder builder; ErrorDTO errorDTO; ResponseStatus responseStatus = AnnotationUtils.findAnnotation(ex.getClass(), ResponseStatus.class); if (responseStatus != null) { builder = ResponseEntity.status(responseStatus.value()); errorDTO = new ErrorDTO("error." + responseStatus.value().value(), responseStatus.reason()); } else { builder = ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR); errorDTO = new ErrorDTO(ErrorConstants.ERR_INTERNAL_SERVER_ERROR, "Internal server error"); } return builder.body(errorDTO); }
Example 13
Source File: _ExceptionTranslator.java From jhipster-ribbon-hystrix with GNU General Public License v3.0 | 5 votes |
@ExceptionHandler(Exception.class) public ResponseEntity<ErrorDTO> processRuntimeException(Exception ex) throws Exception { BodyBuilder builder; ErrorDTO errorDTO; ResponseStatus responseStatus = AnnotationUtils.findAnnotation(ex.getClass(), ResponseStatus.class); if (responseStatus != null) { builder = ResponseEntity.status(responseStatus.value()); errorDTO = new ErrorDTO("error." + responseStatus.value().value(), responseStatus.reason()); } else { builder = ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR); errorDTO = new ErrorDTO(ErrorConstants.ERR_INTERNAL_SERVER_ERROR, "Internal server error"); } return builder.body(errorDTO); }
Example 14
Source File: ExceptionTranslator.java From flair-registry with Apache License 2.0 | 5 votes |
@ExceptionHandler(Exception.class) public ResponseEntity<ErrorVM> processRuntimeException(Exception ex) { BodyBuilder builder; ErrorVM errorVM; ResponseStatus responseStatus = AnnotationUtils.findAnnotation(ex.getClass(), ResponseStatus.class); if (responseStatus != null) { builder = ResponseEntity.status(responseStatus.value()); errorVM = new ErrorVM("error." + responseStatus.value().value(), responseStatus.reason()); } else { builder = ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR); errorVM = new ErrorVM(ErrorConstants.ERR_INTERNAL_SERVER_ERROR, "Internal server error"); } return builder.body(errorVM); }
Example 15
Source File: ExceptionTranslator.java From jhipster-ribbon-hystrix with GNU General Public License v3.0 | 5 votes |
@ExceptionHandler(Exception.class) public ResponseEntity<ErrorDTO> processRuntimeException(Exception ex) throws Exception { BodyBuilder builder; ErrorDTO errorDTO; ResponseStatus responseStatus = AnnotationUtils.findAnnotation(ex.getClass(), ResponseStatus.class); if (responseStatus != null) { builder = ResponseEntity.status(responseStatus.value()); errorDTO = new ErrorDTO("error." + responseStatus.value().value(), responseStatus.reason()); } else { builder = ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR); errorDTO = new ErrorDTO(ErrorConstants.ERR_INTERNAL_SERVER_ERROR, "Internal server error"); } return builder.body(errorDTO); }
Example 16
Source File: ExceptionTranslator.java From jhipster-microservices-example with Apache License 2.0 | 5 votes |
@ExceptionHandler(Exception.class) public ResponseEntity<ErrorVM> processRuntimeException(Exception ex) { BodyBuilder builder; ErrorVM errorVM; ResponseStatus responseStatus = AnnotationUtils.findAnnotation(ex.getClass(), ResponseStatus.class); if (responseStatus != null) { builder = ResponseEntity.status(responseStatus.value()); errorVM = new ErrorVM("error." + responseStatus.value().value(), responseStatus.reason()); } else { builder = ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR); errorVM = new ErrorVM(ErrorConstants.ERR_INTERNAL_SERVER_ERROR, "Internal server error"); } return builder.body(errorVM); }
Example 17
Source File: TestController.java From cloud-security-xsuaa-integration with Apache License 2.0 | 5 votes |
@GetMapping("/v1/sayHello") public Mono<ResponseEntity<String>> sayHello() { ResponseEntity.BodyBuilder unAuthenticated = ResponseEntity.status(HttpStatus.UNAUTHORIZED); return ReactiveSecurityContext.getToken() .doOnError(throwable -> Mono.just(unAuthenticated)) .map(token -> ResponseEntity.ok().contentType(MediaType.TEXT_PLAIN) .body(new Base64JwtDecoder().decode(token.getAppToken()).getPayload())); }
Example 18
Source File: ExceptionTranslator.java From flair-engine with Apache License 2.0 | 5 votes |
@ExceptionHandler(Exception.class) public ResponseEntity<ErrorVM> processException(Exception ex) { if (log.isDebugEnabled()) { log.debug("An unexpected error occurred: {}", ex.getMessage(), ex); } else { log.error("An unexpected error occurred: {}", ex.getMessage()); } BodyBuilder builder; ErrorVM errorVM; ResponseStatus responseStatus = AnnotationUtils.findAnnotation(ex.getClass(), ResponseStatus.class); if (responseStatus != null) { builder = ResponseEntity.status(responseStatus.value()); errorVM = new ErrorVM("error." + responseStatus.value().value(), responseStatus.reason()); } else { builder = ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR); errorVM = new ErrorVM(ErrorConstants.ERR_INTERNAL_SERVER_ERROR, "Internal server error"); } return builder.body(errorVM); }
Example 19
Source File: SecurityHandlerConfig.java From microservices-platform with Apache License 2.0 | 5 votes |
@Bean public WebResponseExceptionTranslator webResponseExceptionTranslator() { return new DefaultWebResponseExceptionTranslator() { public static final String BAD_MSG = "坏的凭证"; @Override public ResponseEntity<OAuth2Exception> translate(Exception e) throws Exception { OAuth2Exception oAuth2Exception; if (e.getMessage() != null && e.getMessage().equals(BAD_MSG)) { oAuth2Exception = new InvalidGrantException("用户名或密码错误", e); } else if (e instanceof InternalAuthenticationServiceException) { oAuth2Exception = new InvalidGrantException(e.getMessage(), e); } else if (e instanceof RedirectMismatchException) { oAuth2Exception = new InvalidGrantException(e.getMessage(), e); } else if (e instanceof InvalidScopeException) { oAuth2Exception = new InvalidGrantException(e.getMessage(), e); } else { oAuth2Exception = new UnsupportedResponseTypeException("服务内部错误", e); } ResponseEntity<OAuth2Exception> response = super.translate(oAuth2Exception); ResponseEntity.status(oAuth2Exception.getHttpErrorCode()); response.getBody().addAdditionalInformation("resp_code", oAuth2Exception.getHttpErrorCode() + ""); response.getBody().addAdditionalInformation("resp_msg", oAuth2Exception.getMessage()); return response; } }; }
Example 20
Source File: ResponseEntityPro.java From spring-boot-start-current with Apache License 2.0 | 4 votes |
private static ResponseEntity.BodyBuilder buildStatus ( int status ) { return ResponseEntity.status( status ); }