List of usage examples for org.apache.http.client.utils URIBuilder build
public URI build() throws URISyntaxException
From source file:com.github.tmyroadctfig.icloud4j.ICloudService.java
/** * Gets the trusted two-factor authentication devices for the current account. * * @return the list of trusted devices./*from w ww . ja v a 2 s . com*/ */ public List<TrustedDevice> getTrustedDevices() { try { URIBuilder uriBuilder = new URIBuilder(setupEndPoint + "/listDevices"); populateUriParameters(uriBuilder); URI uri = uriBuilder.build(); HttpGet httpGet = new HttpGet(uri); populateRequestHeadersParameters(httpGet); try (CloseableHttpResponse response = httpClient.execute(httpGet)) { TrustedDevices trustedDevices = ICloudUtils .fromJson(new StringResponseHandler().handleResponse(response), TrustedDevices.class); return Arrays.asList(trustedDevices.devices); } } catch (Exception e) { throw Throwables.propagate(e); } }
From source file:ph.com.globe.connect.Payment.java
/** * Build request url./*from ww w . j a v a 2s . c om*/ * * @param url target url * @return String * @throws ApiException api exception */ protected String buildUrl(String url) throws ApiException { // try parsing url try { // initialize url builder URIBuilder builder = new URIBuilder(url); // set access token parameter builder.setParameter("access_token", this.accessToken); // build the url url = builder.build().toString(); return url; } catch (URISyntaxException e) { // throw exception throw new ApiException(e.getMessage()); } }
From source file:com.singularity.ee.agent.systemagent.monitors.KeynoteMonitor.java
public URI getGraphDataURI(List<Integer> slotIdList) throws URISyntaxException { URIBuilder uriBuilder = getURIBuilder("getgraphdata"); uriBuilder.addParameter("slotidlist", StringUtils.join(slotIdList, ",")); uriBuilder.addParameter("bucket", Integer.toString(bucketSize)); uriBuilder.addParameter("timemode", "relative"); uriBuilder.addParameter("relativehours", "14400"); uriBuilder.addParameter("timezone", "UCT"); return uriBuilder.build(); }
From source file:com.palominolabs.crm.sf.rest.HttpApiClient.java
@Nonnull private URI getUriForPath(String path, List<NameValuePair> params) throws IOException { URIBuilder b = getUriBuilderForPath(path); for (NameValuePair param : params) { b.addParameter(param.getName(), param.getValue()); }/*w w w. j a v a 2s . co m*/ try { return b.build(); } catch (URISyntaxException e) { throw new IOException("Couldn't create URI", e); } }
From source file:com.github.tmyroadctfig.icloud4j.ICloudService.java
/** * Gets the iCloud storage usage.//from w w w. jav a 2s .c om * * @return the map of storage usage details. */ public Map<String, Object> getStorageUsage() { try { URIBuilder uriBuilder = new URIBuilder(setupEndPoint + "/storageUsageInfo"); populateUriParameters(uriBuilder); URI uri = uriBuilder.build(); HttpPost post = new HttpPost(uri); populateRequestHeadersParameters(post); try (CloseableHttpResponse response = httpClient.execute(post)) { Map<String, Object> result = new JsonToMapResponseHandler().handleResponse(response); if (Boolean.FALSE.equals(result.get("success"))) { throw new RuntimeException("Failed to get storage usage info: " + result.get("error")); } return result; } } catch (Exception e) { throw Throwables.propagate(e); } }
From source file:com.ibm.twitter.TwitterInsights.java
public TweetList getTweetList(String bookTitle, String bookAuthor) { TweetList returnedTweets = new TweetList(); try {/*from w w w .j av a2 s .c o m*/ CredentialsProvider credentialsProvider = new BasicCredentialsProvider(); credentialsProvider.setCredentials(new AuthScope(AuthScope.ANY_HOST, AuthScope.ANY_PORT), new UsernamePasswordCredentials(usernameTwitter, passwordTwitter)); CookieStore cookieStore = new BasicCookieStore(); CookieSpecProvider csf = new CookieSpecProvider() { @Override public CookieSpec create(HttpContext context) { return new DefaultCookieSpec() { @Override public void validate(Cookie cookie, CookieOrigin origin) throws MalformedCookieException { // Allow all cookies } }; } }; RequestConfig requestConfig = RequestConfig.custom().setCookieSpec("easy").setSocketTimeout(10 * 1000) .setConnectTimeout(10 * 1000).build(); CloseableHttpClient httpClient = HttpClientBuilder.create() .setDefaultCredentialsProvider(credentialsProvider).setDefaultCookieStore(cookieStore) .setDefaultCookieSpecRegistry(RegistryBuilder.<CookieSpecProvider>create() .register(CookieSpecs.DEFAULT, csf).register("easy", csf).build()) .setDefaultRequestConfig(requestConfig).build(); URIBuilder builder = new URIBuilder(); builder.setScheme("https").setHost(baseURLTwitter).setPath("/api/v1/messages/search") .setParameter("q", "\"" + bookTitle + "\"" + " AND " + "\"" + bookAuthor + "\"") .setParameter("size", "5"); URI uri = builder.build(); HttpGet httpGet = new HttpGet(uri); httpGet.setHeader("Content-Type", "text/plain"); HttpResponse httpResponse = httpClient.execute(httpGet); if (httpResponse.getStatusLine().getStatusCode() == 200) { BufferedReader rd = new BufferedReader( new InputStreamReader(httpResponse.getEntity().getContent(), "UTF-8")); // Read all the books from the best seller list ObjectMapper mapper = new ObjectMapper(); returnedTweets = mapper.readValue(rd, TweetList.class); } } catch (Exception e) { logger.error("Twitter error: {}", e.getMessage()); } return returnedTweets; }
From source file:com.anrisoftware.simplerest.owncloudocs.OwncloudOcsCreateShare.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()); addParameters(builder);/*from w ww. ja v a 2 s. c om*/ String statusPath = String.format("%s%s", extraPath, propertiesProvider.getOwncloudSharesPath()); builder.setPath(statusPath); return builder.build(); }
From source file:com.github.tmyroadctfig.icloud4j.ICloudService.java
/** * <p>Requests that a two-factor verification code be sent to the given trusted device. The value sent to the device * should be submitted to {@link #validateManualVerificationCode(TrustedDevice, String, char[])} for verification.</p> * * <p>Note: newer devices will automatically display a verification code without manually requesting one, and that * must be submitted via {@link }.</p> * * @param device the device to send the verification code to. *//*from www . j av a 2s .c om*/ public void sendManualVerificationCode(TrustedDevice device) { try { URIBuilder uriBuilder = new URIBuilder(setupEndPoint + "/sendVerificationCode"); populateUriParameters(uriBuilder); URI uri = uriBuilder.build(); HttpPost post = new HttpPost(uri); post.setEntity(new StringEntity(ICloudUtils.toJson(device), Consts.UTF_8.name())); populateRequestHeadersParameters(post); Map<String, Object> response = httpClient.execute(post, new JsonToMapResponseHandler()); if (!Boolean.TRUE.equals(response.get("success"))) { throw new IllegalStateException( "Failed to send verification code: " + response.get("errorMessage")); } } catch (Exception e) { throw Throwables.propagate(e); } }
From source file:mx.openpay.client.core.impl.DefaultHttpServiceClient.java
protected URI createUriWithParams(final String url, final Map<String, String> queryParams) throws IllegalArgumentException { URIBuilder builder = new URIBuilder(URI.create(url)); for (Entry<String, String> entry : queryParams.entrySet()) { if (entry.getValue() != null) { builder.addParameter(entry.getKey(), entry.getValue()); }//from ww w . ja v a 2 s.com } try { return builder.build(); } catch (URISyntaxException e) { throw new IllegalArgumentException(e); } }
From source file:org.talend.dataprep.api.service.command.dataset.DataSetList.java
private HttpRequestBase onExecute(Sort sort, Order order, String name, boolean certified, boolean favorite, boolean limit) { try {/*from ww w . j ava 2 s . c o m*/ URIBuilder uriBuilder = new URIBuilder(datasetServiceUrl + "/datasets"); uriBuilder.addParameter("sort", sort.camelName()); uriBuilder.addParameter("order", order.camelName()); uriBuilder.addParameter("name", name); uriBuilder.addParameter("certified", Boolean.toString(certified)); uriBuilder.addParameter("favorite", Boolean.toString(favorite)); uriBuilder.addParameter("limit", Boolean.toString(limit)); return new HttpGet(uriBuilder.build()); } catch (URISyntaxException e) { throw new TDPException(CommonErrorCodes.UNEXPECTED_EXCEPTION, e); } }