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.googlesource.gerrit.plugins.auditsl4j.LoggerAuditToJsonTest.java

@Test
public void testHttpJsonAudit() throws Exception {
    AuditWriterToStringList auditStrings = getPluginInstance(AuditWriterToStringList.class);

    Request.Get(webUrl + "config/server/version").execute().returnResponse();

    assertThat(waitFor(() -> auditStrings.strings.size() == 1)).isTrue();

    String auditJsonString = auditStrings.strings.get(0);
    assertThat(auditJsonString).contains(Version.getVersion());
    JsonObject auditJson = new Gson().fromJson(auditJsonString, JsonObject.class);
    assertThat(auditJson).isNotNull();// ww w.  j  a v  a 2 s.c  o  m
}

From source file:com.jaspersoft.studio.server.utils.HttpUtils.java

public static Request get(String url, ServerProfile sp) throws HttpException, IOException {
    System.out.println(url);/*from w  w w  . jav a  2s .  c om*/
    return HttpUtils.setRequest(Request.Get(url), sp);
}

From source file:com.qwazr.graph.GraphSingleClient.java

@Override
public GraphResult getGraph(String graphName) {
    UBuilder uBuilder = new UBuilder(GRAPH_PREFIX, graphName);
    Request request = Request.Get(uBuilder.build());
    return commonServiceRequest(request, null, null, GraphResult.class, 200);
}

From source file:com.qwazr.scripts.ScriptSingleClient.java

@Override
public List<ScriptRunStatus> runScript(String scriptPath, Boolean local, String group, Integer msTimeout,
        TargetRuleEnum rule) {//from   www.  j a  v a 2s . c  o  m
    UBuilder uriBuilder = new UBuilder(SCRIPT_PREFIX_RUN, scriptPath).setParameters(local, group, msTimeout)
            .setParameter("rule", rule);
    Request request = Request.Get(uriBuilder.build());
    return commonServiceRequest(request, null, null, ListRunStatusTypeRef, 200, 202);
}

From source file:org.trendafilov.odesk.notifier.connectivity.RequestHandler.java

public String get(SearchCriteria criteria) {
    String result = "";
    try {/* w  ww . j  ava  2 s . co  m*/
        result = Request.Get(buildUrl(criteria))
                .userAgent(Configuration.getInstance().getStringValue("profile.agent")).connectTimeout(5000)
                .socketTimeout(5000).execute().returnContent().asString();
    } catch (IOException e) {
        Logger.error(e, "Connection error");
    } catch (ConfigurationException e) {
        Logger.error(e, "Configuration error");
    }
    return result;
}

From source file:in.flipbrain.Utils.java

public static String httpGet(String uri, HashMap<String, String> params) {
    StringBuilder query = new StringBuilder();
    for (Map.Entry<String, String> entrySet : params.entrySet()) {
        String key = entrySet.getKey();
        String value = entrySet.getValue();
        query.append(URLEncoder.encode(key)).append("=");
        query.append(URLEncoder.encode(value)).append("&");
    }//from  ww  w  . j a v  a2s .  c  o m
    if (query.length() > 0) {
        query.insert(0, "?").insert(0, uri);
    }
    String res = null;
    try {
        String fullUrl = query.toString();
        logger.debug("Request URL: " + fullUrl);
        res = Request.Get(fullUrl).execute().returnContent().asString();
        logger.debug("Response: " + res);
    } catch (IOException e) {
        logger.fatal("Failed to process request. ", e);
    }
    return res;
}

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

@RunAsClient
@Test/* www.  ja  v  a 2 s. c  o  m*/
public void shouldGetHtmlForAllowedUser() throws Exception {
    String response = Request.Get("http://localhost:8080/mpjwt/content-types")
            .setHeader("Authorization", "Bearer " + createToken("MappedRole2"))
            .setHeader("Accept", MediaType.TEXT_HTML).execute().returnContent().asString();
    Assert.assertEquals(ContentTypesResource.HTML_RESPONSE, response);
}

From source file:com.softinstigate.restheart.integrationtest.SecurityIT.java

@Test
public void testGetUnauthenticated() throws Exception {
    // *** GET root
    Response resp = unauthExecutor.execute(Request.Get(rootUri));
    check("check get root unauthorized", resp, HttpStatus.SC_UNAUTHORIZED);

    // *** GET db
    resp = unauthExecutor.execute(Request.Get(dbUri));
    check("check get db unauthorized", resp, HttpStatus.SC_UNAUTHORIZED);

    // *** GET coll1
    resp = unauthExecutor.execute(Request.Get(collection1Uri));
    check("check get coll1 unauthorized", resp, HttpStatus.SC_OK);

    // *** GET doc1
    resp = unauthExecutor.execute(Request.Get(document1Uri));
    check("check get doc1 unauthorized", resp, HttpStatus.SC_OK);

    // *** GET coll2
    resp = unauthExecutor.execute(Request.Get(collection2Uri));
    check("check get coll2 unauthorized", resp, HttpStatus.SC_UNAUTHORIZED);

    // *** GET doc2
    resp = unauthExecutor.execute(Request.Get(document2Uri));
    check("check get doc2 unauthorized", resp, HttpStatus.SC_UNAUTHORIZED);

    // *** GET root with silent authorization (no auth challenge must be sent)
    resp = unauthExecutor.execute(Request.Get(rootUri).addHeader(SecurityHandler.SILENT_HEADER_KEY, ""));
    check("check get root unauthorized", resp, HttpStatus.SC_FORBIDDEN);

    resp = unauthExecutor.execute(Request.Get(rootUri).addHeader(SecurityHandler.SILENT_HEADER_KEY, ""));
    HttpResponse httpResp = resp.returnResponse();

    assertTrue("check get root unauthorized silent",
            httpResp.getHeaders(Headers.WWW_AUTHENTICATE_STRING).length == 0);
}

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

@Test
public void testDeleteDB() throws Exception {
    try {//  w  w  w .ja  v  a  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 delete without etag
        resp = adminExecutor.execute(Request.Delete(dbTmpUri));
        check("check delete tmp doc without etag", resp, HttpStatus.SC_CONFLICT);

        // try to delete with wrong etag
        resp = adminExecutor.execute(Request.Delete(dbTmpUri).addHeader(Headers.IF_MATCH_STRING, "pippoetag"));
        check("check delete tmp doc with wrong etag", resp, HttpStatus.SC_PRECONDITION_FAILED);

        resp = adminExecutor.execute(Request.Get(dbTmpUri).addHeader(Headers.CONTENT_TYPE_STRING,
                Representation.HAL_JSON_MEDIA_TYPE));
        //check("getting etag of tmp doc", resp, HttpStatus.SC_OK);

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

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

        // try to delete with correct etag
        resp = adminExecutor.execute(Request.Delete(dbTmpUri).addHeader(Headers.IF_MATCH_STRING, etag));
        check("check delete tmp doc with correct etag", resp, HttpStatus.SC_NO_CONTENT);

        resp = adminExecutor.execute(Request.Get(dbTmpUri).addHeader(Headers.CONTENT_TYPE_STRING,
                Representation.HAL_JSON_MEDIA_TYPE));
        check("check get deleted tmp doc", resp, HttpStatus.SC_NOT_FOUND);
    } finally {
        mongoClient.dropDatabase(dbTmpName);
    }
}

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

@Test
public void testGetUnauthenticated() throws Exception {
    // *** GET root
    Response resp = unauthExecutor.execute(Request.Get(rootUri));
    check("check get root unauthorized", resp, HttpStatus.SC_UNAUTHORIZED);

    // *** GET db
    resp = unauthExecutor.execute(Request.Get(dbUri));
    check("check get db unauthorized", resp, HttpStatus.SC_UNAUTHORIZED);

    // *** GET coll1
    resp = unauthExecutor.execute(Request.Get(collection1Uri));
    check("check get coll1 unauthorized", resp, HttpStatus.SC_OK);

    // *** GET doc1
    resp = unauthExecutor.execute(Request.Get(document1Uri));
    check("check get doc1 unauthorized", resp, HttpStatus.SC_OK);

    // *** GET coll2
    resp = unauthExecutor.execute(Request.Get(collection2Uri));
    check("check get coll2 unauthorized", resp, HttpStatus.SC_UNAUTHORIZED);

    // *** GET doc2
    resp = unauthExecutor.execute(Request.Get(document2Uri));
    check("check get doc2 unauthorized", resp, HttpStatus.SC_UNAUTHORIZED);

    // *** GET root with silent authorization (no auth challenge must be sent)
    resp = unauthExecutor//from  w w w . j  a  v a2 s .co  m
            .execute(Request.Get(rootUri).addHeader(SecurityHandlerDispacher.SILENT_HEADER_KEY, ""));
    check("check get root unauthorized", resp, HttpStatus.SC_FORBIDDEN);

    resp = unauthExecutor
            .execute(Request.Get(rootUri).addHeader(SecurityHandlerDispacher.SILENT_HEADER_KEY, ""));
    HttpResponse httpResp = resp.returnResponse();

    assertTrue("check get root unauthorized silent",
            httpResp.getHeaders(Headers.WWW_AUTHENTICATE_STRING).length == 0);
}