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();
}
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();
}
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());
}
Aggregations