List of usage examples for org.apache.http.client.fluent Request Get
public static Request Get(final String uri)
From source file:org.mule.module.http.functional.proxy.HttpProxyTemplateErrorHandlingTestCase.java
@Test public void catchExceptionStrategy() throws Exception { HttpResponse response = Request.Get(getProxyUrl("catchExceptionStrategy")).connectTimeout(RECEIVE_TIMEOUT) .execute().returnResponse(); assertThat(response.getStatusLine().getStatusCode(), is(200)); assertThat(IOUtils.toString(response.getEntity().getContent()), equalTo(SERVICE_DOWN_MESSAGE)); SensingNullMessageProcessor processor = muleContext.getRegistry() .lookupObject(CATCH_SENSING_PROCESSOR_NAME); assertThat(processor.event, is(notNullValue())); }
From source file:junit.org.rapidpm.microservice.demo.ServletTest.java
@Test public void testServletGetReq002() throws Exception { final Content returnContent = Request.Get(url).execute().returnContent(); Assert.assertEquals("Hello World CDI Service", returnContent.asString()); // Request.Post("http://targethost/login") // .bodyForm(Form.form().add("username", "vip").add("password", "secret").build()) // .execute().returnContent(); }
From source file:org.obm.opush.HealthCheckTest.java
@Test public void testHealthCheckInstalled() throws Exception { mocksControl.replay();/*from w w w . ja va2 s . co m*/ opushServer.start(); HttpResponse response = Request .Get("http://localhost:" + opushServer.getHttpPort() + "/opush/healthcheck/java/version").execute() .returnResponse(); assertThat(response.getStatusLine().getStatusCode()).isEqualTo(HttpServletResponse.SC_OK); assertThat(IOUtils.toString(response.getEntity().getContent())) .isEqualTo(System.getProperty("java.version")); }
From source file:com.tpatterson.playground.work.FindAccounts.java
private String getResponseFor(String urlRequest) { String contents;/*from www . j ava 2 s. c o m*/ try { contents = Request.Get(urlRequest).execute().returnContent().asString(); } catch (IOException e) { throw new RuntimeException("Error in retrieving: " + urlRequest, e); } throwIfError(urlRequest, contents); return contents; }
From source file:org.mule.service.http.impl.functional.server.HttpServerClientTimeoutTestCase.java
@Test public void executingRequestsFinishesOnDispose() throws Exception { try {/*from w w w. j av a 2 s. c om*/ Request.Get(format("http://localhost:%s/%s", port.getValue(), "test")).connectTimeout(TIMEOUT) .socketTimeout(TIMEOUT).execute(); fail(); } catch (SocketTimeoutException ste) { // Expected } server.stop(); Future<?> disposeTask = newSingleThreadExecutor().submit(() -> { server.dispose(); server = null; }); requestLatch.countDown(); disposeTask.get(TIMEOUT, MILLISECONDS); responseLatch.await(TIMEOUT, MILLISECONDS); }
From source file:interactivenetworksmathematica.TopologyHandler.java
public String getStringFromURL(URL url) { try {/*from w w w.j a v a 2 s. c o m*/ System.out.print("getting url: " + url.toString()); return Request.Get(url.toString()).execute().returnContent().toString(); } catch (ClientProtocolException ex) { Logger.getLogger(TopologyHandler.class.getName()).log(Level.SEVERE, null, ex); } catch (IOException ex) { Logger.getLogger(TopologyHandler.class.getName()).log(Level.SEVERE, null, ex); } return ""; }
From source file:com.twosigma.beaker.r.rest.RShellRest.java
int getPortFromCore() throws IOException, ClientProtocolException { String password = System.getenv("beaker_core_password"); String auth = encoder.encodeBase64String(("beaker:" + password).getBytes("ASCII")); String response = Request.Get("http://127.0.0.1:" + corePort + "/rest/plugin-services/getAvailablePort") .addHeader("Authorization", "Basic " + auth).execute().returnContent().asString(); return Integer.parseInt(response); }
From source file:org.mule.module.http.functional.listener.HttpListenerLifecycleTestCase.java
@Test public void stoppedListenerConfigDoNotListen() throws Exception { HttpListenerConfig httpListenerConfig = muleContext.getRegistry().get("testLifecycleListenerConfig"); httpListenerConfig.stop();// w w w . j a v a 2s. c om expectedException.expect(ConnectException.class); Request.Get(getLifecycleConfigUrl("/path/subpath")).execute(); }
From source file:org.n52.youngs.harvest.KvpCswSource.java
@Override public Collection<SourceRecord> getRecords(long startPosition, long maxRecords, Report report) { log.debug("Requesting {} records from catalog starting at {}", maxRecords, startPosition); Collection<SourceRecord> records = Lists.newArrayList(); String recordsRequest = createRequest(startPosition, maxRecords); log.trace("GetRecords request: {}", recordsRequest); try {/*from w w w.j a va 2 s. c om*/ InputStream response = Request.Get(recordsRequest).execute().returnContent().asStream(); JAXBElement<GetRecordsResponseType> jaxb_response = unmarshaller.unmarshal(new StreamSource(response), GetRecordsResponseType.class); BigInteger numberOfRecordsReturned = jaxb_response.getValue().getSearchResults() .getNumberOfRecordsReturned(); log.debug("Got response with {} records", numberOfRecordsReturned); List<Object> nodes = jaxb_response.getValue().getSearchResults().getAny(); if (!nodes.isEmpty()) { log.trace("Found {} \"any\" nodes.", nodes.size()); nodes.stream().filter(n -> n instanceof Node).map(n -> (Node) n).map(n -> new NodeSourceRecord(n)) .forEach(records::add); } List<JAXBElement<? extends AbstractRecordType>> jaxb_records = jaxb_response.getValue() .getSearchResults().getAbstractRecord(); if (!jaxb_records.isEmpty()) { log.trace("Found {} \"AbstractRecordType\" records.", jaxb_records.size()); DocumentBuilder db = DocumentBuilderFactory.newInstance().newDocumentBuilder(); jaxb_records.stream().map(type -> { return getNode(type, context, db); }).filter(Objects::nonNull).map(n -> new NodeSourceRecord(n)).forEach(records::add); } } catch (IOException | JAXBException | ParserConfigurationException e) { log.error("Could not retrieve records using url {}", recordsRequest, e); report.addMessage(String.format("Error retrieving record from endpoint %s: %s", this, e)); } return records; }
From source file:org.restheart.test.integration.PatchDocumentIT.java
@Test public void testPatchDocument() throws Exception { try {//from w w w. j av a 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").asObject().get("$oid").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); } }