List of usage examples for org.springframework.http HttpStatus CREATED
HttpStatus CREATED
To view the source code for org.springframework.http HttpStatus CREATED.
Click Source Link
From source file:fr.olympicinsa.riocognized.ImageController.java
@RequestMapping(value = "/api/upload", method = RequestMethod.POST) @ResponseStatus(HttpStatus.CREATED) @ResponseBody//from ww w. j a v a2 s . c o m public Image handleFileUpload(@RequestBody final Image image) { if (image.getContent().length < 1 || !image.getContentType().startsWith("image")) { throw new InvalidContent(); } Image created = imageRepository.save(image); return created; }
From source file:org.ow2.proactive.procci.rest.SwarmRest.java
@RequestMapping(method = RequestMethod.POST) public ResponseEntity<ResourceRendering> createSwarm(@RequestBody ResourceRendering swarmRendering) { logger.debug("Deploy a swarm " + swarmRendering.toString()); try {/* www. j ava2 s. c om*/ swarmRendering.checkAttributes(Swarm.getAttributes(), "Compute", mixinService); SwarmBuilder swarmBuilder = new SwarmBuilder(mixinService, swarmRendering); Resource response = instanceService.create(swarmBuilder.build(), transformerManager.getTransformerProvider(TransformerType.SWARM), mixinService); return new ResponseEntity<>(response.getRendering(), HttpStatus.CREATED); } catch (ClientException e) { logger.error(this.getClass().getName(), e); return new ResponseEntity(e.getJsonError(), HttpStatus.BAD_REQUEST); } catch (ServerException e) { logger.error(this.getClass().getName(), e); return new ResponseEntity(HttpStatus.INTERNAL_SERVER_ERROR); } }
From source file:com.sms.server.controller.AdminController.java
@RequestMapping(value = "/user/role", method = RequestMethod.POST, headers = { "Content-type=application/json" }) @ResponseBody//from w w w .j ava 2s. co m public ResponseEntity<String> createUserRole(@RequestBody UserRole userRole) { // Check mandatory fields. if (userRole.getUsername() == null || userRole.getRole() == null) { return new ResponseEntity<>("Missing required parameter.", HttpStatus.BAD_REQUEST); } // Check unique fields if (userDao.getUserByUsername(userRole.getUsername()) == null) { return new ResponseEntity<>("Username is not registered.", HttpStatus.NOT_ACCEPTABLE); } // Add user role to the database. if (!userDao.createUserRole(userRole)) { LogService.getInstance().addLogEntry(Level.ERROR, CLASS_NAME, "Error adding role'" + userRole.getRole() + "' to user '" + userRole.getUsername() + "'.", null); return new ResponseEntity<>("Error adding user role to database.", HttpStatus.INTERNAL_SERVER_ERROR); } LogService.getInstance().addLogEntry(Level.INFO, CLASS_NAME, "Added role'" + userRole.getRole() + "' to user '" + userRole.getUsername() + "'.", null); return new ResponseEntity<>("User role added successfully.", HttpStatus.CREATED); }
From source file:com.envision.envservice.rest.EvaluationResource.java
/** * ?/*ww w . j a va 2 s .c om*/ * * */ @POST @Path("/addNullEvaluationForManager") @Consumes(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON) public Response addNullEvaluationForManager(EvaluationBo evaluationBo) throws Exception { HttpStatus status = HttpStatus.CREATED; String response = StringUtils.EMPTY; if (!checkParamForManager(evaluationBo.getRemark())) { status = HttpStatus.BAD_REQUEST; response = FailResult.toJson(Code.PARAM_ERROR, "?"); } else { response = evaluationService.addNullEvaluationForManager(evaluationBo.getRemark()).toJSONString(); } return Response.status(status.value()).entity(response).build(); }
From source file:com.tamnd.app.rest.controller.AccountController.java
@RequestMapping(method = RequestMethod.POST) public ResponseEntity<AccountResource> createAccount(@RequestBody AccountResource sentAccount) { try {/*from w w w . java2 s.com*/ //Encode BCrypt password BCryptPasswordEncoder passwordEncoder = new BCryptPasswordEncoder(); String hashedPassword = passwordEncoder.encode(sentAccount.getPassword()); sentAccount.setPassword(hashedPassword); Account newAccount = sentAccount.toAccount(); Set<AccountRole> roles = new HashSet(0); roles.add(new AccountRole(newAccount, "ROLE_USER")); newAccount.setUserRole(roles); Account account = accountService.createAccount(newAccount); AccountResource res = new AccountResourceAsm().toResource(account); HttpHeaders headers = new HttpHeaders(); headers.setLocation(URI.create(res.getLink("self").getHref())); return new ResponseEntity<>(res, headers, HttpStatus.CREATED); } catch (AccountExistsException ex) { throw new ConflictException(ex); } }
From source file:org.cloudfoundry.identity.uaa.login.test.TestClient.java
private void restfulCreate(String adminAccessToken, String json, String url) { HttpHeaders headers = new HttpHeaders(); headers.add("Authorization", "Bearer " + adminAccessToken); headers.add("Accept", "application/json"); headers.add("Content-Type", "application/json"); HttpEntity<String> requestEntity = new HttpEntity<String>(json, headers); ResponseEntity<Void> exchange = restTemplate.exchange(url, HttpMethod.POST, requestEntity, Void.class); Assert.assertEquals(HttpStatus.CREATED, exchange.getStatusCode()); }
From source file:de.unimannheim.spa.process.rest.ProjectRestController.java
@RequestMapping(method = RequestMethod.POST) public ResponseEntity<Map<String, Object>> createProject(@RequestParam String projectLabel) { Project projectCreated = spaService.createProject(projectLabel); spaService.saveProject(projectCreated); spaService.createDataPool(projectCreated, "Default DataPool"); return ResponseEntity.status(HttpStatus.CREATED).contentType(JSON_CONTENT_TYPE) .body(serializeProject(projectCreated)); }
From source file:com.tsg.cms.BlogPostController.java
@RequestMapping(value = "/adminQuickChangeBlogPostStatus/{id}/{status}", method = RequestMethod.PUT) @ResponseStatus(HttpStatus.CREATED) @ResponseBody// w w w. j a v a 2s.c om public void adminQuickChangeBlogPostStatus(@PathVariable("id") int id, @PathVariable("status") String status) { blogPostDao.adminQuickChangeBlogPostStatus(id, status); }
From source file:nu.yona.server.goals.rest.GoalController.java
@RequestMapping(value = "/", method = RequestMethod.POST) @ResponseBody//from w w w . jav a2s. c om public HttpEntity<GoalDto> addGoal(@RequestHeader(value = PASSWORD_HEADER) Optional<String> password, @PathVariable UUID userId, @RequestBody GoalDto goal, @RequestParam(value = "message", required = false) String messageStr) { try (CryptoSession cryptoSession = CryptoSession.start(password, () -> userService.doPreparationsAndCheckCanAccessPrivateData(userId))) { setActivityCategoryId(goal); return createResponse(goalService.addGoal(userId, goal, Optional.ofNullable(messageStr)), HttpStatus.CREATED, createResourceAssembler(userId)); } }
From source file:org.bonitasoft.web.designer.controller.PageResource.java
@RequestMapping(method = RequestMethod.POST) public ResponseEntity<Page> create(@RequestBody Page page, @RequestParam(value = "duplicata", required = false) String sourcePageId) throws RepositoryException { // the page should not have an ID. If it has one, we ignore it and generate one String pageId = UUID.randomUUID().toString(); page.setId(pageId);//w w w . j ava 2 s . co m page.setAssets(filter(page.getAssets(), new PageAssetPredicate())); pageRepository.updateLastUpdateAndSave(page); if (isNotEmpty(sourcePageId)) { assetService.duplicateAsset(pageRepository.resolvePath(sourcePageId), pageRepository.resolvePath(sourcePageId), sourcePageId, pageId); } else { assetService.loadDefaultAssets(page); } return new ResponseEntity<>(page, HttpStatus.CREATED); }