Example usage for org.apache.http.client.utils URIBuilder getHost

List of usage examples for org.apache.http.client.utils URIBuilder getHost

Introduction

In this page you can find the example usage for org.apache.http.client.utils URIBuilder getHost.

Prototype

public String getHost() 

Source Link

Usage

From source file:com.amos.tool.SelfRedirectStrategy.java

/**
 * @since 4.1/*from   w  w w . ja  v a2 s .  co m*/
 */
protected URI createLocationURI(final String location) throws ProtocolException {

    System.out.println("redirect_location:" + location);

    try {
        final URIBuilder b = new URIBuilder(new URI(location).normalize());
        final String host = b.getHost();
        if (host != null) {
            b.setHost(host.toLowerCase(Locale.ENGLISH));
        }
        final String path = b.getPath();
        if (TextUtils.isEmpty(path)) {
            b.setPath("/");
        }
        return b.build();
    } catch (final URISyntaxException ex) {
        throw new ProtocolException("Invalid redirect URI: " + location, ex);
    }
}

From source file:com.linagora.james.mailets.GuessClassificationMailet.java

private Executor createHttpExecutor() throws MailetException {
    try {/*from  w w  w  .j  av a 2s . c  o  m*/
        URIBuilder uriBuilder = new URIBuilder(serviceUrl);
        HttpHost host = new HttpHost(uriBuilder.getHost(), uriBuilder.getPort(), uriBuilder.getScheme());

        return Executor.newInstance().authPreemptive(host).auth(host,
                new UsernamePasswordCredentials(serviceUsername, servicePassword));
    } catch (URISyntaxException e) {
        throw new MailetException("invalid 'serviceUrl'", e);
    }
}

From source file:com.mbeddr.pluginmanager.com.intellij.ide.plugins.RepositoryHelper.java

@NotNull
public static List<IdeaPluginDescriptor> loadPlugins(@Nullable String repositoryUrl,
        @Nullable BuildNumber buildnumber, @Nullable String channel, boolean forceHttps,
        @Nullable final ProgressIndicator indicator) throws IOException {
    String url;/*from  www .  j  ava2  s .c  om*/
    final File pluginListFile;
    final String host;

    try {
        URIBuilder uriBuilder;
        if (repositoryUrl == null) {
            uriBuilder = new URIBuilder(ApplicationInfoImpl.getShadowInstance().getPluginsListUrl());
            pluginListFile = new File(PathManager.getPluginsPath(),
                    channel == null ? PLUGIN_LIST_FILE : channel + "_" + PLUGIN_LIST_FILE);
            if (pluginListFile.length() > 0) {
                uriBuilder.addParameter("crc32", Files.hash(pluginListFile, Hashing.crc32()).toString());
            }
        } else {
            uriBuilder = new URIBuilder(repositoryUrl);
            pluginListFile = null;
        }

        if (!URLUtil.FILE_PROTOCOL.equals(uriBuilder.getScheme())) {
            uriBuilder.addParameter("build", (buildnumber != null ? buildnumber.asString()
                    : ApplicationInfoImpl.getShadowInstance().getApiVersion()));
            if (channel != null)
                uriBuilder.addParameter("channel", channel);
        }

        host = uriBuilder.getHost();
        url = uriBuilder.build().toString();
    } catch (URISyntaxException e) {
        throw new IOException(e);
    }

    if (indicator != null) {
        indicator.setText2(IdeBundle.message("progress.connecting.to.plugin.manager", host));
    }

    RequestBuilder request = HttpRequests.request(url).forceHttps(forceHttps);
    return process(repositoryUrl,
            request.connect(new HttpRequests.RequestProcessor<List<IdeaPluginDescriptor>>() {
                @Override
                public List<IdeaPluginDescriptor> process(@NotNull HttpRequests.Request request)
                        throws IOException {
                    if (indicator != null) {
                        indicator.checkCanceled();
                    }

                    URLConnection connection = request.getConnection();
                    if (pluginListFile != null && pluginListFile.length() > 0
                            && connection instanceof HttpURLConnection && ((HttpURLConnection) connection)
                                    .getResponseCode() == HttpURLConnection.HTTP_NOT_MODIFIED) {
                        return loadPluginList(pluginListFile);
                    }

                    if (indicator != null) {
                        indicator.checkCanceled();
                        indicator.setText2(IdeBundle.message("progress.downloading.list.of.plugins", host));
                    }

                    if (pluginListFile != null) {
                        synchronized (RepositoryHelper.class) {
                            FileUtil.ensureExists(pluginListFile.getParentFile());
                            request.saveToFile(pluginListFile, indicator);
                            return loadPluginList(pluginListFile);
                        }
                    } else {
                        return parsePluginList(request.getReader());
                    }
                }
            }));
}

From source file:com.qualinsight.plugins.sonarqube.badges.internal.QualityGateStatusRetriever.java

private String responseBodyForKey(final String key) throws IOException, URISyntaxException {
    final URIBuilder uriBuilder = new URIBuilder(this.settings.getString(SERVER_BASE_URL_KEY));
    final String uriQuery = new StringBuilder().append("resource=").append(key)
            .append("&metrics=quality_gate_details&format=json").toString();
    this.httpGet.setURI(new URI(uriBuilder.getScheme(), null, uriBuilder.getHost(), uriBuilder.getPort(),
            StringUtils.removeEnd(uriBuilder.getPath(), URI_SEPARATOR) + "/api/resources/index/", uriQuery,
            null));//from  ww w  . j a v a  2 s. co m
    LOGGER.debug("Http GET request line: {}", this.httpGet.getRequestLine());
    final String responseBody = this.httpclient.execute(this.httpGet, this.responseHandler);
    LOGGER.debug("Http GET response body: {}", responseBody);
    return responseBody;
}

From source file:cd.go.contrib.elasticagents.docker.executors.GoServerURLField.java

@Override
public String doValidate(String input) {
    if (StringUtils.isBlank(input)) {
        return this.displayName + " must not be blank.";
    }/*  www .j a  va 2 s  .  c  o m*/

    URIBuilder uriBuilder = null;
    try {
        uriBuilder = new URIBuilder(input);
    } catch (URISyntaxException e) {
        return this.displayName + " must be a valid URL (https://example.com:8154/go)";
    }

    if (!uriBuilder.getScheme().equalsIgnoreCase("https")) {
        return this.displayName + " must be a valid HTTPs URL (https://example.com:8154/go)";
    }

    if (uriBuilder.getHost().equalsIgnoreCase("localhost")
            || uriBuilder.getHost().equalsIgnoreCase("127.0.0.1")) {
        return this.displayName + " must not be localhost, since this gets resolved on the agents";
    }
    return null;
}

From source file:org.aicer.hibiscus.http.client.HttpClient.java

/**
 * A URI representing the Absolute URL for the Request
 *
 * @param uri/*from  ww  w. jav  a 2  s. c  om*/
 * @return
 */
public HttpClient setURI(final URI uri) {

    final URIBuilder builder = new URIBuilder(uri);

    this.scheme = builder.getScheme();
    this.host = builder.getHost();
    this.port = builder.getPort();
    this.path = builder.getPath();

    this.fragment = builder.getFragment();

    this.resetQueryParameters();

    for (NameValuePair nvp : builder.getQueryParams()) {
        this.queryParameters.add(new BasicNameValuePair(nvp.getName(), nvp.getValue()));
    }

    return this;
}

From source file:org.blocks4j.reconf.infra.http.layer.SimpleHttpRequest.java

SimpleHttpRequest(String method, String pathBase, String... pathParam) throws URISyntaxException {
    this.httpMethod = method;

    URIBuilder baseBuilder = new URIBuilder(pathBase);
    if (baseBuilder.getScheme() == null) {
        baseBuilder = new URIBuilder("http://" + pathBase);
    }//  www .java  2 s .co m

    final StringBuilder pathBuilder = new StringBuilder(baseBuilder.getPath());
    for (String param : pathParam) {
        pathBuilder.append("/").append(param);
    }

    this.setURI(new URI(baseBuilder.getScheme(), baseBuilder.getUserInfo(), baseBuilder.getHost(),
            baseBuilder.getPort(), pathBuilder.toString(), null, null));
}

From source file:org.berlin.crawl.parse.WebParser.java

protected String fullURL(final Link link, final URIBuilder lastBuilder, final Set<String> urls) {
    final String uri = link.getUri().trim();
    final boolean basicExclude = (uri.length() != 0) && !uri.equals("/");
    if (basicExclude) {
        String fullURL = "";
        // We have some URL's
        if (extractLinks(uri).size() > 0) {
            // First add full URL to set //
            fullURL = uri;/* www.j a  va2 s  .  co m*/
        } else {
            if (uri.startsWith("/")) {
                fullURL = lastBuilder.getScheme() + "://" + lastBuilder.getHost() + uri;
            } else {
                final String path = parsePath(lastBuilder.getPath());
                fullURL = lastBuilder.getScheme() + "://" + lastBuilder.getHost() + path + uri;
            } // End of the if - else //
        } // End //
        if (urls.contains(fullURL)) {
            // Return null so we don't reprocess 
            return null;
        }
        // We should have a valid full URL.
        urls.add(fullURL);
        return fullURL;
    } // End of the if //
    return null;
}

From source file:com.blackducksoftware.tools.commonframework.core.config.ConfigurationManager.java

/**
 * Provides information from the server URL.
 *
 * @param urlInfo//from  w ww  . j a  v a  2  s  .  c o m
 *            the url info
 * @return the string
 */
@Override
public String findURLInformation(final URL_INFORMATION urlInfo) {
    String returnString = null;
    try {
        final URIBuilder builder = new URIBuilder(serverURL);

        if (urlInfo == URL_INFORMATION.HOST) {
            returnString = builder.getHost();
        } else if (urlInfo == URL_INFORMATION.PORT) {
            returnString = Integer.toString(builder.getPort());
        } else if (urlInfo == URL_INFORMATION.PROTOCOL) {
            returnString = builder.getScheme();
        }
    } catch (final Exception e) {
        log.warn("Unable to determine host name for: " + serverURL, e);
    }

    return returnString;
}

From source file:nl.nn.adapterframework.http.HttpSenderBase.java

protected URIBuilder getURI(String url) throws URISyntaxException {
    URIBuilder uri = new URIBuilder(url);

    if (uri.getPath() == null) {
        uri.setPath("/");
    }//from   w  w w . j a  v a 2  s. com

    log.info(getLogPrefix() + "created uri: scheme=[" + uri.getScheme() + "] host=[" + uri.getHost()
            + "] path=[" + uri.getPath() + "]");
    return uri;
}