List of usage examples for org.springframework.hateoas MediaTypes HAL_JSON
MediaType HAL_JSON
To view the source code for org.springframework.hateoas MediaTypes HAL_JSON.
Click Source Link
From source file:example.stores.StarbucksClient.java
public static void main(String[] args) { Traverson traverson = new Traverson(URI.create("http://localhost:8080"), MediaTypes.HAL_JSON); Map<String, Object> parameters = new HashMap<>(); parameters.put("location", "40.740337,-73.995146"); parameters.put("distance", "0.5miles"); PagedResources<Resource<Store>> resources = traverson. // follow("stores", "search", "by-location").// withTemplateParameters(parameters).// toObject(TYPE_REFERENCE);/* w w w . j a v a 2 s . c om*/ PageMetadata metadata = resources.getMetadata(); System.out.println( String.format("Got %s of %s stores: ", resources.getContent().size(), metadata.getTotalElements())); for (Resource<Store> resource : resources) { Store store = resource.getContent(); System.out.println(String.format("- %s - %s", store.name, store.address)); } }
From source file:com.example.user.UserEndpoint.java
public static void main(String[] args) { final ObjectMapper objectMapper = new ObjectMapper().registerModule(new Jackson2HalModule()) .disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES) .setPropertyNamingStrategy(PropertyNamingStrategy.SNAKE_CASE); final MappingJackson2HttpMessageConverter converter = new MappingJackson2HttpMessageConverter(objectMapper); converter.setSupportedMediaTypes(Collections.singletonList(MediaTypes.HAL_JSON)); final RestTemplate restTemplate = new RestTemplate(Collections.singletonList(converter)); final ResponseEntity<PagedResources<Resource<UserEntity>>> entity = restTemplate.exchange( "http://localhost:5000/db-app/users", HttpMethod.GET, null, new ParameterizedTypeReference<PagedResources<Resource<UserEntity>>>() { });/*ww w . j a va2s . c o m*/ System.out.println(entity.getStatusCode()); final PagedResources<Resource<UserEntity>> body = entity.getBody(); System.out.println(body); final Collection<Resource<UserEntity>> contents = body.getContent(); final List<UserEntity> userEntities = contents.stream().map(Resource::getContent).collect(toList()); }
From source file:curly.commons.web.rest.TraversonFactory.java
public Traverson create(String serviceId) { ServiceInstance instance = loadBalancerClient.choose(serviceId); return new Traverson(instance.getUri(), MediaTypes.HAL_JSON); }
From source file:io.curly.commons.web.rest.TraversonFactory.java
public Traverson create(String serviceId) { ServiceInstance instance = loadBalancerClient.choose(serviceId); if (instance != null) return new Traverson(instance.getUri(), MediaTypes.HAL_JSON); else// www .j av a 2s .c o m throw new IllegalStateException("Instance is null!"); }
From source file:com.netflix.genie.web.controllers.RootRestControllerIntegrationTests.java
/** * Make sure we can get the root resource. * * @throws Exception on configuration issue *///from w w w.ja v a 2 s .c o m @Test public void canGetRootResource() throws Exception { this.mvc.perform(MockMvcRequestBuilders.get("/api/v3")).andExpect(MockMvcResultMatchers.status().isOk()) .andExpect(MockMvcResultMatchers.content().contentTypeCompatibleWith(MediaTypes.HAL_JSON)) .andExpect(MockMvcResultMatchers.jsonPath("$.content.description", Matchers.notNullValue())) .andExpect(MockMvcResultMatchers.jsonPath(LINKS_PATH + ".*", Matchers.hasSize(5))) .andExpect(MockMvcResultMatchers.jsonPath(LINKS_PATH, Matchers.hasKey(SELF_LINK_KEY))) .andExpect(MockMvcResultMatchers.jsonPath(LINKS_PATH, Matchers.hasKey(APPLICATIONS_LINK_KEY))) .andExpect(MockMvcResultMatchers.jsonPath(LINKS_PATH, Matchers.hasKey(COMMANDS_LINK_KEY))) .andExpect(MockMvcResultMatchers.jsonPath(LINKS_PATH, Matchers.hasKey(CLUSTERS_LINK_KEY))) .andExpect(MockMvcResultMatchers.jsonPath(LINKS_PATH, Matchers.hasKey(JOBS_LINK_KEY))); }
From source file:org.springsource.restbucks.order.web.OrderResourceIntegrationTest.java
@Test public void exposesOrdersResourceViaRootResource() throws Exception { mvc.perform(get("/")).// andDo(MockMvcResultHandlers.print()).// andExpect(status().isOk()). // andExpect(content().contentTypeCompatibleWith(MediaTypes.HAL_JSON)). // andExpect(jsonPath("$._links.restbucks:orders.href", notNullValue())); }
From source file:io.github.howiefh.jeews.modules.sys.controller.RoleControllerTest.java
@Test public void testGetList() throws Exception { mockMvc.perform(get("/roles").accept(MediaTypes.HAL_JSON)) // .andExpect(status().isOk()) // 200 .andExpect(content().contentType(MediaTypes.HAL_JSON)); }
From source file:io.github.howiefh.jeews.modules.sys.controller.OrganizationControllerTest.java
@Test public void testGetList() throws Exception { mockMvc.perform(get("/organizations").accept(MediaTypes.HAL_JSON)) // .andExpect(status().isOk()) // 200 .andExpect(content().contentType(MediaTypes.HAL_JSON)); }
From source file:org.springsource.restbucks.training.order.web.OrderResourceIntegrationTest.java
@Test public void exposesOrdersResourceViaRootResource() throws Exception { mvc.perform(get("/")).// andExpect(status().isOk()). // andExpect(content().contentType(MediaTypes.HAL_JSON)). // andExpect(jsonPath("$_links.orders.href", notNullValue())); }
From source file:io.github.howiefh.jeews.modules.sys.controller.SignupControllerTest.java
@Test public void testLogin() throws Exception { String requestBody = "{\"username\":\"fh" + UUID.randomUUID() + "\",\"password\":\"123456\",\"email\":\"" + UUID.randomUUID() + "@qq.om\"}"; mockMvc.perform(post("/signup").contentType(MediaType.APPLICATION_JSON).content(requestBody) .accept(MediaTypes.HAL_JSON)) // .andExpect(status().isCreated()) // 201 .andExpect(jsonPath("$.msg").exists()) // Json path?JSON .andExpect(content().contentType(MediaTypes.HAL_JSON)).andReturn(); }