List of usage examples for org.apache.http.client.utils URIBuilder build
public URI build() throws URISyntaxException
From source file:com.vmware.identity.openidconnect.protocol.URIUtils.java
public static URI appendQueryParameter(URI uri, String parameterName, String parameterValue) { Validate.notNull(uri, "uri"); Validate.notEmpty(parameterName, "parameterName"); Validate.notEmpty(parameterValue, "parameterValue"); URIBuilder uriBuilder = new URIBuilder(uri); uriBuilder.addParameter(parameterName, parameterValue); try {/*from www . j a v a 2 s . co m*/ return uriBuilder.build(); } catch (URISyntaxException e) { throw new IllegalArgumentException("failed to add parameter to uri", e); } }
From source file:no.digipost.api.useragreements.client.ApiService.java
private static URI buildUri(URIBuilder builder) { try {/*from w ww. j a v a 2 s .c o m*/ return builder.build(); } catch (URISyntaxException e) { throw new RuntimeException(e.getMessage(), e); } }
From source file:de.bmarwell.j9kwsolver.util.RequestToURI.java
/** * Returns the URI for requesting the server status. * @param sc the URI for requesting the server status. * @return the URI for requesting the server status. *///from ww w .j av a 2 s . co m public static URI serverStatusToURI(final ServerCheck sc) { URI uri = null; URI apiURI = stringToURI(sc.getUrl()); URIBuilder builder = new URIBuilder(apiURI).addParameter("action", sc.getAction()); try { uri = builder.build(); } catch (URISyntaxException e) { LOG.error("Konnte URI nicht erstellen!", e); } return uri; }
From source file:ch.newscron.shortUrlUtils.ShortenerURL.java
/** * Given a shortened goo.gl URL, the function makes a request to the Google API (with key), receives information as a response in JSONObject format and stores data into a ShortLinkStat object. * @param shortURL is a String representing the shortened goo.gl URL * @return a ShortLinkStat object consisting of the most important information (clicks, long and short URL) *///from w w w .ja v a 2s .co m public static ShortLinkStat getURLJSONObject(String shortURL) { ShortLinkStat linkStat; try { // Creating the URL with Google API URIBuilder urlData = new URIBuilder(google_url); urlData.addParameter("shortUrl", shortURL); urlData.addParameter("projection", "FULL"); URL url = urlData.build().toURL(); // Get the JSONObject format of shortURL as String ObjectMapper mapper = new ObjectMapper(); JsonNode rootNode = mapper.readTree(url); if (rootNode == null) { return null; } linkStat = setData(rootNode); return linkStat; } catch (Exception e) { } return null; }
From source file:adalid.util.google.Translator.java
private static String translate(String arg, URIBuilder builder, CloseableHttpClient client) throws IOException, URISyntaxException { builder.clearParameters();/*from w w w . ja v a 2s . c o m*/ builder.setParameter("langpair", "en|es"); builder.setParameter("text", arg); URI uri = builder.build(); HttpGet get = new HttpGet(uri); HttpUriRequest request = (HttpUriRequest) get; try (CloseableHttpResponse response = client.execute(request)) { StatusLine statusLine = response.getStatusLine(); if (statusLine.getReasonPhrase().equals("OK")) { logger.info(statusLine.toString()); } else { throw new RuntimeException(statusLine.toString()); } HttpEntity entity = response.getEntity(); if (entity != null) { logger.info(entity.getContentType()); return translate(entity); } } catch (ClientProtocolException ex) { logger.fatal(uri, ex); } return null; }
From source file:com.ecofactor.qa.automation.util.HttpUtil.java
/** * Gets the.// w ww . j a va 2 s . c o m * @param url the url * @return the http response */ public static String get(String url, Map<String, String> params, int expectedStatus) { String content = null; HttpClient httpClient = new DefaultHttpClient(); HttpGet request = new HttpGet(url); URIBuilder builder = new URIBuilder(request.getURI()); Set<String> keys = params.keySet(); for (String key : keys) { builder.addParameter(key, params.get(key)); } HttpResponse response = null; try { request.setURI(builder.build()); DriverConfig.setLogString("URL " + request.getURI().toString(), true); response = httpClient.execute(request); content = IOUtils.toString(response.getEntity().getContent()); DriverConfig.setLogString("Content " + content, true); Assert.assertEquals(response.getStatusLine().getStatusCode(), expectedStatus); } catch (Exception e) { LOGGER.error(e.getMessage()); } finally { request.releaseConnection(); } return content; }
From source file:com.infullmobile.jenkins.plugin.restrictedregister.util.AppUrls.java
@Nonnull public static String buildActivationUrl(String code, String secret) throws InvalidUriException { String ret = null;/*from ww w. j a v a2 s .c o m*/ final String path = String.format(Locale.US, FORMAT_REGISTER_PATH, PluginModule.getDefault().getPluginDescriptor().getRootActionURL()); try { final URIBuilder builder = new URIBuilder(getRootURL()); builder.setPath(path); builder.addParameter(BaseFormField.SECRET.getFieldName(), secret); builder.addParameter(BaseFormField.ACTIVATION_CODE.getFieldName(), code); final URI uri = builder.build(); ret = uri.toURL().toExternalForm(); } catch (URISyntaxException | MalformedURLException e) { onError(e.getLocalizedMessage()); } return ret; }
From source file:de.bmarwell.j9kwsolver.util.RequestToURI.java
/** * @param ub - User Balance object./*from w w w . j ava 2 s . co m*/ * @return API-URIor null if ub-object is invalid. */ public static URI userBalanceToURI(final UserBalance ub) { URI uri = null; if (ub == null) { return null; } URI apiURI = stringToURI(ub.getUrl()); URIBuilder builder = new URIBuilder(apiURI).addParameter("action", ub.getAction()).addParameter("apikey", ub.getApikey()); try { uri = builder.build(); } catch (URISyntaxException e) { LOG.error("Konnte URI nicht erstellen!", e); } return uri; }
From source file:org.dbrane.cloud.util.httpclient.HttpClientHelper.java
public static String httpGetRequest(String url, Map<String, Object> params) { try {//from w ww.j av a 2s. c o m URIBuilder ub = new URIBuilder(); ub.setPath(url); ArrayList<NameValuePair> pairs = covertParams2NVPS(params); ub.setParameters(pairs); HttpGet httpGet = new HttpGet(ub.build()); return getResult(httpGet); } catch (Exception e) { logger.debug(ErrorType.Httpclient.toString(), e); throw new BaseException(ErrorType.Httpclient, e); } }
From source file:org.megam.api.http.TransportMachinery.java
public static TransportResponse get(TransportTools nuts) throws URISyntaxException, ClientProtocolException, IOException { DefaultHttpClient httpclient = new DefaultHttpClient(); HttpGet httpget = new HttpGet(nuts.urlString()); if (nuts.headers() != null) { for (Map.Entry<String, String> headerEntry : nuts.headers().entrySet()) { //this if condition is set for twilio Rest API to add credentials to DefaultHTTPClient, conditions met twilio work. if (headerEntry.getKey().equalsIgnoreCase("provider") & headerEntry.getValue().equalsIgnoreCase(nuts.headers().get("provider"))) { httpclient.getCredentialsProvider().setCredentials( new AuthScope(AuthScope.ANY_HOST, AuthScope.ANY_PORT), new UsernamePasswordCredentials( nuts.headers().get("account_sid"), nuts.headers().get("oauth_token"))); }//from w w w . jav a 2 s.c o m //this else part statements for other providers else { httpget.addHeader(headerEntry.getKey(), headerEntry.getValue()); } } } if (nuts.isQuery()) { URIBuilder uribuilder = new URIBuilder(nuts.urlString()); uribuilder.setQuery(URLEncodedUtils.format(nuts.pairs(), nuts.encoding())); httpget.setURI(uribuilder.build()); } TransportResponse transportResp = null; try { HttpResponse httpResp = httpclient.execute(httpget); transportResp = new TransportResponse(httpResp.getStatusLine(), httpResp.getEntity(), httpResp.getLocale()); } finally { httpget.releaseConnection(); } return transportResp; }