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.PatchDocumentIT.java
@Test public void testPatchDocument() throws Exception { try {//w ww. ja va 2s. 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); // *** 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); // *** PUT tmpdoc resp = adminExecutor.execute(Request.Put(documentTmpUri).bodyString("{a:1}", halCT) .addHeader(Headers.CONTENT_TYPE_STRING, Representation.HAL_JSON_MEDIA_TYPE)); check("check put tmp doc", resp, HttpStatus.SC_CREATED); // try to patch without body resp = adminExecutor.execute(Request.Patch(documentTmpUri).addHeader(Headers.CONTENT_TYPE_STRING, Representation.HAL_JSON_MEDIA_TYPE)); check("check patch tmp doc without etag", resp, HttpStatus.SC_NOT_ACCEPTABLE); // try to patch without etag resp = adminExecutor.execute(Request.Patch(documentTmpUri).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(documentTmpUri).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(documentTmpUri).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(documentTmpUri).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(documentTmpUri).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); } finally { mongoClient.dropDatabase(dbTmpName); } }
From source file:biz.dfch.j.clickatell.ClickatellClient.java
public AccountBalanceResponse getBalance() throws URISyntaxException, ClientProtocolException, IOException { String response = Request.Get(uriBalance.toString()).setHeader(headerApiVersion) .setHeader(headerContentType).setHeader(headerAccept).setHeader("Authorization", bearerToken) .execute().returnContent().asString(); ObjectMapper om = new ObjectMapper(); om.configure(SerializationFeature.FAIL_ON_EMPTY_BEANS, true); AccountBalanceResponse accountBalanceResponse = om.readValue(response, AccountBalanceResponse.class); return accountBalanceResponse; }
From source file:org.wildfly.swarm.microprofile.jwtauth.ContentTypesTest.java
@RunAsClient @Test/*w w w . j ava2 s . co m*/ public void shouldNotGetPlainForForbiddenUser() throws Exception { int statusCode = Request.Get("http://localhost:8080/mpjwt/content-types") .setHeader("Authorization", "Bearer " + createToken("MappedRole2")) .setHeader("Accept", MediaType.TEXT_PLAIN).execute().returnResponse().getStatusLine() .getStatusCode(); Assert.assertEquals(403, statusCode); }
From source file:com.baifendian.swordfish.common.storm.StormRestUtil.java
/** * ????/*from w w w.ja v a 2 s .co m*/ */ public static TopologySummaryDto getTopologySummary() throws IOException { String res = Request.Get(getTopologySummaryUrl()).execute().returnContent().toString(); return JsonUtil.parseObject(res, TopologySummaryDto.class); }
From source file:org.n52.youngs.test.ElasticsearchSinkCswMappingIT.java
@Test public void store() throws Exception { Collection<SourceRecord> records = SourceRecordHelper.loadGetRecordsResponse( Resources.asByteSource(Resources.getResource("responses/dab-records-csw.xml")).openStream()); List<SinkRecord> mappedRecords = records.stream().map(mapper::map).collect(Collectors.toList()); boolean stored = sink.store(mappedRecords); Thread.sleep(1000);// w ww . j a v a 2s . com assertThat("all records stored", stored); String query = "http://localhost:9200/" + mapping.getIndex() + "/" + mapping.getType() + "/_search?q=*&size=100"; String searchAllResponse = Request.Get(query).execute().returnContent().asString(); assertThat("all records were added to the index", searchAllResponse, hasJsonPath("hits.total", is(mappedRecords.size()))); assertThat("ids are contains", searchAllResponse, allOf(containsString("urn:x-wmo:md:int.eumetsat::EO:EUM:DAT:METOP:NRP"), containsString("urn:x-wmo:md:int.eumetsat::EO:EUM:DAT:METOP:SEM"), containsString("urn:x-wmo:md:int.eumetsat::EO:EUM:DAT:MFG:CDS-IODC"), containsString("urn:x-wmo:md:int.eumetsat::EO:EUM:DAT:MULT:FDN"), containsString("urn:x-wmo:md:int.eumetsat::EO:EUM:DAT:METEOSAT:OSIDSSI"))); String id = "urn:x-wmo:md:int.eumetsat::EO:EUM:DAT:METOP:ORBITVIEW"; String recordResponse = Request .Get("http://localhost:9200/" + mapping.getIndex() + "/" + mapping.getType() + "/" + id).execute() .returnContent().asString(); assertThat("record is in index", recordResponse, hasJsonPath("_index", is(equalTo(mapping.getIndex())))); assertThat("record is found", recordResponse, hasJsonPath("_id", is(id))); assertThat("record is found", recordResponse, hasJsonPath("_source.type", is("series"))); }
From source file:org.wildfly.swarm.microprofile.jwtauth.ParametrizedPathsTest.java
@RunAsClient @Test/* w w w .j av a 2 s .c o m*/ public void shouldNotGetPlainForForbiddenUser() throws Exception { int statusCode = Request.Get("http://localhost:8080/mpjwt/parameterized-paths/my/hello/view") .setHeader("Authorization", "Bearer " + createToken("MappedRole")) .setHeader("Accept", MediaType.TEXT_PLAIN).execute().returnResponse().getStatusLine() .getStatusCode(); Assert.assertEquals(403, statusCode); }
From source file:com.enitalk.controllers.bots.FillWordsRunnable.java
@RabbitListener(queues = "words") public void process(Message msg) { try {//ww w .j a va2 s . c om ObjectNode word = (ObjectNode) jackson.readTree(msg.getBody()); if (mongo.count(Query.query(Criteria.where("id").is(word.path("id").asInt())), "words") > 0L) { return; } String f = env.getProperty("words.def"); String url = String.format(f, word.path("word").asText()); byte[] def = Request.Get(url).execute().returnContent().asBytes(); JsonNode defJson = jackson.readTree(def); word.set("def", defJson); word.put("i", redis.opsForValue().increment("wc", 1)); mongo.insert(jackson.convertValue(word, HashMap.class), "words"); } catch (Exception e) { logger.error(ExceptionUtils.getFullStackTrace(e)); } }
From source file:photosharing.api.conx.UploadFileDefinition.java
/** * get nonce as described with nonce <a href="http://ibm.co/1fG83gY">Get a * Cryptographic Key</a>/*from www .ja v a 2s . co m*/ * * @param bearer */ private String getNonce(String bearer, HttpServletResponse response) { String nonce = ""; // Build the Request Request get = Request.Get(getNonceUrl()); get.addHeader("Authorization", "Bearer " + bearer); 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(); // Session is no longer valid or access token is expired if (code == HttpStatus.SC_FORBIDDEN) { response.sendRedirect("./api/logout"); } // User is not authorized else if (code == HttpStatus.SC_UNAUTHORIZED) { response.setStatus(HttpStatus.SC_UNAUTHORIZED); } else if (code == HttpStatus.SC_OK) { InputStream in = hr.getEntity().getContent(); nonce = IOUtils.toString(in); } } catch (IOException e) { response.setHeader("X-Application-Error", e.getClass().getName()); response.setStatus(HttpStatus.SC_INTERNAL_SERVER_ERROR); logger.severe("IOException " + e.toString()); } return nonce; }
From source file:edu.jhuapl.dorset.http.apache.ApacheHttpClient.java
private Response get(HttpRequest request) throws IOException { Request apacheRequest = Request.Get(request.getUrl()); prepareRequest(apacheRequest);//from w w w . j a v a2 s.com return apacheRequest.execute(); }
From source file:photosharing.api.conx.PhotoDefinition.java
/** * retrieves a profile photo based on the person's key * //ww w.j a v a 2s. com * @see photosharing.api.base.APIDefinition#run(javax.servlet.http.HttpServletRequest, * javax.servlet.http.HttpServletResponse) */ @Override public void run(HttpServletRequest request, HttpServletResponse response) { /** * check if query is empty, send SC_PRECONDITION_FAILED - 412 */ String query = request.getParameter("key"); if (query == null || query.isEmpty()) { response.setStatus(HttpStatus.SC_PRECONDITION_FAILED); } else { /** * get the users bearer token */ HttpSession session = request.getSession(false); Object oData = session.getAttribute(OAuth20Handler.CREDENTIALS); if (oData == null) { logger.warning("OAuth20Data is null"); } OAuth20Data data = (OAuth20Data) oData; String bearer = data.getAccessToken(); try { /** * Example URL: * http://localhost:9080/photoSharing/api/photo?uid=key maps to * https://apps.collabservnext.com/profiles/photo.do * * and results in an image */ String apiUrl = getApiUrl(query); logger.info("api url is " + apiUrl); Request get = Request.Get(apiUrl); get.addHeader("Authorization", "Bearer " + bearer); Executor exec = ExecutorUtil.getExecutor(); Response apiResponse = exec.execute(get); HttpResponse hr = apiResponse.returnResponse(); /** * Check the status codes */ int code = hr.getStatusLine().getStatusCode(); // Session is no longer valid or access token is expired - 403 if (code == HttpStatus.SC_FORBIDDEN) { response.sendRedirect("./api/logout"); } // User is not authorized // SC_UNAUTHORIZED (401) else if (code == HttpStatus.SC_UNAUTHORIZED) { response.setStatus(HttpStatus.SC_UNAUTHORIZED); } // Content is returned // OK (200) else if (code == HttpStatus.SC_OK) { //Headers response.setContentType(hr.getFirstHeader("Content-Type").getValue()); response.setHeader("content-length", hr.getFirstHeader("content-length").getValue()); // Streams InputStream in = hr.getEntity().getContent(); IOUtils.copy(in, response.getOutputStream()); IOUtils.closeQuietly(in); IOUtils.closeQuietly(response.getOutputStream()); } else { // Unexpected Result response.setStatus(HttpStatus.SC_INTERNAL_SERVER_ERROR); } } catch (IOException e) { response.setHeader("X-Application-Error", e.getClass().getName()); response.setStatus(HttpStatus.SC_INTERNAL_SERVER_ERROR); logger.severe("Photo Definition - IOException " + e.toString()); } } }