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