Example usage for org.springframework.web.util UriComponentsBuilder path

List of usage examples for org.springframework.web.util UriComponentsBuilder path

Introduction

In this page you can find the example usage for org.springframework.web.util UriComponentsBuilder path.

Prototype

@Override
public UriComponentsBuilder path(String path) 

Source Link

Document

Append the given path to the existing path of this builder.

Usage

From source file:com.msyla.usergreeter.user.web.UserPreferenceResource.java

@RequestMapping(value = "/{id}", method = RequestMethod.PUT)
public ResponseEntity<UserPreferenceDto> update(@PathVariable Long id,
        @RequestBody @Valid UserPreferenceDto dto, UriComponentsBuilder builder) {

    UserPreferenceDto updatedDto = service.update(id, dto);

    Link link = ControllerLinkBuilder.linkTo(UserPreferenceResource.class).slash(updatedDto.getKey())
            .withSelfRel();/* w ww  .j  a  v a  2 s . co  m*/
    updatedDto.add(link);

    HttpHeaders headers = new HttpHeaders();
    headers.setLocation(builder.path("/api/user/preferences/{id}").buildAndExpand(updatedDto.getKey()).toUri());
    return new ResponseEntity<>(updatedDto, headers, HttpStatus.CREATED);
}

From source file:org.avidj.zuul.rs.Zuul.java

/**
 * Release the given lock if it is held by the given {@code session}.
 * @param session the session id to release the lock for
 * @param request the request/*from   w ww .j  a va 2  s  . c o m*/
 * @param uriBuilder a builder for the response location header URI
 * @return {@code true}, iff the lock was released
 */
@RequestMapping(value = "/s/{id}/**", method = RequestMethod.DELETE)
public ResponseEntity<String> release(@PathVariable("id") String session, HttpServletRequest request,
        UriComponentsBuilder uriBuilder) {
    final List<String> path = getLockPath(request, session);

    final boolean deleted = lm.release(session, path);
    HttpStatus httpStatus = deleted ? HttpStatus.NO_CONTENT : HttpStatus.FORBIDDEN;

    UriComponents uriComponents = uriBuilder.path("/s/{id}/{lockPath}").buildAndExpand(session,
            Strings.join("/", path));
    HttpHeaders headers = new HttpHeaders();
    headers.setLocation(uriComponents.toUri());
    return new ResponseEntity<String>(headers, httpStatus);
}

From source file:cz.muni.fi.mvc.controllers.StewardController.java

/**
 * Shows a list of stewards which are available at given location at given
 * time.//w  ww.j  av a2 s.  c om
 *
 * @param ident id of lacation, for which we want to find stewards
 * @param name available from date
 * @param surname available to date
 * @param model display data
 * @return jsp page
 */
@RequestMapping()
public String list(@RequestParam(value = "ident", required = false) String ident,
        @RequestParam(value = "name", required = false) String name,
        @RequestParam(value = "surname", required = false) String surname,
        @RequestParam(value = "invalid", required = false, defaultValue = "false") boolean invalid, Model model,
        RedirectAttributes redirectAttributes, UriComponentsBuilder uriBuilder) throws IllegalAccessException {

    StringBuilder sb = new StringBuilder("redirect:" + uriBuilder.path("/steward").toUriString());
    sb.append("?");
    if (ident != null) {
        sb.append("ident=" + ident);
        sb.append("&");
    }
    if (name != null && !name.isEmpty()) {
        sb.append("name=" + name);
        sb.append("&");
    }
    if (surname != null && !surname.isEmpty()) {
        sb.append("surname=" + surname);
        sb.append("&");
    }
    sb.append("invalid=true");

    String returnURI = sb.toString();

    if (!invalid) {
        try {
            List<StewardDTO> stewards = stewardFacade.getRelevantStewards(ident, name, surname);
            model.addAttribute("stewards", stewards);
            Map<Long, List<FlightDTO>> stewardsFlights = new HashMap<>();
            for (StewardDTO steward : stewards) {
                stewardsFlights.put(steward.getId(), stewardFacade.getStewardFlights(steward.getId()));
            }
            model.addAttribute("stewardsFlights", stewardsFlights);
        } catch (Exception e) {
            redirectAttributes.addFlashAttribute("alert_danger", "Error while processing request");
            return returnURI;
        }
    }
    try {
        model.addAttribute("destinations", destinationFacade.getAllDestinations());
        return "steward/list";
    } catch (Exception e) {
        redirectAttributes.addFlashAttribute("alert_danger", "Destinations unloadable");
        return returnURI;
    }
}

From source file:net.orpiske.tcs.service.rest.controller.DomainCommandsController.java

@RequestMapping(value = "/{domain}", method = RequestMethod.POST)
@ResponseBody//from w  w  w  . j  a v  a  2 s  .  co m
public ResponseEntity<Domain> createCspTagCloud(@RequestBody final Domain domain,
        UriComponentsBuilder builder) {

    if (logger.isDebugEnabled()) {
        logger.debug("CSP command controller handling a create CSP request for " + domain);
    }

    DomainCreateEvent tagCloudEvent = tagCloudService.createDomain(new RequestCreateDomainEvent(domain));

    Domain domainObj = tagCloudEvent.getDomain();

    HttpHeaders httpHeaders = new HttpHeaders();

    httpHeaders.setLocation(builder.path("/domain/{domain}").buildAndExpand(domainObj.getDomain()).toUri());

    return new ResponseEntity<Domain>(domainObj, httpHeaders, HttpStatus.OK);
}

From source file:com.jee.shiro.rest.TaskRestController.java

@RequestMapping(method = RequestMethod.POST, consumes = "applaction/json")
public ResponseEntity<?> create(@RequestBody Task task, UriComponentsBuilder uriBuilder) {
    // JSR303 Bean Validator, RestExceptionHandler?.
    BeanValidators.validateWithException(validator, task);

    // ?// ww 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.pa165.carparkapp.web.EmployeeController.java

@RequestMapping(value = "/delete/{id}", method = RequestMethod.POST)
public String delete(@PathVariable int id, RedirectAttributes redirectAttributes, Locale locale,
        UriComponentsBuilder uriBuilder) {
    log.debug("delete({})", id);
    EmployeeDTO employee = employeeService.findEmployeeById(id);
    employeeService.deleteEmployee(employee);
    redirectAttributes.addFlashAttribute("message", messageSource.getMessage("addEmployee.delete.mess",
            new Object[] { employee.getFirstName(), employee.getLastName() }, locale));
    return "redirect:" + uriBuilder.path("/serviceEmployee/addEmployee").build();
}

From source file:cn.aozhi.songify.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);

    // ?//ww  w  .  ja  v a  2s .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: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  a2 s .  com
    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:cn.cdwx.jpa.web.account.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 av a 2 s  . c o  m*/
    taskService.saveTask(task);

    // Restful?url, ?id.
    String 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:org.wallride.support.PostUtils.java

private String path(UriComponentsBuilder builder, Page page, boolean encode) {
    Map<String, Object> params = new HashMap<>();

    List<String> codes = new LinkedList<>();
    Map<Page, String> paths = pageUtils.getPaths(page);
    paths.keySet().stream().map(p -> p.getCode()).forEach(codes::add);

    for (int i = 0; i < codes.size(); i++) {
        String key = "code" + i;
        builder.path("/{" + key + "}");
        params.put(key, codes.get(i));/*  www  .  ja v a  2 s  .c o  m*/
    }

    UriComponents components = builder.buildAndExpand(params);
    if (encode) {
        components = components.encode();
    }
    return components.toUriString();
}