List of usage examples for org.springframework.http HttpHeaders setLocation
public void setLocation(@Nullable URI location)
From source file:web.EventLogRESTController.java
/** * Adds an event to the Event Log through REST API * @param el// ww w. j a va 2 s . c o m * @param ucBuilder * @return */ @RequestMapping(value = "/api/eventlog/", method = RequestMethod.POST) public ResponseEntity<Void> addEvent(@RequestBody EventLog el, UriComponentsBuilder ucBuilder) { dao.addEvent(el); //returns newly added Event info HttpHeaders headers = new HttpHeaders(); headers.setLocation(ucBuilder.path("/api/eventlog/{id}").buildAndExpand(el.getEventid()).toUri()); return new ResponseEntity<Void>(headers, HttpStatus.CREATED); }
From source file:com.haulmont.restapi.controllers.EntitiesController.java
@PostMapping("/{entityName}") public ResponseEntity<String> createEntity(@RequestBody String entityJson, @PathVariable String entityName, @RequestParam(required = false) String modelVersion, HttpServletRequest request) { CreatedEntityInfo entityInfo = entitiesControllerManager.createEntity(entityJson, entityName, modelVersion); UriComponents uriComponents = UriComponentsBuilder.fromHttpUrl(request.getRequestURL().toString()) .path("/{id}").buildAndExpand(entityInfo.getId().toString()); HttpHeaders httpHeaders = new HttpHeaders(); httpHeaders.setLocation(uriComponents.toUri()); return new ResponseEntity<>(entityInfo.getJson(), httpHeaders, HttpStatus.CREATED); }
From source file:eu.supersede.dm.rest.CriteriaRest.java
/** * Create a new criterion.//from ww w.java 2 s. c o m * @param vc */ @RequestMapping(value = "", method = RequestMethod.POST) public ResponseEntity<?> createCriteria(@RequestBody ValutationCriteria vc) { vc.setCriteriaId(null); DMGame.get().getJpa().criteria.save(vc); // valutationCriterias.save(vc); HttpHeaders httpHeaders = new HttpHeaders(); httpHeaders.setLocation(ServletUriComponentsBuilder.fromCurrentRequest().path("/{id}") .buildAndExpand(vc.getCriteriaId()).toUri()); return new ResponseEntity<>(null, httpHeaders, HttpStatus.CREATED); }
From source file:com.nebhale.letsmakeadeal.web.GamesController.java
@RequestMapping(method = RequestMethod.POST, value = "") ResponseEntity<Void> createGame() { Game game = this.gameRepository.create(); HttpHeaders headers = new HttpHeaders(); headers.setLocation(linkTo(GamesController.class).slash(game.getId()).toUri()); return new ResponseEntity<Void>(headers, HttpStatus.CREATED); }
From source file:com.mentat.rest.web.GamesController.java
@RequestMapping(method = RequestMethod.POST, value = "") ResponseEntity<Void> createGame() { Game game = this.gameRepository.create(); HttpHeaders headers = new HttpHeaders(); headers.setLocation(linkTo(GamesController.class).slash(game.getId()).toUri()); return new ResponseEntity<>(headers, HttpStatus.CREATED); }
From source file:com.tamnd2.basicwebapp.rest.mvc.AccountController.java
@RequestMapping(method = RequestMethod.POST) @PreAuthorize("permitAll") public ResponseEntity<AccountResource> createAccount(@RequestBody AccountResource sentAccount) { try {//from w ww .ja va 2 s.c o m Account createdAccount = accountService.createAccount(sentAccount.toAccount()); AccountResource res = new AccountResourceAsm().toResource(createdAccount); HttpHeaders headers = new HttpHeaders(); headers.setLocation(URI.create(res.getLink("self").getHref())); return new ResponseEntity<AccountResource>(res, headers, HttpStatus.CREATED); } catch (AccountExistException exception) { throw new ConflictException(exception); } }
From source file:com.jiwhiz.rest.author.AuthorBlogRestController.java
@RequestMapping(method = RequestMethod.POST, value = URL_AUTHOR_BLOGS) @Transactional/* w w w . j a v a 2s. c om*/ public HttpEntity<Void> createBlogPost(@RequestBody BlogPostForm blogPostForm) { UserAccount currentUser = getCurrentAuthenticatedAuthor(); BlogPost blogPost = new BlogPost(currentUser, blogPostForm.getTitle(), blogPostForm.getContent(), blogPostForm.getTagString()); blogPost = blogPostRepository.save(blogPost); AuthorBlogResource resource = authorBlogResourceAssembler.toResource(blogPost); HttpHeaders httpHeaders = new HttpHeaders(); httpHeaders.setLocation(URI.create(resource.getLink("self").getHref())); return new ResponseEntity<>(httpHeaders, HttpStatus.CREATED); }
From source file:com.jiwhiz.rest.author.AuthorBlogRestController.java
@RequestMapping(method = RequestMethod.PUT, value = URL_AUTHOR_BLOGS_BLOG) @Transactional//from w ww .j a va 2 s .c o m public HttpEntity<Void> updateBlogPost(@PathVariable("blogId") String blogId, @RequestBody BlogPostForm blogPostForm) throws ResourceNotFoundException { BlogPost blogPost = getBlogByIdAndCheckAuthor(blogId); blogPost.setContent(blogPostForm.getContent()); blogPost.setTitle(blogPostForm.getTitle()); blogPost.parseAndSetTagString(blogPostForm.getTagString()); blogPost = blogPostRepository.save(blogPost); AuthorBlogResource resource = authorBlogResourceAssembler.toResource(blogPost); HttpHeaders httpHeaders = new HttpHeaders(); httpHeaders.setLocation(URI.create(resource.getLink("self").getHref())); return new ResponseEntity<Void>(httpHeaders, HttpStatus.NO_CONTENT); }
From source file:com.example.notes.NotesController.java
@ResponseStatus(HttpStatus.CREATED) @RequestMapping(method = RequestMethod.POST) HttpHeaders create(@RequestBody NoteInput noteInput) { Note note = new Note(); note.setTitle(noteInput.getTitle()); note.setBody(noteInput.getBody());//from w ww . jav a 2 s. c o m note.setTags(getTags(noteInput.getTagUris())); this.noteRepository.save(note); HttpHeaders httpHeaders = new HttpHeaders(); httpHeaders.setLocation(linkTo(NotesController.class).slash(note.getId()).toUri()); return httpHeaders; }
From source file:web.UsersRESTController.java
/** * Adds a user to the database through REST API * @param user/*from w w w.j av a2 s . c o m*/ * @param ucBuilder * @return */ @RequestMapping(value = "/api/users/", method = RequestMethod.POST) public ResponseEntity<Void> addUser(@RequestBody Users user, UriComponentsBuilder ucBuilder) { dao.addUser(user); //returns newly added User info HttpHeaders headers = new HttpHeaders(); headers.setLocation(ucBuilder.path("/api/users/userinfo/{id}").buildAndExpand(user.getUserId()).toUri()); return new ResponseEntity<Void>(headers, HttpStatus.CREATED); }