List of usage examples for org.springframework.web.util UriComponentsBuilder path
@Override
public UriComponentsBuilder path(String path)
From source file:cn.dsgrp.field.stock.rest.TaskRestController.java
@RequestMapping(method = RequestMethod.POST, consumes = MediaTypes.JSON) public ResponseEntity<?> create(@RequestBody Task task, UriComponentsBuilder uriBuilder) { // JSR303 Bean Validator, RestExceptionHandler?. BeanValidators.validateWithException(validator, task); // ?/* w w w . j a va 2s . c om*/ taskService.saveTask(task); // Restful?url, ?id. BigInteger 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.mycompany.springrest.controllers.UserController.java
@RequestMapping(value = "/user/", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE, consumes = MediaType.APPLICATION_JSON_VALUE) public ResponseEntity<Void> createUser(@RequestBody User user, UriComponentsBuilder ucBuilder) { logger.info("Creating User " + user.getUserName()); if (userService.isUserExist(user)) { logger.info("A User with name " + user.getUserName() + " already exist"); return new ResponseEntity<Void>(HttpStatus.CONFLICT); }/*from ww w. j ava 2 s.co m*/ userService.addUser(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:cz.muni.fi.mvc.controllers.DestinationController.java
/** * Shows a Destination/* w w w .ja v a2 s . c o m*/ * @param id identificator of the destination * @param model display data * @return jsp page */ @RequestMapping(value = "/detail/{id}", method = RequestMethod.GET) public String detail(@PathVariable long id, Model model, RedirectAttributes redirectAttributes, UriComponentsBuilder uriBuilder) { try { model.addAttribute("destination", destinationFacade.getDestinationWithId(id)); } catch (Exception e) { redirectAttributes.addFlashAttribute("alert_danger", "Destination with id: " + id + " was not found."); return "redirect:" + uriBuilder.path("/destination").toUriString(); } return "destination/detail"; }
From source file:$.TaskRestController.java
@RequestMapping(method = RequestMethod.POST, consumes = MediaTypes.JSON) public ResponseEntity<?> create(@RequestBody Task task, UriComponentsBuilder uriBuilder) { // JSR303 Bean Validator, RestExceptionHandler?. BeanValidators.validateWithException(validator, task); // ?//from w w w . j a v a 2 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:cz.muni.fi.pa165.mvc.controllers.GameController.java
@RequestMapping(value = "/delete/{id}", method = RequestMethod.POST) public String delete(@PathVariable long id, Model model, UriComponentsBuilder uriBuilder, RedirectAttributes redirectAttributes) { GameDTO game = gameFacade.findById(id); gameFacade.delete(game);// ww w . j a v a2s .c o m log.debug("delete({})", id); redirectAttributes.addFlashAttribute("alert_success", "Game \"" + game.toString() + "\" was deleted."); return "redirect:" + uriBuilder.path("/game/list").toUriString(); }
From source file:com.itn.webservices.AdminControllerWebservice.java
@RequestMapping(value = "/food", method = RequestMethod.POST) public ResponseEntity<Void> createFood(@RequestBody FoodInventory food, UriComponentsBuilder ucBuilder) { logger.info("Creating Food " + food.getFoodName()); if (foodInventoryService.isFoodExist(food)) { logger.info("A Food already exist"); return new ResponseEntity<Void>(HttpStatus.CONFLICT); }// w w w .j a va 2 s .c o m foodInventoryService.save(food); HttpHeaders headers = new HttpHeaders(); headers.setLocation(ucBuilder.path("/food/{id}").buildAndExpand(food.getId()).toUri()); return new ResponseEntity<Void>(headers, HttpStatus.CREATED); }
From source file:cz.muni.pa165.carparkapp.web.AdminController.java
@RequestMapping(value = "/car/delete/{id}", method = RequestMethod.POST) public String deleteCar(@PathVariable int id, RedirectAttributes redirectAttributes, Locale locale, UriComponentsBuilder uriBuilder) { log.debug("delete({})", id); CarDTO car = carService.findCarById(id); carService.deleteCar(car);/*from www . ja v a 2s. c o m*/ redirectAttributes.addFlashAttribute("message", messageSource.getMessage("addCar.delete.mess", new Object[] { car.getRegistrationNumber() }, locale)); return "redirect:" + uriBuilder.path("/admin/car/addCar").build(); }
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); }/* w ww .ja va2 s . c o m*/ _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:com.trafficfine.controller.TrafficFineController.java
/** * // w w w. jav a 2 s . 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:it.scoppelletti.wui.AboutAction.java
@Override public String execute() { String uri;/*from ww w .j av a2 s . com*/ UriComponentsBuilder uriBuilder; ApplicationInfo about; ApplicationInfoResource aboutRes; List<String> applList; List<ApplicationInfo> aboutList; aboutList = new ArrayList<ApplicationInfo>(); applList = myApplMgr.listRunningApplications(); for (String ctxPath : applList) { uriBuilder = UriComponentsBuilder.fromHttpUrl(myApplMgr.getBaseUrl()); uriBuilder.path(ctxPath).path(ApplicationInfoResource.PATH); uriBuilder.queryParam(AbstractServerResource.QUERY_LOCALE, getLocale().toString()); uri = uriBuilder.build().toUriString(); aboutRes = ClientResource.create(uri, ApplicationInfoResource.class); try { about = aboutRes.getApplicationInfo(); } catch (Exception ex) { myLogger.error(String.format("Failed to get %1$s.", uri), ex); about = new SimpleApplicationInfo(ctxPath); } if (about == null) { myLogger.error("Failed to get {}.", uri); about = new SimpleApplicationInfo(ctxPath); } aboutList.add(about); } Collections.sort(aboutList, new ApplicationInfoComparator()); myApplList = aboutList; return Action.SUCCESS; }