• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Java Traverson类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Java中org.springframework.hateoas.client.Traverson的典型用法代码示例。如果您正苦于以下问题:Java Traverson类的具体用法?Java Traverson怎么用?Java Traverson使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



Traverson类属于org.springframework.hateoas.client包,在下文中一共展示了Traverson类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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);
}
 
开发者ID:spring-cloud,项目名称:spring-cloud-skipper,代码行数:19,代码来源:DefaultSkipperClient.java


示例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:/";
}
 
开发者ID:spring-projects,项目名称:spring-hateoas-examples,代码行数:24,代码来源:HomeController.java


示例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());
    }
}
 
开发者ID:tuxdevelop,项目名称:spring-data-repositories,代码行数:17,代码来源:CustomerRepositoryDataRestIT.java


示例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());
    }
}
 
开发者ID:tuxdevelop,项目名称:spring-data-repositories,代码行数:23,代码来源:CustomerRepositoryDataRestIT.java


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

}
 
开发者ID:tuxdevelop,项目名称:spring-data-repositories,代码行数:24,代码来源:CustomerRepositoryDataRestIT.java


示例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);
}
 
开发者ID:spring-cloud,项目名称:spring-cloud-skipper,代码行数:12,代码来源:DefaultSkipperClient.java


示例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.");
	}
}
 
开发者ID:spring-cloud,项目名称:spring-cloud-skipper,代码行数:17,代码来源:DefaultSkipperClient.java


示例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);
}
 
开发者ID:spring-cloud,项目名称:spring-cloud-skipper,代码行数:10,代码来源:DefaultSkipperClient.java


示例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);
}
 
开发者ID:spring-cloud,项目名称:spring-cloud-skipper,代码行数:10,代码来源:DefaultSkipperClient.java


示例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);
	}
}
 
开发者ID:spring-cloud,项目名称:spring-cloud-skipper,代码行数:9,代码来源:DefaultSkipperClient.java


示例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));
}
 
开发者ID:Just-Fun,项目名称:spring-data-examples,代码行数:31,代码来源:StarbucksClient.java


示例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";
}
 
开发者ID:spring-projects,项目名称:spring-hateoas-examples,代码行数:25,代码来源:HomeController.java


示例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);
}
 
开发者ID:spencergibb,项目名称:myfeed,代码行数:8,代码来源:TraversonFactory.java


示例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;
}
 
开发者ID:sakaiproject,项目名称:sakai,代码行数:40,代码来源:RubricsServiceImpl.java


示例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);
}
 
开发者ID:spring-cloud,项目名称:spring-cloud-commons,代码行数:8,代码来源:DiscoveredResourceUnitTests.java


示例16: verificationTriggersDiscovery

import org.springframework.hateoas.client.Traverson; //导入依赖的package包/类
@Test
public void verificationTriggersDiscovery() {

	Link link = new Link("target", "rel");

	when(provider.getServiceInstance()).thenReturn(new DefaultServiceInstance("service", "localhost", 8080, false));
	when(builder.asTemplatedLink()).thenReturn(link);

	resource.verifyOrDiscover();

	assertThat(resource.getLink(), is(link));
	verify(provider, times(1)).getServiceInstance();
	verify(traversal, times(1)).buildTraversal(Matchers.any(Traverson.class));
}
 
开发者ID:spring-cloud,项目名称:spring-cloud-commons,代码行数:15,代码来源:DiscoveredResourceUnitTests.java


示例17: resource

import org.springframework.hateoas.client.Traverson; //导入依赖的package包/类
@Bean
public RemoteResource resource() {

	ServiceInstanceProvider provider = new StaticServiceInstanceProvider(
			new DefaultServiceInstance("service", "localhost", 80, false));
	return new DiscoveredResource(provider, new TraversalDefinition() {

		@Override
		public TraversalBuilder buildTraversal(Traverson traverson) {
			return traverson.follow("rel");
		}
	});
}
 
开发者ID:spring-cloud,项目名称:spring-cloud-commons,代码行数:14,代码来源:CloudHypermediaAutoConfigurationIntegrationTests.java


示例18: discoverNamedLink

import org.springframework.hateoas.client.Traverson; //导入依赖的package包/类
public Link discoverNamedLink(URI uri, String... linkNames){
    Traverson traverson = new Traverson(uri, MediaTypes.HAL_JSON);

    Traverson.TraversalBuilder builder = traverson.follow(linkNames);

    return builder.asLink();
}
 
开发者ID:EMBL-EBI-SUBS-OLD,项目名称:subs,代码行数:8,代码来源:ApiLinkDiscovery.java


示例19: discoverLink

import org.springframework.hateoas.client.Traverson; //导入依赖的package包/类
private Link discoverLink() {

		try {

			ServiceInstance service = provider.getServiceInstance();

			if (service == null) {
				return null;
			}

			URI uri = service.getUri();
			String serviceId = service.getServiceId();

			log.debug("Discovered {} system at {}. Discovering resource…", serviceId, uri);

			Traverson traverson = new Traverson(uri, MediaTypes.HAL_JSON);
			Link link = traversal.buildTraversal(traverson).asTemplatedLink();

			log.debug("Found link pointing to {}.", link.getHref());

			return link;

		} catch (RuntimeException o_O) {

			this.link = null;
			log.debug("Target system unavailable. Got: ", o_O.getMessage());

			return null;
		}
	}
 
开发者ID:spring-cloud,项目名称:spring-cloud-commons,代码行数:31,代码来源:DiscoveredResource.java


示例20: buildTraversal

import org.springframework.hateoas.client.Traverson; //导入依赖的package包/类
/**
 * @param traverson the Traverson instance to run the traversal on.
 */
TraversalBuilder buildTraversal(Traverson traverson);
 
开发者ID:spring-cloud,项目名称:spring-cloud-commons,代码行数:5,代码来源:TraversalDefinition.java



注:本文中的org.springframework.hateoas.client.Traverson类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java Map1类代码示例发布时间:2022-05-22
下一篇:
Java SAXParserImpl类代码示例发布时间:2022-05-22
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap