List of usage examples for org.apache.http.client.utils URIBuilder toString
@Override
public String toString()
From source file:org.loklak.api.search.TweetScraper.java
protected String prepareSearchUrl(String type) { URIBuilder url = null; String typeMedia = "tweets"; String midUrl = "search/"; if (this.since != null) { this.query = this.query + " " + "since:" + this.since; }/*from w w w . ja v a2s . com*/ if (this.until != null) { this.query = this.query + " " + "until:" + this.until; } if (this.filterList.contains("video") && this.filterList.size() == 1) { typeMedia = "video"; } try { url = new URIBuilder(this.baseUrl + midUrl); switch (type) { case "user": typeMedia = "users"; break; case "tweet": typeMedia = "tweets"; break; case "image": typeMedia = "images"; break; case "video": typeMedia = "videos"; break; default: typeMedia = "tweets"; break; } url.addParameter("f", typeMedia); url.addParameter("q", this.query); url.addParameter("vertical", "default"); url.addParameter("src", "typd"); } catch (URISyntaxException e) { DAO.log("Invalid Url: baseUrl = " + this.baseUrl + ", mid-URL = " + midUrl + ", query = " + this.query + ", type = " + type); } return url.toString(); }
From source file:teletype.model.vk.Auth.java
public void authorize() throws VKAuthException, IOException { // Phase 1. Send authorization request. // Opening OAuth Authorization Dialog URIBuilder uriBuilder = new URIBuilder(); uriBuilder.setScheme("https").setHost("oauth.vk.com").setPath("/authorize").setParameter("client_id", appID) .setParameter("scope", "messages,friends,status") .setParameter("redirect_uri", "https://oauth.vk.com/blank.html").setParameter("display", "wap") .setParameter("v", "5.28").setParameter("response_type", "token"); BasicCookieStore cookieStore = new BasicCookieStore(); HttpClient httpClient = HttpClientBuilder.create().setDefaultCookieStore(cookieStore).build(); URI uri = getUri(uriBuilder); HttpPost request = new HttpPost(uri); HttpResponse response = httpClient.execute(request); request.abort();// ww w. j a v a 2 s .c om // Get ip_h and to_h parameters for next request StringBuilder contentText = getContentText(response); String ip_h = parseResponse(contentText, "ip_h", 18); //System.out.println("ip_h : " + ip_h); String to_h = parseResponse(contentText, "=\"to\"", 212); //System.out.println("to_h : " + to_h); uriBuilder = new URIBuilder(); uriBuilder.setScheme("https").setHost("login.vk.com").setPath("/").setParameter("act", "login") .setParameter("soft", "1").setParameter("q", "1").setParameter("ip_h", ip_h) .setParameter("from_host", "oauth.vk.com").setParameter("to", to_h).setParameter("expire", "0") .setParameter("email", login).setParameter("pass", password); request = new HttpPost(getUri(uriBuilder)); response = httpClient.execute(request); request.abort(); //System.out.println("Incorrect login url: " + uriBuilder.toString()); // Phase 2. Providing Access Permissions // TODO: if got access request then call externall web browser. possible do it ourselves. // Phase 3. Open url with webengine and receiving "access_token". // It does not work with httpClient LoginControllerHelper.callHiddenWebBrowser(uriBuilder.toString()); //if (true) return; /* printHeader(response); // Phase 2. Got redirect to authorization page. // Filling the form and sending it. //String HeaderLocation = response.getFirstHeader("location").getValue(); request = new HttpPost(HeaderLocation); response = httpClient.execute(request); //System.out.println("==================>"); request.abort(); //String url = response.getFirstHeader("location").getValue(); // Phase 3. Got permissions request. // Open web browser and sending link there. //System.out.println("URL is: " + url); // Calling externall web browser. ControllerHelper.callHiddenWebBrowser(url); //ControllerHelper.callWebBrowser(url); /* * It works by calling external web-browser. * All redirects ok and gives the token. * But doesn't work using HttpClient. * Server redirects me to error page. * request = new HttpPost(url); response = httpClient.execute(request); System.out.println("Sending last ==================>\n"); HeaderLocation = response.getFirstHeader("location").getValue(); //String access_token = HeaderLocation.split("#")[1].split("&")[0].split("=")[1]; System.out.println("Header is: " + HeaderLocation); */ }
From source file:org.apache.ambari.server.controller.AmbariManagementControllerImpl.java
@Override public String getAmbariServerURI(String path) { if (masterProtocol == null || masterHostname == null || masterPort == null) { return null; }/*from www .j a v a 2 s .co m*/ URIBuilder uriBuilder = new URIBuilder(); uriBuilder.setScheme(masterProtocol); uriBuilder.setHost(masterHostname); uriBuilder.setPort(masterPort); uriBuilder.setPath(path); return uriBuilder.toString(); }
From source file:org.apache.ambari.server.controller.metrics.ganglia.GangliaPropertyProviderTest.java
@Test public void testPopulateManyResources() throws Exception { TestStreamProvider streamProvider = new TestStreamProvider("temporal_ganglia_data_1.txt"); TestGangliaHostProvider hostProvider = new TestGangliaHostProvider(); GangliaPropertyProvider propertyProvider = new GangliaHostPropertyProvider( PropertyHelper.getMetricPropertyIds(Resource.Type.Host), streamProvider, configuration, hostProvider, CLUSTER_NAME_PROPERTY_ID, HOST_NAME_PROPERTY_ID); Set<Resource> resources = new HashSet<Resource>(); // host//from w w w.ja v a 2 s. c o m Resource resource = new ResourceImpl(Resource.Type.Host); resource.setProperty(HOST_NAME_PROPERTY_ID, "domU-12-31-39-0E-34-E1.compute-1.internal"); resources.add(resource); resource = new ResourceImpl(Resource.Type.Host); resource.setProperty(HOST_NAME_PROPERTY_ID, "domU-12-31-39-0E-34-E2.compute-1.internal"); resources.add(resource); resource = new ResourceImpl(Resource.Type.Host); resource.setProperty(HOST_NAME_PROPERTY_ID, "domU-12-31-39-0E-34-E3.compute-1.internal"); resources.add(resource); // only ask for one property Map<String, TemporalInfo> temporalInfoMap = new HashMap<String, TemporalInfo>(); temporalInfoMap.put(PROPERTY_ID, new TemporalInfoImpl(10L, 20L, 1L)); Request request = PropertyHelper.getReadRequest(Collections.singleton(PROPERTY_ID), temporalInfoMap); Assert.assertEquals(3, propertyProvider.populateResources(resources, request, null).size()); URIBuilder uriBuilder = new URIBuilder(); uriBuilder.setScheme((configuration.isGangliaSSL() ? "https" : "http")); uriBuilder.setHost("domU-12-31-39-0E-34-E1.compute-1.internal"); uriBuilder.setPath("/cgi-bin/rrd.py"); uriBuilder.setParameter("c", "HDPJobTracker,HDPHBaseMaster,HDPResourceManager,HDPFlumeServer,HDPSlaves,HDPHistoryServer,HDPJournalNode,HDPTaskTracker,HDPHBaseRegionServer,HDPNameNode"); uriBuilder.setParameter("h", "domU-12-31-39-0E-34-E3.compute-1.internal,domU-12-31-39-0E-34-E1.compute-1.internal,domU-12-31-39-0E-34-E2.compute-1.internal"); uriBuilder.setParameter("m", "jvm.metrics.gcCount"); uriBuilder.setParameter("s", "10"); uriBuilder.setParameter("e", "20"); uriBuilder.setParameter("r", "1"); String expected = uriBuilder.toString(); Assert.assertEquals(expected, streamProvider.getLastSpec()); for (Resource res : resources) { Assert.assertEquals(2, PropertyHelper.getProperties(res).size()); Assert.assertNotNull(res.getPropertyValue(PROPERTY_ID)); } }
From source file:org.flowable.http.HttpActivityExecutor.java
public HttpResponse perform(CloseableHttpClient client, VariableContainer execution, final HttpRequest requestInfo, HttpRequestHandler httpRequestHandler, HttpResponseHandler httpResponseHandler, int socketTimeout, int connectTimeout, int connectionRequestTimeout) { HttpRequestBase request;//from w w w . j av a 2 s .co m CloseableHttpResponse response = null; try { if (httpRequestHandler != null) { httpRequestHandler.handleHttpRequest(execution, requestInfo, client); } } catch (Exception e) { throw new FlowableException("Exception while invoking HttpRequestHandler: " + e.getMessage(), e); } try { URIBuilder uri = new URIBuilder(requestInfo.getUrl()); switch (requestInfo.getMethod()) { case "GET": { request = new HttpGet(uri.toString()); break; } case "POST": { HttpPost post = new HttpPost(uri.toString()); if (requestInfo.getBody() != null) { post.setEntity(new StringEntity(requestInfo.getBody())); } request = post; break; } case "PUT": { HttpPut put = new HttpPut(uri.toString()); put.setEntity(new StringEntity(requestInfo.getBody())); request = put; break; } case "DELETE": { request = new HttpDelete(uri.toString()); break; } default: { throw new FlowableException(requestInfo.getMethod() + " HTTP method not supported"); } } if (requestInfo.getHeaders() != null) { setHeaders(request, requestInfo.getHeaders()); } setConfig(request, requestInfo, socketTimeout, connectTimeout, connectionRequestTimeout); if (requestInfo.getTimeout() > 0) { timer.schedule(new TimeoutTask(request), requestInfo.getTimeout()); } response = client.execute(request); HttpResponse responseInfo = new HttpResponse(); if (response.getStatusLine() != null) { responseInfo.setStatusCode(response.getStatusLine().getStatusCode()); responseInfo.setProtocol(response.getStatusLine().getProtocolVersion().toString()); responseInfo.setReason(response.getStatusLine().getReasonPhrase()); } if (response.getAllHeaders() != null) { responseInfo.setHeaders(getHeadersAsString(response.getAllHeaders())); } if (response.getEntity() != null) { responseInfo.setBody(EntityUtils.toString(response.getEntity())); } try { if (httpResponseHandler != null) { httpResponseHandler.handleHttpResponse(execution, responseInfo); } } catch (Exception e) { throw new FlowableException("Exception while invoking HttpResponseHandler: " + e.getMessage(), e); } return responseInfo; } catch (final ClientProtocolException e) { throw new FlowableException("HTTP exception occurred", e); } catch (final IOException e) { throw new FlowableException("IO exception occurred", e); } catch (final URISyntaxException e) { throw new FlowableException("Invalid URL exception occurred", e); } finally { if (response != null) { try { response.close(); } catch (Throwable e) { LOGGER.error("Could not close http response", e); } } } }
From source file:org.flowable.http.impl.HttpActivityBehaviorImpl.java
@Override public HttpResponse perform(final DelegateExecution execution, final HttpRequest requestInfo) { HttpRequestBase request = null;//from w ww . j a v a 2 s. co m CloseableHttpResponse response = null; ProcessEngineConfigurationImpl processEngineConfiguration = CommandContextUtil .getProcessEngineConfiguration(); try { if (httpServiceTask.getHttpRequestHandler() != null) { HttpRequestHandler httpRequestHandler = createHttpRequestHandler( httpServiceTask.getHttpRequestHandler(), processEngineConfiguration); httpRequestHandler.handleHttpRequest(execution, requestInfo, client); } } catch (Exception e) { throw new FlowableException("Exception while invoking HttpRequestHandler: " + e.getMessage(), e); } try { URIBuilder uri = new URIBuilder(requestInfo.getUrl()); switch (requestInfo.getMethod()) { case "GET": { request = new HttpGet(uri.toString()); break; } case "POST": { HttpPost post = new HttpPost(uri.toString()); post.setEntity(new StringEntity(requestInfo.getBody())); request = post; break; } case "PUT": { HttpPut put = new HttpPut(uri.toString()); put.setEntity(new StringEntity(requestInfo.getBody())); request = put; break; } case "DELETE": { HttpDelete delete = new HttpDelete(uri.toString()); request = delete; break; } default: { throw new FlowableException(requestInfo.getMethod() + " HTTP method not supported"); } } if (requestInfo.getHeaders() != null) { setHeaders(request, requestInfo.getHeaders()); } setConfig(request, requestInfo, CommandContextUtil.getProcessEngineConfiguration().getHttpClientConfig()); if (requestInfo.getTimeout() > 0) { timer.schedule(new TimeoutTask(request), requestInfo.getTimeout()); } response = client.execute(request); HttpResponse responseInfo = new HttpResponse(); if (response.getStatusLine() != null) { responseInfo.setStatusCode(response.getStatusLine().getStatusCode()); responseInfo.setProtocol(response.getStatusLine().getProtocolVersion().toString()); responseInfo.setReason(response.getStatusLine().getReasonPhrase()); } if (response.getAllHeaders() != null) { responseInfo.setHeaders(getHeadersAsString(response.getAllHeaders())); } if (response.getEntity() != null) { responseInfo.setBody(EntityUtils.toString(response.getEntity())); } try { if (httpServiceTask.getHttpResponseHandler() != null) { HttpResponseHandler httpResponseHandler = createHttpResponseHandler( httpServiceTask.getHttpResponseHandler(), processEngineConfiguration); httpResponseHandler.handleHttpResponse(execution, responseInfo); } } catch (Exception e) { throw new FlowableException("Exception while invoking HttpResponseHandler: " + e.getMessage(), e); } return responseInfo; } catch (final ClientProtocolException e) { throw new FlowableException("HTTP exception occurred", e); } catch (final IOException e) { throw new FlowableException("IO exception occurred", e); } catch (final URISyntaxException e) { throw new FlowableException("Invalid URL exception occurred", e); } catch (final FlowableException e) { throw e; } finally { if (response != null) { try { response.close(); } catch (Throwable e) { LOGGER.error("Could not close http response", e); } } } }
From source file:org.flowable.ui.admin.service.engine.AppDeploymentService.java
public JsonNode listDeployments(ServerConfig serverConfig, Map<String, String[]> parameterMap) { URIBuilder builder = null; try {//from w w w . ja va 2 s. co m builder = new URIBuilder("app-repository/deployments"); } catch (Exception e) { LOGGER.error("Error building uri", e); throw new FlowableServiceException("Error building uri", e); } for (String name : parameterMap.keySet()) { builder.addParameter(name, parameterMap.get(name)[0]); } HttpGet get = new HttpGet(clientUtil.getServerUrl(serverConfig, builder.toString())); return clientUtil.executeRequest(get, serverConfig); }