List of usage examples for org.apache.http.client.utils URIBuilder build
public URI build() throws URISyntaxException
From source file:org.apache.streams.riak.http.RiakHttpPersistReader.java
@Override public StreamsResultSet readAll() { Queue<StreamsDatum> readAllQueue = constructQueue(); URIBuilder lk = null; try {//from w w w. ja va2 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:windows.webservices.utilidades.EjecutorJson.java
private void prepararParam() { if (param != null) { URIBuilder builder = new URIBuilder(uri); for (Map.Entry entry : param.entrySet()) { builder.addParameter(entry.getKey().toString(), entry.getValue().toString()); }//from w w w . j a va2 s . c o m try { this.uri = builder.build(); } catch (URISyntaxException ex) { Logger.getLogger(EjecutorJson.class.getName()).log(Level.SEVERE, null, ex); } } }
From source file:com.esri.geoportal.commons.agp.client.AgpClient.java
/** * Reads item information.//w ww . ja v a 2 s. com * @param itemId item id * @param token token * @return item entry * @throws URISyntaxException if invalid URL * @throws IOException if operation fails */ public ItemEntry readItem(String itemId, String token) throws IOException, URISyntaxException { URIBuilder builder = new URIBuilder(itemInfoUri(itemId)); builder.setParameter("f", "json"); if (token != null) { builder.setParameter("token", token); } HttpGet req = new HttpGet(builder.build()); return execute(req, ItemEntry.class); }
From source file:org.obiba.magma.datasource.mongodb.MongoDBDatasourceFactory.java
public URI getUri() { try {// w ww .ja va 2 s. c om URIBuilder uriBuilder = new URIBuilder(url); if (!Strings.isNullOrEmpty(username)) { if (Strings.isNullOrEmpty(password)) { uriBuilder.setUserInfo(username); } else { uriBuilder.setUserInfo(username, password); } } Properties prop = readOptions(); for (Map.Entry<Object, Object> entry : prop.entrySet()) { uriBuilder.addParameter(entry.getKey().toString(), entry.getValue().toString()); } return uriBuilder.build(); } catch (URISyntaxException e) { throw new RuntimeException("Cannot create MongoDB URI", e); } }
From source file:com.qwazr.crawler.web.manager.WebCrawlThread.java
/** * Remove the fragment and the query parameters following the configuration * * @param uri/*from w w w . j a v a2s . c o m*/ * @return */ private URI checkLink(URI uri) { URIBuilder uriBuilder = new URIBuilder(uri); checkRemoveFragment(uriBuilder); checkRemoveParameter(uriBuilder); try { return uriBuilder.build(); } catch (URISyntaxException e) { logger.warn(e.getMessage(), e); return null; } }
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."); }//from ww w. j a v a 2 s. 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); } }
From source file:com.github.woz_dialog.ros_woz_dialog_project.TTSHTTPClient.java
/** * Builds the REST clients for speech recognition and synthesis. * * @/*from w w w . j ava2s .c om*/ */ private void buildClients() { // Initialize the HTTP clients asrClient = HttpClientBuilder.create().build(); ttsClient = HttpClientBuilder.create().build(); try { URIBuilder builder = new URIBuilder(); builder.setScheme("https"); builder.setHost("dictation.nuancemobility.net"); builder.setPort(443); builder.setPath("/NMDPAsrCmdServlet/dictation"); builder.setParameter("appId", APP_ID); builder.setParameter("appKey", APP_KEY); builder.setParameter("id", "0000"); asrURI = builder.build(); builder.setHost("tts.nuancemobility.net"); builder.setPath("/NMDPTTSCmdServlet/tts"); builder.setParameter("ttsLang", LANGUAGE); builder.setParameter("voice", VOICE); ttsURI = builder.build(); } catch (Exception e) { throw new RuntimeException("cannot build client: " + e); } }
From source file:com.geoxp.oss.client.OSSClient.java
private static void changeACL(boolean remove, String ossURL, String sshKeyFingerprint, String secretname, List<String> keyfpr) throws OSSException { SSHAgentClient agent = null;/* w ww. j a va 2 s.c om*/ HttpClient httpclient = null; try { agent = new SSHAgentClient(); List<SSHKey> sshkeys = agent.requestIdentities(); // // If no SSH Key fingerprint was provided, try all SSH keys available in the agent // List<String> fingerprints = new ArrayList<String>(); if (null == sshKeyFingerprint) { for (SSHKey key : sshkeys) { fingerprints.add(key.fingerprint); } } else { fingerprints.add(sshKeyFingerprint.toLowerCase().replaceAll("[^0-9a-f]", "")); } int idx = 0; for (String fingerprint : fingerprints) { idx++; // // Ask the SSH agent for the SSH key blob // byte[] keyblob = null; for (SSHKey key : sshkeys) { if (key.fingerprint.equals(fingerprint)) { keyblob = key.blob; break; } } // // Throw an exception if this condition is encountered as it can only happen if // there was a provided fingerprint which is not in the agent. // if (null == keyblob) { throw new OSSException("SSH Key " + sshKeyFingerprint + " was not found by your SSH agent."); } // // Retrieve OSS RSA key // RSAPublicKey pubkey = getOSSRSA(ossURL); // // Build the token // // <TS> <<SECRET_NAME><FINGERPRINT1>....<FINGERPRINTN>> <SSH Signing Key Blob> <SSH Signature Blob> // ByteArrayOutputStream token = new ByteArrayOutputStream(); byte[] tsdata = nowBytes(); token.write(CryptoHelper.encodeNetworkString(tsdata)); ByteArrayOutputStream subtoken = new ByteArrayOutputStream(); subtoken.write(CryptoHelper.encodeNetworkString(secretname.getBytes("UTF-8"))); for (String fpr : keyfpr) { subtoken.write(CryptoHelper .encodeNetworkString(fpr.toLowerCase().replaceAll("[^a-f0-9]", "").getBytes("UTF-8"))); } token.write(CryptoHelper.encodeNetworkString(subtoken.toByteArray())); token.write(CryptoHelper.encodeNetworkString(keyblob)); byte[] sigblob = agent.sign(keyblob, token.toByteArray()); token.write(CryptoHelper.encodeNetworkString(sigblob)); // // Encrypt the token with a random AES256 key // byte[] aeskey = new byte[32]; CryptoHelper.getSecureRandom().nextBytes(aeskey); byte[] wrappedtoken = CryptoHelper.wrapAES(aeskey, token.toByteArray()); // // Encrypt the random key with OSS' RSA key // byte[] sealedaeskey = CryptoHelper.encryptRSA(pubkey, aeskey); // // Create the token // token.reset(); token.write(CryptoHelper.encodeNetworkString(wrappedtoken)); token.write(CryptoHelper.encodeNetworkString(sealedaeskey)); // // Base64 encode the encryptedtoken // String b64token = new String(Base64.encode(token.toByteArray()), "UTF-8"); // // Send request to OSS // URIBuilder builder = new URIBuilder(ossURL + (remove ? GuiceServletModule.SERVLET_PATH_REMOVE_ACL : GuiceServletModule.SERVLET_PATH_ADD_ACL)); builder.addParameter("token", b64token); URI uri = builder.build(); String qs = uri.getRawQuery(); HttpPost post = new HttpPost( uri.getScheme() + "://" + uri.getHost() + ":" + uri.getPort() + uri.getPath()); post.setHeader("Content-Type", "application/x-www-form-urlencoded"); post.setEntity(new StringEntity(qs)); httpclient = newHttpClient(); HttpResponse response = httpclient.execute(post); HttpEntity resEntity = response.getEntity(); String content = EntityUtils.toString(resEntity, "UTF-8"); post.reset(); if (HttpServletResponse.SC_OK != response.getStatusLine().getStatusCode()) { // Only throw an exception if this is the last SSH key we could try if (idx == fingerprints.size()) { throw new OSSException("None of the provided keys (" + idx + ") could be used to modify ACL. Latest error message was: " + response.getStatusLine().getReasonPhrase()); } else { continue; } } return; } } catch (OSSException osse) { throw osse; } catch (Exception e) { throw new OSSException(e); } finally { if (null != httpclient) { httpclient.getConnectionManager().shutdown(); } if (null != agent) { agent.close(); } } }
From source file:com.gsma.mobileconnect.impl.ParseDiscoveryRedirectTest.java
@Test public void parseDiscoveryRedirect_withValidURL_shouldSucceed() throws URISyntaxException { // GIVEN/* ww w .j av a 2s .c o m*/ URIBuilder builder = new URIBuilder("http://localhost/redirect"); String expectedMCC = "901"; String expectedMNC = "01"; builder.addParameter(MCC_MNC_PARAMETER, expectedMCC + "_" + expectedMNC); String expectedEncryptedMsisdn = "expected msisdn"; builder.addParameter("subscriber_id", expectedEncryptedMsisdn); IDiscovery discovery = Factory.getDiscovery(null, null); CaptureParsedDiscoveryRedirect captureParsedDiscoveryRedirect = new CaptureParsedDiscoveryRedirect(); // WHEN discovery.parseDiscoveryRedirect(builder.build().toString(), captureParsedDiscoveryRedirect); // THEN ParsedDiscoveryRedirect parsedDiscoveryRedirect = captureParsedDiscoveryRedirect .getParsedDiscoveryRedirect(); assertEquals(expectedMCC, parsedDiscoveryRedirect.getSelectedMCC()); assertEquals(expectedMNC, parsedDiscoveryRedirect.getSelectedMNC()); assertEquals(expectedEncryptedMsisdn, parsedDiscoveryRedirect.getEncryptedMSISDN()); assertTrue(parsedDiscoveryRedirect.hasMCCAndMNC()); }
From source file:org.openhim.mediator.engine.connectors.HTTPConnector.java
private URI buildURI(MediatorHTTPRequest req) throws URISyntaxException { URIBuilder builder = new URIBuilder().setScheme(req.getScheme()).setHost(req.getHost()) .setPort(req.getPort()).setPath(req.getPath()); if (req.getParams() != null) { Iterator<String> iter = req.getParams().keySet().iterator(); while (iter.hasNext()) { String param = iter.next(); builder.addParameter(param, req.getParams().get(param)); }//from w ww . j av a 2 s . c o m } return builder.build(); }