Search in sources :

Example 1 with ServletUriComponentsBuilder

use of org.springframework.web.servlet.support.ServletUriComponentsBuilder in project spring-boot by spring-projects.

the class HalBrowserMvcEndpoint method browse.

@RequestMapping(produces = MediaType.TEXT_HTML_VALUE)
public String browse(HttpServletRequest request) {
    ServletUriComponentsBuilder builder = ServletUriComponentsBuilder.fromRequest(request);
    String uriString = builder.build().toUriString();
    return "redirect:" + uriString + (uriString.endsWith("/") ? "" : "/") + this.location.getHtmlFile();
}
Also used : ServletUriComponentsBuilder(org.springframework.web.servlet.support.ServletUriComponentsBuilder) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 2 with ServletUriComponentsBuilder

use of org.springframework.web.servlet.support.ServletUriComponentsBuilder in project spring-security-oauth by spring-projects.

the class OAuth2ClientContextFilter method calculateCurrentUri.

/**
	 * Calculate the current URI given the request.
	 * 
	 * @param request
	 *            The request.
	 * @return The current uri.
	 */
protected String calculateCurrentUri(HttpServletRequest request) throws UnsupportedEncodingException {
    ServletUriComponentsBuilder builder = ServletUriComponentsBuilder.fromRequest(request);
    // Now work around SPR-10172...
    String queryString = request.getQueryString();
    boolean legalSpaces = queryString != null && queryString.contains("+");
    if (legalSpaces) {
        builder.replaceQuery(queryString.replace("+", "%20"));
    }
    UriComponents uri = null;
    try {
        uri = builder.replaceQueryParam("code").build(true);
    } catch (IllegalArgumentException ex) {
        // make sense for redirection purposes anyway.
        return null;
    }
    String query = uri.getQuery();
    if (legalSpaces) {
        query = query.replace("%20", "+");
    }
    return ServletUriComponentsBuilder.fromUri(uri.toUri()).replaceQuery(query).build().toString();
}
Also used : UriComponents(org.springframework.web.util.UriComponents) ServletUriComponentsBuilder(org.springframework.web.servlet.support.ServletUriComponentsBuilder)

Example 3 with ServletUriComponentsBuilder

use of org.springframework.web.servlet.support.ServletUriComponentsBuilder in project spring-framework by spring-projects.

the class UriComponentsBuilderMethodArgumentResolverTests method resolveArgument.

@Test
public void resolveArgument() throws Exception {
    this.servletRequest.setContextPath("/myapp");
    this.servletRequest.setServletPath("/main");
    this.servletRequest.setPathInfo("/accounts");
    Object actual = this.resolver.resolveArgument(this.builderParam, new ModelAndViewContainer(), this.webRequest, null);
    assertNotNull(actual);
    assertEquals(ServletUriComponentsBuilder.class, actual.getClass());
    assertEquals("http://localhost/myapp/main", ((ServletUriComponentsBuilder) actual).build().toUriString());
}
Also used : ServletUriComponentsBuilder(org.springframework.web.servlet.support.ServletUriComponentsBuilder) ModelAndViewContainer(org.springframework.web.method.support.ModelAndViewContainer) Test(org.junit.Test)

Aggregations

ServletUriComponentsBuilder (org.springframework.web.servlet.support.ServletUriComponentsBuilder)3 Test (org.junit.Test)1 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)1 ModelAndViewContainer (org.springframework.web.method.support.ModelAndViewContainer)1 UriComponents (org.springframework.web.util.UriComponents)1