List of usage examples for java.net URI getAuthority
public String getAuthority()
From source file:org.apache.hadoop.security.ProviderUtils.java
/** * Convert a nested URI to decode the underlying path. The translation takes * the authority and parses it into the underlying scheme and authority. * For example, "myscheme://hdfs@nn/my/path" is converted to * "hdfs://nn/my/path"./*from w w w. j av a 2 s. c om*/ * @param nestedUri the URI from the nested URI * @return the unnested path */ public static Path unnestUri(URI nestedUri) { StringBuilder result = new StringBuilder(); String authority = nestedUri.getAuthority(); if (authority != null) { String[] parts = nestedUri.getAuthority().split("@", 2); result.append(parts[0]); result.append("://"); if (parts.length == 2) { result.append(parts[1]); } } result.append(nestedUri.getPath()); if (nestedUri.getQuery() != null) { result.append("?"); result.append(nestedUri.getQuery()); } if (nestedUri.getFragment() != null) { result.append("#"); result.append(nestedUri.getFragment()); } return new Path(result.toString()); }
From source file:org.eclipse.aether.transport.http.UriUtils.java
public static URI resolve(URI base, URI ref) { String path = ref.getRawPath(); if (path != null && path.length() > 0) { path = base.getRawPath();//from w w w .j a v a2 s . c om if (path == null || !path.endsWith("/")) { try { base = new URI(base.getScheme(), base.getAuthority(), base.getPath() + '/', null, null); } catch (URISyntaxException e) { throw new IllegalStateException(e); } } } return URIUtils.resolve(base, ref); }
From source file:utils.Config.java
/** * Make a full URI from the given {@code uri} and the configuration. * * The new url is created by copying the given url and fill scheme and * authority if they are empty./* w w w . j ava 2s . co m*/ * * @param uri * @return * @throws URISyntaxException */ public static URI createFullURI(URI uri) throws URISyntaxException { String scheme = uri.getScheme(); String authority = uri.getAuthority(); scheme = (scheme != null) ? scheme : getScheme(); authority = (authority != null) ? authority : getHostport(); return new URI(scheme, authority, uri.getPath(), uri.getQuery(), uri.getFragment()); }
From source file:AIR.Common.Web.FileFtpHandler.java
/** * Makes FTP call to the provided URI and retrieves contents * /*from w ww. j a va 2s. co m*/ * @param uri * @return ByteArrayInputStream * @throws FtpResourceException */ public static byte[] getBytes(URI uri) throws FtpResourceException { try { FTPClient ftp = new FTPClient(); String[] credentialsAndHost = uri.getAuthority().split("@"); String host = credentialsAndHost[1]; String[] credentials = credentialsAndHost[0].split(":"); ftp.connect(host); ftp.enterLocalPassiveMode(); if (!ftp.login(credentials[0], credentials[1])) { ftp.logout(); ftp.disconnect(); throw new RuntimeException("FTP Authentication Failure"); } int reply = ftp.getReplyCode(); if (!FTPReply.isPositiveCompletion(reply)) { ftp.logout(); ftp.disconnect(); throw new RuntimeException("FTP No reponse from server"); } ftp.setFileType(FTPClient.BINARY_FILE_TYPE); ByteArrayOutputStream output = new ByteArrayOutputStream(); ftp.retrieveFile(uri.getPath(), output); output.close(); ftp.logout(); ftp.disconnect(); return output.toByteArray(); } catch (IOException ex) { throw new FtpResourceException(ex); } }
From source file:eu.eubrazilcc.lvl.core.servlet.ServletUtils.java
/** * Gets the portal endpoint by inspecting the application configuration. In case that the endpoint * cannot be discovered from the configuration, * @param baseUri - the base URI where the service is running * @return//from ww w . j a va 2s. co m */ public static final URI getPortalEndpoint(final URI baseUri) { URI portalUri = null; try { final String portalEndpoint = CONFIG_MANAGER.getPortalEndpoint(); portalUri = isNotBlank(portalEndpoint) ? new URI(portalEndpoint.replaceAll("/$", "")) : new URI(baseUri.getScheme(), baseUri.getAuthority(), null, null, null); } catch (URISyntaxException e) { LOGGER.error("Failed to create LVL portal endpoint", e); } return portalUri; }
From source file:org.apache.hadoop.yarn.server.webproxy.ProxyUriUtils.java
/** * Get a proxied URI for the original URI. * @param originalUri the original URI to go through the proxy, or null if * a default path "/" can be used. /*from w w w. java2 s . c o m*/ * @param proxyUri the URI of the proxy itself, scheme, host and port are used. * @param id the id of the application * @return the proxied URI */ public static URI getProxyUri(URI originalUri, URI proxyUri, ApplicationId id) { try { String path = getPath(id, originalUri == null ? "/" : originalUri.getPath()); return new URI(proxyUri.getScheme(), proxyUri.getAuthority(), path, originalUri == null ? null : originalUri.getQuery(), originalUri == null ? null : originalUri.getFragment()); } catch (URISyntaxException e) { throw new RuntimeException("Could not proxify " + originalUri, e); } }
From source file:org.wso2.carbon.identity.oidc.session.util.OIDCSessionManagementUtil.java
/** * Returns the origin of the provided url * <scheme>://<host>:<port> * * @param url/*ww w. j a v a 2 s . c om*/ * @return origin of the url */ public static String getOrigin(String url) { try { URI uri = new URL(url).toURI(); return uri.getScheme() + "://" + uri.getAuthority(); } catch (MalformedURLException | URISyntaxException e) { log.error("Error while parsing URL origin of " + url + ". URL seems to be malformed."); } return null; }
From source file:com.ibm.jaggr.core.util.PathUtil.java
public static URI stripJsExtension(URI value) throws URISyntaxException { if (value == null) { return null; }/*from w ww .j a v a 2s .co m*/ return value.getPath().endsWith(".js") ? //$NON-NLS-1$ new URI(value.getScheme(), value.getAuthority(), value.getPath().substring(0, value.getPath().length() - 3), value.getQuery(), value.getFragment()) : value; }
From source file:net.oauth.signature.OAuthSignatureMethod.java
protected static String normalizeUrl(String url) throws URISyntaxException { URI uri = new URI(url); String scheme = uri.getScheme().toLowerCase(); String authority = uri.getAuthority().toLowerCase(); boolean dropPort = (scheme.equals("http") && uri.getPort() == 80) || (scheme.equals("https") && uri.getPort() == 443); if (dropPort) { // find the last : in the authority int index = authority.lastIndexOf(":"); if (index >= 0) { authority = authority.substring(0, index); }//from ww w .j a va2 s . com } String path = uri.getRawPath(); if (path == null || path.length() <= 0) { path = "/"; // conforms to RFC 2616 section 3.2.2 } // we know that there is no query and no fragment here. return scheme + "://" + authority + path; }
From source file:org.apache.hadoop.fs.s3native.S3xLoginHelper.java
/** * Build the filesystem URI. This can include stripping down of part * of the URI.//w ww . ja v a2 s . c o m * @param uri filesystem uri * @return the URI to use as the basis for FS operation and qualifying paths. * @throws IllegalArgumentException if the URI is in some way invalid. */ public static URI buildFSURI(URI uri) { Objects.requireNonNull(uri, "null uri"); Objects.requireNonNull(uri.getScheme(), "null uri.getScheme()"); if (uri.getHost() == null && uri.getAuthority() != null) { Objects.requireNonNull(uri.getHost(), "null uri host." + " This can be caused by unencoded / in the password string"); } Objects.requireNonNull(uri.getHost(), "null uri host."); return URI.create(uri.getScheme() + "://" + uri.getHost()); }