Example usage for java.net URI getAuthority

List of usage examples for java.net URI getAuthority

Introduction

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

Prototype

public String getAuthority() 

Source Link

Document

Returns the decoded authority component of this URI.

Usage

From source file:oauth.signpost.signature.SignatureBaseString.java

public 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  v a2 s.  co  m
    }
    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.solr.client.solrj.io.sql.DriverImpl.java

protected URI processUrl(String url) throws SQLException {
    URI uri;
    try {// w  ww .  j a  v a 2s.c o  m
        uri = new URI(url.replaceFirst("jdbc:", ""));
    } catch (URISyntaxException e) {
        throw new SQLException(e);
    }

    if (uri.getAuthority() == null) {
        throw new SQLException("The zkHost must not be null");
    }

    return uri;
}

From source file:com.github.brandtg.pantopod.crawler.DbiBasedCrawlingEventHandler.java

@Override
protected void handleExternalDomain(URI srcUrl, URI dstUrl) throws IOException {
    try (Handle handle = dbi.open()) {
        int numRows = handle.update("INSERT IGNORE INTO `pantopod_ext` (`src_url`, `dst_url`) VALUES (?, ?)",
                srcUrl.getAuthority(), dstUrl.getAuthority());
        if (numRows > 0) {
            LOG.info("Inserted {} #=> {}", srcUrl.getAuthority(), dstUrl.getAuthority());
        }// www .  ja v  a 2  s.co m
    }
}

From source file:watchserver.util.FTPConfig.java

/**
 * //from  w w  w .  j  a  v a  2 s.  c o m
 * @return
 *     The FTP folder string to be monitored 
 */
public String getFullFTPUri() {
    URI uri = URI.create(getFolder());
    return uri.getScheme() + "://" + connection.getUsername() + ":" + connection.getPassword() + "@"
            + uri.getAuthority() + ":" + connection.getPort() + connection.getPathtomonitor();
}

From source file:org.apache.oozie.tools.TestOozieSharelibCLI.java

private FileSystem getTargetFileSysyem() throws Exception {
    if (fs == null) {
        HadoopAccessorService has = getServices().get(HadoopAccessorService.class);
        URI uri = new Path(outPath).toUri();
        Configuration fsConf = has.createJobConf(uri.getAuthority());
        fs = has.createFileSystem(System.getProperty("user.name"), uri, fsConf);
    }//from  w  w  w.j  a  v a 2s  .  co  m
    return fs;

}

From source file:com.bazaarvoice.seo.sdk.util.BVUtility.java

public static String removeBVParameters(String url) {
    String newUrl = url;/*  w w  w  .  j  a v a2s. co  m*/
    if (newUrl.contains("bvstate=")) {
        // Handle usecase with more parameters after bvstate
        newUrl = newUrl.replaceAll(BVConstant.BVSTATE_REGEX_WITH_TRAILING_SEPARATOR, "");

        // Handle usecase where bvstate is the last parameter
        if (newUrl.endsWith("?") | newUrl.endsWith("&")) {
            newUrl = newUrl.substring(0, newUrl.length() - 1);
        }
        if (newUrl.endsWith(BVConstant.ESCAPED_FRAGMENT_MULTIVALUE_SEPARATOR)) {
            newUrl = newUrl.substring(0, newUrl.length() - 3);
        }
    }

    if (hasBVQueryParameters(newUrl)) {
        final URI uri;
        try {
            uri = new URI(newUrl);
        } catch (URISyntaxException e) {
            return newUrl;
        }

        try {
            String newQuery = null;
            if (uri.getQuery() != null && uri.getQuery().length() > 0) {
                List<NameValuePair> newParameters = new ArrayList<NameValuePair>();
                List<NameValuePair> parameters = URLEncodedUtils.parse(uri.getQuery(),
                        Charset.forName("UTF-8"));
                for (NameValuePair parameter : parameters) {
                    if (!bvQueryParameters.contains(parameter.getName())) {
                        newParameters.add(parameter);
                    }
                }
                newQuery = newParameters.size() > 0
                        ? URLEncodedUtils.format(newParameters, Charset.forName("UTF-8"))
                        : null;
            }

            return new URI(uri.getScheme(), uri.getAuthority(), uri.getPath(), newQuery, null).toString();
        } catch (URISyntaxException e) {
            return newUrl;
        }
    }
    return newUrl;
}

From source file:com.rightscale.provider.rest.DashboardSession.java

public HttpGet createGet(URI uri) {
    HttpGet get = new HttpGet(uri.toString());
    get.addHeader("Host", uri.getAuthority());
    get.addHeader("Accept", "application/json,text/json,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5");
    get.addHeader("User-Agent", "com.rightscale.provider");
    get.addHeader("X-API-Version", "1.0");
    return get;//ww  w . j  a  va2s .c  om
}

From source file:org.apache.hadoop.hive.ql.exec.repl.bootstrap.events.filesystem.FSTableEvent.java

FSTableEvent(HiveConf hiveConf, String metadataDir) {
    try {/* www . java 2  s.  c o  m*/
        URI fromURI = EximUtil.getValidatedURI(hiveConf, PlanUtils.stripQuotes(metadataDir));
        fromPath = new Path(fromURI.getScheme(), fromURI.getAuthority(), fromURI.getPath());
        FileSystem fs = FileSystem.get(fromURI, hiveConf);
        metadata = EximUtil.readMetaData(fs, new Path(fromPath, EximUtil.METADATA_NAME));
        this.hiveConf = hiveConf;
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}

From source file:org.portletbridge.portlet.BridgeFunctions.java

private URI resolveUrl(URI base, String trim) {
    URI url = null;//from www.j  av a2s  . c o  m
    if (trim.startsWith("?")) {
        return URI.create(base.getScheme() + "://" + base.getAuthority() + base.getPath() + trim);
    } else {
        url = base.resolve(trim);
    }
    return url;
}

From source file:org.apache.bookkeeper.stream.cli.commands.cluster.InitClusterCommand.java

@Override
protected boolean apply(ServiceURI ignored, CompositeConfiguration conf, BKFlags globalFlags, Flags cmdFlags) {
    checkArgument(!cmdFlags.arguments.isEmpty(), "No service URI is provided");

    ServiceURI serviceURI = ServiceURI.create(cmdFlags.arguments.get(0));

    if (null != cmdFlags.clusterName) {
        checkArgument(!cmdFlags.clusterName.contains("/"), "Invalid cluster name : " + cmdFlags.clusterName);
    }//from  w  w  w . j  a v  a2s  .  com

    checkArgument(!Strings.isNullOrEmpty(cmdFlags.ledgersPath) && cmdFlags.ledgersPath.startsWith("/"),
            "Invalid ledgers root metadata path : " + cmdFlags.ledgersPath);

    checkArgument(!Strings.isNullOrEmpty(cmdFlags.dlogPath) && cmdFlags.dlogPath.startsWith("/"),
            "Invalid dlog root metadata path : " + cmdFlags.dlogPath);

    checkArgument(cmdFlags.numStorageContainers > 0,
            "Zero or negative number of storage containers configured");

    String clusterName = null == cmdFlags.clusterName ? "" : cmdFlags.clusterName;
    String ledgersPath = getFullyQualifiedPath(clusterName, cmdFlags.ledgersPath);
    String dlogPath = getFullyQualifiedPath(clusterName, cmdFlags.dlogPath);

    String metadataServiceHosts = StringUtils.join(serviceURI.getServiceHosts(), ",");

    try (CuratorFramework client = CuratorFrameworkFactory.newClient(metadataServiceHosts,
            new BoundedExponentialBackoffRetry(100, 10000, 20))) {
        client.start();

        URI uri = serviceURI.getUri();
        URI rootUri = new URI(uri.getScheme(), uri.getAuthority(), "", null, null);

        String ledgersUri = rootUri.toString() + ledgersPath;
        String dlogUri = rootUri.toString() + dlogPath;

        log.info("Initializing cluster {} : \n" + "\tledgers : path = {}, uri = {}\n"
                + "\tdlog: path = {}, uri = {}\n" + "\tstream storage: path = {}, num_storage_containers = {}",
                clusterName, ledgersPath, ledgersUri, dlogPath, dlogUri, StorageConstants.ZK_METADATA_ROOT_PATH,
                cmdFlags.numStorageContainers);

        // create the cluster root path
        initializeCluster(client, clusterName);

        // init the ledgers metadata
        initLedgersMetadata(ledgersUri);

        // init the dlog metadata
        initDlogMetadata(client, metadataServiceHosts, dlogUri, dlogPath, ledgersPath);

        // init the stream storage metadata
        initStreamStorageMetadata(metadataServiceHosts, ledgersUri, cmdFlags.numStorageContainers);
        log.info("Successfully initialized cluster {}", clusterName);
        return true;
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}