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.gooddata.http.client.GoodDataHttpClient.java

@Override
public HttpResponse execute(HttpUriRequest request, HttpContext context) throws IOException {
    final URI uri = request.getURI();
    final HttpHost httpHost = new HttpHost(uri.getHost(), uri.getPort(), uri.getScheme());
    return execute(httpHost, request, context);
}

From source file:com.trickl.crawler.protocol.http.HttpProtocol.java

@Override
public boolean isAllowed(URI uri) throws IOException {
    if (forceAllow) {
        return forceAllow;
    }/*from w w  w. ja v a  2  s.  co  m*/

    URI baseURI;
    try {
        baseURI = new URI(uri.getScheme(), uri.getUserInfo(), uri.getHost(), uri.getPort(), "/", null, null);
    } catch (URISyntaxException ex) {
        log.error("Unable to determine base URI for " + uri);
        return false;
    }

    NoRobotClient nrc = new NoRobotClient(contentLoader, userAgent);
    try {
        nrc.parse(baseURI);
    } catch (NoRobotException ex) {
        log.error("Failure parsing robots.txt: " + ex.getMessage());
        return false;
    }
    boolean test = nrc.isUrlAllowed(uri);
    if (log.isInfoEnabled()) {
        log.info(uri + " is " + (test ? "allowed" : "denied"));
    }
    return test;
}

From source file:info.magnolia.ui.admincentral.shellapp.favorites.FavoritesPresenter.java

String getWebAppRootURI() {
    final URI currentUri = UI.getCurrent().getPage().getLocation();
    String instancePrefix = currentUri.getScheme() + "://" + currentUri.getHost();
    if (currentUri.getPort() > -1) {
        instancePrefix += ":" + currentUri.getPort();
    }/*from   www .  j a  v  a 2s  .  c  o m*/
    instancePrefix += currentUri.getPath(); // Path contains the ctx
    if (StringUtils.isNotBlank(currentUri.getQuery())) {
        instancePrefix += "?" + currentUri.getQuery();
    }
    return instancePrefix;
}

From source file:edu.wisc.ws.client.support.DestinationOverridingWebServiceTemplate.java

@Override
public String getDefaultUri() {
    final DestinationProvider destinationProvider = this.getDestinationProvider();
    if (destinationProvider != null) {
        final URI uri = destinationProvider.getDestination();
        if (uri == null) {
            return null;
        }// w  w w .  j  a  va  2 s . com

        if (portOverride == null) {
            return uri.toString();
        }

        final URI overridenUri;
        try {
            overridenUri = new URI(uri.getScheme(), uri.getUserInfo(), uri.getHost(), portOverride,
                    uri.getPath(), uri.getQuery(), uri.getFragment());
        } catch (URISyntaxException e) {
            this.logger.error("Could not override port on URI " + uri + " to " + portOverride, e);
            return uri.toString();
        }

        return overridenUri.toString();
    }

    return null;
}

From source file:com.jayway.restassured.internal.http.AuthConfig.java

/**
 * Set authentication credentials to be used for the current
 * {@link HTTPBuilder#getUri() default host}.  This method name is a bit of
 * a misnomer, since these credentials will actually work for "digest"
 * authentication as well./*from  w w  w.jav  a 2s .c o m*/
 *
 * @param user
 * @param pass
 */
public void basic(String user, String pass) {
    URI uri = ((URIBuilder) builder.getUri()).toURI();
    if (uri == null)
        throw new IllegalStateException("a default URI must be set");
    this.basic(uri.getHost(), uri.getPort(), user, pass);
}

From source file:org.apache.jena.atlas.web.auth.AbstractCredentialsAuthenticator.java

@Override
public void apply(AbstractHttpClient client, HttpContext context, URI target) {
    // At least a user name is required or no authentication will be done
    if (!this.hasUserName(target))
        return;//from  w  ww  . j av a  2 s  . c  om

    // Be careful to scope credentials to the specific URI so that
    // HttpClient won't try and send them to other servers
    HttpHost host = new HttpHost(target.getHost(), target.getPort());
    CredentialsProvider provider = new BasicCredentialsProvider();

    provider.setCredentials(new AuthScope(host), this.createCredentials(target));

    client.setCredentialsProvider(provider);
}

From source file:org.jenkinsci.plugins.newrelicnotifier.api.NewRelicClientImpl.java

private CloseableHttpClient getHttpClient(URI url) {
    HttpClientBuilder builder = HttpClientBuilder.create();

    ProxyConfiguration proxyConfig = Jenkins.getInstance().proxy;
    if (proxyConfig != null) {
        Proxy proxy = proxyConfig.createProxy(url.getHost());
        if (proxy != null && proxy.type() == Proxy.Type.HTTP) {
            SocketAddress addr = proxy.address();
            if (addr != null && addr instanceof InetSocketAddress) {
                InetSocketAddress proxyAddr = (InetSocketAddress) addr;
                HttpHost proxyHost = new HttpHost(proxyAddr.getAddress().getHostAddress(), proxyAddr.getPort());
                DefaultProxyRoutePlanner routePlanner = new DefaultProxyRoutePlanner(proxyHost);
                builder = builder.setRoutePlanner(routePlanner);

                String proxyUser = proxyConfig.getUserName();
                if (proxyUser != null) {
                    String proxyPass = proxyConfig.getPassword();
                    CredentialsProvider cred = new BasicCredentialsProvider();
                    cred.setCredentials(new AuthScope(proxyHost),
                            new UsernamePasswordCredentials(proxyUser, proxyPass));
                    builder = builder.setDefaultCredentialsProvider(cred)
                            .setProxyAuthenticationStrategy(new ProxyAuthenticationStrategy());
                }/* w w w .  j a  v a 2s.  co  m*/
            }
        }
    }

    return builder.build();
}

From source file:com.denimgroup.threadfix.remote.HttpRestUtils.java

private void importCert(SSLHandshakeException sslHandshakeException) {
    if (count < 2) {
        LOGGER.warn("Unsigned certificate found. Trying to import it to Java KeyStore.");
        try {//from   ww w.j av a 2  s.c  o m
            URI uri = getURI();
            String domain = uri.getHost();
            domain = domain.startsWith("www.") ? domain.substring(4) : domain;
            if (InstallCert.install(domain, uri.getPort())) {
                count++;
                LOGGER.info("Successfully imported certificate. Please run your command again.");
            }
        } catch (Exception e) {
            LOGGER.error("Error when tried to import certificate. ", e);
        }
    } else {
        LOGGER.error("Unsigned certificate found. We tried to import it but was not successful."
                + "We recommend you import server certificate to the Java cacerts keystore, or add option -Dunsafe-ssl from command line to accept all unsigned certificates. "
                + "Check out https://github.com/denimgroup/threadfix/wiki/Importing-Self-Signed-Certificates on how to import Self Signed Certificates.",
                sslHandshakeException);
    }
}

From source file:org.dasein.security.joyent.AuthClientFactory.java

@Override
public @Nonnull HttpClient getClient(String endpoint) throws CloudException, InternalException {

    if (endpoint == null) {
        throw new CloudException("No cloud endpoint was defined");
    }//ww w.  ja  v a  2s  .c  o  m

    boolean ssl = endpoint.startsWith("https");
    int targetPort;
    URI uri;

    try {
        uri = new URI(endpoint);
        targetPort = uri.getPort();
        if (targetPort < 1) {
            targetPort = (ssl ? 443 : 80);
        }
    } catch (URISyntaxException e) {
        throw new CloudException(e);
    }
    HttpHost targetHost = new HttpHost(uri.getHost(), targetPort, uri.getScheme());

    DefaultHttpClient client = (DefaultHttpClient) super.getClient(endpoint);

    try {
        String userName = new String(getProviderContext().getAccessPublic(), "utf-8");
        String password = new String(getProviderContext().getAccessPrivate(), "utf-8");

        client.getCredentialsProvider().setCredentials(
                new AuthScope(targetHost.getHostName(), targetHost.getPort()),
                new UsernamePasswordCredentials(userName, password));
    } catch (UnsupportedEncodingException e) {
        throw new InternalException(e);
    }
    return client;
}

From source file:fusion.Fusion.java

private static void getSameAsLinks(File file) throws FileNotFoundException, IOException, AlignmentException {

    AlignmentParser a = new AlignmentParser();
    Alignment o = a.parse(file.toURI());
    for (Cell c : o) {

        java.net.URI value1 = c.getObject1AsURI(); // getLocalFromUri(
        java.net.URI value2 = c.getObject2AsURI();
        // keeps only the end of URI ?

        if (!distinctURLs.containsKey(value1.hashCode()))
            distinctURLs.put(value1.hashCode(), value1);
        if (!distinctURLs.containsKey(value2.hashCode()))
            distinctURLs.put(value2.hashCode(), value2);

        links.add(new SameAsLink(distinctURLs.get(value1.hashCode()), distinctURLs.get(value2.hashCode()))); // adding same as links
    }/*from  www . ja  v  a  2  s  .c  om*/

    // ADD SOURCES
    //detecter sources (et demander infos a l'utilisateur ?)

    for (Integer intName : distinctURLs.keySet()) {
        URI name = distinctURLs.get(intName);
        Source source = sources.get(name.getHost()); // detecter la source
        Instance instance = new Instance(name, source);

        instances.put(instance.getUri(), instance);
    }

}