Java Code Examples for org.springframework.http.ResponseEntity#status()
The following examples show how to use
org.springframework.http.ResponseEntity#status() .
These examples are extracted from open source projects.
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 Project: jhipster-microservices-example File: ExceptionTranslator.java License: 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 Project: jhipster-microservices-example File: ExceptionTranslator.java License: 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 Project: klask-io File: ExceptionTranslator.java License: 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 4
Source Project: hesperides File: PlatformsController.java License: 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 5
Source Project: flair-registry File: ExceptionTranslator.java License: 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 6
Source Project: microservices-platform File: SecurityHandlerConfig.java License: 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 7
Source Project: flair-engine File: ExceptionTranslator.java License: 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 8
Source Project: cloud-security-xsuaa-integration File: TestController.java License: 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 9
Source Project: jhipster-microservices-example File: ExceptionTranslator.java License: 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 10
Source Project: jhipster-ribbon-hystrix File: ExceptionTranslator.java License: 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 11
Source Project: jhipster-ribbon-hystrix File: ExceptionTranslator.java License: 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 12
Source Project: jhipster-ribbon-hystrix File: _ExceptionTranslator.java License: 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 Project: jhipster-ribbon-hystrix File: ExceptionTranslator.java License: 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 Project: gpmr File: ExceptionTranslator.java License: 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 15
Source Project: OpenIoE File: ExceptionTranslator.java License: 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 16
Source Project: tutorials File: ExceptionTranslator.java License: 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 17
Source Project: tutorials File: ExceptionTranslator.java License: 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 18
Source Project: tutorials File: ExceptionTranslator.java License: 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 19
Source Project: tutorials File: ExceptionTranslator.java License: 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 20
Source Project: spring-boot-start-current File: ResponseEntityPro.java License: Apache License 2.0 | 4 votes |
private static ResponseEntity.BodyBuilder buildStatus ( int status ) { return ResponseEntity.status( status ); }