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

Following code examples demonstrate how to use org.springframework.web.util.UriComponentsBuilderfrom 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.UriComponentsBuilderand various code implementation of this class.

	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()) {

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

		return createNewInstance(builder.query(components.getQuery()));

    public UriComponentsBuilder queryParamAround(UriComponentsBuilder builder, String name, Object... values) {
        builder.replaceQueryParam(name, values);
        return builder;

	static RequestEntity<Void> findAll(String apiBase, Pageable pageable) {
		UriComponentsBuilder builder = fromHttpUrl(apiBase).pathSegment("v1", "members");
		return get(withPageable(builder, pageable).build().encode().toUri()).build();

    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;

Builder for UriComponents.

Typical usage involves: Create a UriComponentsBuilder with on

e of the static factory methods (such as #fromPath(String) or #fromUri(URI)) Set the various URI components through the respective methods (#scheme(String), #userInfo(String), #host(String), #port(int), #path(String), #pathSegment(String...), #queryParam(String, Object...), and #fragment(String). Build the UriComponents instance with the #build() method. @author Arjen Poutsma @author Rossen Stoyanchev @author Phillip Webb @author Oliver Gierke @author Brian Clozel @author Sebastien Deleuze @since 3.1 @see #newInstance() @see #fromPath(String) @see #fromUri(URI)

Read More