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:com.github.carlomicieli.nerdmovies.controllers.ImageController.java
private ResponseEntity<byte[]> render(String movieId, ImageType t) throws IOException { ObjectId id = new ObjectId(movieId); Movie m = mongoTemplate.findById(id, Movie.class); byte[] aob = null; if (t == ImageType.POSTER) aob = m.getPoster();//from w w w.ja va2 s. c o m else if (t == ImageType.THUMB) aob = m.getThumb(); if (aob == null) return null; InputStream in = new ByteArrayInputStream(aob); final HttpHeaders headers = new HttpHeaders(); headers.setContentType(MediaType.IMAGE_PNG); return new ResponseEntity<byte[]>(IOUtils.toByteArray(in), headers, HttpStatus.CREATED); }
From source file:com.github.djabry.platform.rest.AuthenticationController.java
/** * @param request The request to change the password * @return True if the password was changed successfully *//*from w ww. j a v a 2 s. co m*/ @Override @ResponseStatus(HttpStatus.CREATED) @RequestMapping(name = "/changepassword", method = RequestMethod.POST) public boolean changePassword(@NotNull ChangePasswordRequest request) { return this.authenticationService.changePassword(request); }
From source file:de.thm.arsnova.controller.LecturerQuestionController.java
@RequestMapping(value = "/", method = RequestMethod.POST) @ResponseStatus(HttpStatus.CREATED) public Question postQuestion(@RequestBody final Question question) { if (questionService.saveQuestion(question) != null) { return question; }/*from w ww. j a v a 2s .co m*/ throw new BadRequestException(); }
From source file:fr.esiea.windmeal.controller.crud.CrudMenuCtrl.java
@Secured("ROLE_USER") @RequestMapping(method = RequestMethod.POST, consumes = "application/json;charset=UTF-8") @ResponseStatus(HttpStatus.CREATED) public void create(@RequestBody Menu menu) throws ServiceException, DaoException { LOGGER.info("[Controller] Querying to create new menu : " + menu.toString() + "\""); crudService.insert(menu);// w w w. j ava2s. com }
From source file:com.tsguild.upsproject.controller.HomeController.java
@ResponseBody @ResponseStatus(HttpStatus.CREATED) @RequestMapping(value = "/cannister", method = RequestMethod.POST) public Cannister createCannister(@RequestBody Cannister incomingCannister) { dao.addCannister(incomingCannister); return incomingCannister; }
From source file:de.codecentric.boot.admin.services.ApplicationRegistratorTest.java
@SuppressWarnings("rawtypes") @Test//from w w w .j a v a 2 s.co m public void register_successful() { when(restTemplate.postForEntity(isA(String.class), isA(HttpEntity.class), eq(Map.class))) .thenReturn(new ResponseEntity<Map>(Collections.singletonMap("id", "-id-"), HttpStatus.CREATED)); assertTrue(registrator.register()); verify(restTemplate).postForEntity("http://sba:8080/api/applications", new HttpEntity<>(Application.create("AppName").withHealthUrl("http://localhost:8080/health") .withManagementUrl("http://localhost:8080/mgmt").withServiceUrl("http://localhost:8080") .build(), headers), Map.class); }
From source file:com.jee.shiro.rest.TaskRestController.java
@RequestMapping(method = RequestMethod.POST, consumes = "applaction/json") public ResponseEntity<?> create(@RequestBody Task task, UriComponentsBuilder uriBuilder) { // JSR303 Bean Validator, RestExceptionHandler?. BeanValidators.validateWithException(validator, task); // ?/*w ww . ja va2 s. c o m*/ taskService.saveTask(task); // Restful?url, ?id. Long id = task.getId(); URI uri = uriBuilder.path("/api/v1/task/" + id).build().toUri(); HttpHeaders headers = new HttpHeaders(); headers.setLocation(uri); return new ResponseEntity(headers, HttpStatus.CREATED); }
From source file:com.ns.retailmgr.controller.ShopController.java
@ApiOperation(consumes = MediaType.APPLICATION_JSON_VALUE, produces = MediaType.APPLICATION_JSON_VALUE, httpMethod = "POST", value = "", response = String.class, notes = "Save the shop details") @RequestMapping(method = RequestMethod.POST, consumes = MediaType.APPLICATION_JSON_VALUE, produces = MediaType.APPLICATION_JSON_VALUE) public ResponseEntity<Object> saveShop(@RequestBody ShopDetails shopDetails) { LOGGER.info("Started endpoint method {}, params - {}", "saveShop"); try {//from w w w .j a v a 2 s .c o m ShopDetails newShopDetails = shopService.addShop(shopDetails); if (newShopDetails == null) { return new ResponseEntity<Object>( "Unable to find latitude and logitude for shop details provided, please check and resubmit again", HttpStatus.BAD_REQUEST); } if (newShopDetails.getStatus() != null) return new ResponseEntity<Object>(HttpStatus.CREATED); else return new ResponseEntity<Object>(newShopDetails, HttpStatus.OK); } catch (Exception e) { LOGGER.error("Exception {}", e); return new ResponseEntity(e.getMessage(), HttpStatus.INTERNAL_SERVER_ERROR); } }
From source file:plbtw.klmpk.barang.hilang.controller.RoleController.java
@RequestMapping(method = RequestMethod.PUT, produces = "application/json") public CustomResponseMessage updateRole(@RequestBody RoleRequest roleRequest) { try {//w w w. ja va 2 s . com Role role = roleService.getRole(roleRequest.getId()); System.out.println(role.toString()); role.setRole(roleRequest.getRole()); roleService.updateRole(role); return new CustomResponseMessage(HttpStatus.CREATED, "Update Role Succesfull"); } catch (Exception ex) { return new CustomResponseMessage(HttpStatus.BAD_REQUEST, ex.toString()); } }
From source file:de.hska.ld.core.controller.RoleController.java
/** * <pre>/* w w w . j a va 2s.c om*/ * Saves a role. If no ID is provided a new role will be created otherwise an existing role will be updated. * * <b>Required roles:</b> ROLE_ADMIN * <b>Path:</b> POST {@value Core#RESOURCE_ROLE} * </pre> * * @param role the role instance to be saved or modified as request body. Example: <br> * {name: 'ROLE_SUBSCRIBER'} * @return <b>201 Created</b> and the role ID or <br> * <b>200 OK</b> and the ID of the updated role instance or <br> * <b>403 Forbidden</b> if authorization failed */ @Secured(Core.ROLE_ADMIN) @RequestMapping(method = RequestMethod.POST) public Callable saveRole(@RequestBody @Valid final Role role) { return () -> { boolean isNew = false; if (role.getId() == null) { isNew = true; } Role dbRole = roleService.findById(role.getId()); if (dbRole != null) { dbRole.setName(role.getName()); } dbRole = roleService.save(role); IdDto idDto = new IdDto(dbRole.getId()); if (isNew) { return new ResponseEntity<>(idDto, HttpStatus.CREATED); } else { return new ResponseEntity<>(idDto, HttpStatus.OK); } }; }