Search in sources :

Example 1 with UriTemplate

use of org.springframework.web.util.UriTemplate in project spring-data-document-examples by spring-projects.

the class RestTemplate method execute.

public <T> T execute(String url, HttpMethod method, RequestCallback requestCallback, ResponseExtractor<T> responseExtractor, Map<String, ?> urlVariables) throws RestClientException {
    UriTemplate uriTemplate = new HttpUrlTemplate(url);
    URI expanded = uriTemplate.expand(urlVariables);
    return doExecute(expanded, method, requestCallback, responseExtractor);
}
Also used : UriTemplate(org.springframework.web.util.UriTemplate) URI(java.net.URI)

Example 2 with UriTemplate

use of org.springframework.web.util.UriTemplate in project spring-security-oauth by spring-projects.

the class OAuth2RestTemplateTests method testNonEncodingOfUriTemplate.

/**
	 * tests no double encoding of existing query parameter
	 */
@Test
public void testNonEncodingOfUriTemplate() throws Exception {
    OAuth2AccessToken token = new DefaultOAuth2AccessToken("12345");
    UriTemplate uriTemplate = new UriTemplate("https://graph.facebook.com/fql?q={q}");
    URI expanded = uriTemplate.expand("[q: fql]");
    URI appended = restTemplate.appendQueryParameter(expanded, token);
    assertEquals("https://graph.facebook.com/fql?q=%5Bq:%20fql%5D&bearer_token=12345", appended.toString());
}
Also used : DefaultOAuth2AccessToken(org.springframework.security.oauth2.common.DefaultOAuth2AccessToken) OAuth2AccessToken(org.springframework.security.oauth2.common.OAuth2AccessToken) UriTemplate(org.springframework.web.util.UriTemplate) URI(java.net.URI) DefaultOAuth2AccessToken(org.springframework.security.oauth2.common.DefaultOAuth2AccessToken) Test(org.junit.Test)

Example 3 with UriTemplate

use of org.springframework.web.util.UriTemplate in project spring-security-oauth by spring-projects.

the class ServerRunning method apply.

public Statement apply(final Statement base, FrameworkMethod method, Object target) {
    // Check at the beginning, so this can be used as a static field
    if (assumeOnline) {
        Assume.assumeTrue(serverOnline.get(port));
    } else {
        Assume.assumeTrue(serverOffline.get(port));
    }
    RestTemplate client = new RestTemplate();
    boolean followRedirects = HttpURLConnection.getFollowRedirects();
    HttpURLConnection.setFollowRedirects(false);
    boolean online = false;
    try {
        client.getForEntity(new UriTemplate(getUrl("/sparklr2/login.jsp")).toString(), String.class);
        online = true;
        logger.info("Basic connectivity test passed");
    } catch (RestClientException e) {
        logger.warn(String.format("Not executing tests because basic connectivity test failed for hostName=%s, port=%d", hostName, port), e);
        if (assumeOnline) {
            Assume.assumeNoException(e);
        }
    } finally {
        HttpURLConnection.setFollowRedirects(followRedirects);
        if (online) {
            serverOffline.put(port, false);
            if (!assumeOnline) {
                Assume.assumeTrue(serverOffline.get(port));
            }
        } else {
            serverOnline.put(port, false);
        }
    }
    return new Statement() {

        @Override
        public void evaluate() throws Throwable {
            try {
                postForStatus("/sparklr2/oauth/uncache_approvals", new LinkedMultiValueMap<String, String>());
                base.evaluate();
            } finally {
                postForStatus("/sparklr2/oauth/cache_approvals", new LinkedMultiValueMap<String, String>());
            }
        }
    };
}
Also used : Statement(org.junit.runners.model.Statement) RestTemplate(org.springframework.web.client.RestTemplate) RestClientException(org.springframework.web.client.RestClientException) UriTemplate(org.springframework.web.util.UriTemplate)

Example 4 with UriTemplate

use of org.springframework.web.util.UriTemplate in project spring-security-oauth by spring-projects.

the class ServerRunning method apply.

public Statement apply(final Statement base, FrameworkMethod method, Object target) {
    // Check at the beginning, so this can be used as a static field
    if (assumeOnline) {
        Assume.assumeTrue(serverOnline.get(port));
    } else {
        Assume.assumeTrue(serverOffline.get(port));
    }
    RestTemplate client = new RestTemplate();
    boolean followRedirects = HttpURLConnection.getFollowRedirects();
    HttpURLConnection.setFollowRedirects(false);
    boolean online = false;
    try {
        client.getForEntity(new UriTemplate(getUrl("/sparklr2/login.jsp")).toString(), String.class);
        online = true;
        logger.info("Basic connectivity test passed");
    } catch (RestClientException e) {
        logger.warn(String.format("Not executing tests because basic connectivity test failed for hostName=%s, port=%d", hostName, port), e);
        if (assumeOnline) {
            Assume.assumeNoException(e);
        }
    } finally {
        HttpURLConnection.setFollowRedirects(followRedirects);
        if (online) {
            serverOffline.put(port, false);
            if (!assumeOnline) {
                Assume.assumeTrue(serverOffline.get(port));
            }
        } else {
            serverOnline.put(port, false);
        }
    }
    final RestOperations savedClient = getRestTemplate();
    postForStatus(savedClient, "/sparklr2/oauth/uncache_approvals", new LinkedMultiValueMap<String, String>());
    return new Statement() {

        @Override
        public void evaluate() throws Throwable {
            try {
                base.evaluate();
            } finally {
                postForStatus(savedClient, "/sparklr2/oauth/cache_approvals", new LinkedMultiValueMap<String, String>());
            }
        }
    };
}
Also used : Statement(org.junit.runners.model.Statement) RestTemplate(org.springframework.web.client.RestTemplate) RestClientException(org.springframework.web.client.RestClientException) UriTemplate(org.springframework.web.util.UriTemplate) RestOperations(org.springframework.web.client.RestOperations)

Example 5 with UriTemplate

use of org.springframework.web.util.UriTemplate in project engine by craftercms.

the class RestScriptsController method parseScriptUrlForVariables.

protected String parseScriptUrlForVariables(SiteContext siteContext, String scriptUrl, Map<String, Object> variables) {
    ContentStoreService storeService = siteContext.getStoreService();
    if (!storeService.exists(siteContext.getContext(), scriptUrl) && urlTemplateScanner != null) {
        List<UriTemplate> urlTemplates = urlTemplateScanner.scan(siteContext);
        if (CollectionUtils.isNotEmpty(urlTemplates)) {
            for (UriTemplate template : urlTemplates) {
                if (template.matches(scriptUrl)) {
                    Map<String, String> pathVars = template.match(scriptUrl);
                    String actualScriptUrl = template.toString();
                    variables.put(GroovyScriptUtils.VARIABLE_PATH_VARS, pathVars);
                    return actualScriptUrl;
                }
            }
        }
    }
    return scriptUrl;
}
Also used : ContentStoreService(org.craftercms.core.service.ContentStoreService) UriTemplate(org.springframework.web.util.UriTemplate)

Aggregations

UriTemplate (org.springframework.web.util.UriTemplate)11 URI (java.net.URI)4 ContentStoreService (org.craftercms.core.service.ContentStoreService)2 Test (org.junit.Test)2 Statement (org.junit.runners.model.Statement)2 RestClientException (org.springframework.web.client.RestClientException)2 RestTemplate (org.springframework.web.client.RestTemplate)2 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 Matcher (java.util.regex.Matcher)1 Link (org.apache.geode.management.internal.web.domain.Link)1 Context (org.craftercms.core.service.Context)1 ScriptFactory (org.craftercms.engine.scripting.ScriptFactory)1 SiteContext (org.craftercms.engine.service.context.SiteContext)1 DefaultOAuth2AccessToken (org.springframework.security.oauth2.common.DefaultOAuth2AccessToken)1 OAuth2AccessToken (org.springframework.security.oauth2.common.OAuth2AccessToken)1 RestOperations (org.springframework.web.client.RestOperations)1