Java Code Examples for org.springframework.web.util.UriComponentsBuilder

Following code examples demonstrate how to use org.springframework.web.util.UriComponentsBuilder from spring-framework. These examples are extracted from various highly rated open source projects. You can directly use these code snippets or view their entire linked source code. These snippets are extracted to provide contextual information about how to use this class in the real world. These samples also let you understand some good practices on how to use org.springframework.web.util.UriComponentsBuilder and various code implementation of this class.
Example 1
Project : spring-framework Source File : PageParam.java View Source Code on GitHub

   public String getLink(String path) {
	   
	   return UriComponentsBuilder.fromPath(path)
			   .queryParam("bno", this.bno)
			   .queryParam("page", this.page)
			   .toUriString();
   }
			
Example 2
Project : spring-framework Source File : LinkBuilderSupport.java View Source Code on GitHub

	public T slash(Object object) {

		if (object == null) {
			return getThis();
		}

		if (object instanceof Identifiable) {
			return slash((Identifiable<?>) object);
		}

		String path = object.toString();

		if (path.endsWith("#")) {
			path = path.substring(0, path.length() - 1);
		}

		if (!StringUtils.hasText(path)) {
			return getThis();
		}

		String uriString = uriComponents.toUriString();
		UriComponentsBuilder builder = uriString.isEmpty() ? fromUri(uriComponents.toUri())
				: fromUriString(uriString);

		UriComponents components = UriComponentsBuilder.fromUriString(path).build();

		for (String pathSegment : components.getPathSegments()) {
			builder.pathSegment(pathSegment);
		}

		String fragment = components.getFragment();
		if (StringUtils.hasText(fragment)) {
			builder.fragment(fragment);
		}

		return createNewInstance(builder.query(components.getQuery()));
	}
			
Example 3
Project : spring-framework Source File : OAuth2AuthenticationFailureHandler.java View Source Code on GitHub

    public void onAuthenticationFailure(HttpServletRequest request, HttpServletResponse response, AuthenticationException exception) throws IOException, ServletException {
        String targetUrl = CookieUtils.getCookie(request, REDIRECT_URI_PARAM_COOKIE_NAME)
                .map(Cookie::getValue)
                .orElse(("/"));

        targetUrl = UriComponentsBuilder.fromUriString(targetUrl)
                .queryParam("error", exception.getLocalizedMessage())
                .build().toUriString();

        httpCookieOAuth2AuthorizationRequestRepository.removeAuthorizationRequestCookies(request, response);

        getRedirectStrategy().sendRedirect(request, response, targetUrl);
    }
			
Example 4
Project : spring-framework Source File : CurrencyServiceImpl.java View Source Code on GitHub

    public HistoricalResponse getHistorical(LocalDate date) throws CurrencyException {
        UriComponentsBuilder urlBuilder = fromHttpUrl(HISTORICAL_URL)
                .queryParam(PARAM_ACCESS_KEY, properties.getAccessKey())
                .queryParam(PARAM_DATE, date.toString());
        final HistoricalResponse response = restTemplate
                .getForObject(urlBuilder.toUriString(), HistoricalResponse.class);
        if (null == response) {
            throw new CurrencyException("Request failed");
        } else if (null != response.getError()) {
            throw new CurrencyException(response.getError());
        }
        return response;
    }