List of usage examples for org.apache.http.client.fluent Request Get
public static Request Get(final String uri)
From source file:com.softinstigate.restheart.integrationtest.ContentEncodingIT.java
@Test public void testGzipAcceptEncoding() throws Exception { Response resp = notDecompressingExecutor .execute(Request.Get(rootUri).addHeader(Headers.ACCEPT_ENCODING_STRING, Headers.GZIP.toString())); HttpResponse httpResp = resp.returnResponse(); assertNotNull(httpResp);/*from w ww. j a v a 2 s .c o m*/ HttpEntity entity = httpResp.getEntity(); assertNotNull(entity); StatusLine statusLine = httpResp.getStatusLine(); assertNotNull(statusLine); String content = EntityUtils.toString(entity); Header h = httpResp.getFirstHeader("Content-Encoding"); assertNotNull("check accept encoding header not null", h); assertEquals("check accept encoding header value", Headers.GZIP.toString(), h.getValue()); assertEquals("check status code", HttpStatus.SC_OK, statusLine.getStatusCode()); try { GZIPInputStream gzipis = new GZIPInputStream( new ByteArrayInputStream(content.getBytes(StandardCharsets.ISO_8859_1))); while (gzipis.read() > 0) { } } catch (Exception ex) { fail("check decompressing content"); } }
From source file:com.softinstigate.restheart.integrationtest.DeleteDBIT.java
@Test public void testDeleteDB() throws Exception { try {//from w w w. j a v a 2 s . c o m 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").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.SecurityAuthTokenIT.java
@Test public void testAuthToken() throws Exception { Response resp = adminExecutor.execute(Request.Get(rootUri)); HttpResponse httpResp = resp.returnResponse(); assertNotNull(httpResp);//ww w . java 2 s .c o m StatusLine statusLine = httpResp.getStatusLine(); assertNotNull(statusLine); assertEquals("check authorized", HttpStatus.SC_OK, statusLine.getStatusCode()); Header[] _authToken = httpResp.getHeaders(AUTH_TOKEN_HEADER.toString()); Header[] _authTokenValid = httpResp.getHeaders(AUTH_TOKEN_VALID_HEADER.toString()); Header[] _authTokenLocation = httpResp.getHeaders(AUTH_TOKEN_LOCATION_HEADER.toString()); assertNotNull("check not null auth token header", _authToken); assertNotNull("check not null auth token valid header", _authTokenValid); assertNotNull("check not null auth token location header", _authTokenLocation); assertTrue("check not empty array auth token header array ", _authToken.length == 1); assertTrue("check not empty array auth token valid header array", _authTokenValid.length == 1); assertTrue("check not empty array auth token location header array", _authTokenLocation.length == 1); assertTrue("check not empty array auth token header value not null or empty", _authToken[0] != null && _authToken[0].getValue() != null && !_authToken[0].getValue().isEmpty()); assertTrue("check not empty array auth token valid value not null or empty", _authTokenValid[0] != null && _authTokenValid[0].getValue() != null && !_authTokenValid[0].getValue().isEmpty()); assertTrue("check not empty array auth token location not null or empty", _authTokenLocation[0] != null && _authTokenLocation[0].getValue() != null && !_authTokenLocation[0].getValue().isEmpty()); Response resp2 = unauthExecutor.auth(new Credentials() { @Override public Principal getUserPrincipal() { return new BasicUserPrincipal("admin"); } @Override public String getPassword() { return _authToken[0].getValue(); } }).execute(Request.Get(rootUri)); HttpResponse httpResp2 = resp2.returnResponse(); assertNotNull(httpResp2); StatusLine statusLine2 = httpResp2.getStatusLine(); assertNotNull(statusLine2); assertEquals("check authorized via auth token", HttpStatus.SC_OK, statusLine2.getStatusCode()); }
From source file:org.wildfly.swarm.microprofile.jwtauth.ParametrizedPathsTest.java
@RunAsClient @Test/* www . j a v a 2s . c om*/ public void shouldGetHtmlForAllowedUser() throws Exception { String response = Request.Get("http://localhost:8080/mpjwt/parameterized-paths/my/hello/admin") .setHeader("Authorization", "Bearer " + createToken("MappedRole")) .setHeader("Accept", MediaType.TEXT_HTML).execute().returnContent().asString(); Assert.assertEquals("Admin accessed hello", response); }
From source file:org.ow2.proactive.procci.service.CloudAutomationVariablesClient.java
public String get(String key) { logger.debug("get " + key + " on " + requestUtils.getProperty(VARIABLES_ENDPOINT)); String url = getResourceUrl(key); try {/*from w ww .j a v a 2s .c o m*/ Response response = Request.Get(url).version(HttpVersion.HTTP_1_1).execute(); return requestUtils.readHttpResponse(response.returnResponse(), url, "GET"); } catch (IOException ex) { logger.error("Unable to get on " + getResourceUrl(key) + ", exception : " + ex.getMessage()); throw new ServerException(); } }
From source file:com.softinstigate.restheart.integrationtest.GetDocumentIT.java
private void testGetDocument(URI uri) throws Exception { Response resp = adminExecutor.execute(Request.Get(uri)); HttpResponse httpResp = resp.returnResponse(); assertNotNull(httpResp);/*from w w w . j a v a 2 s .c o 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("parsing received json"); } assertNotNull("check json not null", json); assertNotNull("check not null @etag property", json.get("_etag")); assertNotNull("check not null @lastupdated_on property", json.get("_lastupdated_on")); assertNotNull("check not null @created_on property", json.get("_created_on")); assertNotNull("check not null @_id property", json.get("_id")); assertEquals("check @_id value", document1Id, json.get("_id").asString()); assertNotNull("check not null a", json.get("a")); assertEquals("check a value", 1, json.get("a").asInt()); assertNotNull("check not null mtm links", json.get("_links").asObject().get("mtm")); assertNotNull("check not null mto links", json.get("_links").asObject().get("mto")); assertNotNull("check not null otm links", json.get("_links").asObject().get("otm")); assertNotNull("check not null oto links", json.get("_links").asObject().get("oto")); assertTrue("check mtm link", json.get("_links").asObject().get("mtm").asObject().get("href").asString() .endsWith("?filter={'mtm':{'$in':['doc2']}}")); assertTrue("check mto link", json.get("_links").asObject().get("mto").asObject().get("href").asString().endsWith("/doc2")); assertTrue("check otm link", json.get("_links").asObject().get("otm").asObject().get("href").asString() .endsWith("?filter={'otm':{'$in':['doc2']}}")); assertTrue("check oto link", json.get("_links").asObject().get("oto").asObject().get("href").asString().endsWith("/doc2")); String mtm = json.get("_links").asObject().get("mtm").asObject().get("href").asString(); String mto = json.get("_links").asObject().get("mto").asObject().get("href").asString(); String otm = json.get("_links").asObject().get("otm").asObject().get("href").asString(); String oto = json.get("_links").asObject().get("oto").asObject().get("href").asString(); URIBuilder ub = new URIBuilder(); String[] mtms = mtm.split("\\?"); String[] mtos = mtm.split("\\?"); String[] otms = mtm.split("\\?"); String[] otos = mtm.split("\\?"); URI _mtm = ub.setScheme(uri.getScheme()).setHost(uri.getHost()).setPort(uri.getPort()).setPath(mtms[0]) .setCustomQuery(mtms[1]).build(); URI _mto = ub.setScheme(uri.getScheme()).setHost(uri.getHost()).setPort(uri.getPort()).setPath(mtos[0]) .setCustomQuery(mtos[1]).build(); URI _otm = ub.setScheme(uri.getScheme()).setHost(uri.getHost()).setPort(uri.getPort()).setPath(otms[0]) .setCustomQuery(otms[1]).build(); URI _oto = ub.setScheme(uri.getScheme()).setHost(uri.getHost()).setPort(uri.getPort()).setPath(otos[0]) .setCustomQuery(otos[1]).build(); Response respMtm = adminExecutor.execute(Request.Get(_mtm)); HttpResponse httpRespMtm = respMtm.returnResponse(); assertNotNull("check not null get mtm response", httpRespMtm); assertEquals("check get mtm response status code", HttpStatus.SC_OK, httpRespMtm.getStatusLine().getStatusCode()); Response respMto = adminExecutor.execute(Request.Get(_mto)); HttpResponse httpRespMto = respMto.returnResponse(); assertNotNull("check not null get mto response", httpRespMto); assertEquals("check get mto response status code", HttpStatus.SC_OK, httpRespMto.getStatusLine().getStatusCode()); Response respOtm = adminExecutor.execute(Request.Get(_otm)); HttpResponse httpRespOtm = respOtm.returnResponse(); assertNotNull("check not null get otm response", httpRespOtm); assertEquals("check get otm response status code", HttpStatus.SC_OK, httpRespOtm.getStatusLine().getStatusCode()); Response respOto = adminExecutor.execute(Request.Get(_oto)); HttpResponse httpRespOto = respOto.returnResponse(); assertNotNull("check not null get oto response", httpRespOto); assertEquals("check get oto response status code", HttpStatus.SC_OK, httpRespOto.getStatusLine().getStatusCode()); }
From source file:org.mule.module.oauth2.internal.authorizationcode.functional.AbstractAuthorizationCodeBasicTestCase.java
@Test public void localAuthorizationUrlRedirectsToOAuthAuthorizationUrl() throws Exception { wireMockRule.stubFor(get(urlMatching(AUTHORIZE_PATH + ".*")).willReturn(aResponse().withStatus(200))); Request.Get(localAuthorizationUrl.getValue()).connectTimeout(RECEIVE_TIMEOUT).socketTimeout(RECEIVE_TIMEOUT) .execute();//w w w. j a v a 2 s.c o m final List<LoggedRequest> requests = findAll(getRequestedFor(urlMatching(AUTHORIZE_PATH + ".*"))); assertThat(requests.size(), is(1)); AuthorizationRequestAsserter.create((requests.get(0))).assertMethodIsGet() .assertClientIdIs(clientId.getValue()).assertRedirectUriIs(redirectUrl.getValue()) .assertResponseTypeIsCode(); }
From source file:org.restheart.test.integration.GetDocumentIT.java
private void testGetDocument(URI uri) throws Exception { Response resp = adminExecutor.execute(Request.Get(uri)); HttpResponse httpResp = resp.returnResponse(); assertNotNull(httpResp);//from w w w. j a v a2 s . com 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("parsing received json"); } assertNotNull("check json not null", json); assertNotNull("check not null _etag property", json.get("_etag")); assertNotNull("check not null _lastupdated_on property", json.get("_lastupdated_on")); if (ObjectId.isValid(json.get("_id").asString())) assertNotNull("check not null _created_on property", json.get("_created_on")); else assertNull("check null _created_on property", json.get("_created_on")); assertNotNull("check not null _id property", json.get("_id")); assertEquals("check _id value", document1Id, json.get("_id").asString()); assertNotNull("check not null a", json.get("a")); assertEquals("check a value", 1, json.get("a").asInt()); assertNotNull("check not null mtm links", json.get("_links").asObject().get("mtm")); assertNotNull("check not null mto links", json.get("_links").asObject().get("mto")); assertNotNull("check not null otm links", json.get("_links").asObject().get("otm")); assertNotNull("check not null oto links", json.get("_links").asObject().get("oto")); assertTrue("check mtm link", json.get("_links").asObject().get("mtm").asObject().get("href").asString() .endsWith("?filter={'_id':{'$in':['doc2']}}")); assertTrue("check mto link", json.get("_links").asObject().get("mto").asObject().get("href").asString().endsWith("/doc2")); assertTrue("check otm link", json.get("_links").asObject().get("otm").asObject().get("href").asString() .endsWith("?filter={'_id':{'$in':['doc2']}}")); assertTrue("check oto link", json.get("_links").asObject().get("oto").asObject().get("href").asString().endsWith("/doc2")); String mtm = json.get("_links").asObject().get("mtm").asObject().get("href").asString(); String mto = json.get("_links").asObject().get("mto").asObject().get("href").asString(); String otm = json.get("_links").asObject().get("otm").asObject().get("href").asString(); String oto = json.get("_links").asObject().get("oto").asObject().get("href").asString(); URIBuilder ub = new URIBuilder(); String[] mtms = mtm.split("\\?"); String[] mtos = mtm.split("\\?"); String[] otms = mtm.split("\\?"); String[] otos = mtm.split("\\?"); URI _mtm = ub.setScheme(uri.getScheme()).setHost(uri.getHost()).setPort(uri.getPort()).setPath(mtms[0]) .setCustomQuery(mtms[1]).build(); URI _mto = ub.setScheme(uri.getScheme()).setHost(uri.getHost()).setPort(uri.getPort()).setPath(mtos[0]) .setCustomQuery(mtos[1]).build(); URI _otm = ub.setScheme(uri.getScheme()).setHost(uri.getHost()).setPort(uri.getPort()).setPath(otms[0]) .setCustomQuery(otms[1]).build(); URI _oto = ub.setScheme(uri.getScheme()).setHost(uri.getHost()).setPort(uri.getPort()).setPath(otos[0]) .setCustomQuery(otos[1]).build(); Response respMtm = adminExecutor.execute(Request.Get(_mtm)); HttpResponse httpRespMtm = respMtm.returnResponse(); assertNotNull("check not null get mtm response", httpRespMtm); assertEquals("check get mtm response status code", HttpStatus.SC_OK, httpRespMtm.getStatusLine().getStatusCode()); Response respMto = adminExecutor.execute(Request.Get(_mto)); HttpResponse httpRespMto = respMto.returnResponse(); assertNotNull("check not null get mto response", httpRespMto); assertEquals("check get mto response status code", HttpStatus.SC_OK, httpRespMto.getStatusLine().getStatusCode()); Response respOtm = adminExecutor.execute(Request.Get(_otm)); HttpResponse httpRespOtm = respOtm.returnResponse(); assertNotNull("check not null get otm response", httpRespOtm); assertEquals("check get otm response status code", HttpStatus.SC_OK, httpRespOtm.getStatusLine().getStatusCode()); Response respOto = adminExecutor.execute(Request.Get(_oto)); HttpResponse httpRespOto = respOto.returnResponse(); assertNotNull("check not null get oto response", httpRespOto); assertEquals("check get oto response status code", HttpStatus.SC_OK, httpRespOto.getStatusLine().getStatusCode()); }
From source file:com.enitalk.controllers.bots.FillWordsRunnable.java
public void sendCandidates(String url, Integer type) { try {/*from w w w . ja va2 s .c o m*/ Response json = Request.Get(url).execute(); String rs = json.returnContent().asString(); JsonNode randomContent = jackson.readTree(rs); Iterator<JsonNode> els = randomContent.elements(); while (els.hasNext()) { ObjectNode el = (ObjectNode) els.next(); if (Character.isUpperCase(el.path("word").asText().charAt(0)) || StringUtils.contains(el.path("word").asText(), " ")) { els.remove(); } else { el.put("type", type); rabbit.send("words", MessageBuilder.withBody(jackson.writeValueAsBytes(el)).build()); } } } catch (Exception e) { logger.error(ExceptionUtils.getFullStackTrace(e)); } }
From source file:org.mule.module.http.functional.listener.HttpListenerLifecycleTestCase.java
@Test public void restartListener() throws Exception { HttpListener httpListener = (HttpListener) ((Flow) getFlowConstruct("testPathFlow")).getMessageSource(); httpListener.stop();//from w w w . ja v a2s.c o m httpListener.start(); final Response response = Request.Get(getLifecycleConfigUrl("/path/subpath")).execute(); final HttpResponse httoResponse = response.returnResponse(); assertThat(httoResponse.getStatusLine().getStatusCode(), is(200)); assertThat(IOUtils.toString(httoResponse.getEntity().getContent()), is("ok")); }