Search in sources :

Example 96 with UriComponentsBuilder

use of org.springframework.web.util.UriComponentsBuilder in project java-chassis by ServiceComb.

the class CseUriTemplateHandler method expandInternal.

@Override
protected URI expandInternal(String uriTemplate, Map<String, ?> uriVariables) {
    UriComponentsBuilder uriComponentsBuilder = initUriComponentsBuilder(uriTemplate);
    UriComponents uriComponents = expandAndEncode(uriComponentsBuilder, uriVariables);
    return createUri(uriTemplate, uriComponents);
}
Also used : UriComponents(org.springframework.web.util.UriComponents) UriComponentsBuilder(org.springframework.web.util.UriComponentsBuilder)

Example 97 with UriComponentsBuilder

use of org.springframework.web.util.UriComponentsBuilder in project java-chassis by ServiceComb.

the class CseUriTemplateHandler method fromUriString.

private static UriComponentsBuilder fromUriString(String uri) {
    Assert.notNull(uri, "URI must not be null");
    Matcher matcher = URI_PATTERN.matcher(uri);
    if (matcher.matches()) {
        UriComponentsBuilder builder = UriComponentsBuilder.newInstance();
        String scheme = matcher.group(2);
        String userInfo = matcher.group(5);
        String host = matcher.group(6);
        String port = matcher.group(8);
        String path = matcher.group(9);
        String query = matcher.group(11);
        String fragment = matcher.group(13);
        boolean opaque = false;
        if (StringUtils.hasLength(scheme)) {
            String rest = uri.substring(scheme.length());
            if (!rest.startsWith(":/")) {
                opaque = true;
            }
        }
        builder.scheme(scheme);
        if (opaque) {
            String ssp = uri.substring(scheme.length()).substring(1);
            if (StringUtils.hasLength(fragment)) {
                ssp = ssp.substring(0, ssp.length() - (fragment.length() + 1));
            }
            builder.schemeSpecificPart(ssp);
        } else {
            builder.userInfo(userInfo);
            builder.host(host);
            if (StringUtils.hasLength(port)) {
                builder.port(port);
            }
            builder.path(path);
            builder.query(query);
        }
        if (StringUtils.hasText(fragment)) {
            builder.fragment(fragment);
        }
        return builder;
    } else {
        throw new IllegalArgumentException("[" + uri + "] is not a valid URI");
    }
}
Also used : Matcher(java.util.regex.Matcher) UriComponentsBuilder(org.springframework.web.util.UriComponentsBuilder)

Example 98 with UriComponentsBuilder

use of org.springframework.web.util.UriComponentsBuilder in project java-chassis by ServiceComb.

the class CseUriTemplateHandler method initUriComponentsBuilder.

@Override
protected UriComponentsBuilder initUriComponentsBuilder(String uriTemplate) {
    UriComponentsBuilder builder = fromUriString(uriTemplate);
    if (shouldParsePath() && !isStrictEncoding()) {
        List<String> pathSegments = builder.build().getPathSegments();
        builder.replacePath(null);
        for (String pathSegment : pathSegments) {
            builder.pathSegment(pathSegment);
        }
    }
    return builder;
}
Also used : UriComponentsBuilder(org.springframework.web.util.UriComponentsBuilder)

Example 99 with UriComponentsBuilder

use of org.springframework.web.util.UriComponentsBuilder in project java-chassis by ServiceComb.

the class CseUriTemplateHandler method expandInternal.

@Override
protected URI expandInternal(String uriTemplate, Object... uriVariables) {
    UriComponentsBuilder uriComponentsBuilder = initUriComponentsBuilder(uriTemplate);
    UriComponents uriComponents = expandAndEncode(uriComponentsBuilder, uriVariables);
    return createUri(uriTemplate, uriComponents);
}
Also used : UriComponents(org.springframework.web.util.UriComponents) UriComponentsBuilder(org.springframework.web.util.UriComponentsBuilder)

Example 100 with UriComponentsBuilder

use of org.springframework.web.util.UriComponentsBuilder in project cf-java-client by cloudfoundry.

the class FilterBuilderTest method test.

@Test
public void test() {
    UriComponentsBuilder builder = UriComponentsBuilder.newInstance();
    FilterBuilder.augment(builder, new StubFilterParamsSubClass());
    MultiValueMap<String, String> queryParams = builder.build().encode().getQueryParams();
    List<String> q = queryParams.get("q");
    assertThat(q).hasSize(8).containsOnly("test-greater-than%3Etest-value-1", "test-greater-than-or-equal-to%3E%3Dtest-value-2", "test-in%20IN%20test-value-3,test-value-4", "test-is:test-value-5", "test-less-than%3Ctest-value-6", "test-less-than-or-equal-to%3C%3Dtest-value-7", "test-default%20IN%20test-value-8,test-value-9", "test-override:test-value-10");
}
Also used : UriComponentsBuilder(org.springframework.web.util.UriComponentsBuilder) Test(org.junit.Test)

Aggregations

UriComponentsBuilder (org.springframework.web.util.UriComponentsBuilder)131 Test (org.junit.Test)34 UriComponents (org.springframework.web.util.UriComponents)23 ServletUriComponentsBuilder (org.springframework.web.servlet.support.ServletUriComponentsBuilder)12 URI (java.net.URI)9 Test (org.junit.jupiter.api.Test)9 SearchRequest (org.nzbhydra.searching.searchrequests.SearchRequest)8 MvcUriComponentsBuilder (org.springframework.web.servlet.mvc.method.annotation.MvcUriComponentsBuilder)8 ArrayList (java.util.ArrayList)7 LinkedMultiValueMap (org.springframework.util.LinkedMultiValueMap)7 List (java.util.List)6 User (com.serotonin.m2m2.vo.User)5 RestProcessResult (com.serotonin.m2m2.web.mvc.rest.v1.message.RestProcessResult)5 ApiOperation (com.wordnik.swagger.annotations.ApiOperation)5 HashMap (java.util.HashMap)5 HttpEntity (org.springframework.http.HttpEntity)5 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)5 HttpClientErrorException (org.springframework.web.client.HttpClientErrorException)5 IOException (java.io.IOException)4 Map (java.util.Map)4