public UserGroupList getUserGroups(Integer page, Integer entries, boolean all) { WebResource wr = getBaseWebResource("usergroups"); wr = wr.queryParam("page", page.toString()); wr = wr.queryParam("entries", entries.toString()); wr = wr.queryParam("all", "" + all); return wr.header("Content-Type", MediaType.TEXT_XML) .accept(MediaType.TEXT_XML) .get(UserGroupList.class); }
private ReviewableItemsStatistics execGet( final String mapId, final String reviewScoreThresholdMinimum, final String geospatialBounds) throws Exception { WebResource resource = resource().path("/review/statistics"); if (mapId != null) { resource = resource.queryParam("mapId", mapId); } if (reviewScoreThresholdMinimum != null) { resource = resource.queryParam("reviewScoreThresholdMinimum", reviewScoreThresholdMinimum); } if (geospatialBounds != null) { resource = resource.queryParam("geospatialBounds", geospatialBounds); } return resource.accept(MediaType.APPLICATION_JSON).get(ReviewableItemsStatistics.class); }
public static WebResource addOptionalQueryParam( WebResource webResource, String key, int value, int defaultValue) { if (value != defaultValue) { webResource = webResource.queryParam(key, Integer.toString(value)); } return webResource; }
/** Reproducer test for JERSEY-1893. */ @Test public void testGet() { WebResource r = resource().path("/"); String s; // check that the regular filter gets involved s = r.path("direct").get(String.class); Assert.assertEquals("[DIRECT]", s); // the regular filter should work for directly requested forward resource as well. s = r.path("forward").get(String.class); Assert.assertEquals("[FORWARD]", s); // forward action should enforce forward filter to be invoked s = r.queryParam("action", "forward").get(String.class); Assert.assertEquals(">>FORWARD", s); // direct call to the include resource s = r.path("included").get(String.class); Assert.assertEquals("[INCLUDED]", s); // include call should involve both regular and include filter s = r.path("included").queryParam("action", "include").get(String.class); Assert.assertEquals("[SOMETHING INCLUDED]", s); }
/** * Lists workflows according to the provided tag or with not tag restriction if null is provided. * * @param tag the tag to filter or null * @return a list of workflows */ public List<WorkflowInfo> listWorkflows(String tag) { GenericType<JAXBElement<SearchResult>> searchResultType = new GenericType<JAXBElement<SearchResult>>() {}; WebResource workflows = myExperiment.path(WORKFLOWS_PATH); if (tag != null) { workflows = workflows.queryParam("tag", tag); } LOG.debug("Querying myExperiments for workflows with tag [{}]", tag); return workflows .queryParam("elements", QUERY_ELEMENTS) .accept(MediaType.APPLICATION_XML_TYPE) .get(searchResultType) .getValue() .getWorkflows(); }
public static WebResource addOptionalQueryParam( WebResource webResource, String key, Object value) { if (value != null) { webResource = webResource.queryParam(key, value.toString()); } return webResource; }
/** * Retrieves from Keystone server a list of tenants from the given optional marker and limit * values. The marker and limit values are appended to the actual HTTP request to Keystone as * query string parameters. The return object of {@link KeystoneTenantList} represents the * response body from the Keystone API containing the tenant list. * * @param marker The ID of the tenant fetched in the previous request. The returned list will * start from the tenant after the tenant with this ID. A null and empty values are ignored. * @param limit The number of tenants to fetch. Must be greater than 0. This field is ignored if * the value is less than 1. * @return {@link KeystoneTenantList} object, representing the response from the Keystone API. * @throws KeystoneServerException * @throws KeystoneConnectionException */ public KeystoneTenantList getTenants(String marker, int limit) throws KeystoneServerException, KeystoneConnectionException { log.debug("KeystoneClient.getTenants: entered marker=" + marker + ", limit=" + limit); Client client = Client.create(clientConfig); WebResource resource = client.resource(getTenantsUrl()); if (!StringUtils.isEmpty(marker)) { resource = resource.queryParam(MARKER_QUERY, marker); } if (limit > 0) { resource = resource.queryParam(LIMIT_QUERY, Integer.toString(limit)); } return sendGetRequest(resource, KeystoneTenantList.class); }
public UserList getUsers(Integer page, Integer entries) { WebResource wr = getBaseWebResource("users"); return wr.queryParam("page", page.toString()) .queryParam("entries", entries.toString()) .header("Content-Type", MediaType.TEXT_XML) .accept(MediaType.TEXT_XML) .get(UserList.class); }
public <T> T getRawData(Class<T> clazz, Long id, RawFormat decodeFrom) { WebResource wr = getBaseWebResource("data", id, "raw"); if (decodeFrom != null) { wr = wr.queryParam("decode", decodeFrom.name()); } return wr.get(clazz); }
public Resource getResource(Long id, boolean full) { WebResource resource = getBaseWebResource("resources", "resource", id); if (full) resource = resource.queryParam("full", Boolean.toString(full)); return resource .header("Content-Type", MediaType.TEXT_XML) .accept(MediaType.TEXT_XML) .get(Resource.class); }
@Test public void testQueryEndpointMultipleColumns() throws Exception { Node andres = createNode("name", "Andres"); cypherRsPath.put(ClientResponse.class, MULTI_COLUMN_QUERY); ClientResponse response = cypherRsPath.queryParam("ids", String.valueOf(andres.getId())).get(ClientResponse.class); String result = response.getEntity(String.class); assertEquals(result, 200, response.getStatus()); assertEquals("{\"l\":6,\"name\":\"Andres\"}", result); }
private ClientResponse addProperty(String guid, String property, String value) { WebResource resource = service.path(ENTITIES).path(guid); return resource .queryParam("property", property) .queryParam("value", value) .accept(Servlets.JSON_MEDIA_TYPE) .type(Servlets.JSON_MEDIA_TYPE) .method(HttpMethod.PUT, ClientResponse.class); }
@Test public void testQueryEndpoint() throws Exception { Node node = createNode("foo", "bar"); cypherRsPath.put(ClientResponse.class, QUERY); ClientResponse response = cypherRsPath.queryParam("id", String.valueOf(node.getId())).get(ClientResponse.class); String result = response.getEntity(String.class); assertEquals(result, 200, response.getStatus()); assertEquals("{\"foo\":\"bar\"}", result); }
@Test public void testQueryEndpointNoResults() throws Exception { cypherRsPath.put(ClientResponse.class, MULTI_COLUMN_QUERY); ClientResponse response = cypherRsPath .queryParam("ids", String.valueOf(-234)) .queryParam("ids", String.valueOf(-567)) .get(ClientResponse.class); assertEquals(204, response.getStatus()); }
public ExtGroupList searchUserGroup(Integer start, Integer limit, String nameLike, boolean all) { WebResource wr = getBaseWebResource("extjs", "search", "groups", nameLike); wr = wr.queryParam("start", start.toString()) .queryParam("limit", limit.toString()) .queryParam("all", Boolean.toString(all)); return wr.header("Content-Type", MediaType.TEXT_XML) .accept(MediaType.TEXT_XML) .get(ExtGroupList.class); }
private <T, F, R> List<T> getContactsCommon( WebResource resource, ProfileField<F, R> key, F value, Integer limit, Integer offset, final ProfileType<T> type, ContactOrder order, ContactType contactType) { if (key != null && value != null) { resource = resource .queryParam("key", key.getName().toLowerCase()) .queryParam("value", key.format(value).toString()); } if (limit != null) { resource = resource.queryParam("limit", limit.toString()); } if (offset != null) { resource = resource.queryParam("offset", offset.toString()); } resource = resource.queryParam("type", type.getName()); if (order != null) { resource = resource.queryParam("order", order.name().toLowerCase()); } if (contactType != null) { resource = resource.queryParam("contact_type", contactType.name().toLowerCase()); } return resource.get(getGenericType(type)); }
@Test public void testQueryEndpointMultipleResults() throws Exception { Node andres = createNode("name", "Andres"); Node peter = createNode("name", "Peter"); cypherRsPath.put(ClientResponse.class, "match n where id(n) in {ids} return n"); ClientResponse response = cypherRsPath .queryParam("ids", String.valueOf(andres.getId())) .queryParam("ids", String.valueOf(peter.getId())) .get(ClientResponse.class); String result = response.getEntity(String.class); assertEquals(result, 200, response.getStatus()); assertEquals("[{\"name\":\"Andres\"},{\"name\":\"Peter\"}]", result); }
/* * https://www.twilio.com/docs/api/rest/available-phone-numbers#local-get-basic-example-1 * available local phone numbers in the United States in the 510 area code. */ @Test public void testSearchUSLocalPhoneNumbersWith501AreaCode() { stubFor( put(urlEqualTo("/test/configuration/voiceuri")) .willReturn( aResponse() .withStatus(200) .withHeader("Content-Type", "application/json") .withBody(VoxboneAvailablePhoneNumbersEndpointTestUtils.VoiceURIJSonResponse))); stubFor( get(urlEqualTo( "/test/inventory/didgroup?countryCodeA3=USA&areaCode=501&pageNumber=0&pageSize=50")) .willReturn( aResponse() .withStatus(200) .withHeader("Content-Type", "application/json") .withBody(VoxboneAvailablePhoneNumbersEndpointTestUtils.body501AreaCode))); // Get Account using admin email address and user email address Client jerseyClient = Client.create(); jerseyClient.addFilter(new HTTPBasicAuthFilter(adminUsername, adminAuthToken)); String provisioningURL = deploymentUrl + baseURL + "US/Local.json"; WebResource webResource = jerseyClient.resource(provisioningURL); ClientResponse clientResponse = webResource .queryParam("areaCode", "501") .accept("application/json") .get(ClientResponse.class); assertTrue(clientResponse.getStatus() == 200); String response = clientResponse.getEntity(String.class); System.out.println(response); assertTrue(!response.trim().equalsIgnoreCase("[]")); JsonParser parser = new JsonParser(); JsonArray jsonResponse = parser.parse(response).getAsJsonArray(); System.out.println(jsonResponse); assertTrue(jsonResponse.size() == 15); System.out.println((jsonResponse.get(0).getAsJsonObject().toString())); assertTrue( jsonResponse .get(0) .getAsJsonObject() .toString() .equalsIgnoreCase( VoxboneAvailablePhoneNumbersEndpointTestUtils.firstJSonResult501AreaCode)); }
/** Finishes the query for execution. */ public void finishQuery() { finishMigrationPathFilter(); finishDependencyLabelFilter(); finishMigrationPathSource(); finishHandlesMimetypes(); IndentedLineBuffer formatBuffer = new IndentedLineBuffer(); FormatterElement.format(formatBuffer, new SerializationContext(prefixMapping), query); try { String encqs = URLEncoder.encode(formatBuffer.toString(), "UTF-8"); String encpf = URLEncoder.encode(prefixes, "UTF-8"); resource = resource.queryParam(PREFIX_NAME, encpf).queryParam(QUERY_NAME, encqs); } catch (UnsupportedEncodingException e) { LOG.error("Error encoding query", e); } }
@Test public void testGetTraitNames() throws Exception { String[] traitsAdded = addTraits(); WebResource resource = service.path("api/atlas/types"); ClientResponse clientResponse = resource .queryParam("type", DataTypes.TypeCategory.TRAIT.name()) .accept(Servlets.JSON_MEDIA_TYPE) .type(Servlets.JSON_MEDIA_TYPE) .method(HttpMethod.GET, ClientResponse.class); assertEquals(clientResponse.getStatus(), Response.Status.OK.getStatusCode()); String responseAsString = clientResponse.getEntity(String.class); Assert.assertNotNull(responseAsString); JSONObject response = new JSONObject(responseAsString); Assert.assertNotNull(response.get(AtlasClient.REQUEST_ID)); final JSONArray list = response.getJSONArray(AtlasClient.RESULTS); Assert.assertNotNull(list); Assert.assertTrue(list.length() >= traitsAdded.length); }
protected WebResource addQParam(WebResource wb, String key, Object value) { if (value != null) return wb.queryParam(key, value.toString()); else return wb; }
@Test public void testGetQueryWriteQueryShouldReturnInvalidMethod() throws Exception { cypherRsPath.put(ClientResponse.class, WRITE_QUERY); ClientResponse response = cypherRsPath.queryParam("name", "foobar").get(ClientResponse.class); assertEquals(Response.Status.NOT_ACCEPTABLE.getStatusCode(), response.getStatus()); }
@Test public void testQueryNonExistingEndpoint() throws Exception { ClientResponse response = cypherRsPath.queryParam("id", "123").get(ClientResponse.class); assertEquals(404, response.getStatus()); }