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

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

Introduction

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

Prototype

public URIBuilder setPath(final String path) 

Source Link

Document

Sets URI path.

Usage

From source file:adalid.jaas.google.GoogleRecaptcha.java

private static boolean verify(String userResponse) {
    if (userResponse == null) {
        return VERIFY_NULL_RESPONSE;
    }//w w w .jav a 2s .c om
    URIBuilder builder = new URIBuilder();
    builder.setScheme("https");
    builder.setHost("www.google.com");
    builder.setPath("/recaptcha/api/siteverify");
    //      builder.clearParameters();
    builder.setParameter("secret", SECRET_KEY);
    builder.setParameter("response", userResponse);
    URI uri;
    try {
        uri = builder.build();
    } catch (URISyntaxException ex) {
        logger.log(Level.SEVERE, ex.toString(), ex);
        return false;
    }
    HttpUriRequest request = (HttpUriRequest) new HttpGet(uri);
    try (CloseableHttpClient client = HttpClients.createDefault()) {
        try (CloseableHttpResponse response = client.execute(request)) {
            StatusLine statusLine = response.getStatusLine();
            logger.log(TRACE, "Status Line: {0}", statusLine);
            if (statusLine.getReasonPhrase().equals("OK")) {
                return success(response.getEntity());
            }
        } catch (ClientProtocolException ex) {
            logger.log(Level.SEVERE, ex.toString(), ex);
        }
    } catch (IOException ex) {
        logger.log(Level.SEVERE, ex.toString(), ex);
    }
    return false;
}

From source file:org.glom.web.server.Utils.java

/**
 * @param documentID/*from   ww  w. j a va  2s  .c o m*/
 * @param tableName
 * @return
 */
private static URIBuilder buildImageDataUrlStart(final String documentID, final String tableName) {
    final URIBuilder uriBuilder = new URIBuilder();
    //uriBuilder.setHost(GWT.getModuleBaseURL());
    uriBuilder.setPath("OnlineGlom/gwtGlomImages"); //The name of our images servlet. See OnlineGlomImagesServlet.
    uriBuilder.setParameter("document", documentID);
    uriBuilder.setParameter("table", tableName);
    return uriBuilder;
}

From source file:alluxio.cli.LogLevel.java

private static void setLogLevel(final TargetInfo targetInfo, String logName, String level) throws IOException {
    URIBuilder uriBuilder = new URIBuilder();
    uriBuilder.setScheme("http");
    uriBuilder.setHost(targetInfo.getHost());
    uriBuilder.setPort(targetInfo.getPort());
    uriBuilder.setPath(Constants.REST_API_PREFIX + "/" + targetInfo.getRole() + "/" + LOG_LEVEL);
    uriBuilder.addParameter(LOG_NAME_OPTION_NAME, logName);
    if (level != null) {
        uriBuilder.addParameter(LEVEL_OPTION_NAME, level);
    }/*from  ww  w .j a  va 2 s.co  m*/
    HttpUtils.post(uriBuilder.toString(), 5000, new HttpUtils.IProcessInputStream() {
        @Override
        public void process(InputStream inputStream) throws IOException {
            ObjectMapper mapper = new ObjectMapper();
            LogInfo logInfo = mapper.readValue(inputStream, LogInfo.class);
            System.out.println(targetInfo.toString() + logInfo.toString());
        }
    });
}

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//from   w  w w  .  ja  v  a  2s  .com
 *            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:edu.berkeley.ground.plugins.hive.util.PluginUtil.java

public static String buildURL(String path, String name) throws GroundException {
    try {/*  www  .jav a  2 s  . c  o  m*/
        URIBuilder uri = new URIBuilder(groundServerAddress);
        StringBuilder pathBuilder = new StringBuilder();
        pathBuilder.append("/").append(path);
        if (name != null) {
            pathBuilder.append("/").append(name);
        }
        return uri.setPath(pathBuilder.toString()).build().toString();
    } catch (URISyntaxException e) {
        throw new GroundException(e);
    }
}

From source file:azkaban.utils.RestfulApiClient.java

/** helper function to build a valid URI.
 *  @param host   host name.//from w  w  w.j a  v  a2 s.c o m
 *  @param port   host port.
 *  @param path   extra path after host.
 *  @param isHttp indicates if whether Http or HTTPS should be used.
 *  @param params extra query parameters.
 *  @return the URI built from the inputs.
 *  @throws IOException
 * */
public static URI buildUri(String host, int port, String path, boolean isHttp, Pair<String, String>... params)
        throws IOException {
    URIBuilder builder = new URIBuilder();
    builder.setScheme(isHttp ? "http" : "https").setHost(host).setPort(port);

    if (null != path && path.length() > 0) {
        builder.setPath(path);
    }

    if (params != null) {
        for (Pair<String, String> pair : params) {
            builder.setParameter(pair.getFirst(), pair.getSecond());
        }
    }

    URI uri = null;
    try {
        uri = builder.build();
    } catch (URISyntaxException e) {
        throw new IOException(e);
    }

    return uri;
}

From source file:de.shadowhunt.subversion.internal.URIUtils.java

private static URI createURI0(final URI repository, final Resource... resources) throws URISyntaxException {
    final URIBuilder builder = new URIBuilder();
    builder.setScheme(repository.getScheme());
    builder.setHost(repository.getHost());
    builder.setPort(repository.getPort());
    final StringBuilder completePath = new StringBuilder(repository.getPath());
    for (final Resource resource : resources) {
        completePath.append(resource.getValue());
    }// w  w  w .j  a  v  a 2s  .c om
    builder.setPath(completePath.toString());
    return builder.build();
}

From source file:com.redhat.refarch.microservices.trigger.service.TriggerService.java

private static URIBuilder getUriBuilder(Object... path) {

    URIBuilder uriBuilder = new URIBuilder();
    uriBuilder.setScheme("http");
    uriBuilder.setHost("gateway-service");
    uriBuilder.setPort(9091);//from w ww.  j av  a  2 s  . c om

    StringWriter stringWriter = new StringWriter();
    for (Object part : path) {
        stringWriter.append('/').append(String.valueOf(part));
    }
    uriBuilder.setPath(stringWriter.toString());
    return uriBuilder;
}

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

/**
 * Builds the URI from the URI parameter hash
 * <p>/*from   w ww.j  a  v a2 s. co m*/
 * 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);//from ww w . j  a va 2  s  .  co  m
    uriBuilder.setPort(port);
    uriBuilder.setPath("/ws/v1/timeline/metrics");
    return uriBuilder;
}