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:org.pentaho.di.trans.ael.websocket.SessionConfigurator.java

private HttpContext getContext(URI uri) {
    HttpClientContext httpClientContext = HttpClientContext.create();
    //used by httpclient version >= 4.3
    httpClientContext.setAttribute(HttpClientContext.HTTP_ROUTE,
            new HttpRoute(new HttpHost(uri.getHost(), uri.getPort())));
    //used by httpclient version 4.2
    httpClientContext.setAttribute(HttpClientContext.HTTP_TARGET_HOST,
            new HttpHost(uri.getHost(), uri.getPort()));
    return httpClientContext;
}

From source file:com.microsoft.office365.http.FroyoHttpConnection.java

@Override
public ListenableFuture<Response> execute(final Request request) {

    final SettableFuture<Response> future = SettableFuture.create();

    final RequestTask requestTask = new RequestTask() {

        AndroidHttpClient mClient;/*from w w w.j  a  v  a  2 s.  c o  m*/
        InputStream mResponseStream;

        @Override
        protected Void doInBackground(Void... voids) {
            if (request == null) {
                future.setException(new IllegalArgumentException("request"));
            }

            mClient = AndroidHttpClient.newInstance(Platform.getUserAgent());
            mResponseStream = null;
            URI uri;

            try {
                HttpRequest realRequest = createRealRequest(request);
                uri = new URI(request.getUrl());

                HttpHost host = new HttpHost(uri.getHost(), uri.getPort(), uri.getScheme());

                HttpResponse response;

                try {
                    response = mClient.execute(host, realRequest);
                } catch (SocketTimeoutException timeoutException) {
                    closeStreamAndClient();
                    future.setException(timeoutException);
                    return null;
                }

                mResponseStream = response.getEntity().getContent();
                Header[] headers = response.getAllHeaders();
                Map<String, List<String>> headersMap = new HashMap<String, List<String>>();
                for (Header header : headers) {
                    String headerName = header.getName();
                    if (headersMap.containsKey(headerName)) {
                        headersMap.get(headerName).add(header.getValue());
                    } else {
                        List<String> headerValues = new ArrayList<String>();
                        headerValues.add(header.getValue());
                        headersMap.put(headerName, headerValues);
                    }
                }

                future.set(new StreamResponse(mResponseStream, response.getStatusLine().getStatusCode(),
                        headersMap));
                closeStreamAndClient();
            } catch (Exception e) {
                closeStreamAndClient();

                future.setException(e);
            }

            return null;
        }

        protected void closeStreamAndClient() {
            if (mResponseStream != null) {
                try {
                    mResponseStream.close();
                } catch (IOException e) {
                }
            }

            if (mClient != null) {
                mClient.close();
            }
        }
    };

    Futures.addCallback(future, new FutureCallback<Response>() {
        @Override
        public void onFailure(Throwable arg0) {
            requestTask.closeStreamAndClient();

        }

        @Override
        public void onSuccess(Response response) {
        }
    });

    executeTask(requestTask);

    return future;
}

From source file:eu.esdihumboldt.hale.common.core.io.PathUpdate.java

/**
 * Create an alternative path for the given location if it matches changes
 * from old to new location. If either old or new location is null, or the
 * given URI wasn't changed in the same way, this method has no effect.
 * //from   w w  w.  j av a  2  s .co m
 * @param oldSource path where the file was saved to
 * @return the new URI
 */
public URI changePath(URI oldSource) {
    if (oldRaw == null || oldRaw.isEmpty()) {
        return oldSource;
    } else {
        if (oldSource.toString().startsWith(oldRaw)) {
            return URI.create(oldSource.toString().replace(oldRaw, newRaw));
        } else {
            // try to fix cases where oldRaw matches '<scheme>:///<rest>'
            // but oldSource matches '<scheme>:/<rest>' or vice versa
            try {
                URI oldRawUri = new URI(oldRaw);
                // URI.normalize() will not remove the additional slashes
                URI normalizedOldRaw = new URI(oldRawUri.getScheme(), oldRawUri.getHost(), oldRawUri.getPath(),
                        oldRawUri.getQuery(), oldRawUri.getFragment());
                URI normalizedOldSource = new URI(oldSource.getScheme(), oldSource.getHost(),
                        oldSource.getPath(), oldSource.getQuery(), oldSource.getFragment());

                return URI.create(normalizedOldSource.toString().replace(normalizedOldRaw.toString(), newRaw));
            } catch (URISyntaxException e) {
                // tough luck
                return oldSource;
            }
        }
    }
}

From source file:com.snowplowanalytics.refererparser.Parser.java

public Referer parse(URI refererUri, String pageHost, List<String> internalDomains) {
    if (refererUri == null) {
        return null;
    }//from   www  .ja v a  2s.c  om
    return parse(refererUri.getScheme(), refererUri.getHost(), refererUri.getPath(), refererUri.getRawQuery(),
            pageHost, internalDomains);
}

From source file:org.apache.storm.scheduler.utils.ArtifactoryConfigLoader.java

private Map loadFromURI(URI uri) throws IOException {
    String host = uri.getHost();
    Integer port = uri.getPort();
    String location = uri.getPath();
    if (location.toLowerCase().startsWith(baseDirectory.toLowerCase())) {
        location = location.substring(baseDirectory.length());
    }/*w  w  w .j  av  a2 s  . c o  m*/

    if (!cacheInitialized) {
        makeArtifactoryCache(location);
    }

    // Get the most recent artifact as a String, and then parse the yaml
    String yamlConfig = loadMostRecentArtifact(location, host, port);

    // If we failed to get anything from Artifactory try to get it from our local cache
    if (yamlConfig == null) {
        Map ret = getLatestFromCache();
        updateLastReturned(ret);
        return ret;
    }

    // Now parse it and return the map.
    Yaml yaml = new Yaml(new SafeConstructor());
    Map ret = null;
    try {
        ret = (Map) yaml.load(yamlConfig);
    } catch (Exception e) {
        LOG.error("Could not parse yaml.");
        return null;
    }

    if (ret != null) {
        LOG.debug("returning a new map from Artifactory");
        updateLastReturned(ret);
        return ret;
    }

    return null;
}

From source file:com.taobao.gecko.service.impl.DefaultRemotingClient.java

private InetSocketAddress getSocketAddrFromGroup(String group) throws NotifyRemotingException {
    if (group == null) {
        throw new IllegalArgumentException("Null group");
    }/*from  www.j a  v  a  2 s . c  om*/
    group = group.trim();
    if (!group.startsWith(this.config.getWireFormatType().getScheme())) {
        throw new NotifyRemotingException(
                "Group" + this.config.getWireFormatType().getScheme() + "");
    }
    try {
        final URI uri = new URI(group);
        return new InetSocketAddress(uri.getHost(), uri.getPort());
    } catch (final Exception e) {
        throw new NotifyRemotingException("uri,url=" + group, e);
    }
}