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

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

Introduction

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

Prototype

public URIBuilder(final URI uri) 

Source Link

Document

Construct an instance from the provided URI.

Usage

From source file:com.vmware.identity.openidconnect.protocol.URIUtils.java

public static URI changePathComponent(URI uri, String path) {
    Validate.notNull(uri, "uri");
    Validate.notEmpty(path, "path");

    URIBuilder uriBuilder = new URIBuilder(uri);
    uriBuilder.setPath(path);/*from w w w  .j av a2s  . c  o  m*/
    try {
        return uriBuilder.build();
    } catch (URISyntaxException e) {
        throw new IllegalArgumentException("failed to change uri path component", e);
    }
}

From source file:de.bmarwell.j9kwsolver.util.RequestToURI.java

/**
 * Returns the URI for requesting the server status.
 * @param sc the URI for requesting the server status.
 * @return the URI for requesting the server status.
 *///from   w  ww . j  av  a  2 s .  c  om
public static URI serverStatusToURI(final ServerCheck sc) {
    URI uri = null;

    URI apiURI = stringToURI(sc.getUrl());
    URIBuilder builder = new URIBuilder(apiURI).addParameter("action", sc.getAction());

    try {
        uri = builder.build();
    } catch (URISyntaxException e) {
        LOG.error("Konnte URI nicht erstellen!", e);
    }

    return uri;
}

From source file:email.mandrill.MandrillApiHandler.java

public static Map<String, Object> getEmailDetails(String mandrillEmailId)
        throws URISyntaxException, IOException {
    Map<String, Object> emailDetails = new HashMap<>();
    HttpClient httpclient = HttpClients.createDefault();
    HttpGet httpGet = new HttpGet("https://mandrillapp.com/api/1.0/messages/info.json");
    URI uri = new URIBuilder(httpGet.getURI()).addParameter("key", SendEmail.MANDRILL_KEY)
            .addParameter("id", mandrillEmailId).build();
    logger.info("Getting Email details: " + uri.toString());
    Gson gson = new Gson();
    httpGet.setURI(uri);//  www.  j ava 2  s.co m

    //Execute and get the response.
    HttpResponse response = httpclient.execute(httpGet);
    HttpEntity responseEntity = response.getEntity();
    if (responseEntity != null) {
        String jsonContent = EntityUtils.toString(responseEntity);
        logger.info(jsonContent);
        // Create a Reader from String
        Reader stringReader = new StringReader(jsonContent);

        // Pass the string reader to JsonReader constructor
        JsonReader reader = new JsonReader(stringReader);
        reader.setLenient(true);
        Map<String, Object> mandrillEmailDetails = gson.fromJson(reader, Map.class);
        emailDetails.put("sent_on", mandrillEmailDetails.get("ts"));
        emailDetails.put("mandrill_id", mandrillEmailDetails.get("_id"));
        emailDetails.put("email_state", mandrillEmailDetails.get("state"));
        emailDetails.put("subject", mandrillEmailDetails.get("subject"));
        emailDetails.put("email", mandrillEmailDetails.get("email"));
        emailDetails.put("tags", mandrillEmailDetails.get("tags"));
        emailDetails.put("opens", mandrillEmailDetails.get("opens"));
        emailDetails.put("clicks", mandrillEmailDetails.get("clicks"));
        emailDetails.put("sender", mandrillEmailDetails.get("sender"));

    }

    return emailDetails;
}

From source file:com.appdirect.sdk.support.HttpClientHelper.java

public static HttpGet get(String endpoint, String... params) throws URISyntaxException {
    if (params.length % 2 != 0) {
        throw new IllegalArgumentException("pass params in name=value form");
    }//from   w  w  w  .  j a  va  2s.c  o  m

    URIBuilder builder = new URIBuilder(endpoint);
    for (int i = 0; i < params.length; i = i + 2) {
        builder.addParameter(params[i], params[i + 1]).build();
    }
    return new HttpGet(builder.build());
}

From source file:com.hp.autonomy.hod.client.api.authentication.SignedRequest.java

static SignedRequest sign(final Hmac hmac, final String endpoint,
        final AuthenticationToken<?, TokenType.HmacSha1> token, final Request<String, String> request) {
    final URIBuilder uriBuilder;

    try {//from   w ww. j  av  a  2s.  c o m
        uriBuilder = new URIBuilder(endpoint + request.getPath());
    } catch (final URISyntaxException e) {
        throw new IllegalArgumentException("Invalid endpoint or request path");
    }

    if (request.getQueryParameters() != null) {
        for (final Map.Entry<String, List<String>> entry : request.getQueryParameters().entrySet()) {
            for (final String value : entry.getValue()) {
                uriBuilder.addParameter(entry.getKey(), value);
            }
        }
    }

    final String bodyString;

    if (request.getBody() == null) {
        bodyString = null;
    } else {
        final List<NameValuePair> pairs = new LinkedList<>();

        for (final Map.Entry<String, List<String>> entry : request.getBody().entrySet()) {
            pairs.addAll(entry.getValue().stream().map(value -> new BasicNameValuePair(entry.getKey(), value))
                    .collect(Collectors.toList()));
        }

        bodyString = URLEncodedUtils.format(pairs, UTF8);
    }

    final String tokenString = hmac.generateToken(request, token);
    return new SignedRequest(uriBuilder.toString(), request.getVerb(), bodyString, tokenString);
}

From source file:com.infullmobile.jenkins.plugin.restrictedregister.util.AppUrls.java

@Nonnull
public static String buildActivationUrl(String code, String secret) throws InvalidUriException {
    String ret = null;/*from   w ww.  ja  v a2 s. c  o m*/
    final String path = String.format(Locale.US, FORMAT_REGISTER_PATH,
            PluginModule.getDefault().getPluginDescriptor().getRootActionURL());
    try {
        final URIBuilder builder = new URIBuilder(getRootURL());
        builder.setPath(path);
        builder.addParameter(BaseFormField.SECRET.getFieldName(), secret);
        builder.addParameter(BaseFormField.ACTIVATION_CODE.getFieldName(), code);
        final URI uri = builder.build();
        ret = uri.toURL().toExternalForm();
    } catch (URISyntaxException | MalformedURLException e) {
        onError(e.getLocalizedMessage());
    }
    return ret;
}

From source file:com.thoughtworks.go.util.UrlUtil.java

public static String urlWithQuery(String oldUrl, String paramName, String paramValue)
        throws URISyntaxException {
    URIBuilder uriBuilder = new URIBuilder(oldUrl);
    uriBuilder.addParameter(paramName, paramValue);
    return uriBuilder.toString();
}

From source file:org.sentilo.common.utils.URIUtils.java

public static String getURI(final String host, final String path, final RequestParameters parameters) {

    try {/*from w w w. j a v  a  2  s  . c o m*/
        final URI baseURI = getBaseURI(host, path);
        final URIBuilder builder = new URIBuilder(baseURI);

        if (parameters != null && parameters.size() > 0) {
            for (final String key : parameters.keySet()) {
                final String value = parameters.get(key);
                builder.setParameter(key, value);
            }
        }
        return builder.build().toString();
    } catch (final URISyntaxException e) {
        throw buildIllegalArgumentException(host, path, e);
    }
}

From source file:org.fao.geonet.harvester.wfsfeatures.worker.OwsUtils.java

public static String getGetCapabilitiesUrl(final String wfsUrl, final String version) throws Exception {
    URIBuilder builder = new URIBuilder(wfsUrl);
    builder.addParameter("request", "GetCapabilities");
    builder.addParameter("service", "WFS");
    builder.addParameter("version", version);

    String url = builder.build().toURL().toString();
    return url;//w  w w .  j ava2s .co  m
}

From source file:org.ovirt.engine.sdk4.internal.SsoUtils.java

/**
 * Construct SSO URL to obtain token from kerberos authentication.
 *
 * @param url oVirt engine URL//from   ww w  .  j a v a 2 s.c om
 * @return URI to be used to obtain token
 */
public static URI buildSsoUrlKerberos(String url) {
    try {
        URI uri = new URI(url);
        URIBuilder uriBuilder = new URIBuilder(String.format("%1$s://%2$s/ovirt-engine/sso/oauth/%3$s",
                uri.getScheme(), uri.getAuthority(), ENTRY_POINT_HTTP));
        return uriBuilder.build();
    } catch (URISyntaxException ex) {
        throw new Error("Failed to build SSO authentication URL", ex);
    }
}