List of usage examples for org.springframework.http ResponseEntity created
public static BodyBuilder created(URI location)
From source file:com.epages.checkout.CartController.java
@PostMapping public ResponseEntity<Void> createCart() { Cart cart = cartRepository.saveAndFlush(new Cart()); URI location = entityLinks.linkForSingleResource(cart).toUri(); return ResponseEntity.created(location).build(); }
From source file:com.training.rest.api.BookController.java
@RequestMapping(value = "/books", method = RequestMethod.POST) public ResponseEntity<Void> addBook(@RequestBody Book book) { Book saved = bookService.save(book); URI location = MvcUriComponentsBuilder.fromMethodCall(on(BookController.class).getBook(saved.getId())) .build().toUri();/* w w w. ja v a2 s .c o m*/ return ResponseEntity.created(location).build(); }
From source file:org.lecture.controller.BaseController.java
/** * A conviniencemethod for creating new Entities. * * @param newEntity The entity that should be created * @param <T> Type of the entity that should get created * @return The formal Response for the childcontroller. *//*from w w w . j a v a2s . com*/ public <T extends BaseEntity> ResponseEntity<?> createEntity(T newEntity) { return ResponseEntity.created(entityLinks.linkForSingleResource(newEntity).toUri()).build(); }
From source file:de.lgblaumeiser.ptm.rest.ActivityRestController.java
@RequestMapping(method = RequestMethod.POST) ResponseEntity<?> addActivity(@RequestBody ActivityBody activityData) { Activity newActivity = services.activityStore() .store(newActivity().setActivityName(activityData.activityName) .setBookingNumber(activityData.bookingNumber).setHidden(activityData.hidden).build()); URI location = ServletUriComponentsBuilder.fromCurrentRequest().path("/{id}") .buildAndExpand(newActivity.getId()).toUri(); return ResponseEntity.created(location).build(); }
From source file:com.mycompany.geocoordinate.controller.PolygonController.java
@ResponseStatus(HttpStatus.CREATED) @PostMapping(value = "/polygon", consumes = MediaType.APPLICATION_JSON_UTF8_VALUE, produces = MediaType.APPLICATION_JSON_UTF8_VALUE) public @ResponseBody ResponseEntity<List<Integer>> polygon(@RequestBody GeoObject geoObject) throws IOException, JsonException { boolean check = coordinateMapper.isThereGeoObjectFromPolygontype(GeoType.POLYGON) != null & coordinateMapper.selectCoordinateForLineorCircle(geoObject.getCoordinate()) != null; coordinateMapper.insertCoordinateForLineorCircle(GeoType.POLYGON, geoObject.getCoordinate()); List<Integer> responseType = coordinateMapper.selectIdGeo(geoObject.getCoordinate()); return ResponseEntity.created(URI.create("/polygon/id")).body(responseType); }
From source file:com.mycompany.geocoordinate.controller.PointController.java
@ResponseStatus(HttpStatus.CREATED) @PostMapping(value = "/point", consumes = MediaType.APPLICATION_JSON_UTF8_VALUE, produces = MediaType.APPLICATION_JSON_UTF8_VALUE) public @ResponseBody ResponseEntity<List<Integer>> point(@RequestBody GeoObject geoObject) throws IOException, JSONException { boolean check = coordinateMapper.isThereGeoObjectFromCircleType(GeoType.GEOPOINT) != null & coordinateMapper.selectCoordinateForLineorCircle(geoObject.getCoordinate()) != null; coordinateMapper.insertCoordinateForLineorCircle(GeoType.GEOPOINT, geoObject.getCoordinate()); List<Integer> responseType = coordinateMapper.selectIdGeo(geoObject.getCoordinate()); return ResponseEntity.created(URI.create("/point/id")).body(responseType); }
From source file:com.greglturnquist.springagram.fileservice.s3.ApplicationController.java
@RequestMapping(method = RequestMethod.POST, value = "/files") public ResponseEntity<?> newFile(@RequestParam("name") String filename, @RequestParam("file") MultipartFile file) { try {/* ww w . j av a 2 s . c o m*/ this.fileService.saveFile(file.getInputStream(), file.getSize(), filename); Link link = linkTo(methodOn(ApplicationController.class).getFile(filename)).withRel(filename); return ResponseEntity.created(new URI(link.getHref())).build(); } catch (IOException | URISyntaxException e) { return ResponseEntity.badRequest().body("Couldn't process the request"); } }
From source file:com.greglturnquist.springagram.fileservice.mongodb.ApplicationController.java
@RequestMapping(method = RequestMethod.POST, value = "/files") public ResponseEntity<?> newFile(@RequestParam("name") String filename, @RequestParam("file") MultipartFile file) { if (!file.isEmpty()) { try {//from www. ja va2 s . c o m this.fileService.saveFile(file.getInputStream(), filename); Link link = linkTo(methodOn(ApplicationController.class).getFile(filename)).withRel(filename); return ResponseEntity.created(new URI(link.getHref())).build(); } catch (IOException | URISyntaxException e) { return ResponseEntity.badRequest().body("Couldn't process the request"); } } else { return ResponseEntity.status(HttpStatus.NOT_ACCEPTABLE).body("File is empty"); } }
From source file:com.onyxscheduler.web.JobController.java
@RequestMapping(value = "/groups/{group}/jobs", method = RequestMethod.POST) public ResponseEntity<Job> addJob(@PathVariable String group, @RequestBody Job job) throws NonMatchingGroupsException, Scheduler.DuplicateJobKeyException { if (job.getGroup() != null && !job.getGroup().equals(group)) { //throwing an exception instead of ResponseEntity.badRequest().build() to have a proper description of the bad request throw new NonMatchingGroupsException(group, job.getGroup()); }//from w w w. j a va2s.c o m job.setGroup(group); scheduler.scheduleJob(job); URI location = ServletUriComponentsBuilder.fromCurrentRequest().path("/{job}").buildAndExpand(job.getName()) .toUri(); return ResponseEntity.created(location).body(job); }
From source file:com.eretailservice.security.BookingRestController.java
@RequestMapping(method = RequestMethod.POST) ResponseEntity<?> add(Principal principal, @RequestBody Booking input) { this.validateUser(principal); return accountRepository.findByUsername(principal.getName()).map(account -> { Booking booking = bookingRepository.save(new Booking(account, input.uri, input.description)); Link forOneBooking = new BookingResource(booking).getLink(Link.REL_SELF); return ResponseEntity.created(URI.create(forOneBooking.getHref())).build(); }).orElse(ResponseEntity.noContent().build()); }