List of usage examples for org.springframework.http HttpStatus CONFLICT
HttpStatus CONFLICT
To view the source code for org.springframework.http HttpStatus CONFLICT.
Click Source Link
From source file:com.logsniffer.web.controller.sniffer.publisher.PublishersResourceController.java
@ExceptionHandler(value = Throwable.class) @ResponseBody/*from w w w. j a va2 s . c om*/ public void handleAllExceptions(final Throwable ex, final HttpServletResponse response) throws IOException { logger.info("Failed to test event publishing", ex); response.setStatus(HttpStatus.CONFLICT.value()); response.setContentType(MediaType.TEXT_PLAIN_VALUE); final String stackTrace = ExceptionUtils.getStackTrace(ex); IOUtils.write(stackTrace, response.getOutputStream()); }
From source file:edu.kit.scc.RestServiceController.java
/** * Linking endpoint.//from w w w .j a v a 2 s. c o m * * @param basicAuthorization authorization header value * @param scimUsers a JSON serialized list of SCIM users for linking * @param response the HttpServletResponse * @return a JSON serialized list of SCIM users containing the modifications done */ @RequestMapping(path = "/link", method = RequestMethod.POST, consumes = "application/scim+json", produces = "application/scim+json") public ResponseEntity<?> linkUsers(@RequestHeader("Authorization") String basicAuthorization, @RequestBody List<ScimUser> scimUsers, HttpServletResponse response) { if (!verifyAuthorization(basicAuthorization)) { return new ResponseEntity<String>("REST Service Unauthorized", HttpStatus.UNAUTHORIZED); } log.debug("Request body {}", scimUsers); List<ScimUser> modifiedUsers = identityHarmonizer.harmonizeIdentities(scimUsers); if (!modifiedUsers.isEmpty()) { return new ResponseEntity<List<ScimUser>>(modifiedUsers, HttpStatus.OK); } return new ResponseEntity<String>("Conflicting information", HttpStatus.CONFLICT); }
From source file:io.github.microcks.web.ServiceController.java
@RequestMapping(value = "/services/generic", method = RequestMethod.POST) public ResponseEntity<Service> createGenericResourceService(@RequestBody GenericResourceServiceDTO serviceDTO) { log.debug("Creating a new Service '{}-{}' for generic resource '{}'", serviceDTO.getName(), serviceDTO.getVersion(), serviceDTO.getResource()); try {/*from w w w . j a v a 2s . c om*/ Service service = serviceService.createGenericResourceService(serviceDTO.getName(), serviceDTO.getVersion(), serviceDTO.getResource()); return new ResponseEntity<>(service, HttpStatus.CREATED); } catch (EntityAlreadyExistsException eaee) { log.error("Service '{}-{} already exists'", serviceDTO.getName(), serviceDTO.getVersion()); return new ResponseEntity<>(HttpStatus.CONFLICT); } }
From source file:jetbrains.buildServer.projectPush.PostProjectToSandboxController.java
@Nullable @Override// w ww . j a v a2 s . c o m protected ModelAndView doHandle(@NotNull HttpServletRequest request, @NotNull HttpServletResponse response) throws Exception { if (!isPost(request)) { response.sendError(HttpStatus.METHOD_NOT_ALLOWED.value()); return null; } final StringBuilder stringBuffer = new StringBuilder(); try { String line; BufferedReader reader = request.getReader(); while ((line = reader.readLine()) != null) stringBuffer.append(line); } catch (Exception e) { response.sendError(HttpStatus.BAD_REQUEST.value(), e.getMessage()); return null; } final String projectName = stringBuffer.toString(); if (projectName.isEmpty()) { response.sendError(HttpStatus.BAD_REQUEST.value(), "Project name is empty."); return null; } if (mySettings.isDisabled()) { response.sendError(HttpStatus.FORBIDDEN.value(), "Sandbox disabled."); return null; } SUser user; user = SessionUser.getUser(request); if (user == null) { user = myAuthHelper.getAuthenticatedUser(request, response); } if (user == null) return null; final Role projectAdminRole = myRolesHelper.findProjectAdminRole(); if (projectAdminRole == null) { response.sendError(HttpStatus.INTERNAL_SERVER_ERROR.value(), "Failed to locate Project Admin role on the server."); return null; } final SProject project; try { final String sandboxProjectId = mySettings.getSandboxProjectId(); final SProject sandboxProject = myProjectManager.findProjectByExternalId(sandboxProjectId); if (sandboxProject == null) { response.sendError(HttpStatus.INTERNAL_SERVER_ERROR.value(), "Failed to locate sandbox project by ID " + sandboxProjectId); return null; } if (sandboxProject.findProjectByName(projectName) != null) { response.sendError(HttpStatus.CONFLICT.value(), "Project with name " + projectName + " already exists."); return null; } project = sandboxProject.createProject( myProjectIdentifiersManager.generateNewExternalId(null, projectName, null), projectName); project.persist(); } catch (Exception e) { response.sendError(HttpStatus.INTERNAL_SERVER_ERROR.value(), e.getMessage()); return null; } try { myRolesHelper.addRole(user, RoleScope.projectScope(project.getProjectId()), projectAdminRole); } catch (Throwable throwable) { response.sendError(HttpStatus.INTERNAL_SERVER_ERROR.value(), throwable.getMessage()); return null; } response.setStatus(HttpStatus.CREATED.value()); response.setHeader(HttpHeaders.LOCATION, RESTApiHelper.getProjectURI(project)); return null; }
From source file:org.echocat.marquardt.authority.spring.SpringAuthorityController.java
@ExceptionHandler(UserAlreadyExistsException.class) @ResponseStatus(value = HttpStatus.CONFLICT, reason = "User already exists.") public void handleUserExistsException(final UserAlreadyExistsException ex) { LOGGER.info(ex.getMessage());//w w w . j a v a 2 s .c o m }
From source file:bg.vitkinov.edu.services.JokeService.java
@RequestMapping(method = { RequestMethod.POST, RequestMethod.PUT }) public ResponseEntity<?> insert(@RequestParam String title, @RequestParam String content, @RequestParam(required = false, defaultValue = "false") boolean base64) { String jokeContent = base64 ? new String(Base64.getDecoder().decode(content)) : content; Optional<Joke> joke = jokeRepository.findFirstByContentIgnoreCaseContaining(jokeContent); if (joke.isPresent()) { return new ResponseEntity<>(joke.get(), HttpStatus.CONFLICT); }//from w w w . ja v a 2 s. c o m Joke newJoke = new Joke(); newJoke.setTitle(title); newJoke.setContent(jokeContent); newJoke.setCategory(findCategories(jokeContent)); return new ResponseEntity<>(jokeRepository.save(newJoke), HttpStatus.CREATED); }
From source file:com.novation.eligibility.rest.spring.web.servlet.handler.DefaultRestErrorResolver.java
protected final Map<String, String> createDefaultExceptionMappingDefinitions() { Map<String, String> m = new LinkedHashMap<String, String>(); // 400/*from ww w . j ava 2 s.c om*/ applyDef(m, HttpMessageNotReadableException.class, HttpStatus.BAD_REQUEST); applyDef(m, MissingServletRequestParameterException.class, HttpStatus.BAD_REQUEST); applyDef(m, TypeMismatchException.class, HttpStatus.BAD_REQUEST); applyDef(m, "javax.validation.ValidationException", HttpStatus.BAD_REQUEST); // 404 applyDef(m, NoSuchRequestHandlingMethodException.class, HttpStatus.NOT_FOUND); applyDef(m, "org.hibernate.ObjectNotFoundException", HttpStatus.NOT_FOUND); // 405 applyDef(m, HttpRequestMethodNotSupportedException.class, HttpStatus.METHOD_NOT_ALLOWED); // 406 applyDef(m, HttpMediaTypeNotAcceptableException.class, HttpStatus.NOT_ACCEPTABLE); // 409 //can't use the class directly here as it may not be an available dependency: applyDef(m, "org.springframework.dao.DataIntegrityViolationException", HttpStatus.CONFLICT); // 415 applyDef(m, HttpMediaTypeNotSupportedException.class, HttpStatus.UNSUPPORTED_MEDIA_TYPE); return m; }
From source file:com.nebhale.letsmakeadeal.web.GamesController.java
@ExceptionHandler(IllegalTransitionException.class) ResponseEntity<String> handleConflicts(Exception e) { return new ResponseEntity<String>(e.getMessage(), HttpStatus.CONFLICT); }
From source file:org.mitre.oauth2.web.ScopeAPI.java
@PreAuthorize("hasRole('ROLE_ADMIN')") @RequestMapping(value = "", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE, consumes = MediaType.APPLICATION_JSON_VALUE) public String createScope(@RequestBody String json, ModelMap m) { SystemScope scope = gson.fromJson(json, SystemScope.class); SystemScope alreadyExists = scopeService.getByValue(scope.getValue()); if (alreadyExists != null) { //Error, cannot save a scope with the same value as an existing one logger.error("Error: attempting to save a scope with a value that already exists: " + scope.getValue()); m.put(HttpCodeView.CODE, HttpStatus.CONFLICT); m.put(JsonErrorView.ERROR_MESSAGE, "A scope with value " + scope.getValue() + " already exists, please choose a different value."); return JsonErrorView.VIEWNAME; }// w w w .j av a 2s. c om scope = scopeService.save(scope); if (scope != null && scope.getId() != null) { m.put(JsonEntityView.ENTITY, scope); return JsonEntityView.VIEWNAME; } else { logger.error("createScope failed; JSON was invalid: " + json); m.put(HttpCodeView.CODE, HttpStatus.BAD_REQUEST); m.put(JsonErrorView.ERROR_MESSAGE, "Could not save new scope " + scope + ". The scope service failed to return a saved entity."); return JsonErrorView.VIEWNAME; } }
From source file:com.oolong.platform.web.error.DefaultRestErrorResolver.java
protected final Map<String, String> createDefaultExceptionMappingDefinitions() { Map<String, String> m = new LinkedHashMap<String, String>(); // 400//from www . j a v a 2 s . co m applyDef(m, HttpMessageNotReadableException.class, HttpStatus.BAD_REQUEST); applyDef(m, MissingServletRequestParameterException.class, HttpStatus.BAD_REQUEST); applyDef(m, TypeMismatchException.class, HttpStatus.BAD_REQUEST); applyDef(m, "javax.validation.ValidationException", HttpStatus.BAD_REQUEST); // 404 applyDef(m, NoSuchRequestHandlingMethodException.class, HttpStatus.NOT_FOUND); applyDef(m, "org.hibernate.ObjectNotFoundException", HttpStatus.NOT_FOUND); // 405 applyDef(m, HttpRequestMethodNotSupportedException.class, HttpStatus.METHOD_NOT_ALLOWED); // 406 applyDef(m, HttpMediaTypeNotAcceptableException.class, HttpStatus.NOT_ACCEPTABLE); // 409 // can't use the class directly here as it may not be an available // dependency: applyDef(m, "org.springframework.dao.DataIntegrityViolationException", HttpStatus.CONFLICT); // 415 applyDef(m, HttpMediaTypeNotSupportedException.class, HttpStatus.UNSUPPORTED_MEDIA_TYPE); return m; }