Example usage for org.apache.http.client.fluent Request Get

List of usage examples for org.apache.http.client.fluent Request Get

Introduction

In this page you can find the example usage for org.apache.http.client.fluent Request Get.

Prototype

public static Request Get(final String uri) 

Source Link

Usage

From source file:org.restheart.test.integration.GetAggreationIT.java

private String getEtag(URI uri) throws IOException {
    Response resp = adminExecutor.execute(Request.Get(uri));

    HttpResponse httpResp = resp.returnResponse();
    assertNotNull(httpResp);// w  ww  .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 not null json", json);

    assertNotNull("check not null _etag", json.get("_etag"));
    assertTrue("check _etag is object", json.get("_etag").isObject());

    assertNotNull("check not null _etag.$oid", json.get("_etag").asObject().get("$oid"));

    assertNotNull("check _etag.$oid is string", json.get("_etag").asObject().get("$oid").isString());

    return json.get("_etag").asObject().get("$oid").asString();
}

From source file:org.mule.module.http.functional.proxy.HttpProxyTemplateTestCase.java

private void assertRequestOk(String url, String expectedResponse) throws IOException {
    Response response = Request.Get(url).connectTimeout(RECEIVE_TIMEOUT).execute();
    HttpResponse httpResponse = response.returnResponse();
    assertThat(httpResponse.getStatusLine().getStatusCode(), is(200));
    if (expectedResponse != null) {
        assertThat(IOUtils.toString(httpResponse.getEntity().getContent()), is(expectedResponse));
    }//from  w w w  . jav a 2 s  .  c  o m
}

From source file:com.qwazr.crawler.web.driver.BrowserDriver.java

void httpClientDownload(String url, String userAgent, File file) throws NoSuchAlgorithmException,
        KeyStoreException, KeyManagementException, IOException, URISyntaxException {
    URI uri = new URI(url);
    final CloseableHttpClient httpClient = HttpUtils.createHttpClient_AcceptsUntrustedCerts();
    try {// w  w w.  j  a v  a2 s .  c o m
        final Executor executor = Executor.newInstance(httpClient);
        Request request = Request.Get(uri.toString()).addHeader("Connection", "close").connectTimeout(60000)
                .socketTimeout(60000);
        if (userAgent != null)
            request = request.addHeader("User-Agent", userAgent);
        if (currentProxy != null) {
            if (currentProxy.http_proxy != null && !currentProxy.http_proxy.isEmpty())
                request = request.viaProxy(currentProxy.http_proxy);
            if ("https".equals(uri.getScheme()) && currentProxy.ssl_proxy != null
                    && !currentProxy.ssl_proxy.isEmpty())
                request = request.viaProxy(currentProxy.ssl_proxy);
        }
        executor.execute(request).saveContent(file);
    } finally {
        IOUtils.close(httpClient);
    }
}

From source file:org.apache.james.jmap.methods.integration.cucumber.DownloadStepdefs.java

@When("^\"([^\"]*)\" downloads \"([^\"]*)\" with wrong blobId$")
public void getDownloadWithWrongBlobId(String username, String attachmentId) throws Throwable {
    String blobId = blobIdByAttachmentId.get(attachmentId);

    URIBuilder uriBuilder = mainStepdefs.baseUri()
            .setPath("/download/badbadbadbadbadbadbadbadbadbadbadbadbadb");
    trustForBlobId(blobId, username);
    AttachmentAccessTokenKey key = new AttachmentAccessTokenKey(username, blobId);
    uriBuilder.addParameter("access_token", attachmentAccessTokens.get(key).serialize());
    response = Request.Get(uriBuilder.build()).execute().returnResponse();
}

From source file:org.elasticsearch.packaging.test.ArchiveTestCase.java

public void test80RelativePathConf() throws IOException {
    assumeThat(installation, is(notNullValue()));

    final Path temp = getTempDir().resolve("esconf-alternate");
    final Path tempConf = temp.resolve("config");

    try {// w  w w  . j a  v  a2 s  . co  m
        mkdir(tempConf);
        Stream.of("elasticsearch.yml", "log4j2.properties", "jvm.options")
                .forEach(file -> cp(installation.config(file), tempConf.resolve(file)));

        append(tempConf.resolve("elasticsearch.yml"), "node.name: relative");

        final Shell sh = new Shell();
        Platforms.onLinux(() -> sh.run("chown -R elasticsearch:elasticsearch " + temp));
        Platforms.onWindows(() -> sh.run("$account = New-Object System.Security.Principal.NTAccount 'vagrant'; "
                + "$tempConf = Get-ChildItem '" + temp + "' -Recurse; " + "$tempConf += Get-Item '" + temp
                + "'; " + "$tempConf | ForEach-Object { " + "$acl = Get-Acl $_.FullName; "
                + "$acl.SetOwner($account); " + "Set-Acl $_.FullName $acl " + "}"));

        final Shell serverShell = new Shell(temp);
        serverShell.getEnv().put("ES_PATH_CONF", "config");
        Archives.runElasticsearch(installation, serverShell);

        final String nodesResponse = makeRequest(Request.Get("http://localhost:9200/_nodes"));
        assertThat(nodesResponse, containsString("\"name\":\"relative\""));

        Archives.stopElasticsearch(installation);

    } finally {
        rm(tempConf);
    }
}

From source file:com.twosigma.beaker.NamespaceClient.java

private Map<String, String> getVersionInfo() throws IOException {
    String result = Request.Get(utilUrl + "/getVersionInfo").addHeader("Authorization", auth).execute()
            .returnContent().asString();
    return objectMapper.get().<HashMap<String, String>>readValue(result,
            new TypeReference<HashMap<String, String>>() {
            });//from w  w  w  .ja va  2s. c om
}

From source file:com.mywork.framework.util.RemoteHttpUtil.java

/**
 * FluentAPI/*from  www.  j a  va2 s. c  o  m*/
 */
@SuppressWarnings("unused")
public void fluentAPIDemo(String contentUrl) throws IOException {
    try {
        // demo1: ? , (200 total/100 per route), returnContent()??inputstream
        String resultString = Request.Get(contentUrl).execute().returnContent().asString();

        // demo2: ?, 
        byte[] resultBytes = Request.Get(contentUrl).connectTimeout(TIMEOUT_SECONDS * 1000)
                .socketTimeout(TIMEOUT_SECONDS * 1000).execute().returnContent().asBytes();

        // demo3: ??httpClient
        Executor executor = Executor.newInstance(httpClient);
        String resultString2 = executor.execute(Request.Get(contentUrl)).returnContent().asString();
    } catch (HttpResponseException e) {
        logger.error("Status code:" + e.getStatusCode(), e);
    }
}

From source file:com.qwazr.search.index.IndexSingleClient.java

@Override
public List<BackupStatus> getBackups(String schema_name, String index_name) {
    UBuilder uriBuilder = new UBuilder("/indexes/", schema_name, "/", index_name, "/backup");
    Request request = Request.Get(uriBuilder.build());
    return commonServiceRequest(request, null, null, ListBackupStatusTypeRef, 200);
}

From source file:com.seekret.data.flickr.FlickrRequestHandler.java

public Set<PointOfInterest> getPicturesForCluster(Cluster cluster) {
    double latitude = cluster.getLatitude();
    double longitude = cluster.getLongitude();
    LatLng position = new LatLng(latitude, longitude);
    int requestedPage = 1;
    int numberPages = 1;
    double radiusInKm = 0.1;
    Set<PointOfInterest> result = new HashSet<PointOfInterest>();
    int maxViewCount = 1;
    List<String> picture_ids = new ArrayList<String>();
    String urlForRequest = buildPhotoRequestURL(requestedPage, position, radiusInKm,
            LicenseEnum.ONLY_NON_COMMERCIAL);

    JsonObject photosObject;/* w w w .ja  va2  s  . c  om*/

    try {
        log.log(Level.FINE,
                "Retrieving first images page (license free) for cluster " + cluster + " -> " + urlForRequest);
        String jsonResponse = Request.Get(urlForRequest.toString()).execute().returnContent().asString();
        requestedPage++;
        photosObject = JsonObject.readFrom(jsonResponse);

        numberPages = handleFlickrPictureResult(result, picture_ids, numberPages, maxViewCount, photosObject);
    } catch (Exception e) {
        log.log(Level.WARNING, "Could not load picture page from flickr", e);
    }
    if (!result.isEmpty()) {
        log.log(Level.FINE, "number of pictures found for cluster[" + cluster + "]: " + result.size());
    }
    return result;
}

From source file:org.mule.module.http.functional.listener.HttpListenerHttpMessagePropertiesTestCase.java

@Test
public void getBasePath() throws Exception {
    final String url = String.format("http://localhost:%s%s", listenBasePort.getNumber(), API_CONTEXT_PATH);
    Request.Get(url).connectTimeout(RECEIVE_TIMEOUT).execute();
    final MuleMessage message = muleContext.getClient().request("vm://out", RECEIVE_TIMEOUT);
    assertThat(message.<String>getInboundProperty(HttpConstants.RequestProperties.HTTP_LISTENER_PATH),
            is("/api/*"));
    assertThat(message.<String>getInboundProperty(HttpConstants.RequestProperties.HTTP_REQUEST_PATH_PROPERTY),
            is(API_CONTEXT_PATH));/*from w  w w. j ava  2  s .  c  o m*/
    assertThat(message.<String>getInboundProperty(HttpConstants.RequestProperties.HTTP_RELATIVE_PATH),
            is(CONTEXT_PATH));
    ParameterMap uriParams = message.getInboundProperty(HttpConstants.RequestProperties.HTTP_URI_PARAMS);
    assertThat(uriParams, notNullValue());
    assertThat(uriParams.isEmpty(), is(true));
}