List of usage examples for org.springframework.http HttpStatus FAILED_DEPENDENCY
HttpStatus FAILED_DEPENDENCY
To view the source code for org.springframework.http HttpStatus FAILED_DEPENDENCY.
Click Source Link
From source file:at.ac.tuwien.dsg.cloud.utilities.gateway.registry.UserController.java
@RequestMapping(method = RequestMethod.PUT, value = REST_USER_PATH_VARIABLE) public ResponseEntity<String> register(@PathVariable String user) { RequestEntity<KongUserCreateDto> request = RequestEntity .post(URI.create(this.kongUris.getKongConsumersUri())).contentType(MediaType.APPLICATION_JSON) .body(KongUserCreateDto.build(user)); ResponseEntity<KongUser> resp = restUtilities.simpleRestExchange(request, KongUser.class); if (resp == null || resp.getStatusCode() != HttpStatus.CREATED) { return new ResponseEntity<>(HttpStatus.INTERNAL_SERVER_ERROR); }/*from ww w . j a v a 2s .c o m*/ KongUser kongUser = resp.getBody(); kongUser.setKey(kongService.createKeyForUser(kongUser.getUserName())); if (kongUser.getKey() == null) { return new ResponseEntity<>("User was created but key generation failed!", HttpStatus.FAILED_DEPENDENCY); } this.kongUsers.getUsers().add(kongUser); return new ResponseEntity(kongUser.getKey().getKey(), HttpStatus.OK); }
From source file:com.sms.server.controller.AdminController.java
@RequestMapping(value = "/media/folder", method = RequestMethod.POST, headers = { "Content-type=application/json" }) @ResponseBody//from w w w .j ava 2 s.co m public ResponseEntity<String> createMediaFolder(@RequestBody MediaFolder mediaFolder) { // Check mandatory fields. if (mediaFolder.getName() == null || mediaFolder.getType() == null || mediaFolder.getPath() == null) { return new ResponseEntity<>("Missing required parameter.", HttpStatus.BAD_REQUEST); } // Check unique fields if (settingsDao.getMediaFolderByPath(mediaFolder.getPath()) != null) { return new ResponseEntity<>("Media folder path already exists.", HttpStatus.NOT_ACCEPTABLE); } // Check path is readable if (!new File(mediaFolder.getPath()).isDirectory()) { return new ResponseEntity<>("Media folder path does not exist or is not readable.", HttpStatus.FAILED_DEPENDENCY); } // Add Media Folder to the database. if (!settingsDao.createMediaFolder(mediaFolder)) { LogService.getInstance().addLogEntry(Level.ERROR, CLASS_NAME, "Error adding media folder with path '" + mediaFolder.getPath() + "' to database.", null); return new ResponseEntity<>("Error adding media folder to database.", HttpStatus.INTERNAL_SERVER_ERROR); } LogService.getInstance().addLogEntry(Level.INFO, CLASS_NAME, "Media folder with path '" + mediaFolder.getPath() + "' added successfully.", null); return new ResponseEntity<>("Media Folder added successfully.", HttpStatus.CREATED); }
From source file:com.sms.server.controller.AdminController.java
@RequestMapping(value = "/media/folder", method = RequestMethod.PUT, headers = { "Content-type=application/json" }) @ResponseBody/*ww w. ja va 2 s. co m*/ public ResponseEntity<String> updateMediaFolder(@RequestBody MediaFolder update) { MediaFolder mediaFolder = settingsDao.getMediaFolderByID(update.getID()); if (mediaFolder == null) { return new ResponseEntity<>("Media folder does not exist.", HttpStatus.BAD_REQUEST); } if (update.getName() != null) { mediaFolder.setName(update.getName()); } if (update.getType() != null) { mediaFolder.setType(update.getType()); } if (update.getPath() != null) { // Check unique fields if (settingsDao.getMediaFolderByPath(update.getPath()) != null) { return new ResponseEntity<>("New media folder path already exists.", HttpStatus.NOT_ACCEPTABLE); } // Check path is readable if (!new File(update.getPath()).isDirectory()) { return new ResponseEntity<>("New media folder path does not exist or is not readable.", HttpStatus.FAILED_DEPENDENCY); } mediaFolder.setPath(update.getPath()); } if (update.getEnabled() != null) { mediaFolder.setEnabled(update.getEnabled()); } // Update database if (!settingsDao.updateMediaFolder(mediaFolder)) { LogService.getInstance().addLogEntry(Level.ERROR, CLASS_NAME, "Error updating media folder with ID '" + mediaFolder.getID() + "'.", null); return new ResponseEntity<>("Error updating media folder.", HttpStatus.INTERNAL_SERVER_ERROR); } LogService.getInstance().addLogEntry(Level.INFO, CLASS_NAME, "Media folder with ID '" + mediaFolder.getID() + "' updated successfully.", null); return new ResponseEntity<>("Media folder updated successfully.", HttpStatus.ACCEPTED); }
From source file:org.geoserver.rest.security.UserPasswordController.java
@PutMapping(consumes = { MediaType.APPLICATION_JSON_VALUE, MediaType.APPLICATION_XML_VALUE, MediaType.TEXT_XML_VALUE, MediaTypeExtensions.TEXT_JSON_VALUE }) public void passwordPut(@RequestBody Map<String, String> putMap) { if (!getManager().checkAuthenticationForRole(SecurityContextHolder.getContext().getAuthentication(), GeoServerRole.AUTHENTICATED_ROLE)) // yes, for backwards compat, it's really METHOD_NOT_ALLOWED throw new RestException("Amdinistrative privelges required", HttpStatus.METHOD_NOT_ALLOWED); try {/* w w w. j a va2s . c o m*/ // Look for the service that handles the current user String userName = SecurityContextHolder.getContext().getAuthentication().getName(); GeoServerUserGroupService ugService = null; for (GeoServerUserGroupService service : getManager().loadUserGroupServices()) { if (service.getUserByUsername(userName) != null) { ugService = service; break; } } if (ugService == null) { throw new RestException("Cannot calculate if PUT is allowed (service not found)", HttpStatus.UNPROCESSABLE_ENTITY); } } catch (IOException e) { throw new RestException("Cannot calculate if PUT is allowed (" + e.getMessage() + ")", HttpStatus.UNPROCESSABLE_ENTITY, e); } String newpass = putMap.get(UP_NEW_PW); if (StringUtils.isBlank(newpass)) throw new RestException("Missing '" + UP_NEW_PW + "'", HttpStatus.BAD_REQUEST); GeoServerUser user = null; GeoServerUserGroupService ugService = null; try { // Look for the authentication service String userName = SecurityContextHolder.getContext().getAuthentication().getName(); for (GeoServerUserGroupService service : getManager().loadUserGroupServices()) { user = service.getUserByUsername(userName); if (user != null) { ugService = service; break; } } } catch (IOException e) { throw new RestException("Cannot retrieve user service", HttpStatus.FAILED_DEPENDENCY, e); } if (ugService == null) { throw new RestException("User service not found", HttpStatus.FAILED_DEPENDENCY); } // Check again if the provider allows updates if (!ugService.canCreateStore()) { throw new RestException("User service does not support changing pw", HttpStatus.FAILED_DEPENDENCY); } try { UserGroupStoreValidationWrapper ugStore = new UserGroupStoreValidationWrapper(ugService.createStore()); user.setPassword(newpass); ugStore.updateUser(user); ugStore.store(); ugService.load(); LOGGER.log(Level.INFO, "Changed password for user {0}", user.getUsername()); } catch (IOException e) { throw new RestException("Internal IO error", HttpStatus.INTERNAL_SERVER_ERROR, e); } catch (PasswordPolicyException e) { throw new RestException("Bad password", HttpStatus.UNPROCESSABLE_ENTITY, e); } }