List of usage examples for java.net URI getPath
public String getPath()
From source file:com.sworddance.util.UriFactoryImpl.java
/** * suitable for namespacing//from w w w .ja va2 s .c om * @return the uri with relative schema ( ex. //facebook.com/path/to/stuff?query ) */ public static URI createNamespaceUri(Object uriStr) { URI temp = createUriWithOptions(uriStr, true, true); try { URI namesUri = new URI(null, temp.getUserInfo(), temp.getHost(), -1, temp.getPath(), temp.getQuery(), temp.getFragment()); return namesUri; } catch (URISyntaxException e) { return null; } }
From source file:org.soyatec.windowsazure.internal.util.HttpUtilities.java
/** * Get normalize path/*from w w w . j a v a 2 s . c o m*/ * * @param uri * @return String */ public static String getNormalizePath(URI uri) { if (Utilities.isNullOrEmpty(uri.getPath())) { return ConstChars.Slash; } else { if (!uri.getPath().startsWith(ConstChars.Slash)) { return ConstChars.Slash + uri.getPath(); } else { return uri.getPath(); } } }
From source file:eu.stratosphere.nephele.fs.s3.S3FileSystem.java
static Path extendPath(final Path parent, final String extension) throws IOException { final URI parentUri = parent.toUri(); if (extension.isEmpty()) { return parent; }//from w ww . j av a 2 s. c o m final String path = parentUri.getPath(); String extendedPath; if (path.isEmpty()) { if (extension.charAt(0) == Path.SEPARATOR_CHAR) { extendedPath = extension; } else { extendedPath = Path.SEPARATOR + extension; } } else { if (path.charAt(path.length() - 1) == Path.SEPARATOR_CHAR) { if (extension.charAt(0) == Path.SEPARATOR_CHAR) { if (extension.length() > 1) { extendedPath = path + extension.substring(1); } else { extendedPath = path; } } else { extendedPath = path + extension; } } else { if (extension.charAt(0) == Path.SEPARATOR_CHAR) { extendedPath = path + extension; } else { extendedPath = path + Path.SEPARATOR + extension; } } } try { final URI extendedUri = new URI(parentUri.getScheme(), ((parentUri.getAuthority() != null) ? parentUri.getAuthority() : ""), extendedPath, parentUri.getQuery(), parentUri.getFragment()); return new Path(extendedUri); } catch (URISyntaxException e) { throw new IOException(StringUtils.stringifyException(e)); } }
From source file:org.apache.hive.jdbc.Utils.java
/** * Parse JDBC connection URL/*from w w w . ja v a2 s.c o m*/ * The new format of the URL is: * jdbc:hive2://<host1>:<port1>,<host2>:<port2>/dbName;sess_var_list?hive_conf_list#hive_var_list * where the optional sess, conf and var lists are semicolon separated <key>=<val> pairs. * For utilizing dynamic service discovery with HiveServer2 multiple comma separated host:port pairs can * be specified as shown above. * The JDBC driver resolves the list of uris and picks a specific server instance to connect to. * Currently, dynamic service discovery using ZooKeeper is supported, in which case the host:port pairs represent a ZooKeeper ensemble. * * As before, if the host/port is not specified, it the driver runs an embedded hive. * examples - * jdbc:hive2://ubuntu:11000/db2?hive.cli.conf.printheader=true;hive.exec.mode.local.auto.inputbytes.max=9999#stab=salesTable;icol=customerID * jdbc:hive2://?hive.cli.conf.printheader=true;hive.exec.mode.local.auto.inputbytes.max=9999#stab=salesTable;icol=customerID * jdbc:hive2://ubuntu:11000/db2;user=foo;password=bar * * Connect to http://server:10001/hs2, with specified basicAuth credentials and initial database: * jdbc:hive2://server:10001/db;user=foo;password=bar?hive.server2.transport.mode=http;hive.server2.thrift.http.path=hs2 * * @param uri * @return * @throws SQLException */ public static JdbcConnectionParams parseURL(String uri) throws JdbcUriParseException, SQLException, ZooKeeperHiveClientException { JdbcConnectionParams connParams = new JdbcConnectionParams(); if (!uri.startsWith(URL_PREFIX)) { throw new JdbcUriParseException("Bad URL format: Missing prefix " + URL_PREFIX); } // For URLs with no other configuration // Don't parse them, but set embedded mode as true if (uri.equalsIgnoreCase(URL_PREFIX)) { connParams.setEmbeddedMode(true); return connParams; } // The JDBC URI now supports specifying multiple host:port if dynamic service discovery is // configured on HiveServer2 (like: host1:port1,host2:port2,host3:port3) // We'll extract the authorities (host:port combo) from the URI, extract session vars, hive // confs & hive vars by parsing it as a Java URI. // To parse the intermediate URI as a Java URI, we'll give a dummy authority(dummy:00000). // Later, we'll substitute the dummy authority for a resolved authority. String dummyAuthorityString = "dummyhost:00000"; String suppliedAuthorities = getAuthorities(uri, connParams); if ((suppliedAuthorities == null) || (suppliedAuthorities.isEmpty())) { // Given uri of the form: // jdbc:hive2:///dbName;sess_var_list?hive_conf_list#hive_var_list connParams.setEmbeddedMode(true); } else { LOG.info("Supplied authorities: " + suppliedAuthorities); String[] authorityList = suppliedAuthorities.split(","); connParams.setSuppliedAuthorityList(authorityList); uri = uri.replace(suppliedAuthorities, dummyAuthorityString); } // Now parse the connection uri with dummy authority URI jdbcURI = URI.create(uri.substring(URI_JDBC_PREFIX.length())); // key=value pattern Pattern pattern = Pattern.compile("([^;]*)=([^;]*)[;]?"); // dbname and session settings String sessVars = jdbcURI.getPath(); if ((sessVars != null) && !sessVars.isEmpty()) { String dbName = ""; // removing leading '/' returned by getPath() sessVars = sessVars.substring(1); if (!sessVars.contains(";")) { // only dbname is provided dbName = sessVars; } else { // we have dbname followed by session parameters dbName = sessVars.substring(0, sessVars.indexOf(';')); sessVars = sessVars.substring(sessVars.indexOf(';') + 1); if (sessVars != null) { Matcher sessMatcher = pattern.matcher(sessVars); while (sessMatcher.find()) { if (connParams.getSessionVars().put(sessMatcher.group(1), sessMatcher.group(2)) != null) { throw new JdbcUriParseException( "Bad URL format: Multiple values for property " + sessMatcher.group(1)); } } } } if (!dbName.isEmpty()) { connParams.setDbName(dbName); } } // parse hive conf settings String confStr = jdbcURI.getQuery(); if (confStr != null) { Matcher confMatcher = pattern.matcher(confStr); while (confMatcher.find()) { connParams.getHiveConfs().put(confMatcher.group(1), confMatcher.group(2)); } } // parse hive var settings String varStr = jdbcURI.getFragment(); if (varStr != null) { Matcher varMatcher = pattern.matcher(varStr); while (varMatcher.find()) { connParams.getHiveVars().put(varMatcher.group(1), varMatcher.group(2)); } } // Handle all deprecations here: String newUsage; String usageUrlBase = "jdbc:hive2://<host>:<port>/dbName;"; // Handle deprecation of AUTH_QOP_DEPRECATED newUsage = usageUrlBase + JdbcConnectionParams.AUTH_QOP + "=<qop_value>"; handleParamDeprecation(connParams.getSessionVars(), connParams.getSessionVars(), JdbcConnectionParams.AUTH_QOP_DEPRECATED, JdbcConnectionParams.AUTH_QOP, newUsage); // Handle deprecation of TRANSPORT_MODE_DEPRECATED newUsage = usageUrlBase + JdbcConnectionParams.TRANSPORT_MODE + "=<transport_mode_value>"; handleParamDeprecation(connParams.getHiveConfs(), connParams.getSessionVars(), JdbcConnectionParams.TRANSPORT_MODE_DEPRECATED, JdbcConnectionParams.TRANSPORT_MODE, newUsage); // Handle deprecation of HTTP_PATH_DEPRECATED newUsage = usageUrlBase + JdbcConnectionParams.HTTP_PATH + "=<http_path_value>"; handleParamDeprecation(connParams.getHiveConfs(), connParams.getSessionVars(), JdbcConnectionParams.HTTP_PATH_DEPRECATED, JdbcConnectionParams.HTTP_PATH, newUsage); // Extract host, port if (connParams.isEmbeddedMode()) { // In case of embedded mode we were supplied with an empty authority. // So we never substituted the authority with a dummy one. connParams.setHost(jdbcURI.getHost()); connParams.setPort(jdbcURI.getPort()); } else { // Else substitute the dummy authority with a resolved one. // In case of dynamic service discovery using ZooKeeper, it picks a server uri from ZooKeeper String resolvedAuthorityString = resolveAuthority(connParams); LOG.info("Resolved authority: " + resolvedAuthorityString); uri = uri.replace(dummyAuthorityString, resolvedAuthorityString); connParams.setJdbcUriString(uri); // Create a Java URI from the resolved URI for extracting the host/port URI resolvedAuthorityURI = null; try { resolvedAuthorityURI = new URI(null, resolvedAuthorityString, null, null, null); } catch (URISyntaxException e) { throw new JdbcUriParseException("Bad URL format: ", e); } connParams.setHost(resolvedAuthorityURI.getHost()); connParams.setPort(resolvedAuthorityURI.getPort()); } return connParams; }
From source file:edu.internet2.middleware.openid.message.encoding.EncodingUtils.java
/** * Append the URL encoded OpenID message parameters to the query string of the provided URI. * //from w w w. j a v a 2 s. c om * @param uri URI to append OpenID message parameter to * @param message URL encoded OpenID message parameters * @return URI with message parameters appended */ public static URI appendMessageParameters(URI uri, String message) { if (uri == null || message == null) { return uri; } // build new query string StringBuffer queryBuffer = new StringBuffer(); if (uri.getRawQuery() != null) { queryBuffer.append(uri.getRawQuery()); } if (queryBuffer.length() > 0 && queryBuffer.charAt(queryBuffer.length() - 1) != '&') { queryBuffer.append('&'); } queryBuffer.append(message); try { return URIUtils.createURI(uri.getScheme(), uri.getHost(), uri.getPort(), uri.getPath(), queryBuffer.toString(), uri.getFragment()); } catch (URISyntaxException e) { log.error("Unable to append message parameters to URI: {}", e); } return null; }
From source file:eu.asterics.mw.services.ResourceRegistry.java
/** * Return the String representation of the given URI. * @param uri//w w w. ja v a 2 s . co m * @return */ public static String toString(URI uri) { return uri.getPath(); }
From source file:org.cloudfoundry.caldecott.client.TunnelHelper.java
public static Map<String, String> getTunnelServiceInfo(CloudFoundryClient client, String serviceName) { String urlToUse = getTunnelUri(client) + "/services/" + serviceName; HttpHeaders requestHeaders = new HttpHeaders(); requestHeaders.set("Auth-Token", getTunnelAuth(client)); HttpEntity<?> requestEntity = new HttpEntity(requestHeaders); HttpEntity<String> response = restTemplate.exchange(urlToUse, HttpMethod.GET, requestEntity, String.class); String json = response.getBody().trim(); Map<String, String> svcInfo = new HashMap<String, String>(); try {//from w w w. jav a2 s .c o m svcInfo = convertJsonToMap(json); } catch (IOException e) { return new HashMap<String, String>(); } if (svcInfo.containsKey("url")) { String svcUrl = svcInfo.get("url"); try { URI uri = new URI(svcUrl); String[] userInfo; if (uri.getUserInfo().contains(":")) { userInfo = uri.getUserInfo().split(":"); } else { userInfo = new String[2]; userInfo[0] = uri.getUserInfo(); userInfo[1] = ""; } svcInfo.put("user", userInfo[0]); svcInfo.put("username", userInfo[0]); svcInfo.put("password", userInfo[1]); svcInfo.put("host", uri.getHost()); svcInfo.put("hostname", uri.getHost()); svcInfo.put("port", "" + uri.getPort()); svcInfo.put("path", (uri.getPath().startsWith("/") ? uri.getPath().substring(1) : uri.getPath())); svcInfo.put("vhost", svcInfo.get("path")); } catch (URISyntaxException e) { } } return svcInfo; }
From source file:org.hl7.fhir.client.ResourceAddress.java
public static URI appendHttpParameters(URI basePath, Map<String, String> parameters) { try {/* w ww .j a va2s . c o m*/ Set<String> httpParameterNames = parameters.keySet(); String query = basePath.getQuery(); for (String httpParameterName : httpParameterNames) { if (query != null) { query += "&"; } else { query = ""; } query += httpParameterName + "=" + parameters.get(httpParameterName); } return new URI(basePath.getScheme(), basePath.getUserInfo(), basePath.getHost(), basePath.getPort(), basePath.getPath(), query, basePath.getFragment()); } catch (Exception e) { throw new EFhirClientException("Error appending http parameter", e); } }
From source file:com.ibm.jaggr.service.impl.deps.DepUtils.java
/** * Maps a resource URI to a {@link DepTreeNode}. This routine finds the key * in <code>dependencies</code> that is an ancestor of * <code>requiestURI</code> and then looks for the {@link DepTreeNode} who's * name corresponds to descendant part of the URI path. * //from ww w.j ava2s .c om * @param requestUri * The URI for the resource location being sought * @param dependencies * Map of file path names to root {@link DepTreeNode}s * @return The node corresponding to <code>requestURI</code> */ static public DepTreeNode getNodeForResource(URI requestUri, Map<URI, DepTreeNode> dependencies) { DepTreeNode result = null; /* * Iterate through the map entries and find the entry who's key is the same, * or an ancestor of, the specified path */ for (Entry<URI, DepTreeNode> dependency : dependencies.entrySet()) { URI uri = dependency.getKey(); if (requestUri.getScheme() == null && uri.getScheme() != null || requestUri.getScheme() != null && !requestUri.getScheme().equals(uri.getScheme())) continue; if (requestUri.getHost() == null && uri.getHost() != null || requestUri.getHost() != null && !requestUri.getHost().equals(uri.getHost())) continue; if (requestUri.getPath().equals(uri.getPath()) || requestUri.getPath().startsWith(uri.getPath()) && (uri.getPath().endsWith("/") || requestUri.getPath().charAt(uri.getPath().length()) == '/')) //$NON-NLS-1$ { /* * Found the entry. Now find the node corresponding to the * remainder of the path. */ if (requestUri.getPath().equals(uri.getPath())) { return dependency.getValue(); } else { String modulePath = requestUri.getPath().substring(uri.getPath().length()); if (modulePath.startsWith("/")) { //$NON-NLS-1$ modulePath = modulePath.substring(1); } result = dependency.getValue().getDescendent(modulePath); } break; } } return result; }
From source file:eu.asterics.mw.services.ResourceRegistry.java
/** * Returns the file/directory name of a given URI. * This method simply splits the URI.getPath into elements seperated by a slash (/) and returns the last element. * @param absolutePath//ww w.ja v a2 s. c o m * @return */ public static String getLastElementOfURI(URI absolutePath) { String[] elems = absolutePath.getPath().split("/"); if (elems != null && elems.length > 0) { return elems[elems.length - 1]; } return ""; }