List of usage examples for org.apache.http.client.fluent Request Get
public static Request Get(final String uri)
From source file:in.flipbrain.Utils.java
public static String httpGet(String fullUrl) { String res = null;//w w w .j av a 2 s .co m try { 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:me.vertretungsplan.additionalinfo.BaseAdditionalInfoParser.java
@SuppressWarnings("SameParameterValue") protected String httpGet(String url, String encoding) throws IOException { return new String(Request.Get(url).execute().returnContent().asBytes(), encoding); }
From source file:com.softinstigate.restheart.integrationtest.PutDBIT.java
@Test public void testPutCollection() throws Exception { try {//from w ww .j a va 2 s. c om 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").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); } }
From source file:org.restheart.test.integration.PatchDBIT.java
@Test public void testPatchDB() throws Exception { try {/*from ww w .j a va 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 patch without etag resp = adminExecutor.execute(Request.Patch(dbTmpUri).bodyString("{a:1}", halCT) .addHeader(Headers.CONTENT_TYPE_STRING, Representation.HAL_JSON_MEDIA_TYPE)); check("check patch tmp doc without etag", resp, HttpStatus.SC_CONFLICT); // try to patch with wrong etag resp = adminExecutor.execute(Request.Patch(dbTmpUri).bodyString("{a:1}", halCT) .addHeader(Headers.CONTENT_TYPE_STRING, Representation.HAL_JSON_MEDIA_TYPE) .addHeader(Headers.IF_MATCH_STRING, "pippoetag")); check("check patch 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)); JsonObject content = JsonObject.readFrom(resp.returnContent().asString()); String etag = content.get("_etag").asObject().get("$oid").asString(); // try to patch with correct etag resp = adminExecutor.execute(Request.Patch(dbTmpUri).bodyString("{b:2}", halCT) .addHeader(Headers.CONTENT_TYPE_STRING, Representation.HAL_JSON_MEDIA_TYPE) .addHeader(Headers.IF_MATCH_STRING, etag)); check("check patch tmp doc 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()); assertNotNull("check patched content", content.get("a")); assertNotNull("check patched content", content.get("b")); assertTrue("check patched content", content.get("a").asInt() == 1 && content.get("b").asInt() == 2); etag = content.get("_etag").asObject().get("$oid").asString(); // try to patch reserved field name resp = adminExecutor.execute(Request.Patch(dbTmpUri).bodyString("{_embedded:\"a\"}", halCT) .addHeader(Headers.CONTENT_TYPE_STRING, Representation.HAL_JSON_MEDIA_TYPE) .addHeader(Headers.IF_MATCH_STRING, etag)); content = JsonObject.readFrom(resp.returnContent().asString()); assertNotNull("check patched content", content.get("_embedded").asObject().get("rh:warnings").asArray()); } finally { mongoClient.dropDatabase(dbTmpName); } }
From source file:org.kie.smoke.wb.util.unit.GetIgnoreRule.java
@Override public Statement apply(Statement base, FrameworkMethod method, Object target) { Statement result = base;// w ww .j av a 2s. co m if (hasConditionalIgnoreAnnotation(method)) { String urlString = getGetUrl(target, method); String message = "Ignored because [GET] " + urlString + " failed."; boolean liveServer = false; try { new URL(urlString); // check that url is a valid url string liveServer = true; } catch (MalformedURLException e) { liveServer = false; message = "Ignored because [" + urlString + "] is not a valid URL."; } if (liveServer) { try { Response response = Request.Get(urlString).execute(); int code = response.returnResponse().getStatusLine().getStatusCode(); if (code > 401) { liveServer = false; message = "Ignored because [GET] " + urlString + " returned " + code; } } catch (HttpHostConnectException hhce) { liveServer = false; message = "Ignored because server is not available: " + hhce.getMessage(); } catch (Exception e) { liveServer = false; message = "Ignored because [GET] " + urlString + " threw: " + e.getMessage(); } } if (!liveServer) { result = new IgnoreStatement(message); } } return result; }
From source file:com.softinstigate.restheart.integrationtest.PatchDBIT.java
@Test public void testPatchDB() throws Exception { try {/* w w w. j a v a 2 s . co 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 patch without etag resp = adminExecutor.execute(Request.Patch(dbTmpUri).bodyString("{a:1}", halCT) .addHeader(Headers.CONTENT_TYPE_STRING, Representation.HAL_JSON_MEDIA_TYPE)); check("check patch tmp doc without etag", resp, HttpStatus.SC_CONFLICT); // try to patch with wrong etag resp = adminExecutor.execute(Request.Patch(dbTmpUri).bodyString("{a:1}", halCT) .addHeader(Headers.CONTENT_TYPE_STRING, Representation.HAL_JSON_MEDIA_TYPE) .addHeader(Headers.IF_MATCH_STRING, "pippoetag")); check("check patch 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)); JsonObject content = JsonObject.readFrom(resp.returnContent().asString()); String etag = content.get("_etag").asString(); // try to patch with correct etag resp = adminExecutor.execute(Request.Patch(dbTmpUri).bodyString("{b:2}", halCT) .addHeader(Headers.CONTENT_TYPE_STRING, Representation.HAL_JSON_MEDIA_TYPE) .addHeader(Headers.IF_MATCH_STRING, etag)); check("check patch tmp doc 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()); assertNotNull("check patched content", content.get("a")); assertNotNull("check patched content", content.get("b")); assertTrue("check patched content", content.get("a").asInt() == 1 && content.get("b").asInt() == 2); etag = content.get("_etag").asString(); // try to patch reserved field name resp = adminExecutor.execute(Request.Patch(dbTmpUri).bodyString("{_embedded:\"a\"}", halCT) .addHeader(Headers.CONTENT_TYPE_STRING, Representation.HAL_JSON_MEDIA_TYPE) .addHeader(Headers.IF_MATCH_STRING, etag)); content = JsonObject.readFrom(resp.returnContent().asString()); assertNotNull("check patched content", content.get("_embedded").asObject().get("rh:warnings").asArray()); } finally { mongoClient.dropDatabase(dbTmpName); } }
From source file:photosharing.api.bss.LogoutDefinition.java
/** * redirects the user to the logout SSO to destroy the login tokens and login sessions * /*from ww w . j a v a2 s .co m*/ * @see photosharing.api.conx.APIDefinition#run(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse) */ public void run(HttpServletRequest request, HttpServletResponse response) { Configuration config = Configuration.getInstance(request); String api = config.getValue(Configuration.BASEURL) + apiUrl; try { //Invalidating photosharing session on the AppServer and IBM Connections Cloud HttpSession session = request.getSession(false); if (session != null) { logger.info(session.getId() + " is being logged out"); Request get = Request.Get(api); try { Executor exec = ExecutorUtil.getExecutor(); Response apiResponse = exec.execute(get); HttpResponse hr = apiResponse.returnResponse(); /** * Check the status codes and if 200, convert to String */ int code = hr.getStatusLine().getStatusCode(); if (code == HttpStatus.SC_OK) { } else { logger.log(Level.SEVERE, "Exception Encountered with IBM Connections Cloud Session"); } } catch (IOException e) { //Catches Exception Related to a Request logger.log(Level.SEVERE, "Exception Encountered"); response.setHeader("X-Application-Error", className); response.setStatus(HttpStatus.SC_INTERNAL_SERVER_ERROR); } //Indvalidates the User's current session and logs them out session.invalidate(); request.logout(); //Sets the Status to SC_OK (Http Status Code 200) to indicate a successful logout response.setStatus(HttpStatus.SC_NO_CONTENT); } else { //Something bad has happened logger.log(Level.SEVERE, "Invalid Request"); response.setStatus(HttpStatus.SC_BAD_REQUEST); } } catch (Exception e) { logger.log(Level.SEVERE, "Exception Encountered - " + e.toString()); //Sets the Status to SC_INTERNAL_SERVER_ERROR (Http Status Code 500) //Indicates an issue with the Server response.setStatus(HttpStatus.SC_INTERNAL_SERVER_ERROR); } }
From source file:io.gravitee.gateway.standalone.QueryParametersTest.java
@Test public void call_get_query_params_emptyvalue() throws Exception { String query = ""; URI target = new URIBuilder("http://localhost:8082/test/my_team").addParameter("q", null).build(); Response response = Request.Get(target).execute(); HttpResponse returnResponse = response.returnResponse(); assertEquals(HttpStatus.SC_OK, returnResponse.getStatusLine().getStatusCode()); String responseContent = StringUtils.copy(returnResponse.getEntity().getContent()); assertEquals(query, responseContent); }
From source file:org.restheart.test.integration.DeleteCollectionIT.java
@Test public void testDeleteCollection() throws Exception { try {//from w w w. j a va 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); // *** PUT tmpcoll resp = adminExecutor.execute(Request.Put(collectionTmpUri).bodyString("{a:1}", halCT) .addHeader(Headers.CONTENT_TYPE_STRING, Representation.HAL_JSON_MEDIA_TYPE)); check("check put coll1", resp, HttpStatus.SC_CREATED); // try to delete without etag resp = adminExecutor.execute(Request.Delete(collectionTmpUri)); check("check delete tmp doc without etag", resp, HttpStatus.SC_CONFLICT); // try to delete with wrong etag resp = adminExecutor .execute(Request.Delete(collectionTmpUri).addHeader(Headers.IF_MATCH_STRING, "pippoetag")); check("check delete tmp doc with wrong etag", resp, HttpStatus.SC_PRECONDITION_FAILED); resp = adminExecutor.execute(Request.Get(collectionTmpUri).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(collectionTmpUri).addHeader(Headers.IF_MATCH_STRING, etag)); check("check delete tmp doc with correct etag", resp, HttpStatus.SC_NO_CONTENT); resp = adminExecutor.execute(Request.Get(collectionTmpUri).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:com.softinstigate.restheart.integrationtest.DeleteCollectionIT.java
@Test public void testDeleteCollection() throws Exception { try {/* w ww . ja v a 2s .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); // *** PUT tmpcoll resp = adminExecutor.execute(Request.Put(collectionTmpUri).bodyString("{a:1}", halCT) .addHeader(Headers.CONTENT_TYPE_STRING, Representation.HAL_JSON_MEDIA_TYPE)); check("check put coll1", resp, HttpStatus.SC_CREATED); // try to delete without etag resp = adminExecutor.execute(Request.Delete(collectionTmpUri)); check("check delete tmp doc without etag", resp, HttpStatus.SC_CONFLICT); // try to delete with wrong etag resp = adminExecutor .execute(Request.Delete(collectionTmpUri).addHeader(Headers.IF_MATCH_STRING, "pippoetag")); check("check delete tmp doc with wrong etag", resp, HttpStatus.SC_PRECONDITION_FAILED); resp = adminExecutor.execute(Request.Get(collectionTmpUri).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(collectionTmpUri).addHeader(Headers.IF_MATCH_STRING, etag)); check("check delete tmp doc with correct etag", resp, HttpStatus.SC_NO_CONTENT); resp = adminExecutor.execute(Request.Get(collectionTmpUri).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); } }