List of usage examples for org.springframework.http HttpHeaders setLocation
public void setLocation(@Nullable URI location)
From source file:com.mycompany.springrest.controllers.RoleController.java
@RequestMapping(value = "/role/", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE, consumes = MediaType.APPLICATION_JSON_VALUE) public ResponseEntity<Void> createRole(@RequestBody Role role, UriComponentsBuilder ucBuilder) { logger.info("Creating Role " + role.getName()); if (roleService.isRoleExist(role)) { logger.info("A Role with name " + role.getName() + " already exist"); return new ResponseEntity<Void>(HttpStatus.CONFLICT); }// w w w . j a v a2s. co m roleService.addRole(role); HttpHeaders headers = new HttpHeaders(); headers.setLocation(ucBuilder.path("/role/{id}").buildAndExpand(role.getId()).toUri()); return new ResponseEntity<Void>(headers, HttpStatus.CREATED); }
From source file:com.example.notes.TagsController.java
@ResponseStatus(HttpStatus.CREATED) @RequestMapping(method = RequestMethod.POST) HttpHeaders create(@RequestBody TagInput tagInput) { Tag tag = new Tag(); tag.setName(tagInput.getName());/*from w w w .j a va2 s .c om*/ this.repository.save(tag); HttpHeaders httpHeaders = new HttpHeaders(); httpHeaders.setLocation(linkTo(TagsController.class).slash(tag.getId()).toUri()); return httpHeaders; }
From source file:rest.DependenciaRestController.java
@RequestMapping(value = "/dependencia/", method = RequestMethod.POST) public ResponseEntity<Void> createDependencia(@RequestBody DependenciaBean dependencia, UriComponentsBuilder ucBuilder) { System.out.println("Registrar una Dependencia"); if (dependenciaService.isDependenciaExist(dependencia)) { System.out.println("La dependencia con Nombre " + dependencia.getDesDep() + " ya existe."); return new ResponseEntity<Void>(HttpStatus.CONFLICT); }// www. j ava 2 s . com dependenciaService.save(dependencia); HttpHeaders headers = new HttpHeaders(); headers.setLocation( ucBuilder.path("/dependencia/{codDep}").buildAndExpand(dependencia.getCodDep()).toUri()); return new ResponseEntity<Void>(headers, HttpStatus.CREATED); }
From source file:com.nebhale.buildmonitor.web.ProjectController.java
@Transactional @RequestMapping(method = RequestMethod.POST, value = "", produces = MEDIA_TYPE) ResponseEntity<?> create(@RequestBody Project project) { if (this.repository.exists(project.getKey())) { return new ResponseEntity<>(HttpStatus.BAD_REQUEST); }//from w w w .jav a 2s. c om this.repository.saveAndFlush(project); HttpHeaders headers = new HttpHeaders(); headers.setLocation(linkTo(ProjectController.class).slash(project.getKey()).toUri()); this.projectsChangedNotifier.projectsChanged(); return new ResponseEntity<>(headers, HttpStatus.CREATED); }
From source file:com._8x8.presentation.restController.UserRestController.java
@RequestMapping(value = "/user/", method = RequestMethod.POST) public ResponseEntity<Void> createUser(@RequestBody User user, UriComponentsBuilder ucBuilder) { System.out.println("Creating Username: " + user.getUsername()); if (_userService.isUserExist(user)) { System.out.println("A User with name " + user.getUsername() + " already exist"); return new ResponseEntity<Void>(HttpStatus.CONFLICT); }//from ww w .j a v a 2s . c om _userService.InsertUser(user); HttpHeaders headers = new HttpHeaders(); headers.setLocation(ucBuilder.path("/user/{id}").buildAndExpand(user.getId()).toUri()); return new ResponseEntity<Void>(headers, HttpStatus.CREATED); }
From source file:za.ac.cput.project.universalhardwarestorev2.api.ItemApi.java
@RequestMapping(value = "/item/create", method = RequestMethod.POST) public ResponseEntity<Void> createItem(@RequestBody Item item, UriComponentsBuilder ucBuilder) { System.out.println("Creating Item " + item.getName()); // USE THIS IF YOU WANT TO CHECK UNIQUE OBJECT // if (ItemService.isItemExist(Item)) { // System.out.println("A Item with name " + Item.getName() + " already exist"); // return new ResponseEntity<Void>(HttpStatus.CONFLICT); // }/*from ww w . j a va 2 s .c om*/ service.save(item); HttpHeaders headers = new HttpHeaders(); headers.setLocation(ucBuilder.path("/item/{id}").buildAndExpand(item.getId()).toUri()); return new ResponseEntity<Void>(headers, HttpStatus.CREATED); }
From source file:fi.hsl.parkandride.front.FacilityController.java
@RequestMapping(method = POST, value = FACILITIES, produces = APPLICATION_JSON_VALUE) public ResponseEntity<Facility> createFacility(@RequestBody Facility facility, User currentUser, UriComponentsBuilder builder) {/* www. ja v a 2 s .c om*/ log.info("createFacility"); Facility newFacility = facilityService.createFacility(facility, currentUser); log.info("createFacility({})", newFacility.id); HttpHeaders headers = new HttpHeaders(); headers.setLocation(builder.path(FACILITY).buildAndExpand(newFacility.id).toUri()); return new ResponseEntity<>(newFacility, headers, CREATED); }
From source file:com.tamnd.app.rest.controller.AccountController.java
@RequestMapping(method = RequestMethod.POST) public ResponseEntity<AccountResource> createAccount(@RequestBody AccountResource sentAccount) { try {/*from w ww.ja v a 2s . c o m*/ //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.hobsoft.contacts.server.controller.ContactsController.java
@RequestMapping(value = "/contacts", method = RequestMethod.POST, consumes = MediaType.APPLICATION_FORM_URLENCODED_VALUE) public ResponseEntity<Object> create(Contact contact) { contactRepository.create(contact);/* w w w .j a v a 2 s. co m*/ Link link = contactResourceAssembler.toResource(contact).getId(); URI location = UriComponentsBuilder.fromUriString(link.getHref()).build().toUri(); HttpHeaders headers = new HttpHeaders(); headers.setLocation(location); return new ResponseEntity<>(headers, HttpStatus.SEE_OTHER); }
From source file:org.hobsoft.contacts.server.controller.ContactsController.java
@RequestMapping(value = "/contact/{id}", method = RequestMethod.DELETE) public ResponseEntity<Object> delete(@PathVariable long id) { Contact contact = contactRepository.get(id); contactRepository.delete(contact);/*from ww w.j a va2 s . co m*/ Link link = contactResourceAssembler.toResource(contact).getLink(Relation.COLLECTION.rel()); URI location = UriComponentsBuilder.fromUriString(link.getHref()).build().toUri(); HttpHeaders headers = new HttpHeaders(); headers.setLocation(location); return new ResponseEntity<>(headers, HttpStatus.SEE_OTHER); }