private ObjectNode dependenciesLink(String appUrl) { String uri = (appUrl != null) ? appUrl + "/dependencies" : "/dependencies"; UriTemplate uriTemplate = new UriTemplate(uri, this.dependenciesVariables); ObjectNode result = nodeFactory().objectNode(); result.put("href", uriTemplate.toString()); result.put("templated", true); return result; }
private String generateTemplatedUri(String appUrl, Type type) { String uri = (appUrl != null) ? appUrl + type.getAction() : type.getAction(); uri = uri + "?type=" + type.getId(); UriTemplate uriTemplate = new UriTemplate(uri, this.templateVariables); return uriTemplate.toString(); }
private UriTemplate getUriTemplate() { if (template == null) { this.template = new UriTemplate(href); } return template; }
/** * Creates a new {@link Link} to the given URI with the given rel. * * @param href must not be {@literal null} or empty. * @param rel must not be {@literal null} or empty. */ public Link(String href, String rel) { this(new UriTemplate(href), rel); }
public @Bean CurieProvider curieProvider() { return new DefaultCurieProvider(CURIE_NAMESPACE, new UriTemplate("/docs/{rel}.html")); }
private URIAndHeaders traverseToExpandedFinalUrl() { UriStringAndHeaders uriAndHeaders = getAndFindLinkWithRel(baseUri.toString(), this.rels.iterator(), HttpHeaders.EMPTY); return new URIAndHeaders(new UriTemplate(uriAndHeaders.getUri()).expand(this.templateParameters), uriAndHeaders.getHttpHeaders()); }
private UriStringAndHeaders traverseToFinalUrl() { UriStringAndHeaders uriAndHeaders = getAndFindLinkWithRel(baseUri.toString(), this.rels.iterator(), HttpHeaders.EMPTY); return new UriStringAndHeaders(new UriTemplate(uriAndHeaders.getUri()).toString(), uriAndHeaders.getHttpHeaders()); }
@Override public Object deserialize(JsonParser jp, DeserializationContext ctxt) throws IOException, JsonProcessingException { String source = jp.getValueAsString(); if (!StringUtils.hasText(source)) { return null; } try { URI uri = new UriTemplate(source).expand(); TypeDescriptor typeDescriptor = TypeDescriptor.valueOf(property.getActualType()); return converter.convert(uri, URI_DESCRIPTOR, typeDescriptor); } catch (IllegalArgumentException o_O) { throw ctxt.weirdStringException(source, URI.class, String.format(UNEXPECTED_VALUE, property)); } }
/** * Returns the link to to the paged colelction resource for the given type, pre-expanding the * * @param type must not be {@literal null}. * @param pageable the pageable to can be {@literal null}. * @return */ public Link linkToPagedResource(Class<?> type, Pageable pageable) { ResourceMetadata metadata = mappings.getMetadataFor(type); String href = linkFor(type).toString(); UriComponents components = prepareUri(href, metadata, pageable); TemplateVariables variables = getTemplateVariables(components, metadata, pageable).// concat(getProjectionVariable(type)); return new Link(new UriTemplate(href, variables), metadata.getRel()); }
/** * Sets the location header pointing to the resource representing the given instance. Will make sure we properly * expand the URI template potentially created as self link. * * @param headers must not be {@literal null}. * @param assembler must not be {@literal null}. * @param source must not be {@literal null}. */ private void addLocationHeader(HttpHeaders headers, PersistentEntityResourceAssembler assembler, Object source) { String selfLink = assembler.getSelfLinkFor(source).getHref(); headers.setLocation(new UriTemplate(selfLink).expand()); }
@Override public Link linkToSingleResource(Class<?> type, Object id) { Assert.isInstanceOf(Serializable.class, id, "Id must be assignable to Serializable!"); ResourceMetadata metadata = mappings.getMetadataFor(type); String mappedId = idConverters.getPluginFor(type)// .orElse(DefaultIdConverter.INSTANCE)// .toRequestId((Serializable) id, type); Link link = linkFor(type).slash(mappedId).withRel(metadata.getItemResourceRel()); return new Link(new UriTemplate(link.getHref(), getProjectionVariable(type)).toString(), metadata.getItemResourceRel()); }
/** * Creates a new {@link UriTemplate} with the current {@link TemplateVariable}s augmented with the given ones. * * @param variables can be {@literal null}. * @return will never be {@literal null}. */ public UriTemplate with(TemplateVariables variables) { if (variables == null) { return this; } UriComponents components = UriComponentsBuilder.fromUriString(baseUri).build(); List<TemplateVariable> result = new ArrayList<>(); for (TemplateVariable variable : variables) { boolean isRequestParam = variable.isRequestParameterVariable(); boolean alreadyPresent = components.getQueryParams().containsKey(variable.getName()); if (isRequestParam && alreadyPresent) { continue; } if (variable.isFragment() && StringUtils.hasText(components.getFragment())) { continue; } result.add(variable); } return new UriTemplate(baseUri, this.variables.concat(result)); }
/** * Returns the links to render for the given {@link Association}. * * @param association must not be {@literal null}. * @param path must not be {@literal null}. * @return */ public List<Link> getLinksFor(Association<? extends PersistentProperty<?>> association, Path path) { Assert.notNull(association, "Association must not be null!"); Assert.notNull(path, "Base path must not be null!"); if (isLinkableAssociation(association)) { PersistentProperty<?> property = association.getInverse(); ResourceMetadata metadata = mappings.getMetadataFor(property.getOwner().getType()); ResourceMapping propertyMapping = metadata.getMappingFor(property); String href = path.slash(propertyMapping.getPath()).toString(); UriTemplate template = new UriTemplate(href, getProjectionVariable(property)); return Collections.singletonList(new Link(template, propertyMapping.getRel())); } return Collections.emptyList(); }
private UriStringAndHeaders getAndFindLinkWithRel(String uri, Iterator<Hop> rels, HttpHeaders extraHeaders) { if (!rels.hasNext()) { return new UriStringAndHeaders(uri, extraHeaders); } HttpEntity<?> request = prepareRequest(mergeHeaders(this.headers, extraHeaders)); UriTemplate template = new UriTemplate(uri); ResponseEntity<String> responseEntity = operations.exchange(template.expand(), GET, request, String.class); MediaType contentType = responseEntity.getHeaders().getContentType(); String responseBody = responseEntity.getBody(); Hop thisHop = rels.next(); Rel rel = Rels.getRelFor(thisHop.getRel(), discoverers); Link link = rel.findInResponse(responseBody, contentType); if (link == null) { throw new IllegalStateException( String.format("Expected to find link with rel '%s' in response %s!", rel, responseBody)); } /* * Don't expand if the parameters are empty */ if (!thisHop.hasParameters()) { return getAndFindLinkWithRel(link.getHref(), rels, thisHop.getHeaders()); } else { return getAndFindLinkWithRel(link.expand(thisHop.getMergedParameters(this.templateParameters)).getHref(), rels, thisHop.getHeaders()); } }
/** * Returns the link pointing to the search resource with the given rel of the given type and pre-expands the * calculated URi tempalte with the given {@link Pageable} and {@link Sort}. * * @param type must not be {@literal null}. * @param rel must not be {@literal null} or empty. * @param pageable can be {@literal null}. * @param sort can be {@literal null}. * @return */ private Link getSearchResourceLinkFor(Class<?> type, String rel, Pageable pageable, Sort sort) { Assert.notNull(type, "Domain type must not be null!"); Assert.hasText(rel, "Relation name must not be null or empty!"); SearchResourceMappings searchMappings = mappings.getSearchResourceMappings(type); MethodResourceMapping mapping = searchMappings.getExportedMethodMappingForRel(rel); if (mapping == null) { return null; } LinkBuilder builder = linkFor(type).// slash(mappings.getSearchResourceMappings(type).getPath()).// slash(mapping.getPath()); UriComponents uriComponents = prepareUri(builder.toString(), mapping, pageable, sort); TemplateVariables variables = getParameterVariables(mapping).// concat(getTemplateVariables(uriComponents, mapping, pageable, sort)).// concat(getProjectionVariable(mapping.getReturnedDomainType())); return new Link(new UriTemplate(uriComponents.toString(), variables), mapping.getRel()); }
/** * Creates a new {@link Link} to the given URI with the given rel. * * @param href must not be {@literal null} or empty. * @param rel must not be {@literal null} or empty. */ public Link(String href, String rel) { this(new UriTemplate(href), rel); }
private UriTemplate getUriTemplate() { if (template == null) { this.template = new UriTemplate(href); } return template; }
public CompletionTemplate(RestTemplate restTemplate, Link streamLink, Link taskLink) { this.restTemplate = restTemplate; this.streamCompletionUriTemplate = new UriTemplate(streamLink.getHref()); this.taskCompletionUriTemplate = new UriTemplate(taskLink.getHref()); }
public CompletionTemplate(RestTemplate restTemplate, Link streamLink, Link taskLink) { this.restTemplate = restTemplate; this.streamCompletionUriTemplate = new UriTemplate(streamLink.getHref()); this.taskCompletionUriTemplate = new UriTemplate(taskLink.getHref()); }
/** * Construct a {@code AppRegistryTemplate} object. * * @param restTemplate template for HTTP/rest commands * @param resourceSupport HATEOAS link support */ public AppRegistryTemplate(RestTemplate restTemplate, ResourceSupport resourceSupport) { this.restTemplate = restTemplate; this.uriTemplate = new UriTemplate(resourceSupport.getLink("apps").getHref()); }