本文整理汇总了Java中org.springframework.web.util.UriTemplate类的典型用法代码示例。如果您正苦于以下问题:Java UriTemplate类的具体用法?Java UriTemplate怎么用?Java UriTemplate使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
UriTemplate类属于org.springframework.web.util包,在下文中一共展示了UriTemplate类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testSimple
import org.springframework.web.util.UriTemplate; //导入依赖的package包/类
@Test
public void testSimple() throws Exception {
final Map<String, Object> body = new HashMap<>();
body.put("foo", "Hello, world!");
body.put("bar", 12345);
body.put("baz", "2017-02-10");
body.put("qux", Collections.emptyList());
final RequestEntity<Map<String, Object>> requestEntity = RequestEntity
.post(new UriTemplate(url).expand(port))
.contentType(MediaType.APPLICATION_JSON)
.accept(MediaType.APPLICATION_JSON)
.body(body);
final ParameterizedTypeReference<Map<String, Object>> responseType = new ParameterizedTypeReference<Map<String, Object>>() {
};
final ResponseEntity<Map<String, Object>> response = restTemplate.exchange(requestEntity,
responseType);
assertThat(response.getBody(), is(body));
}
示例2: uriDataProvider
import org.springframework.web.util.UriTemplate; //导入依赖的package包/类
@DataProvider
Object[][] uriDataProvider() {
return new Object[][] {
{ "/v1/site/123", new UriTemplate("/v1{attribute_uri}"), "/site/123" },
{ "/v1/site/123/asset/345", new UriTemplate("/v1{attribute_uri}/asset/345"), "/site/123" },
{ "/v1/site/123/asset/345", new UriTemplate("/v1{attribute_uri}/asset/{site_id}"), "/site/123" },
{ "/v1/site/123/asset/345", new UriTemplate("/v1/site/123{attribute_uri}"), "/asset/345" },
{ "/v1/site/123/asset/345", new UriTemplate("/v1{attribute_uri}"), "/site/123/asset/345" },
{ "/v1/site/123/asset/345/report", new UriTemplate("/v1{attribute_uri}/report"),
"/site/123/asset/345" },
// template doesnt match uri
{ "/v1/site/123/asset/345/report", new UriTemplate("/v2{attribute_uri}"), null },
// no attribute_uri variable in template
{ "/v1/site/123/asset/345/report", new UriTemplate("/v1{non_existent_variable}"), null },
// multiple attribute_uri variables in template
{ "/v1/site/123/asset/345", new UriTemplate("/v1{attribute_uri}/{attribute_uri}"), "345" }, };
}
示例3: testNest
import org.springframework.web.util.UriTemplate; //导入依赖的package包/类
@Test
public void testNest() throws Exception {
final Map<String, Object> grandchild = new HashMap<>();
grandchild.put("foo", "grandchild");
grandchild.put("bar", 1);
grandchild.put("baz", "2017-02-01");
grandchild.put("qux", Collections.emptyList());
final Map<String, Object> child1 = new HashMap<>();
child1.put("foo", "child1");
child1.put("bar", 2);
child1.put("baz", "2017-02-02");
child1.put("qux", Collections.singletonList(grandchild));
final Map<String, Object> child2 = new HashMap<>();
child2.put("foo", "child2");
child2.put("bar", 3);
child2.put("baz", "2017-02-03");
child2.put("qux", Collections.emptyList());
final Map<String, Object> root = new HashMap<>();
root.put("foo", "root");
root.put("bar", 4);
root.put("baz", "2017-02-04");
root.put("qux", Arrays.asList(child1, child2));
final RequestEntity<Map<String, Object>> requestEntity = RequestEntity
.post(new UriTemplate(url).expand(port))
.contentType(MediaType.APPLICATION_JSON)
.accept(MediaType.APPLICATION_JSON)
.body(root);
final ParameterizedTypeReference<Map<String, Object>> responseType = new ParameterizedTypeReference<Map<String, Object>>() {
};
final ResponseEntity<Map<String, Object>> response = restTemplate.exchange(requestEntity,
responseType);
assertThat(response.getBody(), is(root));
}
示例4: doRequest
import org.springframework.web.util.UriTemplate; //导入依赖的package包/类
private ResponseEntity<Map<String, Object>> doRequest(final Map<String, Object> body) {
final RequestEntity<Map<String, Object>> requestEntity = RequestEntity
.post(new UriTemplate(url).expand(port))
.contentType(MediaType.APPLICATION_JSON)
.accept(MediaType.APPLICATION_JSON)
.body(body);
final ParameterizedTypeReference<Map<String, Object>> responseType = new ParameterizedTypeReference<Map<String, Object>>() {
};
return restTemplate.exchange(requestEntity, responseType);
}
示例5: registerDelegate
import org.springframework.web.util.UriTemplate; //导入依赖的package包/类
@Override
public void registerDelegate(UriTemplate path,
RestDelegate delegate, int priority) {
if (path == null) {
throw new NullPointerException("Argument 'path' is required.");
}
if (delegate == null) {
throw new NullPointerException(
"Argument 'delegate' is required.");
}
logger.debug(
"Registering delegate '{}' for path {} with priority {}.",
delegate, path, priority);
synchronized (mappings) {
mappings.add(new RestDelegateMappingEntry(path, delegate,
priority));
isSorted = false;
}
}
示例6: expand
import org.springframework.web.util.UriTemplate; //导入依赖的package包/类
/**
* Generates an instance of the URI according to the template given by uriTemplate, by expanding the variables
* with the values provided by keyValues.
*
* @param uriTemplate
* The URI template
* @param keyValues
* Dynamic list of string of the form "key:value"
* @return The corresponding URI instance
*/
public static URI expand(final String uriTemplate, final String... keyValues) {
UriTemplate template = new UriTemplate(uriTemplate);
Map<String, String> uriVariables = new HashMap<>();
for (String kv : keyValues) {
String[] keyValue = kv.split(":");
uriVariables.put(keyValue[0], keyValue[1]);
}
return template.expand(uriVariables);
}
示例7: doTestForURITemplateMatch
import org.springframework.web.util.UriTemplate; //导入依赖的package包/类
private void doTestForURITemplateMatch(final String uriTemplate, final String uri,
final Boolean uriTemplateExpectedMatch, final String[] varNames, final String[] varValues) {
UriTemplate template = new UriTemplate(uriTemplate);
Assert.assertEquals(template.matches(uri), uriTemplateExpectedMatch.booleanValue());
Map<String, String> matchedVariables = template.match(uri);
for (int i = 0; i < varNames.length; i++) {
// skip variable match if name is "n/a"
if (varNames[i].equals("n/a")) {
continue;
}
Assert.assertEquals(matchedVariables.get(varNames[i]), varValues[i]);
Assert.assertEquals(matchedVariables.get(varNames[i]), varValues[i]);
}
}
示例8: uriVariablesExpansion
import org.springframework.web.util.UriTemplate; //导入依赖的package包/类
@Test
public void uriVariablesExpansion() throws URISyntaxException {
URI uri = new UriTemplate("http://example.com/{foo}").expand("bar");
RequestEntity.get(uri).accept(MediaType.TEXT_PLAIN).build();
String url = "http://www.{host}.com/{path}";
String host = "example";
String path = "foo/bar";
URI expected = new URI("http://www.example.com/foo/bar");
uri = new UriTemplate(url).expand(host, path);
RequestEntity<?> entity = RequestEntity.get(uri).build();
assertEquals(expected, entity.getUrl());
Map<String, String> uriVariables = new HashMap<>(2);
uriVariables.put("host", host);
uriVariables.put("path", path);
uri = new UriTemplate(url).expand(uriVariables);
entity = RequestEntity.get(uri).build();
assertEquals(expected, entity.getUrl());
}
示例9: getChangelogFor
import org.springframework.web.util.UriTemplate; //导入依赖的package包/类
@Override
@Cacheable("changelogs")
public Changelog getChangelogFor(ModuleIteration moduleIteration) {
Map<String, Object> parameters = newUrlTemplateVariables();
parameters.put("jql", JqlQuery.from(moduleIteration));
parameters.put("fields", "summary,status,resolution,fixVersions");
parameters.put("startAt", 0);
URI searchUri = new UriTemplate(SEARCH_TEMPLATE).expand(parameters);
logger.log(moduleIteration, "Looking up JIRA issues from %s…", searchUri);
JiraIssues issues = operations.getForObject(searchUri, JiraIssues.class);
Tickets tickets = issues.stream().map(this::toTicket).collect(Tickets.toTicketsCollector());
logger.log(moduleIteration, "Created changelog with %s entries.", tickets.getOverallTotal());
return Changelog.of(moduleIteration, tickets);
}
示例10: getAccessToken
import org.springframework.web.util.UriTemplate; //导入依赖的package包/类
public AdmAccessToken getAccessToken(AdmRequestToken requestToken)
{
MultiValueMap<String, String> params = new LinkedMultiValueMap<>(4);
params.add(AdmRequestToken.CLIENT_ID, requestToken.getClientId());
params.add(AdmRequestToken.CLIENT_SECRET, requestToken.getClientSecret());
params.add(AdmRequestToken.GRANT_TYPE, requestToken.getGrantType());
params.add(AdmRequestToken.SCOPE, requestToken.getScope());
URI uri = new UriTemplate(TOKEN_URI).expand();
RequestEntity<MultiValueMap<String, String>> request = RequestEntity.post(uri)//
.contentType(MediaType.APPLICATION_FORM_URLENCODED)//
.body(params);
ResponseEntity<AdmAccessToken> response = restTemplate.exchange(request, AdmAccessToken.class);
return response.getBody();
}
示例11: detectLanguage
import org.springframework.web.util.UriTemplate; //导入依赖的package包/类
/**
* The <code>options</code> parameter when provided, defines the text
* format. Possible values are:
* <ul>
* <li><b>plain</b> - Text without markup (default value).</li>
* <li><b>html</b> - Text in HTML format.</li>
* </ul>
*/
@Override
public String detectLanguage(String text, String... options)
{
LOG.debug("Calling dectectLanguage() with text={}, options={}", text, options);
MultiValueMap<String, String> params = new LinkedMultiValueMap<>(3);
String format = (options.length > 0) ? options[0] : config.getYandex().getOptions().getFormat();
params.add("key", config.getYandex().getApiKey());
params.add("text", text);
params.add("format", format);
URI uri = new UriTemplate(DETECT_URI).expand();
RequestEntity<MultiValueMap<String, String>> request = RequestEntity.post(uri)//
.contentType(MediaType.APPLICATION_FORM_URLENCODED)//
.body(params);
ResponseEntity<DetectedLang> response = restTemplate.exchange(request, DetectedLang.class);
DetectedLang detectedLang = response.getBody();
return detectedLang.getLang();
}
示例12: getSupportedLanguages
import org.springframework.web.util.UriTemplate; //导入依赖的package包/类
/**
* The <code>options</code> parameter when provided, defines the ui language
* used to display supported languages names. Possible values are:
* <ul>
* <li>en - in English</li>
* <li>ru - in Russian</li>
* <li>tr - in Turkish</li>
* <li>uk - in Ukrainian</li>
* </ul>
*/
@Override
public List<String> getSupportedLanguages(String... options)
{
LOG.debug("Calling getSupportedLanguages() with options={}", (Object[]) options);
String ui = (options.length > 0) ? "&ui={ui}" : config.getYandex().getOptions().getUiLang();
URI uri = new UriTemplate(GETLANGS_URI + "?key={key}" + ui).expand(config.getYandex().getApiKey(), options);
RequestEntity<Void> request = RequestEntity.get(uri).build();
ResponseEntity<SupportedLangs> response = restTemplate.exchange(request, SupportedLangs.class);
SupportedLangs supportedLangs = response.getBody();
return new ArrayList<>(supportedLangs.getLangs().keySet());
}
示例13: initialize
import org.springframework.web.util.UriTemplate; //导入依赖的package包/类
/**
* Initializes a new routing instruction.
*
* @param method The HTTP method for the instruction.
* @param uri The URI for the instruction.
* @param target The target for the instruction.
* @param description The description of the instruction.
* @param source The source file of the instruction.
*/
protected void initialize(HTTPMethod method, UriTemplate uri, String target, String description, File source) {
this.method = method;
this.uri = uri;
this.target = target;
java.util.regex.Matcher matcher = SERVICE_PATTERN.matcher(target);
isInvoke = matcher.matches();
if (isInvoke) {
service = NSName.create(target);
}
this.description = description;
this.source = source;
}
示例14: checkParameters
import org.springframework.web.util.UriTemplate; //导入依赖的package包/类
@Test
public void checkParameters() {
Map<String, Object> uriVariables = new HashMap<>();
uriVariables.put("first", "eins");
uriVariables.put("second", "zwei");
uriVariables.put("bar", "baz");
uriVariables.put("thing", "something");
URI uri = new UriTemplate("http://example.org/{first}/path/{second}?foo={bar}&bar={thing}")
.expand(uriVariables);
String uriString = uri.toString();
Assertions.assertThat(uriString).contains("foo=baz");
Assertions.assertThat(uriString).contains("bar=something");
Assertions.assertThat(uriString).contains("eins/path/zwei");
System.out.println(uri.toString());
}
示例15: geoCodeName
import org.springframework.web.util.UriTemplate; //导入依赖的package包/类
private String geoCodeName(double lat, double lng) {
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
throw new IllegalStateException(e);
}
final ResponseEntity<Map> entity = restTemplate.getForEntity(URL, Map.class, lat, lng);
if (entity.getStatusCode().is2xxSuccessful()) {
final Map<?, ?> body = entity.getBody();
final Object addressObj = body.get("address");
if (addressObj instanceof Map) {
final Object roadObj = ((Map) addressObj).get("road");
final Object suburbObj = ((Map) addressObj).get("suburb");
final Object cityObj = ((Map) addressObj).get("city");
return Joiner.on(", ").skipNulls().join(roadObj, suburbObj, cityObj);
}
}
throw new IllegalStateException(String.format("Unable to reverse geocode %s", new UriTemplate(URL).expand(lat, lng)));
}