Java Code Examples for javax.ws.rs.core.Response#getLink()
The following examples show how to use
javax.ws.rs.core.Response#getLink() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ApiBase.java From newrelic-alerts-configurator with Apache License 2.0 | 5 votes |
private <T, LT extends ObjectList<T, LT>> LT followPageable(Link next, LT responseBody, Class<LT> responseType) { while (next != null) { Response nextResponse = client.target(next).request(APPLICATION_JSON_TYPE).get(); LT nextResponseBody = nextResponse.readEntity(responseType); responseBody = responseBody.merge(nextResponseBody); next = nextResponse.getLink("next"); } return responseBody; }
Example 2
Source File: ExplorableDatasetRestTest.java From mobi with GNU Affero General Public License v3.0 | 5 votes |
@Test public void getInstanceDetailsWithNextLinkTest() { //Setup: String pathString = "explorable-datasets/" + encode(RECORD_ID_STR) + "/classes/" + encode(CLASS_ID_STR) + "/instance-details"; Response response = target().path(pathString).queryParam("offset", 0).queryParam("limit", 3).request().get(); assertEquals(response.getStatus(), 200); JSONArray responseArray = JSONArray.fromObject(response.readEntity(String.class)); assertEquals(responseArray.size(), 3); assertEquals(response.getHeaders().get("X-Total-Count").get(0), "13"); Link link = response.getLink("next"); assertTrue(link.getUri().getRawPath().contains(pathString)); assertTrue(link.getRel().equals("next")); }
Example 3
Source File: ExplorableDatasetRestTest.java From mobi with GNU Affero General Public License v3.0 | 5 votes |
@Test public void getInstanceDetailsWithPrevLinkTest() { //Setup: String pathString = "explorable-datasets/" + encode(RECORD_ID_STR) + "/classes/" + encode(CLASS_ID_STR) + "/instance-details"; Response response = target().path(pathString).queryParam("offset", 12).queryParam("limit", 3).request().get(); assertEquals(response.getStatus(), 200); JSONArray responseArray = JSONArray.fromObject(response.readEntity(String.class)); assertEquals(responseArray.size(), 1); assertEquals(response.getHeaders().get("X-Total-Count").get(0), "13"); Link link = response.getLink("prev"); assertTrue(link.getUri().getRawPath().contains(pathString)); assertTrue(link.getRel().equals("prev")); }
Example 4
Source File: JAXRSClientServerSpringBookTest.java From cxf with Apache License 2.0 | 5 votes |
@Test public void testGetBookLink() throws Exception { String address = "http://localhost:" + PORT + "/the/bookstore/link"; WebClient wc = WebClient.create(address); Response r = wc.get(); Link l = r.getLink("self"); assertEquals("<http://localhost:" + PORT + "/the/bookstore/>;rel=\"self\"", l.toString()); }
Example 5
Source File: ApiBase.java From newrelic-alerts-configurator with Apache License 2.0 | 4 votes |
<T, LT extends ObjectList<T, LT>> LT getPageable(Builder request, Class<LT> responseType) { Response response = request.get(); LT responseBody = response.readEntity(responseType); Link next = response.getLink("next"); return followPageable(next, responseBody, responseType); }
Example 6
Source File: OrderResourceTest.java From resteasy-examples with Apache License 2.0 | 4 votes |
@Test public void testCreateCancelPurge() throws Exception { String base = "http://localhost:8080/services/shop"; Response response = client.target(base).request().head(); Link customers = response.getLink("customers"); Link orders = response.getLink("orders"); response.close(); System.out.println("** Create a customer through this URL: " + customers.getUri().toString()); Customer customer = new Customer(); customer.setFirstName("Bill"); customer.setLastName("Burke"); customer.setStreet("10 Somewhere Street"); customer.setCity("Westford"); customer.setState("MA"); customer.setZip("01711"); customer.setCountry("USA"); response = client.target(customers).request().post(Entity.xml(customer)); Assert.assertEquals(201, response.getStatus()); response.close(); Order order = new Order(); order.setTotal("$199.99"); order.setCustomer(customer); order.setDate(new Date().toString()); LineItem item = new LineItem(); item.setCost("$199.99"); item.setProduct("iPhone"); order.setLineItems(new ArrayList<LineItem>()); order.getLineItems().add(item); System.out.println(); System.out.println("** Create an order through this URL: " + orders.getUri().toString()); response = client.target(orders).request().post(Entity.xml(order)); Assert.assertEquals(201, response.getStatus()); URI createdOrderUrl = response.getLocation(); response.close(); System.out.println(); System.out.println("** New list of orders"); response = client.target(orders).request().get(); String orderList = response.readEntity(String.class); System.out.println(orderList); Link purge = response.getLink("purge"); response.close(); response = client.target(createdOrderUrl).request().head(); Link cancel = response.getLink("cancel"); response.close(); if (cancel != null) { System.out.println("** Canceling the order at URL: " + cancel.getUri().toString()); response = client.target(cancel).request().post(null); Assert.assertEquals(204, response.getStatus()); response.close(); } System.out.println(); System.out.println("** New list of orders after cancel: "); orderList = client.target(orders).request().get(String.class); System.out.println(orderList); System.out.println(); System.out.println("** Purge cancelled orders at URL: " + purge.getUri().toString()); response = client.target(purge).request().post(null); Assert.assertEquals(204, response.getStatus()); response.close(); System.out.println(); System.out.println("** New list of orders after purge: "); orderList = client.target(orders).request().get(String.class); System.out.println(orderList); }