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: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  va2  s .  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:io.druid.storage.s3.S3DataSegmentPuller.java

public static URI checkURI(URI uri) {
    if (uri.getScheme().equalsIgnoreCase(scheme)) {
        uri = URI.create("s3" + uri.toString().substring(scheme.length()));
    } else if (!uri.getScheme().equalsIgnoreCase("s3")) {
        throw new IAE("Don't know how to load scheme for URI [%s]", uri.toString());
    }/*from  w  ww  .  ja  va 2  s  .  co m*/
    return uri;
}

From source file:com.magnet.tools.tests.RestStepDefs.java

/**
 * @return get a test http client that trusts all certs
 *//*w w w.  ja v a 2s  .  c o m*/
private static CloseableHttpClient getTestHttpClient(URI uri) {
    String scheme = uri.getScheme();
    int port = uri.getPort();
    if (scheme.toLowerCase().equals("https")) {
        try {
            SSLSocketFactory sf = new SSLSocketFactory(new TrustStrategy() {
                @Override
                public boolean isTrusted(X509Certificate[] chain, String authType) throws CertificateException {
                    return true;
                }
            }, new AllowAllHostnameVerifier());

            SchemeRegistry registry = new SchemeRegistry();
            registry.register(new Scheme("https", port, sf));
            ClientConnectionManager ccm = new ThreadSafeClientConnManager(registry);
            return new DefaultHttpClient(ccm);
        } catch (Exception e) {
            e.printStackTrace();
            return new DefaultHttpClient();
        }
    } else {
        return new DefaultHttpClient();
    }
}

From source file:net.ripe.rpki.commons.crypto.x509cert.X509CertificateUtil.java

public static URI findFirstRsyncCrlDistributionPoint(X509Certificate certificate) {
    URI[] crlDistributionPoints = getCrlDistributionPoints(certificate);
    if (crlDistributionPoints == null) {
        return null;
    }/*from   ww  w .  j av  a 2  s  . c om*/
    for (URI uri : crlDistributionPoints) {
        if (uri.getScheme().equals("rsync")) {
            return uri;
        }
    }
    return null;
}

From source file:org.fcrepo.server.utilities.ServerUtility.java

/**
 * Tell whether the given URL appears to be referring to somewhere within
 * the Fedora webapp.// w w w .j a v a2s  .  c  om
 */
public static boolean isURLFedoraServer(String url) {

    // scheme must be http or https
    URI uri = URI.create(url);
    String scheme = uri.getScheme();
    if (!scheme.equals("http") && !scheme.equals("https")) {
        return false;
    }

    // host must be configured hostname or localhost
    String fHost = CONFIG.getParameter(FEDORA_SERVER_HOST, Parameter.class).getValue();
    String host = uri.getHost();
    if (!host.equals(fHost) && !host.equals("localhost")) {
        return false;
    }

    // path must begin with configured webapp context
    String path = uri.getPath();
    String fedoraContext = CONFIG.getParameter(FEDORA_SERVER_CONTEXT, Parameter.class).getValue();
    if (!path.startsWith("/" + fedoraContext + "/")) {
        return false;
    }

    // port specification must match http or https port as appropriate
    String httpPort = CONFIG.getParameter(FEDORA_SERVER_PORT, Parameter.class).getValue();
    String httpsPort = CONFIG.getParameter(FEDORA_REDIRECT_PORT, Parameter.class).getValue();
    if (uri.getPort() == -1) {
        // unspecified, so fedoraPort must be 80 (http), or 443 (https)
        if (scheme.equals("http")) {
            return httpPort.equals("80");
        } else {
            return httpsPort.equals("443");
        }
    } else {
        // specified, so must match appropriate http or https port
        String port = "" + uri.getPort();
        if (scheme.equals("http")) {
            return port.equals(httpPort);
        } else {
            return port.equals(httpsPort);
        }
    }

}

From source file:com.sap.prd.mobile.ios.mios.SCMUtil.java

public static String getConnectionString(final Properties versionInfo,
        final boolean hideConfidentialInformation) throws IOException {

    final String type = versionInfo.getProperty("type");

    final StringBuilder connectionString = new StringBuilder(128);

    if (type != null && type.equals("git")) {

        final String repo = versionInfo.getProperty("repo");

        if (StringUtils.isBlank(repo)) {
            if (!StringUtils.isBlank(versionInfo.getProperty("repo_1"))) {
                throw new IllegalStateException(
                        "Multipe git repositories provided. This use case is not supported. Provide only one git repository.");
            }/*from   w w w. j  a v a 2  s  .  c  o  m*/
            throw new IllegalStateException("No git repository provided. ");
        }

        if (hideConfidentialInformation) {
            try {
                URI uri = new URI(repo);
                int port = uri.getPort();
                if (port == -1) {
                    final String scheme = uri.getScheme();
                    if (scheme != null && gitDefaultPorts.containsKey(scheme)) {
                        port = gitDefaultPorts.get(scheme);
                    }
                }
                connectionString.append(port);

                if (uri.getHost() != null) {
                    connectionString.append(uri.getPath());
                }
            } catch (URISyntaxException e) {
                throw new IllegalStateException(String.format("Invalid repository uri: %s", repo));
            }
        } else {
            connectionString.append(PROTOCOL_PREFIX_GIT).append(repo);
        }

    } else {

        final String port = versionInfo.getProperty("port");

        if (StringUtils.isBlank(port))
            throw new IllegalStateException("No SCM port provided.");

        final String depotPath = versionInfo.getProperty("depotpath");

        if (hideConfidentialInformation) {
            try {
                URI perforceUri = new URI("perforce://" + port);

                int _port = perforceUri.getPort();
                if (_port == -1) {
                    _port = PERFORCE_DEFAULT_PORT;
                }
                connectionString.append(_port);
                connectionString.append(depotPath);
            } catch (URISyntaxException e) {
                throw new IllegalStateException(String.format("Invalid port: %s", port));
            }
        } else {

            if (StringUtils.isBlank(depotPath))
                throw new IllegalStateException("No depot path provided.");

            connectionString.append(PROTOCOL_PREFIX_PERFORCE).append(port).append(":")
                    .append(getDepotPath(depotPath));
        }
    }

    return connectionString.toString();
}

From source file:com.microsoft.tfs.client.common.ui.teamexplorer.helpers.ArtifactLinkHelpers.java

public static void openHyperlinkLink(final Shell shell, String location) {
    /*/* w w  w .j  a va  2 s . c  o m*/
     * A Hyperlink can hold any string value up to 256 characters - not just
     * well-formed URLs. Try to detect any scheme, and if none is present,
     * use http. Visual Studio's IVsWebBrowsingService.Navigate provides
     * similar functionality.
     */

    URI uri;
    try {
        uri = URIUtils.newURI(location);
        if (StringUtil.isNullOrEmpty(uri.getScheme())) {
            location = "http://" + location; //$NON-NLS-1$
            uri = URIUtils.newURI(location);
        }
    } catch (final IllegalArgumentException e) {
        final String messageFormat = Messages.getString("WorkItemLinksControl.ErrorDialogTextFormat"); //$NON-NLS-1$
        final String message = MessageFormat.format(messageFormat, location);
        MessageBoxHelpers.errorMessageBox(shell, null, message);
        return;
    }

    BrowserFacade.launchURL(uri, location);
}

From source file:ch.entwine.weblounge.common.impl.util.TestUtils.java

/**
 * Issues the the given request.//from  w w  w .ja  va  2 s.  c  om
 * 
 * @param httpClient
 *          the http client
 * @param request
 *          the request
 * @param params
 *          the request parameters
 * @throws Exception
 *           if the request fails
 */
public static HttpResponse request(HttpClient httpClient, HttpUriRequest request, String[][] params)
        throws Exception {
    if (params != null) {
        if (request instanceof HttpGet) {
            List<NameValuePair> qparams = new ArrayList<NameValuePair>();
            if (params.length > 0) {
                for (String[] param : params) {
                    if (param.length < 2)
                        continue;
                    qparams.add(new BasicNameValuePair(param[0], param[1]));
                }
            }
            URI requestURI = request.getURI();
            URI uri = URIUtils.createURI(requestURI.getScheme(), requestURI.getHost(), requestURI.getPort(),
                    requestURI.getPath(), URLEncodedUtils.format(qparams, "utf-8"), null);
            HeaderIterator headerIterator = request.headerIterator();
            request = new HttpGet(uri);
            while (headerIterator.hasNext()) {
                request.addHeader(headerIterator.nextHeader());
            }
        } else if (request instanceof HttpPost) {
            List<NameValuePair> formparams = new ArrayList<NameValuePair>();
            for (String[] param : params)
                formparams.add(new BasicNameValuePair(param[0], param[1]));
            UrlEncodedFormEntity entity = new UrlEncodedFormEntity(formparams, "utf-8");
            ((HttpPost) request).setEntity(entity);
        } else if (request instanceof HttpPut) {
            List<NameValuePair> formparams = new ArrayList<NameValuePair>();
            for (String[] param : params)
                formparams.add(new BasicNameValuePair(param[0], param[1]));
            UrlEncodedFormEntity entity = new UrlEncodedFormEntity(formparams, "utf-8");
            ((HttpPut) request).setEntity(entity);
        }
    } else {
        if (request instanceof HttpPost || request instanceof HttpPut) {
            UrlEncodedFormEntity entity = new UrlEncodedFormEntity(new ArrayList<NameValuePair>(), "utf-8");
            ((HttpEntityEnclosingRequestBase) request).setEntity(entity);
        }
    }
    return httpClient.execute(request);
}

From source file:com.vmware.identity.openidconnect.protocol.URIUtils.java

public static boolean areEqual(URI lhs, URI rhs) {
    Validate.notNull(lhs, "lhs");
    Validate.notNull(rhs, "rhs");

    URI lhsCopy;/*from   www. j av  a 2s. c o m*/
    URI rhsCopy;
    try {
        lhsCopy = new URI(lhs.getScheme(), lhs.getUserInfo(), lhs.getHost(), URIUtils.getPort(lhs),
                lhs.getPath(), lhs.getQuery(), lhs.getFragment());
        rhsCopy = new URI(rhs.getScheme(), rhs.getUserInfo(), rhs.getHost(), URIUtils.getPort(rhs),
                rhs.getPath(), rhs.getQuery(), rhs.getFragment());
    } catch (URISyntaxException e) {
        throw new IllegalArgumentException("failed to transform uri for equality check", e);
    }

    return lhsCopy.equals(rhsCopy);
}

From source file:nl.esciencecenter.octopus.webservice.mac.MacScheme.java

/**
 *
 * @param uri/* w  ww. j  ava  2 s  .co  m*/
 * @return Port of `uri` based on explicit port or derived from scheme
 */
public static int getPort(URI uri) {
    int port = uri.getPort();
    if (port == -1) {
        String scheme = uri.getScheme();
        if (scheme.equals("http")) {
            port = 80;
        } else if (scheme.equals("https")) {
            port = 443;
        }
    }
    return port;
}