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:com.softinstigate.restheart.integrationtest.GetCollectionIT.java

private void testGetCollection(URI uri) throws Exception {
    LOG.info("@@@ testGetCollection URI: " + uri);

    Response resp = adminExecutor.execute(Request.Get(uri));

    HttpResponse httpResp = resp.returnResponse();
    assertNotNull(httpResp);//from  w ww .  ja  va 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("@@@ Failed parsing received json");
    }

    assertNotNull("check json not null", json);
    assertNotNull("check not null _created_on property", json.get("_type"));
    assertNotNull("check not null _created_on property", json.get("_created_on"));
    assertNotNull("check not null _etag property", json.get("_etag"));
    assertNotNull("check not null _lastupdated_on property", json.get("_lastupdated_on"));
    assertNotNull("check not null _collection-props-cached property", json.get("_collection-props-cached"));
    assertNotNull("check not null _returned property", json.get("_returned"));
    assertNull("check null _size property", json.get("_size"));
    assertNull("check 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:doc", embedded.get("rh:doc"));

    assertTrue("check _embedded.rh:doc to be a json array", (embedded.get("rh:doc") instanceof JsonArray));

    JsonArray rhdoc = (JsonArray) embedded.get("rh:doc");

    assertNotNull("check not null _embedded.rh:doc[0]", rhdoc.get(0));

    assertTrue("check _embedded.rh:coll[0] to be a json object", (rhdoc.get(0) instanceof JsonObject));

    JsonObject rhdoc0 = (JsonObject) rhdoc.get(0);

    assertNotNull("check not null _embedded.rh:doc[0]._id", rhdoc0.get("_id"));

    assertNotNull("check not null _embedded.rh:doc[0]._links", rhdoc0.get("_links"));

    assertTrue("check _embedded.rh:doc[0]._links to be a json object",
            (rhdoc0.get("_links") instanceof JsonObject));

    JsonObject rhdoc0Links = (JsonObject) rhdoc0.get("_links");

    assertNotNull("check not null _embedded.rh:doc[0]._links.self", rhdoc0Links.get("self"));

    assertTrue("check _embedded.rh:doc[0]._links.self to be a json object",
            (rhdoc0Links.get("self") instanceof JsonObject));

    JsonObject rhdb0LinksSelf = (JsonObject) rhdoc0Links.get("self");

    assertNotNull("check not null _embedded.rh:doc[0]._links.self.href", rhdb0LinksSelf.get("href"));

    assertTrue("check _embedded.rh:doc[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:doc[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"));
    if (!uri.equals(collection1UriRemappedCollection)) {
        assertNotNull("check not null rh:db", links.get("rh:db"));
    } else {
        assertNull("check null rh:db", links.get("rh:db"));
    }

    assertNotNull("check not null rh:paging", links.get("rh:paging"));
    assertNotNull("check not null curies", links.get("curies"));
}

From source file:me.vertretungsplan.parser.BaseParser.java

protected String httpGet(String url, String encoding, Map<String, String> headers)
        throws IOException, CredentialInvalidException {
    Request request = Request.Get(url).connectTimeout(15000).socketTimeout(15000);
    if (headers != null) {
        for (Entry<String, String> entry : headers.entrySet()) {
            request.addHeader(entry.getKey(), entry.getValue());
        }/*www.ja v a2  s . co m*/
    }
    return executeRequest(encoding, request);
}

From source file:com.evon.injectTemplate.InjectTemplateFilter.java

private void loadContentTemplate(TemplateBean template, String domain, Integer port, boolean https,
        HttpServletRequest httpRequest) throws Exception {
    HTMLInfoBean htmlInfo = templates.get("/" + template.path);

    String sport = (port == null) ? "" : ":" + String.valueOf(port);

    String url = htmlInfo.getProtocol() + "://" + domain + sport + "/" + template.path;

    Request request = Request.Get(url);

    Enumeration<String> headerNames = httpRequest.getHeaderNames();

    while (headerNames.hasMoreElements()) {
        String name = headerNames.nextElement();

        Enumeration<String> headerValues = httpRequest.getHeaders(name);
        while (headerValues.hasMoreElements()) {
            String value = headerValues.nextElement();
            request = request.addHeader(name, value);
        }/*from  w  w  w.  j av a 2s. c o  m*/
    }

    String content = request.execute().returnContent().asString();

    Pattern pattern = Pattern.compile("<INJECT[ ]{1,}selector=[\"'](.*?)[\"']/>",
            Pattern.CASE_INSENSITIVE + Pattern.DOTALL);

    Matcher matcher = pattern.matcher(content);

    List<String> selectors = new ArrayList<String>();

    while (matcher.find()) {
        String tagInject = matcher.group(0);
        String selector = matcher.group(1);
        selectors.add(selector);
        content = content.replace(tagInject, "<INJECT selector='" + selector + "'/>");
    }

    String key = null;

    if (template.cache.equals("SESSION")) {
        String cookiesNames = getCookieHashs(httpRequest);
        key = template.path + cookiesNames;
    } else {
        key = template.path;
    }

    HtmlContentBean contentBean = new HtmlContentBean();
    contentBean.setContent(content);
    contentBean.setLastAccess(System.currentTimeMillis());
    htmlContents.remove(key);
    htmlContents.put(key, contentBean);
    htmlInfo.setSelectors(selectors);
}

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

private void simpleHeaderTest(String url) throws IOException {
    final Response response = Request.Get(url).connectTimeout(1000).execute();
    final HttpResponse httpResponse = response.returnResponse();
    assertThat(httpResponse.getFirstHeader(HttpHeaders.Names.USER_AGENT).getValue(), is("Mule 3.6.0"));
    assertThat(isDateValid(httpResponse.getFirstHeader(HttpHeaders.Names.DATE).getValue()), is(true));
}

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

@Test
public void setXForwardedForHeader() throws Exception {
    handlerExtender = null;/*from   w  ww  .  j a va 2s. c o  m*/

    Response response = Request.Get(getProxyUrl("")).connectTimeout(RECEIVE_TIMEOUT).execute();
    HttpResponse httpResponse = response.returnResponse();
    assertThat(httpResponse.getStatusLine().getStatusCode(), is(200));

    assertThat(getFirstReceivedHeader(X_FORWARDED_FOR), startsWith("/127.0.0.1:"));
}

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

@When("^\"([^\"]*)\" downloads \"([^\"]*)\" with a bad authentication token$")
public void getDownloadWithBadToken(String username, String attachmentId) throws Exception {
    String blobId = blobIdByAttachmentId.get(attachmentId);
    response = Request.Get(//from w  ww  .  j a v a 2s. c  om
            mainStepdefs.baseUri().setPath("/download/" + blobId).addParameter("access_token", "bad").build())
            .execute().returnResponse();
}

From source file:org.talend.components.dataprep.connection.DataPrepConnectionHandler.java

public List<Column> readSourceSchema() throws IOException {
    Request request = Request.Get(url + API_DATASETS + dataSetId + "/metadata");
    request.addHeader(authorisationHeader);

    DataPrepStreamMapper dataPrepStreamMapper = null;
    MetaData metaData;//  ww w.  j  av a 2  s .co m

    try {
        HttpResponse response = request.execute().returnResponse();
        if (returnStatusCode(response) != HttpServletResponse.SC_OK) {
            String moreInformation = extractResponseInformationAndConsumeResponse(response);
            LOGGER.error(messages.getMessage("error.retrieveSchemaFailed", moreInformation));
            throw new IOException(messages.getMessage("error.retrieveSchemaFailed", moreInformation));
        }
        dataPrepStreamMapper = new DataPrepStreamMapper(response.getEntity().getContent());
        metaData = dataPrepStreamMapper.getMetaData();
    } finally {
        if (dataPrepStreamMapper != null) {
            dataPrepStreamMapper.close();
        }
    }

    return metaData.getColumns();
}

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

@Override
public IndexStatus getIndex(String schema_name, String index_name) {
    UBuilder uriBuilder = new UBuilder("/indexes/", schema_name, "/", index_name);
    Request request = Request.Get(uriBuilder.build());
    return commonServiceRequest(request, null, null, IndexStatus.class, 200);
}

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

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

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

    try {//from www  .  j  a  v  a 2  s  .  co m
        mkdir(tempConf);
        cp(installation.config("elasticsearch.yml"), tempConf.resolve("elasticsearch.yml"));
        cp(installation.config("log4j2.properties"), tempConf.resolve("log4j2.properties"));

        // we have to disable Log4j from using JMX lest it will hit a security
        // manager exception before we have configured logging; this will fail
        // startup since we detect usages of logging before it is configured
        final String jvmOptions = "-Xms512m\n" + "-Xmx512m\n" + "-Dlog4j2.disable.jmx=true\n";
        append(tempConf.resolve("jvm.options"), jvmOptions);

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

        final Shell serverShell = new Shell();
        serverShell.getEnv().put("ES_PATH_CONF", tempConf.toString());
        serverShell.getEnv().put("ES_JAVA_OPTS", "-XX:-UseCompressedOops");

        Archives.runElasticsearch(installation, serverShell);

        final String nodesResponse = makeRequest(Request.Get("http://localhost:9200/_nodes"));
        assertThat(nodesResponse, containsString("\"heap_init_in_bytes\":536870912"));
        assertThat(nodesResponse, containsString("\"using_compressed_ordinary_object_pointers\":\"false\""));

        Archives.stopElasticsearch(installation);

    } finally {
        rm(tempConf);
    }
}

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

@Test
public void requestThread() throws Exception {
    Request.Get(getProxyUrl("")).connectTimeout(RECEIVE_TIMEOUT).execute();
    SensingNullRequestResponseMessageProcessor sensingMessageProcessor = getSensingNullRequestResponseMessageProcessor();
    assertThat(sensingMessageProcessor.requestThread.getName(), containsString(requestThreadNameSubString));
}