List of usage examples for org.springframework.http HttpStatus INTERNAL_SERVER_ERROR
HttpStatus INTERNAL_SERVER_ERROR
To view the source code for org.springframework.http HttpStatus INTERNAL_SERVER_ERROR.
Click Source Link
From source file:gateway.test.JobTests.java
/** * Test GET /job/{jobId}//ww w.j a v a 2s .com */ @Test public void testGetStatus() { // Mock ResponseEntity<JobStatusResponse> mockResponse = new ResponseEntity<JobStatusResponse>( new JobStatusResponse(mockJob), HttpStatus.OK); when(restTemplate.getForEntity(anyString(), eq(JobStatusResponse.class))).thenReturn(mockResponse); // Test ResponseEntity<PiazzaResponse> entity = jobController.getJobStatus("123456", user); JobStatusResponse response = (JobStatusResponse) entity.getBody(); // Verify assertTrue(entity.getStatusCode().equals(HttpStatus.OK)); assertTrue(response.data.jobId.equals("123456")); assertTrue(response.data.status.equalsIgnoreCase(StatusUpdate.STATUS_RUNNING)); assertTrue(response.data.progress.getPercentComplete().equals(50)); assertTrue(response.data.createdBy.equals("Test User 2")); // Test Exception when(restTemplate.getForEntity(anyString(), eq(JobStatusResponse.class))) .thenThrow(new HttpServerErrorException(HttpStatus.INTERNAL_SERVER_ERROR)); entity = jobController.getJobStatus("123456", user); assertTrue(entity.getBody() instanceof ErrorResponse); assertTrue(entity.getStatusCode().equals(HttpStatus.INTERNAL_SERVER_ERROR)); }
From source file:org.workspace7.moviestore.controller.HomeController.java
@GetMapping("/healthz") public ResponseEntity healthz() { HealthStatus healthStatus = cacheManager.getNativeCacheManager().getHealth().getClusterHealth() .getHealthStatus();/*from w ww . j ava 2 s . c om*/ if (healthStatus == HealthStatus.HEALTHY) { log.info("HEALTHY"); return new ResponseEntity(HttpStatus.OK); } return new ResponseEntity(HttpStatus.INTERNAL_SERVER_ERROR); }
From source file:org.mitre.uma.web.PermissionRegistrationEndpoint.java
@RequestMapping(method = RequestMethod.POST, consumes = MimeTypeUtils.APPLICATION_JSON_VALUE, produces = MimeTypeUtils.APPLICATION_JSON_VALUE) public String getPermissionTicket(@RequestBody String jsonString, Model m, Authentication auth) { ensureOAuthScope(auth, SystemScopeService.UMA_PROTECTION_SCOPE); try {/*from w w w . j ava2 s . c o m*/ // parse the permission request JsonElement el = parser.parse(jsonString); if (el.isJsonObject()) { JsonObject o = el.getAsJsonObject(); Long rsid = getAsLong(o, "resource_set_id"); Set<String> scopes = getAsStringSet(o, "scopes"); if (rsid == null || scopes == null || scopes.isEmpty()) { // missing information m.addAttribute("code", HttpStatus.BAD_REQUEST); m.addAttribute("errorMessage", "Missing required component of permission registration request."); return JsonErrorView.VIEWNAME; } // trim any restricted scopes Set<SystemScope> scopesRequested = scopeService.fromStrings(scopes); scopesRequested = scopeService.removeRestrictedAndReservedScopes(scopesRequested); scopes = scopeService.toStrings(scopesRequested); ResourceSet resourceSet = resourceSetService.getById(rsid); // requested resource set doesn't exist if (resourceSet == null) { m.addAttribute("code", HttpStatus.NOT_FOUND); m.addAttribute("errorMessage", "Requested resource set not found: " + rsid); return JsonErrorView.VIEWNAME; } // authorized user of the token doesn't match owner of the resource set if (!resourceSet.getOwner().equals(auth.getName())) { m.addAttribute("code", HttpStatus.FORBIDDEN); m.addAttribute("errorMessage", "Party requesting permission is not owner of resource set, expected " + resourceSet.getOwner() + " got " + auth.getName()); return JsonErrorView.VIEWNAME; } // create the permission PermissionTicket permission = permissionService.createTicket(resourceSet, scopes); if (permission != null) { // we've created the permission, return the ticket JsonObject out = new JsonObject(); out.addProperty("ticket", permission.getTicket()); m.addAttribute("entity", out); m.addAttribute("code", HttpStatus.CREATED); return JsonEntityView.VIEWNAME; } else { // there was a failure creating the permission object m.addAttribute("code", HttpStatus.INTERNAL_SERVER_ERROR); m.addAttribute("errorMessage", "Unable to save permission and generate ticket."); return JsonErrorView.VIEWNAME; } } else { // malformed request m.addAttribute("code", HttpStatus.BAD_REQUEST); m.addAttribute("errorMessage", "Malformed JSON request."); return JsonErrorView.VIEWNAME; } } catch (JsonParseException e) { // malformed request m.addAttribute("code", HttpStatus.BAD_REQUEST); m.addAttribute("errorMessage", "Malformed JSON request."); return JsonErrorView.VIEWNAME; } }
From source file:org.openlmis.fulfillment.web.errorhandler.ServiceErrorHandling.java
/** * Handles the {@link ServerException} that indicates server error. * * @param ex the exception that caused the issue * @return the error response// w w w .j a va2 s .c om */ @ExceptionHandler(ServerException.class) @ResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR) @ResponseBody public Message.LocalizedMessage handleServerException(ServerException ex) { logger.error("An internal error occurred", ex); return getLocalizedMessage(ex.getErrorMessage()); }
From source file:org.createnet.raptor.auth.service.controller.TokenController.java
@PreAuthorize("isAuthenticated()") @RequestMapping(value = "/token", method = RequestMethod.POST) @ApiOperation(value = "Create a token", notes = "", response = Token.class, nickname = "createToken") public ResponseEntity<?> create(@AuthenticationPrincipal User currentUser, @RequestBody Token rawToken) { if (rawToken.getSecret().isEmpty()) { return ResponseEntity.status(HttpStatus.BAD_REQUEST) .body(new JsonErrorResponse(400, "Secret cannot be empty")); }/*from w ww. j ava2 s .com*/ Token token = new Token(); token.setName(rawToken.getName()); token.setEnabled(rawToken.getEnabled()); token.setExpires(rawToken.getExpires()); token.setSecret(rawToken.getSecret()); token.setType(rawToken.getType()); token.setUser(currentUser); // Generate the JWT token tokenService.generateToken(token); Token token2 = tokenService.create(token); if (token2 == null) { return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR) .body(new JsonErrorResponse(500, "Cannot create the token")); } return ResponseEntity.status(HttpStatus.CREATED).body(token2); }
From source file:io.github.microcks.web.ServiceController.java
@RequestMapping(value = "/services/{id}/operationDelay", method = RequestMethod.PUT) public ResponseEntity<?> updateServiceOperationDelay(@PathVariable("id") String serviceId, @RequestParam(value = "operationName") String operationName, @RequestParam(value = "delay") Long delay) { log.debug("Updating delay for operation {} of service {}", operationName, serviceId); boolean result = serviceService.updateOperationDelay(serviceId, operationName, delay); if (result) { return new ResponseEntity<>(HttpStatus.OK); }/*from w ww . ja v a2s . com*/ return new ResponseEntity<>(HttpStatus.INTERNAL_SERVER_ERROR); }
From source file:storage.StorageServiceWrapperController.java
protected ResponseEntity<String> create(@Nonnull final String storageServiceId, @Nonnull final String context, @Nonnull final String key, @Nonnull final String value) { try {/* ww w. jav a 2 s . c o m*/ final StorageService storageService = getStorageService(storageServiceId); if (storageService == null) { log.debug("Unable to find storage service with id '{}'", storageServiceId); return seleniumFriendlyResponse(HttpStatus.BAD_REQUEST); } log.debug("Creating in '{}' with context '{}' and key '{}'", storageServiceId, context, key); boolean success = storageService.create(context, key, value, null); log.debug("Create '{}' in '{}' with context '{}' and key '{}'", success, storageServiceId, context, key); if (success) { return seleniumFriendlyResponse(HttpStatus.CREATED); } else { return seleniumFriendlyResponse(HttpStatus.CONFLICT); } } catch (IOException e) { log.debug("An error occurred", e); return seleniumFriendlyResponse(HttpStatus.INTERNAL_SERVER_ERROR); } }
From source file:com.cloudbees.jenkins.plugins.demo.actuator.SampleActuatorApplicationTests.java
@Test public void testErrorPage() throws Exception { ResponseEntity<String> entity = new TestRestTemplate("user", getPassword()) .getForEntity("http://localhost:" + this.port + "/foo", String.class); assertEquals(HttpStatus.INTERNAL_SERVER_ERROR, entity.getStatusCode()); String body = entity.getBody(); assertNotNull(body);//from w w w . ja va2s. c o m assertTrue("Wrong body: " + body, body.contains("\"error\":")); }
From source file:com.basicservice.controller.UserController.java
@RequestMapping(value = "/register", method = RequestMethod.POST) public ResponseEntity<String> register(HttpServletRequest request, @RequestParam(value = "name") String name, @RequestParam(value = "email") EmailValidatedString email, @RequestParam(value = "password") String password) { if (email == null || email.getValue() == null || password == null) { return new ResponseEntity<String>(HttpStatus.FORBIDDEN); }//from w w w . ja v a 2s.com LOG.debug("Got register request: email:" + email.getValue() + ", pass:" + password + ", name:" + name); User user = null; try { user = userService.register(name, email.getValue(), password); } catch (UserRegistrationException e) { if (e.getReason() == UserRegistrationException.reason.EMAIL_EXISTS) { return new ResponseEntity<String>(HttpStatus.FORBIDDEN); } } if (user == null) { return new ResponseEntity<String>(HttpStatus.INTERNAL_SERVER_ERROR); } LOG.debug("Preparing to save user to db"); final String id = userService.save(user); if (id != null) { String from = Constants.REGISTRATION_FROM_ADDRESS; String to = email.getValue(); Locale locale = LocaleContextHolder.getLocale(); String subject = messageLocalizationService.getMessage(Constants.MLS_REGISTRATION_CONFIRMATION_SUBJECT, locale); Object[] args = new String[1]; String path = Utils.getBasicPath(request); ConfirmationString cs = confirmationEmailService.getConfirmationString(user.getId()); URI uri = new UriTemplate("{requestUrl}/api/users/registrationConfirmation/?key={key}").expand(path, cs.getKey()); args[0] = uri.toASCIIString(); String messageHtml = messageLocalizationService.getMessage(Constants.MLS_REGISTRATION_CONFIRMATION_HTML, args, locale); try { mailService.sendEmail(from, to, subject, messageHtml); } catch (Exception e) { LOG.debug("Failed to send confirmation email to: " + to, e); } } final HttpHeaders headers = new HttpHeaders(); headers.add("Set-Cookie", Constants.AUTHENTICATED_USER_ID_COOKIE + "=" + id + "; Path=/"); return new ResponseEntity<String>(headers, HttpStatus.CREATED); }