List of usage examples for org.apache.http.client.fluent Request Get
public static Request Get(final String uri)
From source file:core.net.DriveRequest.java
/** * Retrieves file and folder metadata//from ww w .j a v a2 s .c om * @param path The relative path to the file or folder * @return JSON String * @throws URISyntaxException Invalid URI * @throws IOException Bad request */ public String list(String ID) throws URISyntaxException, IOException { URI uri; uri = Param.create().setUrl(ROOT_META).setParam(MAX_RESULTS, RESULTS_LIMIT_VALUE).buildURI(); String struri = uri.toString(); struri = setquery(struri, ID); struri = settoken(struri, token.getToken().toString()); System.out.println(struri); return Request.Get(struri).execute().returnContent().asString(); }
From source file:rxweb.RxJavaServerTests.java
@Test public void writeBuffer() throws IOException { server.get("/test", (request, response) -> response.status(Status.OK) .content(Observable.just(ByteBuffer.wrap("This is a test!".getBytes(StandardCharsets.UTF_8))))); String content = Request.Get("http://localhost:8080/test").execute().returnContent().asString(); Assert.assertEquals("This is a test!", content); }
From source file:ijfx.service.remote.DefaultLoginService.java
@Override public Task<Boolean> login(final String email, final String password) { Task<Boolean> task = new Task() { @Override//from w w w . j a v a 2 s. c o m protected Boolean call() throws Exception { int response = Request.Get(server + API_USER) .bodyString(JSONUtils.generateJSON(EMAIL, email, PASSWORD, password), ContentType.APPLICATION_JSON) .execute().returnResponse().getStatusLine().getStatusCode(); return response == 200; } }; ImageJFX.getThreadPool().submit(task); return task; }
From source file:io.bitgrillr.gocddockerexecplugin.utils.GoTestUtils.java
/** * Schedules the named pipeline to run./*from www . j a v a 2s. c o m*/ * * @param pipeline Name of the Pipeline to run. * @return Counter of the pipeline instance scheduled. * @throws GoError If Go.CD returns a non 2XX response. * @throws IOException If a communication error occurs. * @throws InterruptedException If something has gone horribly wrong. */ public static int runPipeline(String pipeline) throws GoError, IOException, InterruptedException { final Response scheduleResponse = executor .execute(Request.Post(PIPELINES + pipeline + "/schedule").addHeader("Confirm", "true")); final int scheduleStatus = scheduleResponse.returnResponse().getStatusLine().getStatusCode(); if (scheduleStatus != HttpStatus.SC_ACCEPTED) { throw new GoError(scheduleStatus); } Thread.sleep(5 * 1000); final HttpResponse historyResponse = executor.execute(Request.Get(PIPELINES + pipeline + "/history")) .returnResponse(); final int historyStatus = historyResponse.getStatusLine().getStatusCode(); if (historyStatus != HttpStatus.SC_OK) { throw new GoError(historyStatus); } final JsonArray pipelineInstances = Json.createReader(historyResponse.getEntity().getContent()).readObject() .getJsonArray("pipelines"); JsonObject lastPipelineInstance = pipelineInstances.getJsonObject(0); for (JsonValue pipelineInstance : pipelineInstances) { if (pipelineInstance.asJsonObject().getInt("counter") > lastPipelineInstance.getInt("counter")) { lastPipelineInstance = pipelineInstance.asJsonObject(); } } return lastPipelineInstance.getInt("counter"); }
From source file:org.wildfly.swarm.https.test.HttpsTest.java
@Test @RunAsClient/*from w w w . j a va 2s . c om*/ public void hello() throws IOException, GeneralSecurityException { SSLContext sslContext = SSLContexts.custom().loadTrustMaterial((TrustStrategy) (chain, authType) -> true) .build(); try (CloseableHttpClient httpClient = HttpClients.custom().setSSLContext(sslContext).build()) { String response = Executor.newInstance(httpClient).execute(Request.Get("https://localhost:8443/")) .returnContent().asString(); assertThat(response).contains("Hello on port 8443, secure: true"); } }
From source file:io.gravitee.gateway.standalone.RoundRobinLoadBalancingSingleTest.java
@Test public void call_round_robin_lb_single_endpoint() throws Exception { Request request = Request.Get("http://localhost:8082/echo/helloworld"); int calls = 20; for (int i = 0; i < calls; i++) { Response response = request.execute(); HttpResponse returnResponse = response.returnResponse(); assertEquals(HttpStatus.SC_OK, returnResponse.getStatusLine().getStatusCode()); String workerHeader = returnResponse.getFirstHeader("worker").getValue(); assertEquals("worker#0", workerHeader); }/*from w w w.j a v a 2 s .c o m*/ }
From source file:io.gravitee.gateway.standalone.MultiTenantNotConfiguredGatewayTest.java
@Test public void call_undeployed_api() throws Exception { URI target = new URIBuilder("http://localhost:8082/test/my_team").build(); Response response = Request.Get(target).execute(); HttpResponse returnResponse = response.returnResponse(); assertEquals(HttpStatus.SC_NOT_FOUND, returnResponse.getStatusLine().getStatusCode()); }
From source file:es.uvigo.esei.dai.hybridserver.utils.TestUtils.java
/** * Realiza una peticin por GET y devuelve el contenido de la respuesta. * //from ww w.j a va 2s . com * La peticin se hace en UTF-8 y solicitando el cierre de la conexin. * * Este mtodo comprueba que el cdigo de respuesta HTTP sea 200 OK. * * @param url URL de la pgina solicitada. * @return contenido de la respuesta HTTP. * @throws IOException en el caso de que se produzca un error de conexin. */ public static String getContentWithType(String url, String contentType) throws IOException { final HttpResponse response = Request.Get(url).addHeader("Connection", "close") .addHeader("Content-encoding", "UTF-8").execute().returnResponse(); assertEquals(200, response.getStatusLine().getStatusCode()); assertEquals(contentType, response.getEntity().getContentType().getValue()); return EntityUtils.toString(response.getEntity()); }
From source file:io.gravitee.gateway.standalone.MultiTenantUnavailableGatewayTest.java
@Test public void call_get_query_params() throws Exception { URI target = new URIBuilder("http://localhost:8082/test/my_team").build(); Response response = Request.Get(target).execute(); HttpResponse returnResponse = response.returnResponse(); assertEquals(HttpStatus.SC_SERVICE_UNAVAILABLE, returnResponse.getStatusLine().getStatusCode()); }
From source file:au.csiro.casda.sodalint.Validator.java
/** * Retrieve the content from an address using a GET request. * //from w w w . j av a 2 s.com * @param address The address to be queried. * @return The content, or null if no content could be read. * @throws HttpResponseException If a non 200 response code is returned. * @throws UnsupportedEncodingException If the content does not have an XML format. * @throws IOException If the content could not be read. */ protected String getXmlContentFromUrl(String address) throws HttpResponseException, UnsupportedEncodingException, IOException { Response response = Request.Get(address).execute(); HttpResponse httpResponse = response.returnResponse(); StatusLine statusLine = httpResponse.getStatusLine(); final int statusCodeOk = 200; if (statusLine.getStatusCode() != statusCodeOk) { throw new HttpResponseException(statusLine.getStatusCode(), statusLine.getReasonPhrase()); } HttpEntity entity = httpResponse.getEntity(); if (entity == null) { return null; } ContentType contentType = ContentType.getOrDefault(entity); if (!ContentType.APPLICATION_XML.getMimeType().equals(contentType.getMimeType()) && !ContentType.TEXT_XML.getMimeType().equals(contentType.getMimeType())) { throw new UnsupportedEncodingException(contentType.toString()); } String content = readTextContent(entity); if (StringUtils.isBlank(content)) { return null; } return content; }