List of usage examples for org.springframework.http HttpHeaders setLocation
public void setLocation(@Nullable URI location)
From source file:de.escalon.hypermedia.spring.sample.ReviewController.java
@RequestMapping(value = "/events/{eventId}", method = RequestMethod.POST) public @ResponseBody ResponseEntity<Void> addReview(@PathVariable int eventId, @RequestBody Review review) { Assert.notNull(review);//from ww w. jav a 2 s . c om Assert.notNull(review.getReviewRating()); Assert.notNull(review.getReviewRating().getRatingValue()); final HttpHeaders headers = new HttpHeaders(); headers.setLocation( AffordanceBuilder.linkTo(AffordanceBuilder.methodOn(this.getClass()).getReviews(eventId)).toUri()); return new ResponseEntity(headers, HttpStatus.CREATED); }
From source file:com.moxian.ng.api.user.SignupController.java
@RequestMapping(value = { "/signup" }, method = RequestMethod.POST) @ResponseBody//from w w w . j a v a2 s .c o m public ResponseEntity<Void> signup(@RequestBody @Valid SignupForm form, BindingResult errors, HttpServletRequest req) { if (log.isDebugEnabled()) { log.debug("signup data@" + form); } if (errors.hasErrors()) { throw new InvalidRequestException(errors); } UserDetails saved = userService.registerUser(form); HttpHeaders headers = new HttpHeaders(); headers.setLocation(ServletUriComponentsBuilder.fromContextPath(req) .path(Constants.URI_API_PUBLIC + Constants.URI_USERS + "/{id}").buildAndExpand(saved.getId()) .toUri()); return new ResponseEntity<>(headers, HttpStatus.CREATED); }
From source file:com.arya.latihan.controller.CustomerController.java
@RequestMapping(method = RequestMethod.POST) @Transactional(readOnly = false)/* w ww . j a v a2 s. c om*/ public ResponseEntity<Customer> saveCustomer(@Valid Customer customer) { customer = customerRepository.save(customer); URI location = ServletUriComponentsBuilder.fromCurrentRequest().path("/{id}") .buildAndExpand(customer.getId()).toUri(); HttpHeaders headers = new HttpHeaders(); headers.setLocation(location); return new ResponseEntity<Customer>(headers, HttpStatus.CREATED); }
From source file:com.github.hateoas.forms.spring.sample.test.ReviewController.java
@Action("ReviewAction") @RequestMapping(value = "/events/{eventId}", method = RequestMethod.POST, params = { "review", "rating" }) public @ResponseBody ResponseEntity<Void> addReview(@PathVariable int eventId, @RequestParam String review, @RequestParam int rating) { final HttpHeaders headers = new HttpHeaders(); headers.setLocation(AffordanceBuilder .linkTo(AffordanceBuilder.methodOn(this.getClass()).getReviews(eventId, null)).toUri()); return new ResponseEntity(headers, HttpStatus.CREATED); }
From source file:com.github.hateoas.forms.spring.sample.test.ReviewController.java
@RequestMapping(value = "/events/{eventId}", method = RequestMethod.POST) public @ResponseBody ResponseEntity<Void> addReview(@PathVariable int eventId, @RequestBody Review review) { Assert.notNull(review);/*from www. j a v a 2s . co m*/ Assert.notNull(review.getReviewRating()); Assert.notNull(review.getReviewRating().getRatingValue()); final HttpHeaders headers = new HttpHeaders(); headers.setLocation(AffordanceBuilder .linkTo(AffordanceBuilder.methodOn(this.getClass()).getReviews(eventId, null)).toUri()); return new ResponseEntity(headers, HttpStatus.CREATED); }
From source file:com.nebhale.devoxx2013.web.GameController.java
@RequestMapping(method = RequestMethod.POST, value = "") @Transactional/* w w w. j av a2 s. co m*/ ResponseEntity<Void> create() { Game game = this.gameService.create(); HttpHeaders headers = new HttpHeaders(); headers.setLocation(linkTo(GameController.class).slash(game).toUri()); return new ResponseEntity<>(headers, HttpStatus.CREATED); }
From source file:com.trafficfine.controller.TrafficFineController.java
/** * // w w w .j a v a 2s . c o m * @param infraction * @param ucBuilder * @return */ @RequestMapping(value = "/api/infracao/", method = RequestMethod.POST) public ResponseEntity<Void> createInfraction(@RequestBody Infraction infraction, UriComponentsBuilder ucBuilder) { logger.info("Creating infraction: " + infraction.getPlaca()); if (trafficFineService.isInfractionExist(infraction)) { logger.info("A infraction with license plate " + infraction.getPlaca() + " already exist"); return new ResponseEntity<Void>(HttpStatus.CONFLICT); } trafficFineService.saveInfraction(infraction); HttpHeaders header = new HttpHeaders(); header.setLocation(ucBuilder.path("/").buildAndExpand(infraction.getId()).toUri()); return new ResponseEntity<Void>(header, HttpStatus.CREATED); }
From source file:com.nebhale.gpxconverter.ApplicationController.java
@RequestMapping(method = RequestMethod.POST, value = "", consumes = MediaType.APPLICATION_XML_VALUE, produces = MediaType.IMAGE_PNG_VALUE) ResponseEntity<Void> image(@RequestBody DOMSource source, @RequestParam(defaultValue = "roadmap") String maptype, @RequestParam(defaultValue = "500") Integer width, @RequestParam(defaultValue = "500") Integer height) { this.logger.info("Rendering existing GPX file"); List<Point> points = this.parser.parsePoints((Document) source.getNode()); HttpHeaders headers = new HttpHeaders(); headers.setLocation(this.mapBuilder.build(points, maptype, width, height)); return new ResponseEntity<>(headers, HttpStatus.SEE_OTHER); }
From source file:com.sentinel.web.controllers.RegistrationController.java
@RequestMapping(value = "/user", method = RequestMethod.POST) @ResponseBody//from w w w . ja va 2 s . com public ResponseEntity<Void> createUser(@RequestBody UserForm accountDto, UriComponentsBuilder ucBuilder) { LOG.debug("Registring new user"); final User registered = createUserAccount(accountDto); if (registered == null) { return new ResponseEntity<Void>(HttpStatus.CONFLICT); } /* if (userService.isUserExist(user)) { System.out.println("A User with name " + user.getUsername() + " already exist"); } */ userService.saveRegisteredUser(registered); HttpHeaders headers = new HttpHeaders(); headers.setLocation(ucBuilder.path("/user/{id}").buildAndExpand(registered.getId()).toUri());//TODO return new ResponseEntity<Void>(headers, HttpStatus.CREATED); }
From source file:com.arya.latihan.controller.ItemController.java
@RequestMapping(method = RequestMethod.POST) @Transactional(readOnly = false)/*w w w . j ava 2s. c om*/ public ResponseEntity<Void> saveItem(@RequestBody @Valid Item item) { Integer lastCode = itemRepository.findLastCode(); String code = "M-" + String.format("%08d", (lastCode + 1)); item.setCode(code); item = itemRepository.save(item); URI location = ServletUriComponentsBuilder.fromCurrentRequest().path("/{id}").buildAndExpand(item.getId()) .toUri(); HttpHeaders headers = new HttpHeaders(); headers.setLocation(location); return new ResponseEntity<>(headers, HttpStatus.CREATED); }