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.wildfly.swarm.microprofile.jwtauth.providers.ProvidersMergingTest.java

@RunAsClient
@Test/*from w  w w. j a va 2s .co  m*/
public void shouldOverrideGetResponseWithUsersProvider() throws Exception {
    String response = Request.Get("http://localhost:8080/mpjwt/providers")
            .setHeader("Authorization", "Bearer " + createToken("MappedRole"))
            .setHeader("Accept", MediaType.TEXT_PLAIN).execute().returnContent().asString();
    Assert.assertEquals("overriden get response", response);
}

From source file:io.fabric8.elasticsearch.plugin.HttpsProxyClientCertAuthenticatorIntegrationTest.java

@Test
public void testProxyAuthWithSSL() throws Exception {
    SSLContext sslContext = new SSLContextBuilder()
            .loadTrustMaterial(new File(keyStoreFile), keystorePW.toCharArray(), new TrustSelfSignedStrategy())
            .build();// w w w .jav  a 2  s  .  c  o  m

    try (CloseableHttpClient httpclient = HttpClients.custom().setSSLContext(sslContext)
            .setSSLHostnameVerifier(new HostnameVerifier() {

                @Override
                public boolean verify(String hostname, SSLSession session) {
                    return true;
                }

            }).build()) {
        Executor ex = Executor.newInstance(httpclient);
        Response response = ex.execute(Request.Get("https://localhost:9200/blahobar.234324234/logs/1")
                .addHeader("Authorization", String.format("Bearer %s", token))
                .addHeader("X-Proxy-Remote-User", proxyUser));
        System.out.println(response.returnContent().asString());
    } catch (Exception e) {
        System.out.println(e);
        fail("Test Failed");
    }
}

From source file:com.easarrive.aws.client.cloudsearch.AmazonCloudSearchClient.java

/**
 * Execute a search and return result.// www .  j  a  va  2s  .  c o  m
 *
 * @param query search query to be executed.
 * @return result of the search.
 * @throws AmazonCloudSearchRequestException
 * @throws IllegalStateException
 * @throws AmazonCloudSearchInternalServerException
 */
public AmazonCloudSearchResult search(AmazonCloudSearchQuery query) throws IllegalStateException,
        AmazonCloudSearchRequestException, AmazonCloudSearchInternalServerException {
    if (this.getSearchEndpoint() == null || this.getSearchEndpoint().trim().length() < 1) {
        throw new AmazonCloudSearchRequestException("URI is null.");
    }
    AmazonCloudSearchResult result = null;
    String responseBody = null;
    try {
        Response response = Request
                .Get("https://" + this.getSearchEndpoint() + "/2013-01-01/search?" + query.build())
                .useExpectContinue().version(HttpVersion.HTTP_1_1)
                .addHeader("Content-Type", ContentType.APPLICATION_JSON.getMimeType())
                .addHeader("Accept", ContentType.APPLICATION_JSON.getMimeType()).execute();

        HttpResponse resp = response.returnResponse();
        int statusCode = resp.getStatusLine().getStatusCode();
        int statusType = statusCode / 100;
        if (statusType == 4) {
            throw new AmazonCloudSearchRequestException(statusCode + "", responseBody);
        } else if (statusType == 5) {
            throw new AmazonCloudSearchInternalServerException(
                    "Internal Server Error. Please try again as this might be a transient error condition.");
        }

        responseBody = inputStreamToString(resp.getEntity().getContent());
        result = Jackson.fromJsonString(responseBody, AmazonCloudSearchResult.class);
    } catch (ClientProtocolException e) {
        throw new AmazonCloudSearchInternalServerException(e);
    } catch (IOException e) {
        throw new AmazonCloudSearchInternalServerException(e);
    } catch (Exception e) {
        throw new AmazonCloudSearchInternalServerException(e);
    }

    return result;
}

From source file:io.gravitee.gateway.platforms.jetty.JettyEmbeddedContainerTest.java

@Test
public void doHttpGet() throws IOException {
    Request request = Request.Get("http://localhost:8082/test");
    Response response = request.execute();
    HttpResponse returnResponse = response.returnResponse();

    //assertEquals(HttpStatus.SC_BAD_REQUEST, returnResponse.getStatusLine().getStatusCode());
}

From source file:com.qwazr.crawler.web.client.WebCrawlerSingleClient.java

@Override
public WebCrawlStatus getSession(String session_name, Boolean local, String group, Integer msTimeout) {
    UBuilder uriBuilder = new UBuilder("/crawler/web/sessions/", session_name).setParameters(local, group,
            msTimeout);/*from  w  w  w.  j a  v  a2  s.  c om*/
    Request request = Request.Get(uriBuilder.build());
    return commonServiceRequest(request, null, null, WebCrawlStatus.class, 200);
}

From source file:org.wildfly.swarm.microprofile.jwtauth.PrincipalLeakTest.java

@RunAsClient
@Test//from   w w  w .  j a  v a2  s. c om
public void subjectShouldNotLeakToNonSecuredRequest() throws Exception {
    // project-no-roles-props.yml restricts the number of worker threads to 1,
    // that is, all requests are processed by the same single thread

    String response = Request.Get("http://localhost:8080/mpjwt/subject/secured")
            .setHeader("Authorization", "Bearer " + createToken("MappedRole")).execute().returnContent()
            .asString();
    assertThat(response).isEqualTo(TokenUtils.SUBJECT);

    Content content = Request.Get("http://localhost:8080/mpjwt/subject/unsecured").execute().returnContent();
    assertThat(content).isNull();
}

From source file:com.opensearchserver.client.v1.WebCrawlerApi1.java

/**
 * Crawl an URL and return data/*from w  w  w  . j a va  2s . c  o  m*/
 * 
 * @param indexName
 *            The name of the index
 * @param url
 *            The URL to crawl
 * @param msTimeOut
 *            The timeout in milliseconds *
 * @return the result of the crawl
 * @throws IOException
 *             if any IO error occurs
 * @throws URISyntaxException
 *             if the URI is not valid
 */
public CommonListResult<List<FieldValueList1>> crawlWithData(String indexName, String url, Integer msTimeOut)
        throws IOException, URISyntaxException {
    URIBuilder uriBuilder = client.getBaseUrl("index/", indexName, "/crawler/web/crawl")
            .addParameter("url", url).addParameter("returnData", "true");
    Request request = Request.Get(uriBuilder.build());
    return client.execute(request, null, msTimeOut, LISTCRAWL_TYPEREF, 200);
}

From source file:com.m3958.apps.anonymousupload.integration.java.FileUploadTest.java

@Test
public void testPostOne() throws ClientProtocolException, IOException, URISyntaxException {

    File f = new File("README.md");

    Assert.assertTrue(f.exists());//w w w  .ja  v  a2 s  . com

    String c = Request.Post(new URIBuilder().setScheme("http").setHost("localhost").setPort(8080).build())
            .body(MultipartEntityBuilder.create()
                    .addBinaryBody("afile", f, ContentType.MULTIPART_FORM_DATA, f.getName()).build())
            .execute().returnContent().asString();

    String url = c.trim();
    Assert.assertTrue(url.endsWith(".md"));

    String cc = Request.Get(url).execute().returnContent().asString();
    Assert.assertTrue(cc.contains("vertx runmod"));

    testComplete();
}

From source file:com.qwazr.database.TableSingleClient.java

@Override
public Set<String> list(Integer msTimeOut, Boolean local) {
    UBuilder uriBuilder = new UBuilder("/table").setParameterObject("local", local);
    Request request = Request.Get(uriBuilder.build());
    return commonServiceRequest(request, null, null, SetStringTypeRef, 200);
}

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

@Test
public void testPutCollection() throws Exception {
    try {/*  w  w  w.  j ava  2 s  .  com*/
        Response resp;

        // *** PUT tmpdb
        resp = adminExecutor.execute(Request.Put(dbTmpUri).bodyString("{a:1}", halCT)
                .addHeader(Headers.CONTENT_TYPE_STRING, Representation.HAL_JSON_MEDIA_TYPE));
        check("check put db", resp, HttpStatus.SC_CREATED);

        // try to put without etag
        resp = adminExecutor.execute(Request.Put(dbTmpUri).bodyString("{a:1}", halCT)
                .addHeader(Headers.CONTENT_TYPE_STRING, Representation.HAL_JSON_MEDIA_TYPE));
        check("check put tmp db without etag", resp, HttpStatus.SC_CONFLICT);

        // try to put with wrong etag
        resp = adminExecutor.execute(Request.Put(dbTmpUri).bodyString("{a:1}", halCT)
                .addHeader(Headers.CONTENT_TYPE_STRING, Representation.HAL_JSON_MEDIA_TYPE)
                .addHeader(Headers.IF_MATCH_STRING, "pippoetag"));
        check("check put tmp db with wrong etag", resp, HttpStatus.SC_PRECONDITION_FAILED);

        resp = adminExecutor.execute(Request.Get(dbTmpUri).addHeader(Headers.CONTENT_TYPE_STRING,
                Representation.HAL_JSON_MEDIA_TYPE));

        JsonObject content = JsonObject.readFrom(resp.returnContent().asString());

        String etag = content.get("_etag").asObject().get("$oid").asString();

        // try to put with correct etag
        resp = adminExecutor.execute(Request.Put(dbTmpUri).bodyString("{b:2}", halCT)
                .addHeader(Headers.CONTENT_TYPE_STRING, Representation.HAL_JSON_MEDIA_TYPE)
                .addHeader(Headers.IF_MATCH_STRING, etag));
        check("check put tmp db with correct etag", resp, HttpStatus.SC_OK);

        resp = adminExecutor.execute(Request.Get(dbTmpUri).addHeader(Headers.CONTENT_TYPE_STRING,
                Representation.HAL_JSON_MEDIA_TYPE));

        content = JsonObject.readFrom(resp.returnContent().asString());
        assertNull("check put content", content.get("a"));
        assertNotNull("check put content", content.get("b"));
        assertTrue("check put content", content.get("b").asInt() == 2);
    } finally {
        mongoClient.dropDatabase(dbTmpName);
    }
}