protected String hostInfoForCommandline() { try { URI uri = new URI(url); if (uri.getUserInfo() != null) { //(String scheme, String userInfo, String host, int port, String path, String query, String fragment) uri = new URI(uri.getScheme(), uri.getUserInfo(), uri.getHost(), uri.getPort(), null, null, null); } return uri.toString(); } catch (URISyntaxException e) { // In subversion we may have a file path that is not actually a URL return url; } }
/** * Helper function used to work around the fact that if you use an S3 bucket with an '_' that java.net.URI * behaves differently and sets the host value to null whereas S3 buckets without '_' have a properly * set host field. '_' is only allowed in S3 bucket names in us-east-1. * * @param uri The URI from which to extract a host value. * @return The host value where uri.getAuthority() is used when uri.getHost() returns null as long as no UserInfo is present. * @throws IllegalArgumentException If the bucket can not be determined from the URI. */ public static String getBucketName(URI uri) { if (uri.getHost() != null) { return uri.getHost(); } if (uri.getUserInfo() == null) { return uri.getAuthority(); } throw new IllegalArgumentException("Unable to determine S3 bucket from URI."); }
public static void setData(URI uri, HashMap<String, Object> properties, Set<String> allowableProperties, Map<String, String> query, Map<String, Object> extraProps) { if (allowableProperties.contains("host")) { properties.put("host", "" + uri.getHost()); } if (allowableProperties.contains("port")) { properties.put("port", "" + uri.getPort()); } if (allowableProperties.contains("userInfo")) { properties.put("userInfo", "" + uri.getUserInfo()); } for (Map.Entry<String, String> entry : query.entrySet()) { if (allowableProperties.contains(entry.getKey())) { properties.put(entry.getKey(), entry.getValue()); } else { extraProps.put(entry.getKey(), entry.getValue()); } } }
private void setupStoreAndSmtpTransport(String serverType, String schemePrefix) throws URISyntaxException { String domainPart = EmailHelper.getDomainFromEmailAddress(mAccount.getEmail()); String suggestedStoreServerName = serverNameSuggester.suggestServerName(serverType, domainPart); URI storeUriForDecode = new URI(mAccount.getStoreUri()); URI storeUri = new URI(schemePrefix, storeUriForDecode.getUserInfo(), suggestedStoreServerName, storeUriForDecode.getPort(), null, null, null); mAccount.setStoreUri(storeUri.toString()); String suggestedTransportServerName = serverNameSuggester.suggestServerName(Protocols.SMTP, domainPart); URI transportUriForDecode = new URI(mAccount.getTransportUri()); URI transportUri = new URI("smtp+tls+", transportUriForDecode.getUserInfo(), suggestedTransportServerName, transportUriForDecode.getPort(), null, null, null); mAccount.setTransportUri(transportUri.toString()); }
/** * Set the URI scheme, AKA the 'protocol.' e.g. * <code>setScheme('https')</code> * * @throws URISyntaxException if the given scheme contains illegal characters. */ public URIBuilder setScheme(String scheme) throws URISyntaxException { this.base = new URI(scheme, base.getUserInfo(), base.getHost(), base.getPort(), base.getPath(), base.getQuery(), base.getFragment()); return this; }
private void setupDav() throws URISyntaxException { URI uriForDecode = new URI(mAccount.getStoreUri()); /* * The user info we have been given from * AccountSetupBasics.onManualSetup() is encoded as an IMAP store * URI: AuthType:UserName:Password (no fields should be empty). * However, AuthType is not applicable to WebDAV nor to its store * URI. Re-encode without it, using just the UserName and Password. */ String userPass = ""; String[] userInfo = uriForDecode.getUserInfo().split(":"); if (userInfo.length > 1) { userPass = userInfo[1]; } if (userInfo.length > 2) { userPass = userPass + ":" + userInfo[2]; } String domainPart = EmailHelper.getDomainFromEmailAddress(mAccount.getEmail()); String suggestedServerName = serverNameSuggester.suggestServerName(Protocols.WEBDAV, domainPart); URI uri = new URI("webdav+ssl+", userPass, suggestedServerName, uriForDecode.getPort(), null, null, null); mAccount.setStoreUri(uri.toString()); }
@Override public void initialize(URI uri, Configuration conf) throws IOException { // get super.initialize(uri, conf); // get host information from uri (overrides info in conf) String host = uri.getHost(); host = (host == null) ? conf.get(FS_FTP_HOST, null) : host; if (host == null) { throw new IOException("Invalid host specified"); } conf.set(FS_FTP_HOST, host); // get port information from uri, (overrides info in conf) int port = uri.getPort(); port = (port == -1) ? FTP.DEFAULT_PORT : port; conf.setInt(FS_FTP_HOST_PORT, port); // get user/password information from URI (overrides info in conf) String userAndPassword = uri.getUserInfo(); if (userAndPassword == null) { userAndPassword = (conf.get(FS_FTP_USER_PREFIX + host, null) + ":" + conf .get(FS_FTP_PASSWORD_PREFIX + host, null)); } String[] userPasswdInfo = userAndPassword.split(":"); Preconditions.checkState(userPasswdInfo.length > 1, "Invalid username / password"); conf.set(FS_FTP_USER_PREFIX + host, userPasswdInfo[0]); conf.set(FS_FTP_PASSWORD_PREFIX + host, userPasswdInfo[1]); setConf(conf); this.uri = uri; }
/** * The document fragment, without a preceeding '#' * * @param fragment * @return this URIBuilder instance, for method chaining. * @throws URISyntaxException if the given value contains illegal characters. */ public URIBuilder setFragment(String fragment) throws URISyntaxException { this.base = new URI(base.getScheme(), base.getUserInfo(), base.getHost(), base.getPort(), base.getPath(), base.getQuery(), fragment); return this; }
public static <P> P setData(URI uri, P obj, Map<String, String> query) throws Exception { synchronized (beanUtils) { beanUtils.setProperty(obj, "host", uri.getHost()); beanUtils.setProperty(obj, "port", uri.getPort()); beanUtils.setProperty(obj, "userInfo", uri.getUserInfo()); beanUtils.populate(obj, query); } return obj; }
private URI getSubNamespaceURI(String ns) throws URISyntaxException { return new URI( namespace.getScheme(), namespace.getUserInfo(), namespace.getHost(), namespace.getPort(), namespace.getPath() + "/" + ZNODE_SUB_NAMESPACES + "/" + ns, namespace.getQuery(), namespace.getFragment()); }
final Proxy proxy = new Proxy(Proxy.Type.HTTP, new InetSocketAddress(httpProxyUri.getHost(), httpProxyUri.getPort())); final ProxySelector proxySelector = new ProxySelector() { @Override if (!isNullOrEmpty(httpProxyUri.getUserInfo())) { final List<String> list = Splitter.on(":") .limit(2) .splitToList(httpProxyUri.getUserInfo()); if (list.size() == 2) { clientBuilder.proxyAuthenticator(new ProxyAuthenticator(list.get(0), list.get(1)));
protected String hostInfoForDisplay() { try { URI uri = new URI(url); if (uri.getUserInfo() != null) { //(String scheme, String userInfo, String host, int port, String path, String query, String fragment) uri = new URI(uri.getScheme(), clean(uri.getScheme(), uri.getUserInfo()), uri.getHost(), uri.getPort(), null, null, null); } return uri.toString(); } catch (URISyntaxException e) { // In subversion we may have a file path that is not actually a URL return url; } }
public URIBuilder setPort(int port) throws URISyntaxException { this.base = new URI(base.getScheme(), base.getUserInfo(), base.getHost(), port, base.getPath(), base.getQuery(), base.getFragment()); return this; }
public URIBuilder setHost(String host) throws URISyntaxException { this.base = new URI(base.getScheme(), base.getUserInfo(), host, base.getPort(), base.getPath(), base.getQuery(), base.getFragment()); return this; }
/** * Given a URI value create and return a new URI that matches the target one but with the scheme value * supplied to this method. * * @param bindAddr The URI whose scheme value should be altered. * @param scheme The new scheme value to use for the returned URI. * @return a new URI that is a copy of the original except that its scheme matches the supplied one. * @throws java.net.URISyntaxException */ public static URI changeScheme(URI bindAddr, String scheme) throws URISyntaxException { return new URI(scheme, bindAddr.getUserInfo(), bindAddr.getHost(), bindAddr.getPort(), bindAddr.getPath(), bindAddr.getQuery(), bindAddr.getFragment()); }
/** * Creates a new {@link URI} from the given URI by replacing the host value. * @param uri Original URI * @param newHostPrefix New host for the uri */ public static URI updateUriHost(URI uri, String newHostPrefix) { try { return new URI(uri.getScheme(), uri.getUserInfo(), newHostPrefix + uri.getHost(), uri.getPort(), uri.getPath(), uri.getQuery(), uri.getFragment()); } catch (URISyntaxException e) { throw new RuntimeException(e); } } }
public String defaultRemoteUrl() { final String sanitizedUrl = sanitizeUrl(); try { URI uri = new URI(sanitizedUrl); if (uri.getUserInfo() != null) { uri = new URI(uri.getScheme(), removePassword(uri.getUserInfo()), uri.getHost(), uri.getPort(), uri.getPath(), uri.getQuery(), uri.getFragment()); return uri.toString(); } } catch (URISyntaxException e) { return sanitizedUrl; } return sanitizedUrl; } }
private static URI buildURI(NodeId nodeId, URI baseUri) throws URISyntaxException { final String queryParams = "anonid=" + nodeId.anonymize() + "&version=" + ServerVersion.VERSION.toString(); return new URI( baseUri.getScheme(), baseUri.getUserInfo(), baseUri.getHost(), baseUri.getPort(), baseUri.getPath(), isNullOrEmpty(baseUri.getQuery()) ? queryParams : baseUri.getQuery() + "&" + queryParams, baseUri.getFragment() ); }
/** * Returns the given URI with any path, query or fragment stripped off. */ private static URI toFileSystemUri(URI uri) { try { return new URI( uri.getScheme(), uri.getUserInfo(), uri.getHost(), uri.getPort(), null, null, null); } catch (URISyntaxException e) { throw new AssertionError(e); } }
@Nullable public static URI getUriWithDefaultPath(@Nullable final URI uri, final String path) { if (uri == null) { return null; } try { return new URI( uri.getScheme(), uri.getUserInfo(), uri.getHost(), uri.getPort(), isNullOrEmpty(uri.getPath()) ? path : uri.getPath(), uri.getQuery(), uri.getFragment()); } catch (URISyntaxException e) { throw new RuntimeException("Could not parse URI.", e); } }