本文整理汇总了Java中org.springframework.hateoas.Links类的典型用法代码示例。如果您正苦于以下问题:Java Links类的具体用法?Java Links怎么用?Java Links使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Links类属于org.springframework.hateoas包,在下文中一共展示了Links类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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));
}
示例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);
}
示例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;
}
示例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);
}
示例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));
}
示例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));
}
示例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));
}
示例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));
}
示例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));
}
示例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());
}
示例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"));
}
示例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);
}
}
示例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);
}
示例14: resolveType
import org.springframework.hateoas.Links; //导入依赖的package包/类
@Override
public Class<?> resolveType(Class<?> declaredType, Links resourceLinks, Configuration configuration) {
return mockResolver.resolveType(declaredType, resourceLinks, configuration);
}
示例15: resolveTypeWithUnderspecifiedResourceTypeInfoThrowsException
import org.springframework.hateoas.Links; //导入依赖的package包/类
@Test
public void resolveTypeWithUnderspecifiedResourceTypeInfoThrowsException() {
thrown.expect(IllegalStateException.class);
resolver.resolveType(TypeWithUnderspecifiedInfo.class, new Links(), Configuration.build());
}