Example usage for org.springframework.web.servlet.support ServletUriComponentsBuilder fromContextPath

List of usage examples for org.springframework.web.servlet.support ServletUriComponentsBuilder fromContextPath

Introduction

In this page you can find the example usage for org.springframework.web.servlet.support ServletUriComponentsBuilder fromContextPath.

Prototype

public static ServletUriComponentsBuilder fromContextPath(HttpServletRequest request) 

Source Link

Document

Prepare a builder from the host, port, scheme, and context path of the given HttpServletRequest.

Usage

From source file:com.moxian.ng.api.user.SignupController.java

@RequestMapping(value = { "/signup" }, method = RequestMethod.POST)
@ResponseBody//www .j  a v  a  2  s.  co m
public ResponseEntity<Void> signup(@RequestBody @Valid SignupForm form, BindingResult errors,
        HttpServletRequest req) {
    if (log.isDebugEnabled()) {
        log.debug("signup data@" + form);
    }

    if (errors.hasErrors()) {
        throw new InvalidRequestException(errors);
    }

    UserDetails saved = userService.registerUser(form);

    HttpHeaders headers = new HttpHeaders();
    headers.setLocation(ServletUriComponentsBuilder.fromContextPath(req)
            .path(Constants.URI_API_PUBLIC + Constants.URI_USERS + "/{id}").buildAndExpand(saved.getId())
            .toUri());

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

From source file:net.thewaffleshop.passwd.security.AuthenticationHandler.java

/**
 * Successful login; send the redirect URL
 *
 * @param request/*from   ww  w .  java 2  s. c  om*/
 * @param response
 * @param authentication
 * @throws IOException
 * @throws ServletException
 */
@Override
public void onAuthenticationSuccess(HttpServletRequest request, HttpServletResponse response,
        Authentication authentication) throws IOException, ServletException {
    AccountAuthenticationToken auth = (AccountAuthenticationToken) authentication;

    HttpSession session = request.getSession();
    session.setAttribute("account", auth.getAccount());
    session.setAttribute("secretKey", auth.getSecretKey());

    String url = ServletUriComponentsBuilder.fromContextPath(request).path(TARGET_URL).build().toUriString();

    response.setStatus(HttpServletResponse.SC_OK);
    response.setContentType("application/json");
    response.getWriter().write("{\"success\": true, \"url\": \"" + StringEscapeUtils.escapeJson(url) + "\"}");
}

From source file:be.solidx.hot.data.rest.RestDataStore.java

protected UriComponentsBuilder getDatastoreUri(HttpServletRequest httpRequest, String dbname) {
    return ServletUriComponentsBuilder.fromContextPath(httpRequest).path("/data").path("/" + dbname);
}