Example usage for java.net URI getScheme

List of usage examples for java.net URI getScheme

Introduction

In this page you can find the example usage for java.net URI getScheme.

Prototype

public String getScheme() 

Source Link

Document

Returns the scheme component of this URI.

Usage

From source file:edu.usc.goffish.gofs.namenode.DataNode.java

private static Path convertLocalURIToPath(URI localURI) throws IOException {
    if (localURI == null || localURI.isOpaque() || !localURI.isAbsolute()
            || !"file".equalsIgnoreCase(localURI.getScheme())) {
        throw new IllegalArgumentException();
    }//from w ww. j a va2 s . com
    if (!URIHelper.isLocalURI(localURI)) {
        throw new IOException("uri host " + localURI.getHost() + " is not local");
    }

    String path = localURI.getPath();
    if (path == null) {
        path = "/";
    }
    return Paths.get(URI.create("file://" + path));
}

From source file:com.netflix.iep.http.ClientConfig.java

/** Create a client config instance based on a URI. */
static ClientConfig fromUri(Configuration config, URI uri) {
    Matcher m;//from w  w w  .j  a va  2  s.c  o  m
    ClientConfig cfg;
    switch (uri.getScheme()) {
    case "niws":
        m = NIWS_URI.matcher(uri.toString());
        if (m.matches()) {
            final URI newUri = URI.create(fixPath(relative(uri)));
            cfg = new ClientConfig(config, m.group(1), null, uri, newUri);
        } else {
            throw new IllegalArgumentException("invalid niws uri: " + uri);
        }
        break;
    case "vip":
        m = VIP_URI.matcher(uri.toString());
        if (m.matches()) {
            cfg = new ClientConfig(config, m.group(1), m.group(2), uri, URI.create(relative(uri)));
        } else {
            throw new IllegalArgumentException("invalid vip uri: " + uri);
        }
        break;
    default:
        cfg = new ClientConfig(config, "default", null, uri, uri);
        break;
    }
    return cfg;
}

From source file:eu.planets_project.tb.impl.services.ServiceRegistryManager.java

/**
 * Takes a given http URI and extracts the page's content which is returned as String
 * @param uri//from w  w  w  . ja v  a  2s.c om
 * @return
 * @throws FileNotFoundException
 * @throws IOException
 */
@Deprecated
private static String readUrlContents(URI uri) throws FileNotFoundException, IOException {

    InputStream in = null;
    try {
        if (!uri.getScheme().equals("http")) {
            throw new FileNotFoundException("URI schema " + uri.getScheme() + " not supported");
        }
        in = uri.toURL().openStream();
        boolean eof = false;
        String content = "";
        StringBuffer sb = new StringBuffer();
        while (!eof) {
            int byteValue = in.read();
            if (byteValue != -1) {
                char b = (char) byteValue;
                sb.append(b);
            } else {
                eof = true;
            }
        }
        content = sb.toString();
        if (content != null) {
            //now return the services WSDL content
            return content;
        } else {
            throw new FileNotFoundException("extracted content is null");
        }
    } finally {
        in.close();
    }
}

From source file:com.baidubce.util.HttpUtils.java

/**
 * Returns true if the specified URI is using a non-standard port (i.e. any port other than 80 for HTTP URIs or any
 * port other than 443 for HTTPS URIs)./*  w ww  .  ja v  a 2s  .c  o  m*/
 *
 * @param uri the URI
 * @return True if the specified URI is using a non-standard port, otherwise false.
 */
public static boolean isUsingNonDefaultPort(URI uri) {
    String scheme = uri.getScheme().toLowerCase();
    int port = uri.getPort();
    if (port <= 0) {
        return false;
    }
    if (scheme.equals(Protocol.HTTP.toString())) {
        return port != Protocol.HTTP.getDefaultPort();
    }
    if (scheme.equals(Protocol.HTTPS.toString())) {
        return port != Protocol.HTTPS.getDefaultPort();
    }
    return false;
}

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  ww w  .j  av a2s.  c o  m
        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:io.syndesis.rest.v1.handler.credential.CredentialHandler.java

static URI addFragmentTo(final URI uri, final CallbackStatus status) {
    try {//from  w w  w  .j a  v a 2  s .  c o  m
        final String fragment = SERIALIZER.writeValueAsString(status);

        return new URI(uri.getScheme(), null, uri.getHost(), uri.getPort(), uri.getPath(), uri.getQuery(),
                fragment);
    } catch (JsonProcessingException | URISyntaxException e) {
        throw new IllegalStateException("Unable to add fragment to URI: " + uri + ", for state: " + status, e);
    }
}

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);
        }//ww w  .  j  a va2 s .c  om
    }
    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:com.github.wolf480pl.mias4j.util.AbstractTransformingClassLoader.java

public static URL guessCodeSourceURL(String resourcePath, URL resourceURL) {
    // FIXME: Find a better way to do this
    @SuppressWarnings("restriction")
    String escaped = sun.net.www.ParseUtil.encodePath(resourcePath, false);
    String path = resourceURL.getPath();
    if (!path.endsWith(escaped)) {
        // Umm... whadda we do now? Maybe let's fallback to full resource URL.
        LOG.warn("Resource URL path \"" + path + "\" doesn't end with escaped resource path \"" + escaped
                + "\" for resource \"" + resourcePath + "\"");
        return resourceURL;
    }// w  ww.  jav a2 s .  c  o  m
    path = path.substring(0, path.length() - escaped.length());
    if (path.endsWith("!/")) { // JAR
        path = path.substring(0, path.length() - 2);
    }
    try {
        URI uri = resourceURL.toURI();
        return new URI(uri.getScheme(), uri.getUserInfo(), uri.getHost(), uri.getPort(), path, uri.getQuery(),
                uri.getFragment()).toURL();
    } catch (MalformedURLException | URISyntaxException e) {
        // Umm... whadda we do now? Maybe let's fallback to full resource URL.
        LOG.warn("Couldn't assemble CodeSource URL with modified path", e);
        return resourceURL;
    }
}

From source file:org.springframework.cloud.stream.binder.rabbit.admin.RabbitManagementUtils.java

public static RestTemplate buildRestTemplate(String adminUri, String user, String password) {
    BasicCredentialsProvider credsProvider = new BasicCredentialsProvider();
    credsProvider.setCredentials(new AuthScope(AuthScope.ANY_HOST, AuthScope.ANY_PORT),
            new UsernamePasswordCredentials(user, password));
    HttpClient httpClient = HttpClients.custom().setDefaultCredentialsProvider(credsProvider).build();
    // Set up pre-emptive basic Auth because the rabbit plugin doesn't currently support challenge/response for PUT
    // Create AuthCache instance
    AuthCache authCache = new BasicAuthCache();
    // Generate BASIC scheme object and add it to the local; from the apache docs...
    // auth cache
    BasicScheme basicAuth = new BasicScheme();
    URI uri;
    try {//from ww w  . j ava  2  s . c o m
        uri = new URI(adminUri);
    } catch (URISyntaxException e) {
        throw new RabbitAdminException("Invalid URI", e);
    }
    authCache.put(new HttpHost(uri.getHost(), uri.getPort(), uri.getScheme()), basicAuth);
    // Add AuthCache to the execution context
    final HttpClientContext localContext = HttpClientContext.create();
    localContext.setAuthCache(authCache);
    RestTemplate restTemplate = new RestTemplate(new HttpComponentsClientHttpRequestFactory(httpClient) {

        @Override
        protected HttpContext createHttpContext(HttpMethod httpMethod, URI uri) {
            return localContext;
        }

    });
    restTemplate.setMessageConverters(
            Collections.<HttpMessageConverter<?>>singletonList(new MappingJackson2HttpMessageConverter()));
    return restTemplate;
}

From source file:de.javagl.jgltf.model.io.GltfUtils.java

/**
 * Tries to detect the format of the image data from the given URI, and 
 * return the corresponding string of the <code>"image/..."</code> MIME 
 * type. This may, for example, be <code>"png"</code> or <code>"gif"</code>
 * or <code>"jpeg"</code> (<b>not</b> <code>"jpg"</code>!)
 *  //  w ww  .  ja  va2  s  . co m
 * @param uriString The image data
 * @return The image format string, or <code>null</code> if it can not
 * be detected.
 */
private static String guessImageMimeTypeString(String uriString) {
    try {
        URI uri = new URI(uriString);
        if ("data".equalsIgnoreCase(uri.getScheme())) {
            String raw = uri.getRawSchemeSpecificPart().toLowerCase();
            return getStringBetween(raw, "image/", ";base64");
        }
    } catch (URISyntaxException e) {
        return null;
    }
    int lastDotIndex = uriString.lastIndexOf('.');
    if (lastDotIndex == -1) {
        return null;
    }
    String end = uriString.substring(lastDotIndex + 1).toLowerCase();
    if (end.equals("jpg") || end.equals("jpeg")) {
        return "jpeg";
    }
    return end;
}