Example usage for org.springframework.web.util UriComponents toUriString

List of usage examples for org.springframework.web.util UriComponents toUriString

Introduction

In this page you can find the example usage for org.springframework.web.util UriComponents toUriString.

Prototype

public abstract String toUriString();

Source Link

Document

Concatenate all URI components to return the fully formed URI String.

Usage

From source file:io.lavagna.web.helper.Redirector.java

public static void sendRedirect(HttpServletRequest req, HttpServletResponse resp, String page,
        Map<String, List<String>> params) throws IOException {
    WebApplicationContext ctx = WebApplicationContextUtils.getWebApplicationContext(req.getServletContext());
    String baseApplicationUrl = ctx.getBean(ConfigurationRepository.class).getValue(Key.BASE_APPLICATION_URL);

    UriComponents urlToRedirect = UriComponentsBuilder.fromHttpUrl(baseApplicationUrl).path(page)
            .queryParams(new LinkedMultiValueMap<>(params)).build();

    resp.sendRedirect(urlToRedirect.toUriString());
}

From source file:io.lavagna.web.security.HSTSFilter.java

private static void sendRedirectAbsolute(String baseApplicationUrl, HttpServletResponse resp, String page,
        Map<String, List<String>> params) throws IOException {
    UriComponents urlToRedirect = UriComponentsBuilder.fromHttpUrl(baseApplicationUrl).path(page)
            .queryParams(new LinkedMultiValueMap<>(params)).build();
    resp.sendRedirect(urlToRedirect.toUriString());
}

From source file:com.neiljbrown.brighttalk.channels.reportingapi.client.spring.SpringApiClientImpl.java

/**
 * Builds an absolute HTTP URL from a supplied base URI, a relative path an an optional map of request parameters.
 * <p>/*w  w w.ja  v a  2  s  .c  o m*/
 * Supports building URLs before URL template variables have been expanded - template variable placeholders ({...})
 * will _not_ be encoded.
 * 
 * @param baseUri The {@link URL base URI}.
 * @param relativeUrlPath The relative path to be appended to the base URI.
 * @param requestParams An optional, map representation of request parameters to be appended to the URL. Can be null.
 * @return A String representation of the absolute URL. A return type of String rather than {@link java.net.URI} is
 * used to avoid encoding the URL before any template variables have been replaced.
 */
private static String buildAbsoluteHttpUrl(URI baseUri, String relativeUrlPath,
        Map<String, List<String>> requestParams) {
    UriComponentsBuilder uriBuilder = UriComponentsBuilder.fromUri(baseUri);
    uriBuilder.path(relativeUrlPath);
    if (requestParams != null) {
        for (String paramName : requestParams.keySet()) {
            for (String paramValue : requestParams.get(paramName)) {
                uriBuilder.queryParam(paramName, paramValue);
            }
        }
    }
    UriComponents uriComponents = uriBuilder.build();
    return uriComponents.toUriString();
}

From source file:org.wallride.web.support.Users.java

private String path(UriComponentsBuilder builder, User user, boolean encode) {
    Map<String, Object> params = new HashMap<>();
    builder.path("/author/{code}");
    params.put("code", user.getLoginId());

    UriComponents components = builder.buildAndExpand(params);
    if (encode) {
        components = components.encode();
    }/*from   w ww.  java 2s. c om*/
    return components.toUriString();
}

From source file:cherry.sqlapp.controller.login.LoginControllerImpl.java

@Override
public ModelAndView loginFailed(Locale locale, SitePreference sitePref, HttpServletRequest request,
        RedirectAttributes redirAttr) {/*from ww  w .  j ava 2 s. c om*/

    redirAttr.addFlashAttribute(PathDef.METHOD_LOGIN_FAILED, true);

    UriComponents uc = fromMethodCall(on(LoginController.class).init(locale, sitePref, request)).build();

    ModelAndView mav = new ModelAndView();
    mav.setView(new RedirectView(uc.toUriString(), true));
    return mav;
}

From source file:cherry.sqlapp.controller.login.LoginControllerImpl.java

@Override
public ModelAndView loggedOut(Locale locale, SitePreference sitePref, HttpServletRequest request,
        RedirectAttributes redirAttr) {/*from   w  w w  . ja  v  a  2s.  c  o  m*/

    redirAttr.addFlashAttribute(PathDef.METHOD_LOGGED_OUT, true);

    UriComponents uc = fromMethodCall(on(LoginController.class).init(locale, sitePref, request)).build();

    ModelAndView mav = new ModelAndView();
    mav.setView(new RedirectView(uc.toUriString(), true));
    return mav;
}

From source file:org.wallride.support.PostUtils.java

private String path(UriComponentsBuilder builder, Article article, boolean encode) {
    Map<String, Object> params = new HashMap<>();
    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());

    UriComponents components = builder.buildAndExpand(params);
    if (encode) {
        components = components.encode();
    }/* w w w.j a v  a 2s .  c  o  m*/
    return components.toUriString();
}

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));/*from   www. ja v a2  s.c  o m*/
    }

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

From source file:cherry.sqlapp.controller.sqltool.load.SqltoolLoadControllerImpl.java

@Override
public ModelAndView execute(SqltoolLoadForm form, BindingResult binding, Authentication auth, Locale locale,
        SitePreference sitePref, HttpServletRequest request, RedirectAttributes redirAttr) {

    if (binding.hasErrors()) {
        ModelAndView mav = new ModelAndView(PathDef.VIEW_SQLTOOL_LOAD_INIT);
        return mav;
    }/*from   ww w.  j av a  2  s . c  o m*/

    long asyncId = asyncProcessFacade.launchFileProcess(auth.getName(), "SqltoolLoadController", form.getFile(),
            "execLoadFileProcessHandler", form.getDatabaseName(), form.getSql());

    redirAttr.addFlashAttribute(ASYNC_PARAM, asyncId);

    UriComponents uc = fromMethodCall(on(SqltoolLoadController.class).finish(auth, locale, sitePref, request))
            .build();

    ModelAndView mav = new ModelAndView();
    mav.setView(new RedirectView(uc.toUriString(), true));
    return mav;
}

From source file:cherry.sqlapp.controller.sqltool.load.SqltoolLoadControllerImpl.java

@Override
public ModelAndView create(SqltoolLoadForm form, BindingResult binding, Authentication auth, Locale locale,
        SitePreference sitePref, HttpServletRequest request) {

    if (binding.hasErrors()) {
        ModelAndView mav = new ModelAndView(PathDef.VIEW_SQLTOOL_LOAD_INIT);
        return mav;
    }//from  w  w w  .  j a v a 2  s .co m

    SqltoolLoad record = new SqltoolLoad();
    record.setDatabaseName(form.getDatabaseName());
    record.setQuery(form.getSql());
    record.setLockVersion(form.getLockVersion());

    int id = loadService.create(record, auth.getName());

    UriComponents uc = fromMethodCall(
            on(SqltoolLoadIdController.class).init(id, auth, locale, sitePref, request)).build();

    ModelAndView mav = new ModelAndView();
    mav.setView(new RedirectView(uc.toUriString(), true));
    return mav;
}