List of usage examples for org.apache.http.client.fluent Request Get
public static Request Get(final String uri)
From source file:org.wildfly.swarm.servlet.jpa.jta.test.ServletJpaJtaTest.java
@Test @RunAsClient/*from w w w .j av a2 s.c om*/ @InSequence(5) public void emptyAgain() throws IOException { String result = Request.Get("http://localhost:8080/").execute().returnContent().asString().trim(); assertThat(result).isEmpty(); }
From source file:io.gravitee.gateway.standalone.ServiceUnavailableTest.java
@Test public void call_availableAndUnavailable_api() throws Exception { // Set the endpoint as down api.getProxy().getEndpoints().get(0).setStatus(Endpoint.Status.DOWN); Request request = Request.Get("http://localhost:8082/test/my_team"); Response response = request.execute(); HttpResponse returnResponse = response.returnResponse(); assertEquals(HttpStatus.SC_SERVICE_UNAVAILABLE, returnResponse.getStatusLine().getStatusCode()); // Set the endpoint as up api.getProxy().getEndpoints().get(0).setStatus(Endpoint.Status.UP); Request request2 = Request.Get("http://localhost:8082/test/my_team"); Response response2 = request2.execute(); HttpResponse returnResponse2 = response2.returnResponse(); assertEquals(HttpStatus.SC_OK, returnResponse2.getStatusLine().getStatusCode()); }
From source file:org.wildfly.swarm.microprofile.jwtauth.ContentTypesTest.java
@RunAsClient @Test/* w ww.ja v a 2 s . c o m*/ public void shouldNotGetHtmlForForbiddenUser() throws Exception { int statusCode = Request.Get("http://localhost:8080/mpjwt/content-types") .setHeader("Authorization", "Bearer " + createToken("MappedRole")) .setHeader("Accept", MediaType.TEXT_HTML).execute().returnResponse().getStatusLine() .getStatusCode(); Assert.assertEquals(403, statusCode); }
From source file:com.ibm.watson.ta.retail.ImportHousingServlet.java
/** * Forward the request to the index.jsp file * * @param req the req/* w w w . ja v a 2 s. co m*/ * @param resp the resp * @throws ServletException the servlet exception * @throws IOException Signals that an I/O exception has occurred. */ @Override protected void doGet(HttpServletRequest req, final HttpServletResponse resp) throws ServletException, IOException { logger.info("forwarding..."); req.setCharacterEncoding("UTF-8"); try { String queryStr = req.getQueryString(); String url = baseURL; if (queryStr != null) { url += "?" + queryStr; } URI uri = new URI(url).normalize(); Request newReq = Request.Get(uri); newReq.addHeader("Authorization", "Basic c2ltcGx5cmV0czpzaW1wbHlyZXRz"); logger.log(Level.SEVERE, "My custom log:" + queryStr); Executor executor = Executor.newInstance(); Response response = executor.execute(newReq); HttpResponse httpResponse = response.returnResponse(); resp.setStatus(httpResponse.getStatusLine().getStatusCode()); ServletOutputStream servletOutputStream = resp.getOutputStream(); httpResponse.getEntity().writeTo(servletOutputStream); servletOutputStream.flush(); servletOutputStream.close(); } catch (Exception e) { // Log something and return an error message logger.log(Level.SEVERE, "got error: " + e.getMessage(), e); resp.setStatus(HttpStatus.SC_BAD_GATEWAY); } }
From source file:org.wildfly.swarm.microprofile.jwtauth.ParametrizedPathsTest.java
@RunAsClient @Test// w w w .j a v a 2s .co m public void shouldNotGetHtmlForForbiddenUser() throws Exception { int statusCode = Request.Get("http://localhost:8080/mpjwt/parameterized-paths/my/hello/admin") .setHeader("Authorization", "Bearer " + createToken("MappedRole2")) .setHeader("Accept", MediaType.TEXT_HTML).execute().returnResponse().getStatusLine() .getStatusCode(); Assert.assertEquals(403, statusCode); }
From source file:com.ykun.commons.utils.http.HttpClientUtils.java
public static String get(String url, Header[] headers, Map<String, String> params) { return execute(Request.Get(parse(url, params)).setHeaders(headers)); }
From source file:es.uvigo.esei.dai.hybridserver.utils.TestUtils.java
/** * Realiza una peticin por GET y devuelve el cdigo de la respuesta HTTP. * // w w w . jav a 2 s . c o m * 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 cdigo de la respuesta HTTP. * @throws IOException en el caso de que se produzca un error de conexin. */ public static int getStatus(String url) throws IOException { return Request.Get(url).addHeader("Connection", "close").addHeader("Content-encoding", "UTF-8").execute() .returnResponse().getStatusLine().getStatusCode(); }
From source file:io.gravitee.gateway.platforms.jetty.JettyEmbeddedContainerTest.java
@Test public void doHttp404() throws IOException { Request request = Request.Get("http://localhost:8082/unknow"); Response response = request.execute(); HttpResponse returnResponse = response.returnResponse(); assertEquals(HttpStatusCode.NOT_FOUND_404, returnResponse.getStatusLine().getStatusCode()); }
From source file:com.force.deploy.tools.utils.LogItem.java
public String getRawLog(String serviceEndPoint, String sid) { try {/*from w w w . jav a 2 s . c om*/ serviceEndPoint = serviceEndPoint.replace("/Soap/T/", "/data/v"); serviceEndPoint = serviceEndPoint.substring(0, serviceEndPoint.lastIndexOf("/")); serviceEndPoint = serviceEndPoint + "/tooling/sobjects/ApexLog/" + id.get() + "/Body/"; String rawLog = Request.Get(serviceEndPoint).addHeader("Authorization", "Bearer " + sid).execute() .returnContent().asString(); return rawLog; } catch (Exception ex) { System.out.println("ex" + ex.getMessage()); return ""; } }
From source file:com.softinstigate.restheart.integrationtest.GetCollectionIT.java
@Test public void testGetCollectionCountAndPaging() throws Exception { LOG.info("@@@ testGetCollectionCountAndPaging URI: " + docsCollectionUriCountAndPaging); Response resp = adminExecutor.execute(Request.Get(docsCollectionUriCountAndPaging)); HttpResponse httpResp = resp.returnResponse(); assertNotNull(httpResp);/*from w w w. j a va 2 s.c om*/ 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 not null _link", json.get("_links")); assertTrue("check _link to be a json object", (json.get("_links") instanceof JsonObject)); assertEquals("check _returned value to be 2", 2, json.get("_returned").asInt()); assertEquals("check _size value to be 10", 10, json.get("_size").asInt()); assertEquals("check _total_pages value to be 5", 5, json.get("_total_pages").asInt()); JsonObject links = (JsonObject) json.get("_links"); assertNotNull("check not null self", links.get("self")); assertNotNull("check not null rh:db", links.get("rh:db")); assertNotNull("check not null rh:paging", links.get("rh:paging")); assertNotNull("check not null next", links.get("next")); assertNotNull("check not null first", links.get("first")); assertNotNull("check not null last", links.get("last")); assertNotNull("check not null previous", links.get("previous")); Response respSelf = adminExecutor.execute(Request .Get(docsCollectionUriCountAndPaging.resolve(links.get("self").asObject().get("href").asString()))); HttpResponse httpRespSelf = respSelf.returnResponse(); assertNotNull("check not null get self response", httpRespSelf); assertEquals("check get self response status code", HttpStatus.SC_OK, httpRespSelf.getStatusLine().getStatusCode()); Response respRhdb = adminExecutor.execute(Request.Get( docsCollectionUriCountAndPaging.resolve(links.get("rh:db").asObject().get("href").asString()))); HttpResponse httpRespRhdb = respRhdb.returnResponse(); assertNotNull("check not null rh:doc self response", httpRespRhdb); assertEquals("check get rh:doc response status code", HttpStatus.SC_OK, httpRespRhdb.getStatusLine().getStatusCode()); Response respNext = adminExecutor.execute(Request .Get(docsCollectionUriCountAndPaging.resolve(links.get("next").asObject().get("href").asString()))); HttpResponse httpRespNext = respNext.returnResponse(); assertNotNull("check not null get self response", httpRespNext); assertEquals("check get self response status code", HttpStatus.SC_OK, httpRespSelf.getStatusLine().getStatusCode()); Response respPrevious = adminExecutor.execute(Request.Get( docsCollectionUriCountAndPaging.resolve(links.get("previous").asObject().get("href").asString()))); HttpResponse httpRespPrevious = respPrevious.returnResponse(); assertNotNull("check not null get previous response", httpRespPrevious); assertEquals("check get self previous status code", HttpStatus.SC_OK, httpRespSelf.getStatusLine().getStatusCode()); Response respFirst = adminExecutor .execute(Request.Get(dbUriPaging.resolve(links.get("first").asObject().get("href").asString()))); HttpResponse respRespFirst = respFirst.returnResponse(); assertNotNull("check not null get first response", respRespFirst); assertEquals("check get self first status code", HttpStatus.SC_OK, respRespFirst.getStatusLine().getStatusCode()); Response respLast = adminExecutor .execute(Request.Get(dbUriPaging.resolve(links.get("last").asObject().get("href").asString()))); HttpResponse httpRespLast = respLast.returnResponse(); assertNotNull("check not null get last response", httpRespLast); assertEquals("check get last response status code", HttpStatus.SC_OK, httpRespLast.getStatusLine().getStatusCode()); }