List of usage examples for org.apache.http.client.utils URIBuilder setParameter
public URIBuilder setParameter(final String param, final String value)
From source file:com.nexmo.client.voice.endpoints.ListCallsMethod.java
@Override public RequestBuilder makeRequest(CallsFilter filter) throws NexmoClientException, UnsupportedEncodingException { URIBuilder uriBuilder; try {/*from w w w. j a v a 2s.c o m*/ uriBuilder = new URIBuilder(this.uri); } catch (URISyntaxException e) { throw new NexmoUnexpectedException("Could not parse URI: " + this.uri); } if (filter != null) { List<NameValuePair> params = filter.toUrlParams(); for (NameValuePair param : params) { uriBuilder.setParameter(param.getName(), param.getValue()); } } return RequestBuilder.get().setUri(uriBuilder.toString()); }
From source file:gov.medicaid.screening.dao.impl.OptometryLicenseDAOBean.java
/** * Performs a search for all possible results. * * @param identifier The value to be searched. * @return the search result for licenses * @throws URISyntaxException When an error occurs while building the URL. * @throws ClientProtocolException When client does not support protocol used. * @throws IOException When an error occurs while parsing response. * @throws ParseException When an error occurs while parsing response. * @throws PersistenceException for database related errors * @throws ServiceException for any other problems encountered *///from ww w .j av a2s . co m private SearchResult<License> getAllResults(String identifier) throws URISyntaxException, ClientProtocolException, IOException, ParseException, PersistenceException, ServiceException { DefaultHttpClient client = new DefaultHttpClient(); URIBuilder builder = new URIBuilder(getSearchURL()).setPath("/Default.aspx"); String hostId = builder.build().toString(); builder.setParameter("tabid", "799"); HttpGet httpget = new HttpGet(builder.build()); HttpResponse landing = client.execute(httpget); Document document = Jsoup.parse(EntityUtils.toString(landing.getEntity())); HttpPost httppost = new HttpPost(builder.build()); HttpEntity entity = postForm(hostId, client, httppost, new String[][] { { "_ctl0:_ctl1:_ctl0:txtCriteria", identifier }, { "_ctl0:_ctl1:_ctl0:btnSubmit", "Search" }, { "__EVENTTARGET", "" }, { "__EVENTARGUMENT", "" }, { "__VIEWSTATE", document.select("#Form input[name=__VIEWSTATE]").first().val() } }, true); // licenses list List<License> licenseList = new ArrayList<License>(); while (entity != null) { String result = EntityUtils.toString(entity); document = Jsoup.parse(result); Elements trs = document.select("table.Datagrid tr"); if (trs != null) { for (Element element : trs) { String cssClass = element.attr("class"); if (!"DatagridHeaderStyle".equals(cssClass.trim()) && element.children().size() == 8) { Elements tds = element.children(); licenseList.add(parseLicense(tds)); } } } // done, check if there are additional results entity = null; Elements elements = document.getElementsByTag("a"); for (Element element : elements) { if (element.text().equals("Next >>")) { entity = postForm(hostId, client, httppost, new String[][] { { "_ctl0:_ctl1:_ctl0:txtCriteria", identifier }, { "__EVENTTARGET", "_ctl0:_ctl1:_ctl0:dgrdLicensee:_ctl29:_ctl1" }, { "__EVENTARGUMENT", "" }, { "__VIEWSTATE", document.select("#Form input[name=__VIEWSTATE]").first().val() } }, true); break; } } } SearchResult<License> result = new SearchResult<License>(); result.setItems(licenseList); return result; }
From source file:org.keycloak.broker.provider.util.SimpleHttp.java
private URI appendParameterToUrl(String url) throws IOException { URI uri = null;//from www . j a v a 2 s. c o m try { URIBuilder uriBuilder = new URIBuilder(url); if (params != null) { for (Map.Entry<String, String> p : params.entrySet()) { uriBuilder.setParameter(p.getKey(), p.getValue()); } } uri = uriBuilder.build(); } catch (URISyntaxException e) { } return uri; }
From source file:org.apache.sling.etcd.client.impl.EtcdClientImpl.java
@Nonnull private URI buildUri(@Nonnull URI endpoint, @Nonnull String path, @Nonnull Map<String, String> parameters) { try {/*w ww .ja va 2 s . c o m*/ URIBuilder builder = new URIBuilder(); for (Map.Entry<String, String> p : parameters.entrySet()) { builder.setParameter(p.getKey(), p.getValue()); } return builder.setScheme(endpoint.getScheme()).setHost(endpoint.getHost()).setPort(endpoint.getPort()) .setPath(path).build(); } catch (URISyntaxException e) { throw new EtcdException(e.getMessage(), e); } }
From source file:org.apache.streams.riak.http.RiakHttpPersistReader.java
@Override public StreamsResultSet readAll() { Queue<StreamsDatum> readAllQueue = constructQueue(); URIBuilder lk = null; try {//from www .j av a 2 s .co m lk = new URIBuilder(client.baseURI.toString()); lk.setPath(client.baseURI.getPath().concat("/buckets/" + configuration.getDefaultBucket() + "/keys")); lk.setParameter("keys", "true"); } catch (URISyntaxException e) { LOGGER.warn("URISyntaxException", e); } HttpResponse lkResponse = null; try { HttpGet lkGet = new HttpGet(lk.build()); lkResponse = client.client().execute(lkGet); } catch (IOException e) { LOGGER.warn("IOException", e); return null; } catch (URISyntaxException e) { LOGGER.warn("URISyntaxException", e); return null; } String lkEntityString = null; try { lkEntityString = EntityUtils.toString(lkResponse.getEntity()); } catch (IOException e) { LOGGER.warn("IOException", e); return null; } JsonNode lkEntityNode = null; try { lkEntityNode = MAPPER.readValue(lkEntityString, JsonNode.class); } catch (IOException e) { LOGGER.warn("IOException", e); return null; } ArrayNode keysArray = null; keysArray = (ArrayNode) lkEntityNode.get("keys"); Iterator<JsonNode> keysIterator = keysArray.iterator(); while (keysIterator.hasNext()) { JsonNode keyNode = keysIterator.next(); String key = keyNode.asText(); URIBuilder gk = null; try { gk = new URIBuilder(client.baseURI.toString()); gk.setPath(client.baseURI.getPath() .concat("/buckets/" + configuration.getDefaultBucket() + "/keys/" + key)); } catch (URISyntaxException e) { LOGGER.warn("URISyntaxException", e); continue; } HttpResponse gkResponse = null; try { HttpGet gkGet = new HttpGet(gk.build()); gkResponse = client.client().execute(gkGet); } catch (IOException e) { LOGGER.warn("IOException", e); continue; } catch (URISyntaxException e) { LOGGER.warn("URISyntaxException", e); continue; } String gkEntityString = null; try { gkEntityString = EntityUtils.toString(gkResponse.getEntity()); } catch (IOException e) { LOGGER.warn("IOException", e); continue; } readAllQueue.add(new StreamsDatum(gkEntityString, key)); } return new StreamsResultSet(readAllQueue); }
From source file:org.pentaho.reporting.libraries.pensol.vfs.LocalFileModel.java
public void refresh() throws IOException { getDescriptionEntries().clear();/*from w ww . j av a2 s. c o m*/ final Configuration configuration = LibPensolBoot.getInstance().getGlobalConfig(); final String service = configuration .getConfigProperty("org.pentaho.reporting.libraries.pensol.web.LoadRepositoryDoc"); URI uri; String baseUrl = url + service; try { URIBuilder builder = new URIBuilder(baseUrl); logger.debug("Connecting to '" + baseUrl + '\''); if (username != null) { builder.setParameter("userid", username); } if (password != null) { builder.setParameter("password", password); } uri = builder.build(); } catch (URISyntaxException e) { throw new IOException("Provided URL is invalid: " + baseUrl); } final HttpPost filePost = new HttpPost(uri); filePost.setHeader("Content-Type", "application/x-www-form-urlencoded; charset=utf-8"); HttpResponse httpResponse = client.execute(filePost, context); final int lastStatus = httpResponse.getStatusLine().getStatusCode(); if (lastStatus == HttpStatus.SC_UNAUTHORIZED) { throw new IOException("401: User authentication failed."); } else if (lastStatus == HttpStatus.SC_NOT_FOUND) { throw new IOException("404: Repository service not found on server."); } else if (lastStatus != HttpStatus.SC_OK) { throw new IOException("Server error: HTTP lastStatus code " + lastStatus); } final InputStream postResult = httpResponse.getEntity().getContent(); try { setRoot(performParse(postResult)); } finally { postResult.close(); } }
From source file:gov.medicaid.screening.dao.impl.MarriageAndFamilyTherapyLicenseDAOBean.java
/** * Performs a search for all possible results. * * @param criteria The search criteria./*from w ww.j a v a 2 s .c o m*/ * @param identifier The value to be searched. * @param host The host where to perform search. * @param pageNumber The page number requested * @return the search result for licenses * @throws URISyntaxException When an error occurs while building the URL. * @throws IOException When an error occurs while parsing response. * @throws ParseException When an error occurs while parsing response. * @throws PersistenceException if any db related error is encountered * @throws ServiceException When an error occurs while trying to perform search. */ private SearchResult<License> getAllResults(String criteria, String identifier, String host, int pageNumber) throws URISyntaxException, ParseException, PersistenceException, IOException, ServiceException { HttpClient client = new DefaultHttpClient(); URIBuilder builder = new URIBuilder(host).setPath("/search.asp"); String hostId = builder.build().toString(); builder.setParameter("qry", criteria).setParameter("crit", identifier).setParameter("p", "s") .setParameter("rsp", pageNumber + ""); URI uri = builder.build(); HttpGet httpget = new HttpGet(uri); SearchResult<License> searchResults = new SearchResult<License>(); HttpResponse response = client.execute(httpget); int statusCode = response.getStatusLine().getStatusCode(); if (statusCode == HttpStatus.SC_OK) { HttpEntity entity = response.getEntity(); SearchResult<License> nextResults = null; // licenses list List<License> licenseList = new ArrayList<License>(); if (entity != null) { String result = EntityUtils.toString(entity); Document document = Jsoup.parse(result); Elements trs = document.select("tr[bgcolor]"); for (Element tr : trs) { Elements tds = tr.children(); licenseList.add(parseLicenseInfo(tds)); } // check if there is next page Element next = document.select("a:containsOwn(Next)").first(); if (next != null) { nextResults = getAllResults(criteria, identifier, host, pageNumber + 1); } if (nextResults != null) { licenseList.addAll(nextResults.getItems()); } } searchResults.setItems(licenseList); } verifyAndAuditCall(hostId, response); return searchResults; }
From source file:org.pentaho.reporting.libraries.pensol.vfs.LocalFileModel.java
/** * @noinspection ThrowCaughtLocally/*from ww w .j a va 2 s .co m*/ */ protected byte[] getDataInternally(final FileInfo fileInfo) throws FileSystemException { URI uri; String baseUrl = fileInfo.getUrl(); try { URIBuilder builder = new URIBuilder(baseUrl); logger.debug("Connecting to '" + baseUrl + '\''); if (username != null) { builder.setParameter("userid", username); } if (password != null) { builder.setParameter("password", password); } uri = builder.build(); } catch (URISyntaxException e) { throw new FileSystemException("Provided URL is invalid: " + baseUrl); } final HttpPost filePost = new HttpPost(uri); filePost.setHeader("Content-Type", "application/x-www-form-urlencoded; charset=utf-8"); try { HttpResponse httpResponse = client.execute(filePost, context); final int lastStatus = httpResponse.getStatusLine().getStatusCode(); if (lastStatus == HttpStatus.SC_UNAUTHORIZED) { throw new FileSystemException("401: User authentication failed."); } else if (lastStatus == HttpStatus.SC_NOT_FOUND) { throw new FileSystemException("404: Repository service not found on server."); } else if (lastStatus != HttpStatus.SC_OK) { throw new FileSystemException("Server error: HTTP lastStatus code " + lastStatus); } final InputStream postResult = httpResponse.getEntity().getContent(); try { final MemoryByteArrayOutputStream bout = new MemoryByteArrayOutputStream(); IOUtils.getInstance().copyStreams(postResult, bout); return bout.toByteArray(); } finally { postResult.close(); } } catch (FileSystemException ioe) { throw ioe; } catch (IOException ioe) { throw new FileSystemException("Failed", ioe); } }
From source file:io.mapzone.arena.geocode.here.HereGeocodeService.java
protected URI createUrl(GeocodeQuery query) throws URISyntaxException, IOException { URIBuilder builder = new URIBuilder().setScheme("https").setHost(baseUrl.get()).setPath("/6.2/geocode.json") .setParameter("app_code", appCode.get()).setParameter("app_id", appId.get()) .setParameter("jsonattributes", "1").setParameter("gen", "9"); if (query.country.isPresent()) { builder.setParameter("country", query.country.get().getISO3Country()); }/*from w w w . j ava 2s.c om*/ if (query.targetLanguage.isPresent()) { builder.setParameter("language", query.targetLanguage.get().toLanguageTag()); } builder.setParameter("maxresults", String.valueOf(query.maxResults.get())); if (query.text.isPresent()) { builder.setParameter("searchtext", query.text.get()); } else { final StringBuilder text = new StringBuilder(); if (query.postalCode.isPresent()) { text.append(query.postalCode.get()).append(" "); } if (query.city.isPresent()) { text.append(query.city.get()).append(" "); } if (query.street.isPresent()) { text.append(query.street.get()).append(" "); } if (query.houseNumber.isPresent()) { text.append(query.houseNumber.get()).append(" "); } builder.setParameter("searchtext", text.toString()); } return builder.build(); }
From source file:org.pentaho.reporting.libraries.pensol.vfs.LocalFileModel.java
public void createFolder(final FileName file) throws FileSystemException { final String[] fileName = computeFileNames(file); if (fileName.length < 2) { throw new FileSystemException("Cannot create directory in the root."); }/* w w w .j av a 2s.c om*/ final String[] parentPath = new String[fileName.length - 1]; System.arraycopy(fileName, 0, parentPath, 0, parentPath.length); final FileInfo fileInfo = lookupNode(parentPath); if (fileInfo == null) { throw new FileSystemException("Cannot locate parent directory."); } try { final String solution = fileName[0]; final String path = buildPath(fileName, 1, fileName.length - 1); final String name = fileName[fileName.length - 1]; String description = getDescriptionEntries().get(file); if (description == null) { description = ""; } final Configuration config = LibPensolBoot.getInstance().getGlobalConfig(); final String urlMessage = config .getConfigProperty("org.pentaho.reporting.libraries.pensol.web.CreateNewFolder"); final MessageFormat fmt = new MessageFormat(urlMessage); final String fullpath = fmt .format(new Object[] { URLEncoder.encode(solution, "UTF-8"), URLEncoder.encode(path, "UTF-8"), URLEncoder.encode(name, "UTF-8"), URLEncoder.encode(description, "UTF-8") }); URI uri; String baseUrl = url + fullpath; try { URIBuilder builder = new URIBuilder(baseUrl); logger.debug("Connecting to '" + baseUrl + '\''); if (username != null) { builder.setParameter("user", username); } if (password != null) { builder.setParameter("password", password); } uri = builder.build(); } catch (URISyntaxException e) { throw new FileSystemException("Provided URL is invalid: " + baseUrl); } final HttpPost filePost = new HttpPost(uri); filePost.setHeader("Content-Type", "application/x-www-form-urlencoded; charset=utf-8"); HttpResponse httpResponse = client.execute(filePost, context); final int lastStatus = httpResponse.getStatusLine().getStatusCode(); if (lastStatus != HttpStatus.SC_OK) { throw new FileSystemException("Server error: HTTP status code " + lastStatus); } if (name == null) { throw new FileSystemException("Error creating folder: Empty name"); } new FileInfo(fileInfo, name, description); } catch (FileSystemException fse) { throw fse; } catch (IOException ioe) { throw new FileSystemException("Failed", ioe); } }