本文整理汇总了Java中org.springframework.hateoas.mvc.TypeReferences类的典型用法代码示例。如果您正苦于以下问题:Java TypeReferences类的具体用法?Java TypeReferences怎么用?Java TypeReferences使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
TypeReferences类属于org.springframework.hateoas.mvc包,在下文中一共展示了TypeReferences类的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: traversCustomersIT
import org.springframework.hateoas.mvc.TypeReferences; //导入依赖的package包/类
@Test
public void traversCustomersIT() {
//Travers customers
try {
final Traverson traverson = new Traverson(new URI(BASE_URI), MediaTypes.HAL_JSON);
final PagedResources<Resource<Customer>> resources = traverson
.follow("customers")
.toObject(new TypeReferences.PagedResourcesType<Resource<Customer>>() {
});
assertThat(resources.getContent()).isNotNull();
assertThat(resources.getContent().size()).isEqualTo(3);
System.err.println(resources.getContent());
} catch (URISyntaxException e) {
fail(e.getMessage());
}
}
示例2: traversCustomersResourceIT
import org.springframework.hateoas.mvc.TypeReferences; //导入依赖的package包/类
@Test
public void traversCustomersResourceIT() {
//Travers customers
try {
final Traverson traverson = new Traverson(new URI(BASE_URI), MediaTypes.HAL_JSON);
final PagedResources<Resource<Customer>> resources = traverson
.follow("customers")
.toObject(new TypeReferences.PagedResourcesType<Resource<Customer>>() {
});
assertThat(resources.getContent()).isNotNull();
assertThat(resources.getContent().size()).isEqualTo(3);
System.err.println(resources.getMetadata());
for (Resource<Customer> resource : resources) {
final List<Link> links = resource.getLinks();
System.err.println(links);
final Customer customer = resource.getContent();
System.err.println(customer);
}
} catch (URISyntaxException e) {
fail(e.getMessage());
}
}
示例3: traversCustomerFindByFirstNameIT
import org.springframework.hateoas.mvc.TypeReferences; //导入依赖的package包/类
@Test
public void traversCustomerFindByFirstNameIT() {
//travers to findByFirstName
try {
final Map<String, Object> parameters = new HashMap<>();
parameters.put("firstName", "Donnie");
final Traverson traverson = new Traverson(new URI(BASE_URI), MediaTypes.HAL_JSON);
final PagedResources<Resource<Customer>> resources = traverson
.follow("customers", "search", "findByFirstName")
.withTemplateParameters(parameters)
.toObject(new TypeReferences.PagedResourcesType<Resource<Customer>>() {
});
assertThat(resources.getContent()).isNotNull();
assertThat(resources.getContent().size()).isEqualTo(1);
final List<Resource<Customer>> customers = new LinkedList<>(resources.getContent());
final Customer customer = customers.get(0).getContent();
assertThat(customer).isNotNull();
assertThat(customer.getFirstName()).isEqualTo("Donnie");
} catch (URISyntaxException e) {
fail(e.getMessage());
}
}
示例4: getResource
import org.springframework.hateoas.mvc.TypeReferences; //导入依赖的package包/类
@Async
public <T> Future<Resource<T>> getResource(URI url, TypeReferences.ResourceType<T> type) throws
InterruptedException, IOException {
RequestEntity<Void> request = RequestEntity.get(url).accept(HAL_JSON).build();
LOG.debug("Requesting: " + request.toString());
Resource<T> body = restProxyTemplate.getRestTemplate().exchange(request, type).getBody();
LOG.debug("Received: " + body.toString());
return new AsyncResult<>(body);
}
示例5: getDataList
import org.springframework.hateoas.mvc.TypeReferences; //导入依赖的package包/类
@Async
public <T> Future<Resources<T>> getDataList(URI url, TypeReferences.ResourcesType<T> type) throws
InterruptedException, IOException {
RequestEntity<Void> request = RequestEntity.get(url).accept(HAL_JSON).build();
LOG.debug("Requesting: " + request.toString());
Resources<T> body = restProxyTemplate.getRestTemplate().exchange(request, type).getBody();
LOG.debug("Received: " + body.toString());
return new AsyncResult<>(body);
}
示例6: getRubricAssociationResource
import org.springframework.hateoas.mvc.TypeReferences; //导入依赖的package包/类
/**
* Returns the ToolItemRubricAssociation resource for the given tool and associated item ID, wrapped as an Optional.
* @param toolId the tool id, something like "sakai.assignment"
* @param associatedToolItemId the id of the associated element within the tool
* @return
*/
protected Optional<Resource<ToolItemRubricAssociation>> getRubricAssociationResource(String toolId, String associatedToolItemId) throws Exception {
TypeReferences.ResourcesType<Resource<ToolItemRubricAssociation>> resourceParameterizedTypeReference =
new TypeReferences.ResourcesType<Resource<ToolItemRubricAssociation>>() {};
URI apiBaseUrl = new URI(serverConfigurationService.getServerUrl() + RBCS_SERVICE_URL_PREFIX);
Traverson traverson = new Traverson(apiBaseUrl, MediaTypes.HAL_JSON);
Traverson.TraversalBuilder builder = traverson.follow("rubric-associations", "search",
"by-tool-item-ids");
HttpHeaders headers = new HttpHeaders();
headers.add("Authorization", String.format("Bearer %s", generateJsonWebToken(toolId)));
builder.withHeaders(headers);
Map<String, Object> parameters = new HashMap<>();
parameters.put("toolId", toolId);
parameters.put("itemId", associatedToolItemId);
Resources<Resource<ToolItemRubricAssociation>> associationResources = builder.withTemplateParameters(
parameters).toObject(resourceParameterizedTypeReference);
// Should only be one matching this search criterion
if (associationResources.getContent().size() > 1) {
throw new IllegalStateException(String.format(
"Number of rubric association resources greater than one for request: %s",
associationResources.getLink(Link.REL_SELF).toString()));
}
Optional<Resource<ToolItemRubricAssociation>> associationResource = associationResources.getContent().stream().findFirst();
return associationResource;
}