List of usage examples for org.springframework.web.util UriComponentsBuilder path
@Override
public UriComponentsBuilder path(String path)
From source file:fi.hsl.parkandride.front.OperatorController.java
@RequestMapping(method = POST, value = OPERATORS, produces = APPLICATION_JSON_VALUE) public ResponseEntity<Operator> createOperator(@RequestBody Operator operator, User currentUser, UriComponentsBuilder builder) { log.info("createOperator"); Operator newOperator = operatorService.createOperator(operator, currentUser); log.info("createOperator({})", newOperator.id); HttpHeaders headers = new HttpHeaders(); headers.setLocation(builder.path(OPERATOR).buildAndExpand(newOperator.id).toUri()); return new ResponseEntity<>(newOperator, headers, CREATED); }
From source file:com.salmon.security.xacml.demo.springmvc.rest.controller.MarketPlacePopulatorController.java
@RequestMapping(method = RequestMethod.POST, consumes = "application/json", produces = "application/json", value = "driveradd") @ResponseStatus(HttpStatus.CREATED)//from w w w . j a v a 2s . c o m @ResponseBody public ResponseEntity<Driver> createDriver(@RequestBody Driver driver, UriComponentsBuilder builder) { marketPlaceController.registerDriver(driver); HttpHeaders headers = new HttpHeaders(); URI newDriverLocation = builder.path("/aggregators/dvla/drivers/{license}") .buildAndExpand(driver.getDriversLicense()).toUri(); LOG.info("REST CREATE DRIVER - new driver @ " + newDriverLocation.toString()); headers.setLocation(newDriverLocation); Driver newDriver = marketPlaceController.getDriverDetails(driver.getDriversLicense()); return new ResponseEntity<Driver>(newDriver, headers, HttpStatus.CREATED); }
From source file:web.ClientsRESTController.java
/** * Adds a client to the database through a REST API * @param client//from ww w.j a v a 2 s. c o m * @param ucBuilder * @return */ @RequestMapping(value = "/api/clients/", method = RequestMethod.POST) public ResponseEntity<Void> addClient(@RequestBody Clients client, UriComponentsBuilder ucBuilder) { dao.addClient(client); //returns newly added Client info HttpHeaders headers = new HttpHeaders(); headers.setLocation( ucBuilder.path("/api/clients/clientinfo/{id}").buildAndExpand(client.getClientid()).toUri()); return new ResponseEntity<Void>(headers, HttpStatus.CREATED); }
From source file:org.wallride.web.support.AtomFeedView.java
private String link(Article article) { UriComponentsBuilder builder = ServletUriComponentsBuilder.fromCurrentContextPath(); Map<String, Object> params = new HashMap<>(); Blog blog = blogService.getBlogById(Blog.DEFAULT_ID); if (blog.getLanguages().size() > 1) { builder.path("/{language}"); params.put("language", LocaleContextHolder.getLocale().getLanguage()); }//from w ww .j ava2 s .co m builder.path("/{year}/{month}/{day}/{code}"); params.put("year", String.format("%04d", article.getDate().getYear())); params.put("month", String.format("%02d", article.getDate().getMonth().getValue())); params.put("day", String.format("%02d", article.getDate().getDayOfMonth())); params.put("code", article.getCode()); return builder.buildAndExpand(params).encode().toUriString(); }
From source file:puma.application.webapp.users.AuthenticationController.java
@RequestMapping(value = "/user/login", method = RequestMethod.GET) public RedirectView login(ModelMap model, @RequestParam(value = "RelayState", defaultValue = "") String relayState, @RequestParam(value = "Tenant", defaultValue = "") String tenant, HttpSession session, UriComponentsBuilder builder) { String targetURI = PUMA_AUTHENTICATION_ENDPOINT; // add the RelayState. If none given, use the default. if (relayState.isEmpty()) { relayState = builder.path("/user/login-callback").build().toString(); }/*from w w w .j ava 2 s. com*/ try { relayState = URLEncoder.encode(relayState, "UTF-8"); } catch (UnsupportedEncodingException e) { e.printStackTrace(); } targetURI += "?RelayState=" + relayState; // add the Tenant if given if (!(tenant == null || tenant.isEmpty())) { // TODO get the tenant from the domain if a tenant has a sub-domain? targetURI += "&Tenant=" + tenant; } // model.addAttribute("output", targetURI); // return "test"; return new RedirectView(targetURI); // "redirect:..." would always be relative to the current context path, we do not want that... }
From source file:cz.fi.muni.pa165.presentation.layer.mvc.controllers.GenreController.java
@RequestMapping(value = "/detailAsAdmin/{id}", method = RequestMethod.POST) public String update(@Valid @ModelAttribute("genreDetail") GenreDTO formBean, BindingResult bindingResult, @PathVariable long id, Model model, RedirectAttributes redirectAttributes, UriComponentsBuilder uriComponentsBuilder) { if (bindingResult.hasErrors()) { return "redirect:" + uriComponentsBuilder.path("/genre/detailAsAdmin/{id}").buildAndExpand(id).encode() .toUriString();/* w w w . j a v a 2s . c om*/ } genreFacade.updateTitle(id, formBean.getTitle()); genreFacade.updateYearOfOrigin(id, formBean.getYearOfOrigin()); redirectAttributes.addFlashAttribute("alert_success", "Genre " + formBean.getTitle() + " updated"); return "redirect:" + uriComponentsBuilder.path("/genre/listAsAdmin").buildAndExpand(id).encode().toUriString(); }
From source file:com.minlia.cloud.framework.common.web.controller.AbstractReadOnlyController.java
protected final void findAllRedirectToPagination(final UriComponentsBuilder uriBuilder, final HttpServletResponse response) { final String resourceName = clazz.getSimpleName().toString().toLowerCase(); final String locationValue = uriBuilder.path(WebConstants.PATH_SEP + resourceName).build().encode() .toUriString() + QueryConstants.QUESTIONMARK + "page=0&size=10"; response.setHeader(HttpHeaders.LOCATION, locationValue); }
From source file:am.ik.categolj2.app.authentication.AuthenticationController.java
@RequestMapping(value = "login", method = RequestMethod.POST) String login(@RequestParam("username") String username, @RequestParam("password") String password, UriComponentsBuilder builder, RedirectAttributes attributes, HttpServletRequest request, HttpServletResponse response) throws IOException { logger.info("attempt to login (username={})", username); String tokenEndpoint = builder.path("oauth/token").build().toUriString(); HttpEntity<MultiValueMap<String, Object>> ropRequest = authenticationHelper.createRopRequest(username, password);/*from w w w. ja v a2 s . co m*/ try { ResponseEntity<OAuth2AccessToken> result = restTemplate.postForEntity(tokenEndpoint, ropRequest, OAuth2AccessToken.class); OAuth2AccessToken accessToken = result.getBody(); authenticationHelper.saveAccessTokenInCookie(accessToken, response); authenticationHelper.writeLoginHistory(accessToken, request, response); } catch (HttpStatusCodeException e) { authenticationHelper.handleHttpStatusCodeException(e, attributes); return "redirect:/login"; } catch (ResourceAccessException e) { // I/O error on POST request for "https://xxxx:8080/oauth/token":Unrecognized SSL message, plaintext connection? if (e.getCause() instanceof SSLException) { // fallback to another port UriComponentsBuilder b = builder.replacePath("").port(httpsPort); return login(username, password, b, attributes, request, response); } else { throw e; } } return "redirect:/admin"; }
From source file:de.tobiasbruns.content.storage.ContentController.java
@RequestMapping(method = RequestMethod.POST, consumes = "multipart/form-data") @ResponseStatus(code = HttpStatus.CREATED) public HttpEntity<?> createBinaryContent(HttpServletRequest req, @RequestParam("file") MultipartFile file, UriComponentsBuilder uriBuilder) { String path = service.createContent(getPath(req), buildContent(file)); HttpHeaders headers = new HttpHeaders(); headers.add("Location", uriBuilder.path(path).toUriString()); return new HttpEntity<>(headers); }
From source file:cz.fi.muni.pa165.presentation.layer.mvc.controllers.AlbumController.java
@RequestMapping(value = "/detailAsAdmin/{id}", method = RequestMethod.POST) public String update(@Valid @ModelAttribute("songDetail") AlbumCreateDTO formBean, BindingResult bindingResult, @PathVariable long id, Model model, RedirectAttributes redirectAttributes, UriComponentsBuilder uriComponentsBuilder) { if (bindingResult.hasErrors()) { return "redirect:" + uriComponentsBuilder.path("/album/detailAsAdmin/{id}").buildAndExpand(id).encode() .toUriString();//from ww w. j a va2 s.c om } albumFacade.updateAlbumTitle(id, formBean.getTitle()); albumFacade.updateAlbumMusician(id, formBean.getMusicianId()); SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd"); albumFacade.updateAlbumReleaseDate(id, formBean.getReleaseDate()); albumFacade.updateAlbumCommentary(id, formBean.getCommentary()); redirectAttributes.addFlashAttribute("alert_success", "Album " + formBean.getTitle() + " updated"); return "redirect:" + uriComponentsBuilder.path("/album/listAsAdmin").buildAndExpand(id).encode().toUriString(); }