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.HttpProxyTemplateTestCase.java
@Ignore @Test/*from ww w. j a va 2s . c o m*/ public void proxyProtocolHttp1_0() throws Exception { handlerExtender = new EchoRequestHandlerExtender() { @Override protected String selectRequestPartToReturn(org.eclipse.jetty.server.Request baseRequest) { return baseRequest.getProtocol(); } }; Response response = Request.Get(getProxyUrl("test?parameterName=parameterValue")) .version(HttpVersion.HTTP_1_0).connectTimeout(RECEIVE_TIMEOUT).execute(); HttpResponse httpResponse = response.returnResponse(); assertThat(httpResponse.getStatusLine().getStatusCode(), is(200)); assertThat(IOUtils.toString(httpResponse.getEntity().getContent()), is("HTTP/1.0")); }
From source file:io.fabric8.apps.infinispan.InfinispanServerKubernetesTest.java
/** * Method that gets a value by a key in url as param value. *//*from w w w . j av a 2s .c o m*/ private static String getMethod(String serverURL, String key) throws IOException { return Request.Get(serverURL + "/" + key).addHeader("Content-Type", "text/plain").execute().returnContent() .asString(); }
From source file:org.n52.youngs.test.ElasticsearchSinkTestmappingIT.java
private void assertEmptyNode() throws IOException { String allMappingsResponse = Request.Get("http://localhost:9200/_mapping/_all?pretty").execute() .returnContent().asString(); assertThat("response is empty", allMappingsResponse, not(containsString("mappings"))); StatusLine recordsStatus = Request .Head("http://localhost:9200/" + mapping.getIndex() + "/" + mapping.getType()).execute() .returnResponse().getStatusLine(); assertThat("records type is not available", recordsStatus.getStatusCode(), is(404)); StatusLine mtStatus = Request.Head("http://localhost:9200/" + mapping.getIndex() + "/mt").execute() .returnResponse().getStatusLine(); assertThat("metadata type is not available", mtStatus.getStatusCode(), is(404)); }
From source file:com.amazonaws.sample.entitlement.authorization.LoginWithAmazonOAuth2AuthorizationHandler.java
/** * Verify that the access token is valid and belongs to us. * @param accessToken Login with Amazon access token * @throws AuthorizationException// w ww. j a v a2s. c o m */ @Override Identity verifyAccessToken(String accessToken) throws AuthorizationException { try { ResponseContent r = Request .Get("https://api.amazon.com/auth/o2/tokeninfo?access_token=" + URLEncoder.encode(accessToken, "UTF-8")) .execute().handleResponse(new AllStatusesContentResponseHandler()); int statusCode = r.getStatusCode(); Map<String, String> m = new ObjectMapper().readValue(r.getContent("{}"), new TypeReference<Object>() { }); if (statusCode == HttpStatus.SC_OK) { if (!this.getOauthClientId().equals(m.get("aud"))) { // the access token is valid but it does not belong to us throw new OAuthBadTokenException("access token is invalid", AUTHORIZATION_TYPE); } // The response does not contain enough information to create an Identity object so null is returned. return null; } if (statusCode == HttpStatus.SC_BAD_REQUEST) { throw new OAuthBadRequestException(buildErrorMessageFromResponse(m, statusCode), AUTHORIZATION_TYPE); } if (statusCode >= 500) { throw new RuntimeException(PROVIDER_NAME + " encountered an error. Status code: " + statusCode); } throw new RuntimeException( "Unanticipated response from " + PROVIDER_NAME + ". Status code: " + statusCode); } catch (IOException e) { throw new RuntimeException(e); } }
From source file:com.qwazr.search.index.IndexSingleClient.java
@Override public List<TermDefinition> doAnalyzeQuery(String schema_name, String index_name, String field_name, String text) {/*from w w w . j ava2s. c o m*/ UBuilder uriBuilder = new UBuilder("/indexes/", schema_name, "/", index_name, "/fields/", field_name, "/analyzer/query"); uriBuilder.setParameter("text", text); Request request = Request.Get(uriBuilder.build()); return commonServiceRequest(request, null, null, TermDefinition.MapListTermDefinitionRef, 200); }
From source file:org.mule.module.http.functional.listener.HttpListenerConfigFunctionalTestCase.java
private HttpResponse callAndAssertStatus(String url, int expectedStatus) throws IOException { final Response response = Request.Get(url).connectTimeout(TIMEOUT).execute(); HttpResponse httpResponse = response.returnResponse(); assertThat(httpResponse, hasStatusCode(expectedStatus)); return httpResponse; }
From source file:io.hakbot.providers.appspider.AppSpiderProvider.java
@Override public void getResult(Job job) { // Retrieve the remote instance defined during initialization final RemoteInstance remoteInstance = getRemoteInstance(job); final String token = getJobProperty(job, "token"); // Create the URL where the report will be accessible from final String reportUrl = remoteInstance.getUrl().substring(0, remoteInstance.getUrl().lastIndexOf("/")) + "/Reports/" + token + "/VulnerabilitiesSummary.xml"; if (LOGGER.isDebugEnabled()) { LOGGER.debug("Job UUID: " + job.getUuid() + " - Downloading report from: " + reportUrl); }/*ww w . j a va 2 s . c o m*/ try { // Download report final Response response = Request.Get(reportUrl).execute(); final HttpResponse httpResponse = response.returnResponse(); final StatusLine statusLine = httpResponse.getStatusLine(); final HttpEntity entity = httpResponse.getEntity(); if (httpResponse.getStatusLine().getStatusCode() >= 300) { updateState(job, State.FAILED, "Unable to download report file. Status Code: " + statusLine.getStatusCode()); } // Convert result to byte array and save it final byte[] results = IOUtils.toByteArray(entity.getContent()); addArtifact(job, JobArtifact.Type.PROVIDER_RESULT, JobArtifact.MimeType.XML.value(), results, "VulnerabilitySummary_" + job.getUuid() + ".xml"); } catch (IOException e) { updateState(job, State.FAILED, "Unable to get scan result", e.getMessage()); } }
From source file:org.restheart.test.integration.DocIdTypeIT.java
@Test public void testPostCollectionString() throws Exception { try {//from www. j ava 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); URI collectionTmpUriInt = buildURI("/" + dbTmpName + "/" + collectionTmpName, new NameValuePair[] { new BasicNameValuePair(DOC_ID_TYPE_KEY, DOC_ID_TYPE.STRING.name()) }); // *** POST tmpcoll resp = adminExecutor.execute(Request.Post(collectionTmpUriInt) .bodyString("{_id:{'$oid':'54c965cbc2e64568e235b711'}, a:1}", halCT) .addHeader(Headers.CONTENT_TYPE_STRING, Representation.HAL_JSON_MEDIA_TYPE)); HttpResponse httpResp = check("check post coll1 again", resp, HttpStatus.SC_CREATED); Header[] headers = httpResp.getHeaders(Headers.LOCATION_STRING); assertNotNull("check loocation header", headers); assertTrue("check loocation header", headers.length > 0); Header locationH = headers[0]; String location = locationH.getValue(); //assertTrue("check location header value", location.endsWith("/54c965cbc2e64568e235b711?id_type=STRING")); URI createdDocUri = URI.create(location); resp = adminExecutor.execute(Request.Get(createdDocUri).addHeader(Headers.CONTENT_TYPE_STRING, Representation.HAL_JSON_MEDIA_TYPE)); JsonObject content = JsonObject.readFrom(resp.returnContent().asString()); assertTrue("check created doc content", content.get("_id").asObject().get("$oid").asString().equals("54c965cbc2e64568e235b711")); assertNotNull("check created doc content", content.get("_etag")); assertNotNull("check created doc content", content.get("a")); assertTrue("check created doc content", content.get("a").asInt() == 1); // *** filter - case 1 - with string id should not find it URI collectionTmpUriSearch = buildURI("/" + dbTmpName + "/" + collectionTmpName, new NameValuePair[] { new BasicNameValuePair("filter", "{'_id':'54c965cbc2e64568e235b711'}") }); resp = adminExecutor.execute(Request.Get(collectionTmpUriSearch).addHeader(Headers.CONTENT_TYPE_STRING, Representation.HAL_JSON_MEDIA_TYPE)); content = JsonObject.readFrom(resp.returnContent().asString()); assertTrue("check created doc content", content.get("_returned").asInt() == 0); // *** filter - case 1 - with oid id should find it collectionTmpUriSearch = buildURI("/" + dbTmpName + "/" + collectionTmpName, new NameValuePair[] { new BasicNameValuePair("filter", "{'_id':{'$oid':'54c965cbc2e64568e235b711'}}") }); resp = adminExecutor.execute(Request.Get(collectionTmpUriSearch).addHeader(Headers.CONTENT_TYPE_STRING, Representation.HAL_JSON_MEDIA_TYPE)); content = JsonObject.readFrom(resp.returnContent().asString()); assertTrue("check created doc content", content.get("_returned").asInt() == 1); } finally { mongoClient.dropDatabase(dbTmpName); } }
From source file:com.mywork.framework.util.RemoteHttpUtil.java
/** * ?getpost????/*from w ww.ja v a 2 s.c o m*/ */ public static String fetchSimpleHttpResponse(String method, String contentUrl, Map<String, String> headerMap, Map<String, String> bodyMap) throws IOException { Executor executor = Executor.newInstance(httpClient); if (HttpGet.METHOD_NAME.equalsIgnoreCase(method)) { String result = contentUrl; StringBuilder sb = new StringBuilder(); sb.append(contentUrl); if (bodyMap != null && !bodyMap.isEmpty()) { if (contentUrl.indexOf("?") > 0) { sb.append("&"); } else { sb.append("?"); } result = Joiner.on("&").appendTo(sb, bodyMap.entrySet()).toString(); } return executor.execute(Request.Get(result)).returnContent().asString(); } if (HttpPost.METHOD_NAME.equalsIgnoreCase(method)) { Request request = Request.Post(contentUrl); if (headerMap != null && !headerMap.isEmpty()) { for (Map.Entry<String, String> m : headerMap.entrySet()) { request.addHeader(m.getKey(), m.getValue()); } } if (bodyMap != null && !bodyMap.isEmpty()) { Form form = Form.form(); for (Map.Entry<String, String> m : bodyMap.entrySet()) { form.add(m.getKey(), m.getValue()); } request.bodyForm(form.build()); } return executor.execute(request).returnContent().asString(); } return null; }
From source file:org.mule.module.http.functional.listener.HttpListenerWorkerThreadingProfileTestCase.java
private void executeRequestInAnotherThread(final String url) { new Thread() { @Override//from ww w . ja v a 2s . com public void run() { try { httpClientExecutor.execute(Request.Get(url).connectTimeout(RECEIVE_TIMEOUT)); } catch (IOException e) { throw new RuntimeException(e); } } }.start(); }