本文整理汇总了Java中org.springframework.hateoas.client.Traverson类的典型用法代码示例。如果您正苦于以下问题:Java Traverson类的具体用法?Java Traverson怎么用?Java Traverson使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Traverson类属于org.springframework.hateoas.client包,在下文中一共展示了Traverson类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: search
import org.springframework.hateoas.client.Traverson; //导入依赖的package包/类
@Override
public Resources<PackageMetadata> search(String name, boolean details) {
ParameterizedTypeReference<Resources<PackageMetadata>> typeReference =
new ParameterizedTypeReference<Resources<PackageMetadata>>() { };
Traverson.TraversalBuilder traversalBuilder = this.traverson.follow("packageMetadata");
Map<String, Object> parameters = new HashMap<>();
parameters.put("size", 2000);
if (StringUtils.hasText(name)) {
parameters.put("name", name);
traversalBuilder.follow("search", "findByNameContainingIgnoreCase");
}
if (!details) {
parameters.put("projection", "summary");
parameters.put("sort", "name,asc");
// TODO semver sort..
}
return traversalBuilder.withTemplateParameters(parameters).toObject(typeReference);
}
示例2: newEmployee
import org.springframework.hateoas.client.Traverson; //导入依赖的package包/类
/**
* Instead of putting the creation link from the remote service in the template (a security concern),
* have a local route for {@literal POST} requests. Gather up the information, and form a remote call,
* using {@link Traverson} to fetch the {@literal employees} {@link Link}.
*
* Once a new employee is created, redirect back to the root URL.
*
* @param employee
* @return
* @throws URISyntaxException
*/
@PostMapping("/employees")
public String newEmployee(@ModelAttribute Employee employee) throws URISyntaxException {
Traverson client = new Traverson(new URI(REMOTE_SERVICE_ROOT_URI), MediaTypes.HAL_JSON);
Link employeesLink = client
.follow("employees")
.asLink();
this.rest.postForEntity(employeesLink.expand().getHref(), employee, Employee.class);
return "redirect:/";
}
示例3: traversCustomersIT
import org.springframework.hateoas.client.Traverson; //导入依赖的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());
}
}
示例4: traversCustomersResourceIT
import org.springframework.hateoas.client.Traverson; //导入依赖的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());
}
}
示例5: traversCustomerFindByFirstNameIT
import org.springframework.hateoas.client.Traverson; //导入依赖的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());
}
}
示例6: history
import org.springframework.hateoas.client.Traverson; //导入依赖的package包/类
@Override
public Resources<Release> history(String releaseName) {
ParameterizedTypeReference<Resources<Release>> typeReference =
new ParameterizedTypeReference<Resources<Release>>() { };
Map<String, Object> parameters = new HashMap<>();
parameters.put("name", releaseName);
Traverson.TraversalBuilder traversalBuilder = this.traverson.follow("releases", "search",
"findByNameIgnoreCaseContainingOrderByNameAscVersionDesc");
return traversalBuilder.withTemplateParameters(parameters).toObject(typeReference);
}
示例7: deleteRepository
import org.springframework.hateoas.client.Traverson; //导入依赖的package包/类
@Override
public void deleteRepository(String name) {
ParameterizedTypeReference<Resource<Repository>> typeReference = new ParameterizedTypeReference<Resource<Repository>>() {
};
Traverson.TraversalBuilder traversalBuilder = this.traverson.follow("repositories", "search", "findByName");
Map<String, Object> parameters = new HashMap<>();
parameters.put("name", name);
Resource<Repository> repositoryResource = traversalBuilder.withTemplateParameters(parameters)
.toObject(typeReference);
if (repositoryResource != null) {
this.restTemplate.delete(repositoryResource.getId().getHref());
}
else {
throw new IllegalStateException("The Repository with the " + name + " doesn't exist.");
}
}
示例8: listRepositories
import org.springframework.hateoas.client.Traverson; //导入依赖的package包/类
@Override
public Resources<Repository> listRepositories() {
ParameterizedTypeReference<Resources<Repository>> typeReference = new ParameterizedTypeReference<Resources<Repository>>() {
};
Traverson.TraversalBuilder traversalBuilder = this.traverson.follow("repositories");
Map<String, Object> parameters = new HashMap<>();
parameters.put("size", 2000);
return traversalBuilder.withTemplateParameters(parameters).toObject(typeReference);
}
示例9: listDeployers
import org.springframework.hateoas.client.Traverson; //导入依赖的package包/类
@Override
public Resources<Deployer> listDeployers() {
ParameterizedTypeReference<Resources<Deployer>> typeReference = new ParameterizedTypeReference<Resources<Deployer>>() {
};
Traverson.TraversalBuilder traversalBuilder = this.traverson.follow("deployers");
Map<String, Object> parameters = new HashMap<>();
parameters.put("size", 2000);
return traversalBuilder.withTemplateParameters(parameters).toObject(typeReference);
}
示例10: createTraverson
import org.springframework.hateoas.client.Traverson; //导入依赖的package包/类
protected Traverson createTraverson(String baseUrl, RestOperations restOperations) {
try {
return new Traverson(new URI(baseUrl), MediaTypes.HAL_JSON).setRestOperations(restOperations);
}
catch (URISyntaxException e) {
throw new IllegalStateException("Bad URI syntax: " + baseUrl);
}
}
示例11: discoverStoreSearch
import org.springframework.hateoas.client.Traverson; //导入依赖的package包/类
@Test
public void discoverStoreSearch() {
Traverson traverson = new Traverson(URI.create(String.format(SERVICE_URI, port)), MediaTypes.HAL_JSON);
// Set up path traversal
TraversalBuilder builder = traverson. //
follow("stores", "search", "by-location");
// Log discovered
log.info("");
log.info("Discovered link: {}", builder.asTemplatedLink());
log.info("");
Map<String, Object> parameters = new HashMap<>();
parameters.put("location", "40.740337,-73.995146");
parameters.put("distance", "0.5miles");
PagedResources<Resource<Store>> resources = builder.//
withTemplateParameters(parameters).//
toObject(new PagedResourcesType<Resource<Store>>() {});
PageMetadata metadata = resources.getMetadata();
log.info("Got {} of {} stores: ", resources.getContent().size(), metadata.getTotalElements());
StreamSupport.stream(resources.spliterator(), false).//
map(Resource::getContent).//
forEach(store -> log.info("{} - {}", store.name, store.address));
}
示例12: index
import org.springframework.hateoas.client.Traverson; //导入依赖的package包/类
/**
* Get a listing of ALL {@link Employee}s by querying the remote services' root URI, and then
* "hopping" to the {@literal employees} rel.
*
* NOTE: Also create a form-backed {@link Employee} object to allow creating a new entry with
* the Thymeleaf template.
*
* @param model
* @return
* @throws URISyntaxException
*/
@GetMapping
public String index(Model model) throws URISyntaxException {
Traverson client = new Traverson(new URI(REMOTE_SERVICE_ROOT_URI), MediaTypes.HAL_JSON);
Resources<Resource<Employee>> employees = client
.follow("employees")
.toObject(new ResourcesType<Resource<Employee>>(){});
model.addAttribute("employee", new Employee());
model.addAttribute("employees", employees);
return "index";
}
示例13: create
import org.springframework.hateoas.client.Traverson; //导入依赖的package包/类
public Traverson create(String serviceId) {
ServiceInstance instance = loadBalancerClient.choose(serviceId);
if (instance == null) {
throw new IllegalStateException("No instances for service: "+serviceId);
}
return new Traverson(instance.getUri(), MediaTypes.HAL_JSON);
}
示例14: getRubricAssociationResource
import org.springframework.hateoas.client.Traverson; //导入依赖的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;
}
示例15: setUp
import org.springframework.hateoas.client.Traverson; //导入依赖的package包/类
@Before
public void setUp() {
when(traversal.buildTraversal(Matchers.any(Traverson.class))).thenReturn(builder);
this.resource = new DiscoveredResource(provider, traversal);
this.resource.setRestOperations(operations);
}