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

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

Introduction

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

Prototype

public URIBuilder setHost(final String host) 

Source Link

Document

Sets URI host.

Usage

From source file:org.ireas.mediawiki.MediaWikiUtils.java

/**
 * Constructs an {@code URI} object from {@code scheme}, {@code host},
 * {@code port} and {@code apiPath}. The constructed URI will have the
 * structure {@code "<scheme>://<host>:<port>/<apiPath>"}.
 *
 * @param scheme/*  w  w  w .  ja v  a2 s. c  o  m*/
 *            the scheme of the URI, e. g. {@code "https"}
 * @param host
 *            the host of the URI, e. g. {@code "example.org"}
 * @param port
 *            the port of the URI, e. g. {@code 443}. The port must be
 *            non-negative.
 * @param path
 *            the path of the URI, e. g. {@code "/index.html"}
 * @return an {@code URI} constructed from the given parts
 * @throws MediaWikiException
 *             if the given parts do not form a valid URI
 * @throws NullPointerException
 *             if {@code scheme}, {@code host} or {@code path} is
 *             {@code null}
 * @throws IllegalArgumentException
 *             if {@code port} is negative
 */
public static URI buildUri(final String scheme, final String host, final int port, final String path)
        throws MediaWikiException {
    Preconditions.checkNotNull(scheme);
    Preconditions.checkNotNull(host);
    Preconditions.checkNotNull(path);
    Preconditions.checkArgument(port >= 0);

    URIBuilder uriBuilder = new URIBuilder();
    uriBuilder.setScheme(scheme);
    uriBuilder.setHost(host);
    uriBuilder.setPort(port);
    uriBuilder.setPath(path);
    try {
        return uriBuilder.build();
    } catch (URISyntaxException exception) {
        throw new MediaWikiException(exception);
    }
}

From source file:com.ibm.watson.movieapp.dialog.rest.SearchTheMovieDbProxyResource.java

/**
 * Builds the URI from the URI parameter hash
 * <p>//from w w w.j a  v a2s .c  om
 * This will append each of the {key, value} pairs in uriParamsHash to the URI.
 * 
 * @param uriParamsHash the hashtable containing parameters to be added to the URI for making the call to TMDB
 * @return URI for making the HTTP call to TMDB API
 * @throws URISyntaxException if the uri being built is in the incorrect format
 */
private static URI buildUriStringFromParamsHash(Hashtable<String, String> uriParamsHash, String path)
        throws URISyntaxException {
    URIBuilder urib = new URIBuilder();
    urib.setScheme("http"); //$NON-NLS-1$
    urib.setHost(TMDB_BASE_URL);
    urib.setPath(path);
    urib.addParameter("api_key", themoviedbapikey); //$NON-NLS-1$
    if (uriParamsHash != null) {
        Set<String> keys = uriParamsHash.keySet();
        for (String key : keys) {
            urib.addParameter(key, uriParamsHash.get(key));
        }
    }
    return urib.build();
}

From source file:org.apache.ambari.server.controller.metrics.timeline.AMSPropertyProvider.java

static URIBuilder getAMSUriBuilder(String hostname, int port, boolean httpsEnabled) {
    URIBuilder uriBuilder = new URIBuilder();
    uriBuilder.setScheme(httpsEnabled ? "https" : "http");
    uriBuilder.setHost(hostname);
    uriBuilder.setPort(port);// www.  jav a2 s. com
    uriBuilder.setPath("/ws/v1/timeline/metrics");
    return uriBuilder;
}

From source file:nl.esciencecenter.ptk.web.URIQueryParameters.java

/**
 * Create URI encoded query String from this parameter list.
 * //from  w ww  . ja  v a 2  s  .  com
 * @return URI query string.
 * @throws UnsupportedEncodingException
 */
public String toQueryString() throws UnsupportedEncodingException {
    // Use Apache URI builder !

    URIBuilder uriBuilder = new URIBuilder();
    uriBuilder.setHost("host");
    uriBuilder.setScheme("scheme");
    uriBuilder.setPath("/");

    for (String key : this.keySet()) {
        uriBuilder.setParameter(key, this.get(key));
    }
    // todo: better URI query encoding.
    return uriBuilder.toString().substring("scheme://host/?".length());
}

From source file:org.apache.streams.riak.http.RiakHttpClient.java

public void start() throws Exception {
    Objects.nonNull(config);//from  w w  w. ja  v a  2 s  .  c  o m
    assert (config.getScheme().startsWith("http"));
    URIBuilder uriBuilder = new URIBuilder();
    uriBuilder.setScheme(config.getScheme());
    uriBuilder.setHost(config.getHosts().get(0));
    uriBuilder.setPort(config.getPort().intValue());
    baseURI = uriBuilder.build();
    client = HttpClients.createDefault();
}

From source file:org.mobicents.servlet.restcomm.http.client.HttpRequestDescriptor.java

private URI base(final URI uri) {
    try {/*from  w w w. java 2 s.  c  om*/
        URIBuilder uriBuilder = new URIBuilder();
        uriBuilder.setScheme(uri.getScheme());
        uriBuilder.setHost(uri.getHost());
        uriBuilder.setPort(uri.getPort());
        uriBuilder.setPath(uri.getPath());

        if (uri.getUserInfo() != null) {
            uriBuilder.setUserInfo(uri.getUserInfo());
        }
        return uriBuilder.build();
    } catch (final URISyntaxException ignored) {
        // This should never happen since we are using a valid URI to construct ours.
        return null;
    }
}

From source file:eu.seaclouds.platform.dashboard.http.HttpGetRequestBuilder.java

@Override
public String build() throws IOException, URISyntaxException {
    URIBuilder uriBuilder = new URIBuilder();
    uriBuilder.setScheme(scheme);/*from  w w w.  ja  v  a2s .co m*/
    if (host != null && path != null) {
        uriBuilder.setHost(host);
        uriBuilder.setPath(path);
        if (!params.isEmpty()) {
            uriBuilder.setParameters(params);
        }
    }
    requestBase = new HttpGet(uriBuilder.build());

    for (NameValuePair header : super.headers) {
        requestBase.addHeader(header.getName(), header.getValue());
    }

    try (CloseableHttpClient httpClient = HttpClients.createDefault()) {
        return httpClient.execute(requestBase, responseHandler, context);
    }
}

From source file:de.devbliss.apitester.dummyserver.DummyApiServer.java

public URI buildRequestUri(String pathOnServer) throws URISyntaxException {
    URIBuilder uriBuilder = new URIBuilder();
    uriBuilder.setScheme("http");
    uriBuilder.setHost("localhost");
    uriBuilder.setPort(port);//from ww w.j a va 2 s  .  c o  m
    uriBuilder.setPath(pathOnServer);
    return uriBuilder.build();
}

From source file:fr.insalyon.creatis.vip.query.server.rpc.EndPointSparqlServiceImpl.java

public String getUrlResult(String param1, String param2) {
    String url = null;/*from   w w  w .j ava 2s .  com*/
    String k = null;
    URIBuilder builder = new URIBuilder();
    builder.setHost("ginseng.unice.fr");
    builder.setPort(9000);
    builder.setPath("/sparql");

    builder.setParameter("query", param1);

    builder.setParameter("format", param2);
    try {
        url = builder.build().toString();

    } catch (URISyntaxException ex) {
        Logger.getLogger(EndPointSparqlServiceImpl.class.getName()).log(Level.SEVERE, null, ex);
    }

    return url;

}

From source file:net.datacrow.onlinesearch.bol.BolClient.java

/**
 * Gets the product.//w w  w .j av  a  2s.c  o m
 * @param id The product id (required).
 */
public String getProduct(String ID) throws IOException, URISyntaxException {
    URIBuilder builder = new URIBuilder();
    builder.setScheme("https");
    builder.setHost("openapi.bol.com");
    builder.setPath("/openapi/services/rest/catalog/v3/products/" + ID);
    URI uri = builder.build();

    HttpGet httpGet = new HttpGet(uri);

    HttpOAuthHelper au = new HttpOAuthHelper("application/xml");
    au.handleRequest(httpGet, accessKeyId, secretAccessKey);

    HttpResponse httpResponse = httpClient.execute(httpGet);
    String xml = getXML(httpResponse);
    httpClient.getConnectionManager().shutdown();
    return xml;
}