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

Java Links类代码示例

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

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



Links类属于org.springframework.hateoas包,在下文中一共展示了Links类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: accessServiceUsingRestTemplate

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

	// Access root resource

	URI uri = URI.create(String.format(SERVICE_URI, port));
	RequestEntity<Void> request = RequestEntity.get(uri).accept(HAL_JSON).build();
	Resource<Object> rootLinks = restOperations.exchange(request, new ResourceType<Object>() {}).getBody();
	Links links = new Links(rootLinks.getLinks());

	// Follow stores link

	Link storesLink = links.getLink("stores").expand();
	request = RequestEntity.get(URI.create(storesLink.getHref())).accept(HAL_JSON).build();
	Resources<Store> stores = restOperations.exchange(request, new ResourcesType<Store>() {}).getBody();

	stores.getContent().forEach(store -> log.info("{} - {}", store.name, store.address));
}
 
开发者ID:Just-Fun,项目名称:spring-data-examples,代码行数:19,代码来源:StarbucksClient.java


示例2: resolveType

import org.springframework.hateoas.Links; //导入依赖的package包/类
@Override
public Class<?> resolveType(Class<?> declaredType, Links resourceLinks, Configuration configuration) {
	
	ResourceTypeInfo info = AnnotationUtils.findAnnotation(declaredType, ResourceTypeInfo.class);
	
	if (info == null) {
		return declaredType;
	}
	
	boolean customTypeResolverIsSpecified = info.typeResolver() != ResourceTypeInfo.NullTypeResolver.class;
	
	Assert.state(info.subtypes().length > 0 ^ customTypeResolverIsSpecified,
		"one of subtypes or typeResolver must be specified");
	
	TypeResolver delegateTypeResolver = customTypeResolverIsSpecified
		? BeanUtils.instantiate(info.typeResolver())
		: new SelfLinkTypeResolver(info.subtypes());
	
	return delegateTypeResolver.resolveType(declaredType, resourceLinks, configuration);
}
 
开发者ID:BlackPepperSoftware,项目名称:bowman,代码行数:21,代码来源:DefaultTypeResolver.java


示例3: resolveType

import org.springframework.hateoas.Links; //导入依赖的package包/类
@Override
public Class<?> resolveType(Class<?> declaredType, Links resourceLinks, Configuration configuration) {

	Link self = resourceLinks.getLink(Link.REL_SELF);
	
	if (self == null) {
		return declaredType;
	}

	for (Class<?> candidateClass : subtypes) {
		RemoteResource candidateClassInfo = AnnotationUtils.findAnnotation(candidateClass, RemoteResource.class);
		
		if (candidateClassInfo == null) {
			continue;
		}
		
		String resourcePath = candidateClassInfo.value();
		
		String resourceBaseUriString = UriComponentsBuilder.fromUri(configuration.getBaseUri())
			.path(resourcePath)
			.toUriString();
		
		String selfLinkUriString = toAbsoluteUriString(self.getHref(), configuration.getBaseUri());
		
		if (selfLinkUriString.startsWith(resourceBaseUriString + "/")) {
			return candidateClass;
		}
	}
	
	return declaredType;
}
 
开发者ID:BlackPepperSoftware,项目名称:bowman,代码行数:32,代码来源:SelfLinkTypeResolver.java


示例4: deserialize

import org.springframework.hateoas.Links; //导入依赖的package包/类
@Override
public Resource<?> deserialize(JsonParser p, DeserializationContext ctxt) throws IOException,
	JsonProcessingException {

	ObjectNode node = p.readValueAs(ObjectNode.class);

	ObjectMapper mapper = (ObjectMapper) p.getCodec();

	ResourceSupport resource = mapper.convertValue(node, ResourceSupport.class);
	Links links = new Links(resource.getLinks());
	
	Class<?> resourceContentType = typeResolver.resolveType(handledType(), links, configuration);
	return createResource(resourceContentType, node, links, mapper);
}
 
开发者ID:BlackPepperSoftware,项目名称:bowman,代码行数:15,代码来源:ResourceDeserializer.java


示例5: resolveTypeWithNoResourceTypeInfoReturnsDeclaredType

import org.springframework.hateoas.Links; //导入依赖的package包/类
@Test
public void resolveTypeWithNoResourceTypeInfoReturnsDeclaredType() {
	Class<?> type = resolver.resolveType(TypeWithoutInfo.class,
		new Links(new Link("http://x", Link.REL_SELF)), Configuration.build());
	
	assertThat(type, Matchers.<Class<?>>equalTo(TypeWithoutInfo.class));
}
 
开发者ID:BlackPepperSoftware,项目名称:bowman,代码行数:8,代码来源:DefaultTypeResolverTest.java


示例6: resolveTypeWithSubtypesAndNoMatchingSubtypeReturnsDeclaredType

import org.springframework.hateoas.Links; //导入依赖的package包/类
@Test
public void resolveTypeWithSubtypesAndNoMatchingSubtypeReturnsDeclaredType() {
	Class<?> type = resolver.resolveType(TypeWithSubtypes.class,
		new Links(new Link("http://x", Link.REL_SELF)), Configuration.build());
	
	assertThat(type, Matchers.<Class<?>>equalTo(TypeWithSubtypes.class));
}
 
开发者ID:BlackPepperSoftware,项目名称:bowman,代码行数:8,代码来源:DefaultTypeResolverTest.java


示例7: resolveTypeWithSubtypesAndMatchingAbsoluteUriSubtypeReturnsSubtype

import org.springframework.hateoas.Links; //导入依赖的package包/类
@Test
public void resolveTypeWithSubtypesAndMatchingAbsoluteUriSubtypeReturnsSubtype() {
	Configuration config = Configuration.builder().setBaseUri("http://x.com").build();
	
	Class<?> type = resolver.resolveType(TypeWithSubtypes.class,
		new Links(new Link("http://x.com/2/1", Link.REL_SELF)), config);
	
	assertThat(type, Matchers.<Class<?>>equalTo(TypeWithSubtypesSubtype2.class));
}
 
开发者ID:BlackPepperSoftware,项目名称:bowman,代码行数:10,代码来源:DefaultTypeResolverTest.java


示例8: resolveTypeWithSubtypesAndMatchingAbsolutePathReferenceUriSubtypeReturnsSubtype

import org.springframework.hateoas.Links; //导入依赖的package包/类
@Test
public void resolveTypeWithSubtypesAndMatchingAbsolutePathReferenceUriSubtypeReturnsSubtype() {
	Configuration config = Configuration.builder().setBaseUri("http://x.com").build();
	
	Class<?> type = resolver.resolveType(TypeWithSubtypes.class,
		new Links(new Link("/2/1", Link.REL_SELF)), config);
	
	assertThat(type, Matchers.<Class<?>>equalTo(TypeWithSubtypesSubtype2.class));
}
 
开发者ID:BlackPepperSoftware,项目名称:bowman,代码行数:10,代码来源:DefaultTypeResolverTest.java


示例9: resolveTypeWithResolverReturnsResolvedType

import org.springframework.hateoas.Links; //导入依赖的package包/类
@Test
public void resolveTypeWithResolverReturnsResolvedType() {
	Links links = new Links(new Link("_"));
	Configuration config = Configuration.build();
	
	doReturn(TypeWithResolverSubtype.class)
		.when(Resolver.mockResolver).resolveType(TypeWithResolver.class, links, config);
	
	Class<?> type = resolver.resolveType(TypeWithResolver.class, links, config);
	
	assertThat(type, Matchers.<Class<?>>equalTo(TypeWithResolverSubtype.class));
}
 
开发者ID:BlackPepperSoftware,项目名称:bowman,代码行数:13,代码来源:DefaultTypeResolverTest.java


示例10: declaredTypeResourceDeserializer

import org.springframework.hateoas.Links; //导入依赖的package包/类
private static ResourceDeserializer declaredTypeResourceDeserializer() {
	TypeResolver declaredTypeTypeResolver = mock(TypeResolver.class);
	
	when(declaredTypeTypeResolver.resolveType(any(Class.class), any(Links.class), any(Configuration.class)))
		.then(new Answer<Class<?>>() {
		
			@Override
			public Class<?> answer(InvocationOnMock invocation) throws Throwable {
				return invocation.getArgumentAt(0, Class.class);
			}
		});
	
	return new ResourceDeserializer(Object.class, declaredTypeTypeResolver, Configuration.build());
}
 
开发者ID:BlackPepperSoftware,项目名称:bowman,代码行数:15,代码来源:RestOperationsTest.java


示例11: deserializeReturnsObjectOfResolvedType

import org.springframework.hateoas.Links; //导入依赖的package包/类
@Test
public void deserializeReturnsObjectOfResolvedType() throws Exception {
	doReturn(ResolvedType.class).when(typeResolver).resolveType(DeclaredType.class,
		new Links(new Link("http://x.com/1", Link.REL_SELF)), configuration);
	
	Resource<DeclaredType> resource = mapper.readValue(
		"{\"field\":\"x\",\"_links\":{\"self\":{\"href\":\"http://x.com/1\"}}}",
		new TypeReference<Resource<DeclaredType>>() { /* generic type reference */ });
	
	assertThat("class", resource.getContent().getClass(), Matchers.<Class<?>>equalTo(ResolvedType.class));
	assertThat("field", ((ResolvedType) resource.getContent()).getField(), is("x"));
}
 
开发者ID:BlackPepperSoftware,项目名称:bowman,代码行数:13,代码来源:ResourceDeserializerTest.java


示例12: addSearchLink

import org.springframework.hateoas.Links; //导入依赖的package包/类
public void addSearchLink(Collection<Link> links, Class type) {
            Link collectionLink = repositoryEntityLinks.linkToCollectionResource(type).expand();

    String relBase = collectionLink.getRel();


    Links searchLinks = repositoryEntityLinks.linksToSearchResources(type);

    if (searchLinks == null || searchLinks.isEmpty()) {
        logger.debug("No search links found for class {}", type);
    } else {
        logger.debug("Search links found for class {}: {} ", type, searchLinks);

        String href = collectionLink.getHref() + "/search";
        String rel = relBase + SEARCH_REL_SUFFIX;
        Link searchesLink = new Link(href, rel);

        links.add(searchesLink);

    }
}
 
开发者ID:EMBL-EBI-SUBS-OLD,项目名称:subs,代码行数:22,代码来源:LinkHelper.java


示例13: createResource

import org.springframework.hateoas.Links; //导入依赖的package包/类
private static <T> Resource<T> createResource(Class<T> contentType, ObjectNode sourceTree,
	Links links, ObjectMapper mapper) {
	
	T content = mapper.convertValue(sourceTree, contentType);
	return new Resource<>(content, links);
}
 
开发者ID:BlackPepperSoftware,项目名称:bowman,代码行数:7,代码来源:ResourceDeserializer.java


示例14: resolveType

import org.springframework.hateoas.Links; //导入依赖的package包/类
@Override
public Class<?> resolveType(Class<?> declaredType, Links resourceLinks, Configuration configuration) {
	return mockResolver.resolveType(declaredType, resourceLinks, configuration);
}
 
开发者ID:BlackPepperSoftware,项目名称:bowman,代码行数:5,代码来源:DefaultTypeResolverTest.java


示例15: resolveTypeWithUnderspecifiedResourceTypeInfoThrowsException

import org.springframework.hateoas.Links; //导入依赖的package包/类
@Test
public void resolveTypeWithUnderspecifiedResourceTypeInfoThrowsException() {
	thrown.expect(IllegalStateException.class);

	resolver.resolveType(TypeWithUnderspecifiedInfo.class, new Links(), Configuration.build());
}
 
开发者ID:BlackPepperSoftware,项目名称:bowman,代码行数:7,代码来源:DefaultTypeResolverTest.java


示例16: resolveTypeWithOverspecifiedResourceTypeInfoThrowsException

import org.springframework.hateoas.Links; //导入依赖的package包/类
@Test
public void resolveTypeWithOverspecifiedResourceTypeInfoThrowsException() {
	thrown.expect(IllegalStateException.class);
	
	resolver.resolveType(TypeWithOverspecifiedInfo.class, new Links(), Configuration.build());
}
 
开发者ID:BlackPepperSoftware,项目名称:bowman,代码行数:7,代码来源:DefaultTypeResolverTest.java


示例17: resolveTypeWithSubtypesAndNoSelfLinkReturnsDeclaredType

import org.springframework.hateoas.Links; //导入依赖的package包/类
@Test
public void resolveTypeWithSubtypesAndNoSelfLinkReturnsDeclaredType() {
	Class<?> type = resolver.resolveType(TypeWithSubtypes.class, new Links(), Configuration.build());
	
	assertThat(type, Matchers.<Class<?>>equalTo(TypeWithSubtypes.class));
}
 
开发者ID:BlackPepperSoftware,项目名称:bowman,代码行数:7,代码来源:DefaultTypeResolverTest.java


示例18: serialize

import org.springframework.hateoas.Links; //导入依赖的package包/类
@Override
public void serialize(List<Link> value, JsonGenerator jgen, SerializerProvider provider)
        throws IOException, JsonGenerationException {

    // sort links according to their relation
    Map<String, List<Object>> sortedLinks = new LinkedHashMap<String, List<Object>>();
    List<Link> links = new ArrayList<Link>();

    boolean prefixingRequired = curieProvider != null;
    boolean curiedLinkPresent = false;
    boolean skipCuries = !jgen.getOutputContext().getParent().inRoot();

    Object currentValue = jgen.getCurrentValue();

    if (currentValue instanceof Resources) {
        if (mapper.hasCuriedEmbed((Resources<?>) currentValue)) {
            curiedLinkPresent = true;
        }
    }

    for (Link link : value) {

        if (link.equals(CURIES_REQUIRED_DUE_TO_EMBEDS)) {
            continue;
        }

        String rel = prefixingRequired ? curieProvider.getNamespacedRelFrom(link) : link.getRel();

        if (!link.getRel().equals(rel)) {
            curiedLinkPresent = true;
        }

        if (sortedLinks.get(rel) == null) {
            sortedLinks.put(rel, new ArrayList<Object>());
        }

        links.add(link);

        sortedLinks.get(rel).add(toHalLink(link));
    }

    if (!skipCuries && prefixingRequired && curiedLinkPresent) {

        ArrayList<Object> curies = new ArrayList<Object>();
        curies.add(curieProvider.getCurieInformation(new Links(links)));

        sortedLinks.put("curies", curies);
    }

    TypeFactory typeFactory = provider.getConfig().getTypeFactory();
    JavaType keyType = typeFactory.uncheckedSimpleType(String.class);
    JavaType valueType = typeFactory.constructCollectionType(ArrayList.class, Object.class);
    JavaType mapType = typeFactory.constructMapType(HashMap.class, keyType, valueType);

    MapSerializer serializer = MapSerializer.construct(new String[]{}, mapType, true, null,
            provider.findKeySerializer(keyType, null), new OptionalListJackson2Serializer(property), null);

    serializer.serialize(sortedLinks, jgen, provider);
}
 
开发者ID:mockitoo,项目名称:spring-data-rest-android,代码行数:60,代码来源:Jackson2HalModule.java


示例19: getCurieInformation

import org.springframework.hateoas.Links; //导入依赖的package包/类
@Override
public Collection<? extends Object> getCurieInformation(Links links) {
	return Collections.unmodifiableCollection(curies.values());
}
 
开发者ID:mockitoo,项目名称:spring-data-rest-android,代码行数:5,代码来源:DefaultCurieProvider.java


示例20: getCurieInformation

import org.springframework.hateoas.Links; //导入依赖的package包/类
/**
 * Returns an object to render as the base curie information. Implementations have to make sure, the retunred
 * instances renders as defined in the spec.
 * 
 * @param links the {@link Links} that have been added to the response so far.
 * @return must not be {@literal null}.
 */
Collection<? extends Object> getCurieInformation(Links links);
 
开发者ID:mockitoo,项目名称:spring-data-rest-android,代码行数:9,代码来源:CurieProvider.java



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
Java Result类代码示例发布时间:2022-05-22
下一篇:
Java ServerHeader类代码示例发布时间: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