Example usage for java.net URI getHost

List of usage examples for java.net URI getHost

Introduction

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

Prototype

public String getHost() 

Source Link

Document

Returns the host component of this URI.

Usage

From source file:com.orange.clara.tool.crawlers.rss.RssCrawler.java

@Override
public String generateTitle(WatchedResource watchedResource) throws CrawlerGetContentException {
    URI uri = URI.create(watchedResource.getLink());
    return "Rss feed from " + uri.getHost() + uri.getPath();
}

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

@Override
protected void handleExternalDomain(URI srcUrl, URI dstUrl) throws IOException {
    File srcRoot = new File(outputDir, srcUrl.getHost());
    File extRoot = new File(srcRoot, EXT_FILE);
    File outputDir = new File(extRoot, dstUrl.getHost());
    if (!outputDir.exists()) {
        FileUtils.forceMkdir(outputDir);
    }/*  ww  w.j a  va  2  s.  c om*/
}

From source file:com.orange.clara.cloud.servicedbdumper.helper.UrlForge.java

public String createShowLink(DatabaseDumpFile databaseDumpFile) {
    if (!databaseDumpFile.isShowable()) {
        return "";
    }/*  w w w.  jav a 2 s . c om*/
    URI appInUri = URI.create(appUri);
    String port = this.getPortInString();
    return appInUri.getScheme() + "://" + appInUri.getHost() + port + SHOW_ROUTE + "/"
            + databaseDumpFile.getId();
}

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

@Override
protected void markError(URI url, int errorCode) throws IOException {
    File outputRoot = new File(outputDir, url.getHost() + File.separator + url.getPath());
    FileUtils.forceMkdir(outputRoot);/*from  ww w  . j  a  v a  2  s.  c om*/
    File errFile = new File(outputRoot, ERR_FILE);
    if (!errFile.exists()) {
        try (OutputStream os = new FileOutputStream(errFile)) {
            IOUtils.write(String.valueOf(errorCode).getBytes(), os);
        }
    }
}

From source file:be.fedict.eid.dss.client.DSSProxySelector.java

@Override
public List<Proxy> select(URI uri) {
    LOG.debug("select: " + uri);
    String hostname = uri.getHost();
    Proxy proxy = this.proxies.get(hostname);
    if (null != proxy) {
        LOG.debug("using proxy: " + proxy);
        return Collections.singletonList(proxy);
    }// w w  w.j  a v a2 s.c om
    return this.defaultProxySelector.select(uri);
}

From source file:gate.tagger.tagme.TaggerTagMeWS.java

public static String recodeForDbp38(String uriString) {
    String ret;//from  ww w .j a va2  s  .c  om
    URI uri = null;
    if (uriString.startsWith("http://") || uriString.startsWith("https://")) {
        // First try to parse the string as an URI so that any superfluous 
        // percent-encodings can get decoded later
        try {
            uri = new URI(uriString);
        } catch (Exception ex) {
            throw new GateRuntimeException("Could not parse URI " + uriString, ex);
        }
        // now use this constructor to-recode only the necessary parts
        try {
            String path = uri.getPath();
            path = path.trim();
            path = path.replaceAll(" +", "_");
            uri = new URI(uri.getScheme(), null, uri.getHost(), -1, path, uri.getQuery(), uri.getFragment());
        } catch (Exception ex) {
            throw new GateRuntimeException("Could not re-construct URI: " + uri);
        }
        ret = uri.toString();
    } else {
        if (uriString.contains("\\u")) {
            uriString = StringEscapeUtils.unescapeJava(uriString);
        }
        uriString = uriString.trim();
        uriString = uriString.replaceAll(" +", "_");
        // We need to %-encode colons, otherwise the getPath() method will return
        // null ...
        uriString = uriString.replaceAll(":", "%3A");
        try {
            uri = new URI(uriString);
            // decode and prepare for minimal percent encoding
            uriString = uri.getPath();
        } catch (URISyntaxException ex) {
            // do nothing: the uriString must already be ready for percent-encoding
        }
        uriString = uriString.replaceAll(" +", "_");
        try {
            uri = new URI(null, null, null, -1, "/" + uriString, null, null);
        } catch (Exception ex) {
            throw new GateRuntimeException("Could not re-construct URI part: " + uriString);
        }
        ret = uri.toString().substring(1);
    }
    return ret;
}

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

@Override
protected boolean handleData(URI url, byte[] data) throws IOException {
    File outputRoot = new File(outputDir, url.getHost() + File.separator + url.getPath());
    FileUtils.forceMkdir(outputRoot);/* ww w . j  a  va2 s  .  c  o m*/
    File outputData = new File(outputRoot, DAT_FILE);
    if (!outputData.exists()) {
        try (OutputStream os = new FileOutputStream(outputData)) {
            IOUtils.write(data, os);
            LOG.info("Wrote {}", outputRoot);
        }
        return true;
    }
    return false;
}

From source file:brooklyn.networking.cloudstack.HttpUtil.java

public static HttpClient createHttpClient(URI uri, Optional<Credentials> credentials) {
    final DefaultHttpClient httpClient = new DefaultHttpClient();

    // TODO if supplier returns null, we may wish to defer initialization until url available?
    if (uri != null && "https".equalsIgnoreCase(uri.getScheme())) {
        try {//from  w w  w.  j a va  2  s.  c  om
            int port = (uri.getPort() >= 0) ? uri.getPort() : 443;
            SSLSocketFactory socketFactory = new SSLSocketFactory(new TrustAllStrategy(),
                    SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER);
            Scheme sch = new Scheme("https", port, socketFactory);
            httpClient.getConnectionManager().getSchemeRegistry().register(sch);
        } catch (Exception e) {
            LOG.warn("Error in HTTP Feed of {}, setting trust for uri {}", uri);
            throw Exceptions.propagate(e);
        }
    }

    // Set credentials
    if (uri != null && credentials.isPresent()) {
        String hostname = uri.getHost();
        int port = uri.getPort();
        httpClient.getCredentialsProvider().setCredentials(new AuthScope(hostname, port), credentials.get());
    }

    return httpClient;
}

From source file:de.betterform.connector.xmlrpc.XMLRPCSubmissionHandler.java

/**
 * Parses the URI into three elements.// ww  w.  j  av a2s.  c  om
 * The xmlrpc URL, the function and the params
 *
 * @return a Vector
 */
private Vector parseURI(URI uri) {
    String host = uri.getHost();
    int port = uri.getPort();
    String path = uri.getPath();
    String query = uri.getQuery();

    /* Split the path up into basePath and function */
    int finalSlash = path.lastIndexOf('/');
    String basePath = "";
    if (finalSlash > 0) {
        basePath = path.substring(1, finalSlash);
    }
    String function = path.substring(finalSlash + 1, path.length());

    String rpcURL = "http://" + host + ":" + port + "/" + basePath;

    log.debug("New URL  = " + rpcURL);
    log.debug("Function = " + function);

    Hashtable paramHash = new Hashtable();

    if (query != null) {
        String[] params = query.split("&");

        for (int i = 0; i < params.length; i++) {
            log.debug("params[" + i + "] = " + params[i]);

            String[] keyval = params[i].split("=");

            log.debug("\t" + keyval[0] + " -> " + keyval[1]);

            paramHash.put(keyval[0], keyval[1]);
        }
    }

    Vector ret = new Vector();
    ret.add(rpcURL);
    ret.add(function);
    ret.add(paramHash);
    return ret;
}

From source file:be.fedict.eid.idp.sp.protocol.saml2.artifact.ArtifactProxySelector.java

/**
 * {@inheritDoc}//from  w  ww . j a  v  a  2s.  c  om
 */
@Override
public List<Proxy> select(URI uri) {
    LOG.debug("select: " + uri);
    String hostname = uri.getHost();
    Proxy proxy = this.proxies.get(hostname);
    if (null != proxy) {
        LOG.debug("using proxy: " + proxy);
        return Collections.singletonList(proxy);
    }
    return this.defaultProxySelector.select(uri);
}