当前位置: 首页>>代码示例>>Java>>正文


Java MediaTypes.HAL_JSON属性代码示例

本文整理汇总了Java中org.springframework.hateoas.MediaTypes.HAL_JSON属性的典型用法代码示例。如果您正苦于以下问题:Java MediaTypes.HAL_JSON属性的具体用法?Java MediaTypes.HAL_JSON怎么用?Java MediaTypes.HAL_JSON使用的例子?那么, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在org.springframework.hateoas.MediaTypes的用法示例。


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

示例1: newEmployee

/**
 * 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,代码行数:23,代码来源:HomeController.java

示例2: traversCustomersIT

@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,代码行数:16,代码来源:CustomerRepositoryDataRestIT.java

示例3: traversCustomersResourceIT

@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,代码行数:22,代码来源:CustomerRepositoryDataRestIT.java

示例4: traversCustomerFindByFirstNameIT

@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,代码行数:23,代码来源:CustomerRepositoryDataRestIT.java

示例5: discoverStoreSearch

@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,代码行数:30,代码来源:StarbucksClient.java

示例6: index

/**
 * 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,代码行数:24,代码来源:HomeController.java

示例7: create

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,代码行数:7,代码来源:TraversonFactory.java

示例8: getRubricAssociationResource

/**
 * 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,代码行数:39,代码来源:RubricsServiceImpl.java

示例9: HalLinkDiscoverer

public HalLinkDiscoverer() {
	super("$._links..['%s']..href", MediaTypes.HAL_JSON);
}
 
开发者ID:mockitoo,项目名称:spring-data-rest-android,代码行数:3,代码来源:HalLinkDiscoverer.java

示例10: discoverNamedLink

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,代码行数:7,代码来源:ApiLinkDiscovery.java


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