List of usage examples for org.apache.http.client.utils URIBuilder build
public URI build() throws URISyntaxException
From source file:com.flipkart.aesop.serializer.batch.reader.UserInfoServiceReader.java
/** * Returns a number of {@link UserInfo} instances looked up from a service end-point. * Note : The end-point and parameters used here are very specific to this sample. Also the code is mostly for testing and production * ready (no Http connection pools etc.) * @see org.trpr.platform.batch.spi.spring.reader.BatchItemStreamReader#batchRead(org.springframework.batch.item.ExecutionContext) *//*ww w . jav a2 s . c om*/ public UserInfo[] batchRead(ExecutionContext context) throws Exception, UnexpectedInputException, ParseException { if (!hasRun) { objectMapper.configure(DeserializationConfig.Feature.FAIL_ON_UNKNOWN_PROPERTIES, false); for (int i = 0; i < PHONE_NUMBERS.length; i++) { DefaultHttpClient httpclient = new DefaultHttpClient(); HttpGet executionGet = new HttpGet(SERVICE_URL); URIBuilder uriBuilder = new URIBuilder(executionGet.getURI()); uriBuilder.addParameter("primary_phone", PHONE_NUMBERS[i]); uriBuilder.addParameter("require", "{\"preferences\":true,\"addresses\":true}"); ((HttpRequestBase) executionGet).setURI(uriBuilder.build()); HttpResponse httpResponse = httpclient.execute(executionGet); String response = new String(EntityUtils.toByteArray(httpResponse.getEntity())); SearchResult searchResult = objectMapper.readValue(response, SearchResult.class); results[i] = searchResult.results[0]; // we take only the first result } hasRun = true; } else { if (modIndex < 0) { return null; } System.out.println("Modifiying response object at index : " + modIndex); results[modIndex].setFirst_name("Regu " + modIndex); results[modIndex].setLast_name("B " + modIndex); results[modIndex].setPrimary_email("regunathb@gmail.com" + modIndex); results[modIndex].setPrimary_phone("9886693892" + modIndex); if (results[modIndex].getPreferences() != null && results[modIndex].getPreferences().size() > 0) { Iterator<String> it = results[modIndex].getPreferences().keySet().iterator(); while (it.hasNext()) { String key = it.next(); UserPreferencesInfo upi = results[modIndex].getPreferences().get(key); Map<String, Object> values = new HashMap<String, Object>(); values.put("communication", "email"); values.put("address", "home"); upi.setValue(values); } } modIndex -= 1; } return results; }
From source file:com.anrisoftware.simplerest.owncloudocs.OwncloudOcsStatus.java
private URI getRequestURI0() throws URISyntaxException { URI baseUri = account.getBaseUri(); String extraPath = baseUri.getPath(); URIBuilder builder = new URIBuilder(baseUri); builder.setUserInfo(account.getUser(), account.getPassword()); String statusPath = String.format("%s%s", extraPath, propertiesProvider.getOwncloudStatusPath()); builder.setPath(statusPath);/*from w w w .ja va 2s .c om*/ return builder.build(); }
From source file:org.mobicents.servlet.restcomm.provisioning.number.bandwidth.BandwidthNumberProvisioningManager.java
private String buildOrdersUri() throws URISyntaxException { URIBuilder builder = new URIBuilder(this.uri); builder.setPath("/v1.0/accounts/" + this.accountId + "/orders"); return builder.build().toString(); }
From source file:com.axelor.studio.web.ReportBuilderController.java
private ActionResponse downloadPdf(String html, String fileName, Boolean printPageNo, ActionResponse response) throws URISyntaxException { URIBuilder builder = new URIBuilder("ws/htmlToPdf"); builder.addParameter("html", html); builder.addParameter("fileName", fileName); if (printPageNo != null && printPageNo) { builder.addParameter("printPageNo", "true"); }//from www . j a v a 2 s. com String url = builder.build().toString(); response.setView(ActionView.define(I18n.get("Print")).add("html", url).param("download", "true") .param("fileName", fileName).map()); return response; }
From source file:org.apache.ambari.server.view.ViewURLStreamProvider.java
private String addDoAs(String spec, String userName) throws IOException { if (spec.toLowerCase().contains(DO_AS_PARAM)) { throw new IllegalArgumentException("URL cannot contain \"" + DO_AS_PARAM + "\" parameter."); }/*from www . ja va 2 s . c om*/ try { URIBuilder builder = new URIBuilder(spec); builder.addParameter(DO_AS_PARAM, userName); return builder.build().toString(); } catch (URISyntaxException e) { throw new IOException(e); } }
From source file:com.michaeljones.httpclient.apache.ApacheMethodClient.java
@Override public String GetStringContent(String url, List<Pair<String, String>> queryParams) { try {/*from ww w. j a va 2 s. c om*/ HttpGet httpget = new HttpGet(url); // The Hadoop Web HDFS only serves json, but no harm in being explicit. httpget.setHeader("accept", "application/json"); URIBuilder builder = new URIBuilder(url); for (Pair<String, String> queryParam : queryParams) { builder.addParameter(queryParam.getFirst(), queryParam.getSecond()); } httpget.setURI(builder.build()); CloseableHttpResponse response = clientImpl.execute(httpget); try { HttpEntity entity = response.getEntity(); return EntityUtils.toString(entity); } finally { // I believe this releases the connection to the client pool, but does not // close the connection. response.close(); } } catch (IOException | URISyntaxException ex) { throw new RuntimeException("Apache method get string content: " + ex.getMessage()); } }
From source file:org.mobicents.servlet.restcomm.provisioning.number.bandwidth.BandwidthNumberProvisioningManager.java
private String buildDisconnectsUri() throws URISyntaxException { URIBuilder builder = new URIBuilder(this.uri); builder.setPath("/v1.0/accounts/" + this.accountId + "/disconnects"); return builder.build().toString(); }
From source file:com.kurtraschke.ctatt.gtfsrealtime.services.TrainTrackerDataService.java
public Positions fetchAllTrains(List<String> routes) throws MalformedURLException, IOException, TrainTrackerDataException, URISyntaxException { URIBuilder b = new URIBuilder("http://lapi.transitchicago.com/api/1.0/ttpositions.aspx"); b.addParameter("key", _trainTrackerKey); b.addParameter("rt", Joiner.on(',').join(routes)); CloseableHttpClient client = HttpClients.custom().setConnectionManager(_connectionManager).build(); HttpGet httpget = new HttpGet(b.build()); try (CloseableHttpResponse response = client.execute(httpget)) { HttpEntity entity = response.getEntity(); Positions p = _xmlMapper.readValue(entity.getContent(), Positions.class); if (p.errorCode != 0) { throw new TrainTrackerDataException(p.errorCode, p.errorName); }//from w w w . j a v a 2 s . co m return p; } }
From source file:com.dgpx.web.BaiduTTSBean.java
public CloseableHttpResponse doHttpGet(String url, Map<String, String> params, RequestConfig config) { initHttpClient();/*from ww w . j ava2 s . c o m*/ try { URIBuilder builder = new URIBuilder(url); if (params != null) { for (String k : params.keySet()) { builder.addParameter(k, params.get(k)); } } URI uri = builder.build(); HttpGet httpGet = new HttpGet(uri); if (config != null) { httpGet.setConfig(config); } CloseableHttpResponse response = httpClient.execute(httpGet); if (response.getStatusLine().getStatusCode() == HttpStatus.SC_OK) { return response; } } catch (IOException ex) { Logger.getLogger(BaiduTTSBean.class.getName()).log(Level.SEVERE, null, ex); return null; } catch (URISyntaxException ex) { Logger.getLogger(BaiduTTSBean.class.getName()).log(Level.SEVERE, null, ex); } return null; }