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:de.otto.mongodb.profiler.web.DatabaseController.java

@RequestMapping(value = "/{name:.+}/control", method = RequestMethod.POST, consumes = MediaType.APPLICATION_FORM_URLENCODED_VALUE, params = "action=remove")
public View removeDatabase(@PathVariable("connectionId") final String connectionId,
        @PathVariable("name") final String databaseName, final UriComponentsBuilder uriComponentsBuilder)
        throws ResourceNotFoundException {

    final ProfiledDatabase database = requireDatabase(connectionId, databaseName);
    getProfilerService().removeDatabase(database);

    final String uri = uriComponentsBuilder.path("/connections/{id}").buildAndExpand(connectionId)
            .toUriString();/*w  ww.j  a  v a2s  .c o  m*/

    return new RedirectView(uri);
}

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) {
    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:fi.hsl.parkandride.front.UserController.java

@RequestMapping(method = POST, value = USERS, produces = APPLICATION_JSON_VALUE)
public ResponseEntity<User> createUser(@RequestBody NewUser newUser, User actor, UriComponentsBuilder builder) {
    log.info("createUser({}, {}, {})", newUser.role, urlEncode(newUser.username), newUser.operatorId);
    User createdUser = userService.createUser(newUser, actor);
    log.info("createUser({})", createdUser.id);

    HttpHeaders headers = new HttpHeaders();
    headers.setLocation(builder.path(USER).buildAndExpand(createdUser.id).toUri());
    return new ResponseEntity<>(createdUser, headers, CREATED);
}

From source file:cz.muni.fi.pa165.mvc.controllers.LoginController.java

@RequestMapping(value = "/logout", method = RequestMethod.POST)
public String logout(HttpServletRequest request, Model model, RedirectAttributes redirectAttributes,
        UriComponentsBuilder uriBuilder) {

    HttpSession session = request.getSession(false);

    if (session.getAttribute("authenticatedUser") != null) {
        session.invalidate();//from w  w  w. j  a  va  2  s . c  o m
    }
    redirectAttributes.addFlashAttribute("alert_success", "You were successfully logouted");
    return "redirect:" + uriBuilder.path("/").toUriString();
}

From source file:com.salmon.security.xacml.demo.springmvc.rest.controller.MarketPlacePopulatorController.java

@RequestMapping(method = RequestMethod.POST, consumes = "application/json", produces = "application/json", value = "vehicleadd")
@ResponseStatus(HttpStatus.CREATED)/*from w  ww .  j  ava  2 s  .  c  om*/
@ResponseBody
public ResponseEntity<Vehicle> createVehicle(@RequestBody Vehicle vehicle, UriComponentsBuilder builder) {

    LOG.info("REST CREATE Vechicle - " + vehicle.toString());

    marketPlaceController.registerVehicle(vehicle);

    HttpHeaders headers = new HttpHeaders();

    URI newVehicleLocation = builder.path("/aggregators/dvla/vehicles/{plate}")
            .buildAndExpand(vehicle.getPlate()).toUri();

    LOG.info("REST CREATE VEHICLE - new vehicle @ " + newVehicleLocation.toString());

    headers.setLocation(newVehicleLocation);

    return new ResponseEntity<Vehicle>(vehicle, headers, HttpStatus.CREATED);
}

From source file:cz.muni.fi.pa165.mvc.controllers.LoginController.java

@RequestMapping(value = "/trylogin", method = RequestMethod.POST)
public String trylogin(HttpServletRequest request, @Valid @ModelAttribute("userDTO") UserCreateDTO formBean,
        BindingResult bindingResult, Model model, RedirectAttributes redirectAttributes,
        UriComponentsBuilder uriBuilder) {
    UserDTO matchingUser = userFacade.findUserByEmail(formBean.getEmail());
    if (matchingUser == null) {
        redirectAttributes.addFlashAttribute("alert_danger",
                "Wrong parameters, email or password doesn`t match");
        return "redirect:" + uriBuilder.path("/user/login").toUriString();
    }//w  ww  .ja v  a  2  s . c o  m
    UserAuthenticateDTO userAuthenticateDTO = new UserAuthenticateDTO();
    userAuthenticateDTO.setUserId(matchingUser.getId());
    userAuthenticateDTO.setPassword(formBean.getPassword());

    if (!userFacade.isAdmin(matchingUser)) {
        redirectAttributes.addFlashAttribute("alert_danger",
                "Wrong parameters, email or password doesn`t match");
        return "redirect:" + uriBuilder.path("/user/login").toUriString();
    }
    if (!userFacade.authenticate(userAuthenticateDTO)) {
        redirectAttributes.addFlashAttribute("alert_danger",
                "Wrong parameters, email or password doesn`t match");
        return "redirect:" + uriBuilder.path("/user/login").toUriString();
    }
    log.trace("user", matchingUser);
    request.getSession().setAttribute("authenticatedUser", matchingUser);
    return "redirect:" + uriBuilder.path("/").toUriString();

}

From source file:de.otto.mongodb.profiler.web.ConnectionController.java

@RequestMapping(value = "/{id:.+}/destroy", method = RequestMethod.POST)
public View closeConnection(final @PathVariable("id") String connectionId,
        final UriComponentsBuilder uriComponentsBuilder) throws ResourceNotFoundException {

    final ProfiledConnection connection = requireConnection(connectionId);

    getProfilerService().destroyConnection(connection);

    final String uri = uriComponentsBuilder.path("/connections").build().toUriString();

    return new RedirectView(uri);
}

From source file:com.cloud.baremetal.networkservice.Force10BaremetalSwitchBackend.java

private String buildLink(String switchIp, String path) {
    UriComponentsBuilder builder = UriComponentsBuilder.newInstance();
    builder.scheme("http");
    builder.host(switchIp);//  w  ww  . j a  v  a 2 s . com
    builder.port(8008);
    builder.path(path);
    return builder.build().toUriString();
}

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

@RequestMapping(method = RequestMethod.POST, consumes = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<UserPreferenceDto> create(
        @NotNull(message = "{userPreference.null}") @Valid @RequestBody UserPreferenceDto dto,
        UriComponentsBuilder builder) {
    UserPreferenceDto savedDto = service.create(dto);

    Link link = ControllerLinkBuilder.linkTo(UserPreferenceResource.class).slash(savedDto.getKey())
            .withSelfRel();//from w  w  w  .  j  av  a  2  s.  c o m
    savedDto.add(link);

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

From source file:de.tobiasbruns.content.storage.ContentController.java

@RequestMapping(method = RequestMethod.POST)
@ResponseStatus(code = HttpStatus.CREATED)
public HttpEntity<?> createJsonContent(HttpServletRequest req,
        @RequestBody Content<Map<String, Object>> content, UriComponentsBuilder uriBuilder) {
    setContentTypeIfEmpty(content, "application/json");
    String newPath = service.createContent(getPath(req), content);

    HttpHeaders headers = new HttpHeaders();
    headers.add("Location", uriBuilder.path(newPath).toUriString());
    return new HttpEntity<>(headers);
}