List of usage examples for org.apache.http.client.fluent Request Get
public static Request Get(final String uri)
From source file:org.plukh.fluffymeow.aws.AWSInstanceInfoProviderImpl.java
@Override public InstanceInfo getInstanceInfo() { if (instanceInfo == null) { try {/*from w ww.ja v a2 s . c o m*/ AmazonEC2 ec2 = new AmazonEC2Client(); String instanceId = Request.Get("http://169.254.169.254/latest/meta-data/instance-id").execute() .returnContent().asString(); if (log.isDebugEnabled()) log.debug("Instance Id: " + instanceId); DescribeTagsRequest tagsRequest = new DescribeTagsRequest().withFilters( new Filter().withName("resource-id").withValues(instanceId), new Filter().withName("key").withValues(NAME_TAG, DEPLOYMENT_ID_TAG)); DescribeTagsResult tagsResult = ec2.describeTags(tagsRequest); String name = getTag(tagsResult, NAME_TAG); if (log.isDebugEnabled()) log.debug("Instance name: " + name); String deploymentId = getTag(tagsResult, DEPLOYMENT_ID_TAG); if (log.isDebugEnabled()) log.debug("Deployment: " + deploymentId); instanceInfo = new InstanceInfo().withInstanceId(instanceId).withName(name) .withDeploymentId(deploymentId); } catch (IOException e) { throw new AWSInstanceInfoException("Error retrieving AWS instance info", e); } } return instanceInfo; }
From source file:com.qwazr.semaphores.SemaphoresSingleClient.java
@Override public Set<String> getSemaphoreOwners(String semaphore_id, Boolean local, String group, Integer msTimeout) { UBuilder uriBuilder = new UBuilder(SCRIPT_PREFIX_SEMAPHORES, semaphore_id).setParameters(local, group, msTimeout);//from w w w . j av a2 s. c om Request request = Request.Get(uriBuilder.build()); return commonServiceRequest(request, null, msTimeout, SetStringTypeRef, 200); }
From source file:com.softinstigate.restheart.integrationtest.GetRootIT.java
private void testGetRoot(URI uri) throws Exception { Response resp = adminExecutor.execute(Request.Get(uri)); HttpResponse httpResp = resp.returnResponse(); assertNotNull(httpResp);//from w ww . j av a 2 s. c om HttpEntity entity = httpResp.getEntity(); assertNotNull(entity); StatusLine statusLine = httpResp.getStatusLine(); assertNotNull(statusLine); assertEquals("check status code", HttpStatus.SC_OK, statusLine.getStatusCode()); assertNotNull("content type not null", entity.getContentType()); assertEquals("check content type", Representation.HAL_JSON_MEDIA_TYPE, entity.getContentType().getValue()); String content = EntityUtils.toString(entity); assertNotNull("", content); JsonObject json = null; try { json = JsonObject.readFrom(content); } catch (Throwable t) { fail("parsing received json"); } assertNotNull("check json not null", json); assertNotNull("check not null _returned property", json.get("_returned")); assertNotNull("check not null _size property", json.get("_size")); assertNotNull("check not null _total_pages property", json.get("_total_pages")); assertNotNull("check not null _embedded", json.get("_embedded")); assertTrue("check _embedded to be a json object", (json.get("_embedded") instanceof JsonObject)); JsonObject embedded = (JsonObject) json.get("_embedded"); assertNotNull("check not null _embedded.rh:db", embedded.get("rh:db")); assertTrue("check _embedded to be a json array", (embedded.get("rh:db") instanceof JsonArray)); JsonArray rhdb = (JsonArray) embedded.get("rh:db"); assertNotNull("check not null _embedded.rh:db[0]", rhdb.get(0)); assertTrue("check _embedded.rh:db[0] to be a json object", (rhdb.get(0) instanceof JsonObject)); JsonObject rhdb0 = (JsonObject) rhdb.get(0); assertNotNull("check not null _embedded.rh:db[0]._id", rhdb0.get("_id")); assertNotNull("check not null _embedded.rh:db[0]._links", rhdb0.get("_links")); assertTrue("check _embedded.rh:db[0]._links to be a json object", (rhdb0.get("_links") instanceof JsonObject)); JsonObject rhdb0Links = (JsonObject) rhdb0.get("_links"); assertNotNull("check not null _embedded.rh:db[0]._links.self", rhdb0Links.get("self")); assertTrue("check _embedded.rh:db[0]._links.self to be a json object", (rhdb0Links.get("self") instanceof JsonObject)); JsonObject rhdb0LinksSelf = (JsonObject) rhdb0Links.get("self"); assertNotNull("check not null _embedded.rh:db[0]._links.self.href", rhdb0LinksSelf.get("href")); assertTrue("check _embedded.rh:db[0]._links.self.href to be a string", (rhdb0LinksSelf.get("href").isString())); try { URI _uri = new URI(rhdb0LinksSelf.get("href").asString()); } catch (URISyntaxException use) { fail("check _embedded.rh:db[0]._links.self.href to be a valid URI"); } assertNotNull("check not null _link", json.get("_links")); assertTrue("check _link to be a json object", (json.get("_links") instanceof JsonObject)); JsonObject links = (JsonObject) json.get("_links"); assertNotNull("check not null self", links.get("self")); assertNotNull("check not null rh:paging", links.get("rh:paging")); assertNotNull("check not null curies", links.get("curies")); }
From source file:com.zestedesavoir.zestwriter.utils.Configuration.java
public static String getLastRelease() throws IOException { String projectUrlRelease = "https://api.github.com/repos/firm1/zest-writer/releases/latest"; String json = Request.Get(projectUrlRelease).execute().returnContent().asString(); ObjectMapper mapper = new ObjectMapper(); // can reuse, share globally Map map = mapper.readValue(json, Map.class); if (map.containsKey("tag_name")) { return (String) map.get("tag_name"); }/*from w ww . j a v a 2 s . c o m*/ return null; }
From source file:org.apache.dubbo.remoting.http.jetty.JettyHttpBinderTest.java
@Test public void shouldAbleHandleRequestForJettyBinder() throws Exception { int port = NetUtils.getAvailablePort(); URL url = new URL("http", "localhost", port, new String[] { Constants.BIND_PORT_KEY, String.valueOf(port) }); HttpServer httpServer = new JettyHttpServer(url, new HttpHandler() { @Override/*ww w.j a v a2s. c o m*/ public void handle(HttpServletRequest request, HttpServletResponse response) throws IOException { response.getWriter().write("Jetty"); } }); String response = Request.Get(url.toJavaURL().toURI()).execute().returnContent().asString(); assertThat(response, is("Jetty")); httpServer.close(); }
From source file:org.apache.dubbo.remoting.http.tomcat.TomcatHttpBinderTest.java
@Test public void shouldAbleHandleRequestForTomcatBinder() throws Exception { int port = NetUtils.getAvailablePort(); URL url = new URL("http", "localhost", port, new String[] { Constants.BIND_PORT_KEY, String.valueOf(port) }); HttpServer httpServer = new TomcatHttpBinder().bind(url, new HttpHandler() { @Override/*from w w w . j a v a 2 s . c om*/ public void handle(HttpServletRequest request, HttpServletResponse response) throws IOException { response.getWriter().write("Tomcat"); } }); String response = Request.Get(url.toJavaURL().toURI()).execute().returnContent().asString(); assertThat(response, is("Tomcat")); httpServer.close(); }
From source file:com.qwazr.crawler.web.client.WebCrawlerSingleClient.java
@Override public TreeMap<String, WebCrawlStatus> getSessions(Boolean local, String group, Integer msTimeout) { UBuilder uriBuilder = new UBuilder("/crawler/web/sessions").setParameters(local, group, msTimeout); Request request = Request.Get(uriBuilder.build()); return commonServiceRequest(request, null, null, TreeMapStringCrawlTypeRef, 200); }
From source file:org.restheart.test.integration.GetIndexesIT.java
private void testGetIndexes(URI uri) throws Exception { Response resp = adminExecutor.execute(Request.Get(uri)); HttpResponse httpResp = resp.returnResponse(); assertNotNull(httpResp);//from w w w . j a v a2 s.com HttpEntity entity = httpResp.getEntity(); assertNotNull(entity); StatusLine statusLine = httpResp.getStatusLine(); assertNotNull(statusLine); assertEquals("check status code", HttpStatus.SC_OK, statusLine.getStatusCode()); assertNotNull("content type not null", entity.getContentType()); assertEquals("check content type", Representation.HAL_JSON_MEDIA_TYPE, entity.getContentType().getValue()); String content = EntityUtils.toString(entity); assertNotNull("", content); JsonObject json = null; try { json = JsonObject.readFrom(content); } catch (Throwable t) { fail("parsing received json"); } assertNotNull("check json not null", json); assertNotNull("check not null _returned property", json.get("_returned")); assertNotNull("check not null _size property", json.get("_size")); assertEquals("check _size value to be 7", 7, json.get("_size").asInt()); assertEquals("check _returned value to be 7", 7, json.get("_returned").asInt()); assertNotNull("check not null _link", json.get("_links")); assertTrue("check _link to be a json object", (json.get("_links") instanceof JsonObject)); JsonObject links = (JsonObject) json.get("_links"); assertNotNull("check not null self", links.get("self")); assertNotNull("check not null rh:coll", links.get("rh:coll")); assertNotNull("check not null curies", links.get("curies")); assertTrue("check _embedded to be a json object", (json.get("_embedded") instanceof JsonObject)); JsonObject embedded = (JsonObject) json.get("_embedded"); assertNotNull("check not null _embedded.rh:index", embedded.get("rh:index")); assertTrue("check _embedded.rh:index to be a json array", (embedded.get("rh:index") instanceof JsonArray)); JsonArray rhindex = (JsonArray) embedded.get("rh:index"); assertNotNull("check not null _embedded.rh:index[0]", rhindex.get(0)); assertTrue("check _embedded.rh:index[0] to be a json object", (rhindex.get(0) instanceof JsonObject)); JsonObject rhindex0 = (JsonObject) rhindex.get(0); assertNotNull("check not null _embedded.rh:index[0]._id", rhindex0.get("_id")); assertNotNull("check not null _embedded.rh:index[0].key", rhindex0.get("key")); }
From source file:io.gravitee.gateway.standalone.QueryParametersTest.java
@Test public void call_get_query_params() throws Exception { String query = "true"; URI target = new URIBuilder("http://localhost:8082/test/my_team").addParameter("q", "true").build(); Response response = Request.Get(target).execute(); HttpResponse returnResponse = response.returnResponse(); assertEquals(HttpStatus.SC_OK, returnResponse.getStatusLine().getStatusCode()); String responseContent = StringUtils.copy(returnResponse.getEntity().getContent()); assertEquals(query, responseContent); }
From source file:com.softinstigate.restheart.integrationtest.GetIndexesIT.java
private void testGetIndexes(URI uri) throws Exception { Response resp = adminExecutor.execute(Request.Get(uri)); HttpResponse httpResp = resp.returnResponse(); assertNotNull(httpResp);// ww w . j a v a 2 s . co m HttpEntity entity = httpResp.getEntity(); assertNotNull(entity); StatusLine statusLine = httpResp.getStatusLine(); assertNotNull(statusLine); assertEquals("check status code", HttpStatus.SC_OK, statusLine.getStatusCode()); assertNotNull("content type not null", entity.getContentType()); assertEquals("check content type", Representation.HAL_JSON_MEDIA_TYPE, entity.getContentType().getValue()); String content = EntityUtils.toString(entity); assertNotNull("", content); JsonObject json = null; try { json = JsonObject.readFrom(content); } catch (Throwable t) { fail("parsing received json"); } assertNotNull("check json not null", json); assertNotNull("check not null _returned property", json.get("_returned")); assertNotNull("check not null _size property", json.get("_size")); assertEquals("check _size value to be 8", 8, json.get("_size").asInt()); assertEquals("check _returned value to be 8", 8, json.get("_returned").asInt()); assertNotNull("check not null _link", json.get("_links")); assertTrue("check _link to be a json object", (json.get("_links") instanceof JsonObject)); JsonObject links = (JsonObject) json.get("_links"); assertNotNull("check not null self", links.get("self")); assertNotNull("check not null rh:coll", links.get("rh:coll")); assertNotNull("check not null curies", links.get("curies")); assertTrue("check _embedded to be a json object", (json.get("_embedded") instanceof JsonObject)); JsonObject embedded = (JsonObject) json.get("_embedded"); assertNotNull("check not null _embedded.rh:index", embedded.get("rh:index")); assertTrue("check _embedded.rh:index to be a json array", (embedded.get("rh:index") instanceof JsonArray)); JsonArray rhindex = (JsonArray) embedded.get("rh:index"); assertNotNull("check not null _embedded.rh:index[0]", rhindex.get(0)); assertTrue("check _embedded.rh:index[0] to be a json object", (rhindex.get(0) instanceof JsonObject)); JsonObject rhindex0 = (JsonObject) rhindex.get(0); assertNotNull("check not null _embedded.rh:index[0]._id", rhindex0.get("_id")); assertNotNull("check not null _embedded.rh:index[0].key", rhindex0.get("key")); }