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.ibm.watson.ta.retail.DemoServlet.java

/**
 * Build an executor for the specified url. This disables cookies and sets
 * preemptive authentication (creds are sent without waiting for a 401).
 * /*from w w w.  ja va 2s  . c o  m*/
 * NOTE: This is required to avoid issues with load balancers that use
 * cookies due to Apache Http Client issue:
 * https://issues.apache.org/jira/browse/HTTPCLIENT-1451
 * 
 * @param url
 * @return
 */
private Executor buildExecutor(URI url) {
    return Executor.newInstance().auth(username, password)
            .authPreemptive(new HttpHost(url.getHost(), url.getPort(), url.getScheme()))
            .cookieStore(new CookieStore() {
                // Noop cookie store.
                public void addCookie(Cookie arg0) {
                }

                public void clear() {
                }

                public boolean clearExpired(Date arg0) {
                    return false;
                }

                public List<Cookie> getCookies() {
                    return Collections.emptyList();
                }
            });
}

From source file:com.machinepublishers.jbrowserdriver.CookieStore.java

/**
 * {@inheritDoc}//w  w  w. j  a  va 2 s . com
 */
@Override
public Map<String, List<String>> get(URI uri, Map<String, List<String>> requestHeaders) throws IOException {
    final String reqHost = canonicalHost(uri.getHost());
    final String reqPath = canonicalPath(uri.getPath());
    final boolean reqSecure = isSecure(uri.getScheme());
    final boolean reqJavascript = isJavascript(uri.getScheme());
    StringBuilder builder = new StringBuilder();
    if (reqJavascript) {
        List<Cookie> list;
        synchronized (store) {
            store.clearExpired(new Date());
            list = store.getCookies();
        }
        for (Cookie cookie : list) {
            if ((!cookie.isSecure() || reqSecure) && reqHost.endsWith(canonicalHost(cookie.getDomain()))
                    && reqPath.startsWith(canonicalPath(cookie.getPath()))) {
                if (builder.length() > 0) {
                    builder.append(';');
                }
                builder.append(cookie.getName());
                builder.append('=');
                builder.append(cookie.getValue());
            }
        }
    }
    String cookies = builder.length() == 0 ? null : builder.toString();
    Map<String, List<String>> map;
    if (cookies != null) {
        map = new HashMap<String, List<String>>();
        map.put("Cookie", Arrays.asList(cookies));
    } else {
        map = Collections.emptyMap();
    }
    return map;
}

From source file:com.github.joelittlejohn.embedmongo.StartMojo.java

public IProxyFactory getProxyFactory(Settings settings) {
    URI downloadUri = URI.create(downloadPath);
    final String downloadHost = downloadUri.getHost();
    final String downloadProto = downloadUri.getScheme();

    if (settings.getProxies() != null) {
        for (org.apache.maven.settings.Proxy proxy : (List<org.apache.maven.settings.Proxy>) settings
                .getProxies()) {/*w w w .jav  a  2s .  c  o  m*/
            if (proxy.isActive() && equalsIgnoreCase(proxy.getProtocol(), downloadProto)
                    && !contains(proxy.getNonProxyHosts(), downloadHost)) {
                return new HttpProxyFactory(proxy.getHost(), proxy.getPort());
            }
        }
    }

    return new NoProxyFactory();
}

From source file:com.snaker.DownloadManager.java

public void start(final Downloader d) throws IOException {
    String host = null;/*  ww w  . j ava  2s.  co m*/
    try {
        URI uri = new URI(d.getUrl());
        host = uri.getHost();
        if (host != null) {
            host = host.toLowerCase();
        } else {
            throw new URISyntaxException(d.getUrl(), "Bad url");
        }
    } catch (URISyntaxException e) {
        throw new IOException(e);
    }
    d.setHost(host);

    downloadings.add(d);
    if (d.getHandler() == null) {
        createRunnable(d).run();
    } else {
        queue.put(d);
    }
}

From source file:edu.stanford.junction.api.activity.ActivityScript.java

public void setUri(URI uri) {
    sessionID = JunctionMaker.getSessionIDFromURI(uri);
    host = uri.getHost();
}

From source file:nu.yona.server.sms.PlivoSmsService.java

private HttpClientContext createHttpClientContext() {
    try {/*from  w w  w  .  ja v  a2  s.com*/
        SmsProperties smsProperties = yonaProperties.getSms();

        URI uri = getPlivoUrl(smsProperties);
        CredentialsProvider credentialsProvider = new BasicCredentialsProvider();
        credentialsProvider.setCredentials(new AuthScope(uri.getHost(), uri.getPort()),
                new UsernamePasswordCredentials(smsProperties.getPlivoAuthId(),
                        smsProperties.getPlivoAuthToken()));

        HttpClientContext httpClientContext = HttpClientContext.create();
        httpClientContext.setCredentialsProvider(credentialsProvider);
        return httpClientContext;
    } catch (URISyntaxException e) {
        throw SmsException.smsSendingFailed(e);
    }
}

From source file:org.fcrepo.kernel.impl.identifiers.HttpPidMinter.java

/**
 * Setup authentication in httpclient./*from  ww  w.  j  a va2s .co m*/
**/
protected HttpClient buildClient() {
    HttpClientBuilder builder = HttpClientBuilder.create().useSystemProperties()
            .setConnectionManager(new PoolingHttpClientConnectionManager());
    if (!isBlank(username) && !isBlank(password)) {
        final URI uri = URI.create(url);
        final CredentialsProvider credsProvider = new BasicCredentialsProvider();
        credsProvider.setCredentials(new AuthScope(uri.getHost(), uri.getPort()),
                new UsernamePasswordCredentials(username, password));
        builder = builder.setDefaultCredentialsProvider(credsProvider);
    }
    return builder.build();
}

From source file:com.tascape.reactor.report.SuiteResultExportTestRailView.java

private void getParameters() throws URISyntaxException {
    Map<String, String> map = FacesContext.getCurrentInstance().getExternalContext().getRequestParameterMap();
    String v = map.get("srid");
    if (v != null) {
        this.srid = v;
        LOG.debug("srid={}", this.srid);
    }/*from w ww .  jav a2  s .c  o m*/
    String ref = FacesContext.getCurrentInstance().getExternalContext().getRequestHeaderMap().get("referer");
    URI u = new URI(ref);
    this.logBaseUrl = u.getScheme() + "://" + u.getHost() + ":" + u.getPort() + "/logs/" + srid + "/";
    LOG.debug("logBaseUrl={}", logBaseUrl);
}

From source file:nl.esciencecenter.octopus.webservice.job.OctopusManager.java

/**
 * Submit a job request./*from w w  w . j a v a  2s . c  o  m*/
 *
 * @param request The job request
 * @param httpClient http client used to reporting status to job callback.
 * @return SandboxedJob job
 *
 * @throws OctopusIOException
 * @throws OctopusException
 * @throws URISyntaxException
 */
public SandboxedJob submitJob(JobSubmitRequest request, HttpClient httpClient)
        throws OctopusIOException, OctopusException, URISyntaxException {
    Credential credential = configuration.getCredential();
    // filesystems cant have path in them so strip eg. file:///tmp to file:///
    URI s = configuration.getSandboxRoot();
    URI sandboxURI = new URI(s.getScheme(), s.getUserInfo(), s.getHost(), s.getPort(), "/", s.getQuery(),
            s.getFragment());
    //create sandbox
    FileSystem sandboxFS = octopus.files().newFileSystem(sandboxURI, credential, null);
    String sandboxRoot = configuration.getSandboxRoot().getPath();
    AbsolutePath sandboxRootPath = octopus.files().newPath(sandboxFS, new RelativePath(sandboxRoot));
    Sandbox sandbox = request.toSandbox(octopus, sandboxRootPath, null);

    // create job description
    JobDescription description = request.toJobDescription();
    description.setQueueName(configuration.getQueue());
    description.setWorkingDirectory(sandbox.getPath().getPath());
    long cancelTimeout = configuration.getPollConfiguration().getCancelTimeout();
    // CancelTimeout is in milliseconds and MaxTime must be in minutes, so convert it
    int maxTime = (int) TimeUnit.MINUTES.convert(cancelTimeout, TimeUnit.MILLISECONDS);
    description.setMaxTime(maxTime);

    // stage input files
    sandbox.upload();

    // submit job
    Job job = octopus.jobs().submitJob(scheduler, description);

    // store job in jobs map
    SandboxedJob sjob = new SandboxedJob(sandbox, job, request, httpClient);
    jobs.put(sjob.getIdentifier(), sjob);

    // JobsPoller will poll job status and download sandbox when job is done.

    return sjob;
}

From source file:tools.devnull.boteco.client.rest.impl.DefaultRestConfiguration.java

@Override
public RestConfiguration withAuthentication(String user, String password) {
    // Create AuthCache instance
    AuthCache authCache = new BasicAuthCache();
    // Generate BASIC scheme object and add it to the local auth cache
    BasicScheme basicAuth = new BasicScheme();
    CredentialsProvider provider = new BasicCredentialsProvider();

    URI uri = request.getURI();
    authCache.put(new HttpHost(uri.getHost(), uri.getPort(), uri.getScheme()), basicAuth);
    provider.setCredentials(new AuthScope(uri.getHost(), AuthScope.ANY_PORT),
            new UsernamePasswordCredentials(user, password));

    this.context.setCredentialsProvider(provider);
    this.context.setAuthCache(authCache);

    return this;
}