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.github.tomakehurst.wiremock.common.UniqueFilenameGenerator.java

public static String generateIdFromUrl(final String prefix, final String id, final String url) {
    URIBuilder urlbuild = null;/*from w w w  . j ava 2s  .c om*/
    try {
        urlbuild = new URIBuilder(url);
        urlbuild = urlbuild.removeQuery();
        return getRandomId(prefix, id, new URI(urlbuild.toString()));
    } catch (URISyntaxException e) {
        e.printStackTrace();
    }
    return null;
}

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

public static URI changeHostComponent(URI uri, String host) {
    Validate.notNull(uri, "uri");
    Validate.notEmpty(host, "host");

    URIBuilder uriBuilder = new URIBuilder(uri);
    uriBuilder.setHost(host);//from  w w w  .j a  v  a 2  s  . c  om
    try {
        return uriBuilder.build();
    } catch (URISyntaxException e) {
        throw new IllegalArgumentException("failed to change uri host component", e);
    }
}

From source file:integration.IntegrationTestsConfig.java

public static URI getGlServerURL() throws MalformedURLException, URISyntaxException {
    URIBuilder result = new URIBuilder(GL_BASE_URI);
    if (GL_PORT != null) {
        result.setPort(Integer.parseInt(GL_PORT));
    }/*  w w w  .j  a  va 2  s.  c om*/

    final String username;
    final String password;
    if (result.getUserInfo() == null) {
        username = GL_ADMIN_USER;
        password = GL_ADMIN_PASSWORD;
    } else {
        final String[] userInfo = result.getUserInfo().split(":");
        username = (GL_ADMIN_USER != null ? GL_ADMIN_USER : userInfo[0]);
        password = (GL_ADMIN_PASSWORD != null ? GL_ADMIN_PASSWORD : userInfo[1]);
    }

    result.setUserInfo(firstNonNull(username, "admin"), firstNonNull(password, "admin"));

    return result.build();
}

From source file:com.comoyo.emjar.EmJarTest.java

protected File getResourceFile(String name) throws URISyntaxException {
    final ClassLoader cl = getClass().getClassLoader();
    final URI base = cl.getResource("com/comoyo/emjar/").toURI();
    URIBuilder builder = new URIBuilder(base);
    builder.setPath(builder.getPath() + name);
    final URI uri = builder.build();
    if (!"file".equals(uri.getScheme())) {
        throw new IllegalArgumentException("Resource " + name + " not present as file (" + uri + ")");
    }/*from w  w w.  ja v  a2s .co m*/
    return new File(uri.getSchemeSpecificPart());
}

From source file:ch.asadzia.cognitive.EmotionDetect.java

public ServiceResult process() {

    HttpClient httpclient = HttpClients.createDefault();

    try {/*from w w w  .  j a  v a2s  .  c o  m*/
        URIBuilder builder = new URIBuilder("https://api.projectoxford.ai/emotion/v1.0/recognize");

        URI uri = builder.build();
        HttpPost request = new HttpPost(uri);
        request.setHeader("Content-Type", "application/octet-stream");
        request.setHeader("Ocp-Apim-Subscription-Key", apikey);

        // Request body
        FileEntity reqEntity = new FileEntity(imageData);
        request.setEntity(reqEntity);

        HttpResponse response = httpclient.execute(request);
        HttpEntity entity = response.getEntity();

        if (entity != null) {
            String responseStr = EntityUtils.toString(entity);

            if (response.getStatusLine().getStatusCode() != HttpStatus.SC_OK) {
                System.err.println(responseStr);
                return null;
            }

            JSONArray jsonArray = (JSONArray) new JSONParser().parse(responseStr);
            JSONObject jsonObject = (JSONObject) jsonArray.get(0);

            HashMap<char[], Double> scores = (HashMap) jsonObject.get("scores");

            Map.Entry<char[], Double> maxEntry = null;

            for (Map.Entry<char[], Double> entry : scores.entrySet()) {
                System.out.println("Key = " + entry.getKey() + ", Value = " + entry.getValue());

                if (maxEntry == null || entry.getValue().compareTo(maxEntry.getValue()) > 0) {
                    maxEntry = entry;
                }
            }
            Object key = maxEntry.getKey();

            String winningEmotionName = (String) key;

            ServiceResult result = new ServiceResult(translateEmotion(winningEmotionName), winningEmotionName);

            System.out.println(responseStr);

            return result;
        }
    } catch (Exception e) {
        System.err.println(e.toString());
    }
    return null;
}

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

public static String getQueryParamFromUrl(String url, String paramName) {
    try {/*from  w  w  w  .ja v  a2s.com*/
        List<NameValuePair> queryParams = new URIBuilder(url).getQueryParams();
        for (NameValuePair pair : queryParams) {
            if (pair.getName().equals(paramName)) {
                return pair.getValue();
            }
        }
        return StringUtils.EMPTY;
    } catch (URISyntaxException e) {
        return StringUtils.EMPTY;
    }
}

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

/**
 * The CaptchaGet-Request URI Builder.//  w  w  w  .  j a  v a2 s .c  om
 * @param cg The Get request for the new captcha.
 * @return the URI for the API request.
 */
public static URI captchaGetToURI(final CaptchaGet cg) {
    URI uri = null;

    URI apiURI = stringToURI(cg.getUrl());

    URIBuilder builder = new URIBuilder(apiURI)
            .addParameter("debug", BooleanUtils10.toIntegerString(cg.isDebug()))
            .addParameter("action", cg.getAction()).addParameter("apikey", cg.getApikey())
            .addParameter("source", cg.getSource())
            .addParameter("withok", BooleanUtils10.toIntegerString(cg.isWithok()))
            .addParameter("nocaptcha", BooleanUtils10.toIntegerString(cg.isNocaptcha()))
            .addParameter("extended", BooleanUtils10.toIntegerString(cg.isExtended()))
            .addParameter("text", cg.getText().getYesNoString());

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

    return uri;
}

From source file:net.oneandone.shared.artifactory.UtilsTest.java

/**
 * Test of toUri method, of class Utils.
 *///from w  w w . j  a  v  a  2  s.c  o  m
@Test
public void testToUri() {
    URI expResult = URI.create("http://localhost/");
    URIBuilder uriBuilder = new URIBuilder(expResult);
    String errorMessage = "oops";
    URI result = Utils.toUri(uriBuilder, errorMessage);
    assertEquals(expResult, result);
}

From source file:org.apache.sling.distribution.util.RequestUtils.java

public static URI appendDistributionRequest(URI uri, DistributionRequest distributionRequest)
        throws URISyntaxException {
    URIBuilder uriBuilder = new URIBuilder(uri);
    uriBuilder.addParameter(DistributionParameter.ACTION.toString(),
            distributionRequest.getRequestType().name());

    String[] paths = distributionRequest.getPaths();

    if (paths != null) {
        for (String path : paths) {
            uriBuilder.addParameter(DistributionParameter.PATH.toString(), path);
        }//from  w  ww .  jav  a 2 s.c  o  m
    }

    return uriBuilder.build();
}

From source file:com.triage.radium.testweb.it.ITTestWeb.java

@Test
public void testThatEchoServletReturnsUnsanitizedContent() throws Exception {
    String unsanitizedInput = "<xml>Unsantized!</xml>";
    URI uri = new URIBuilder(WEBAPP_BASE_URL + "/echo").addParameter("in", unsanitizedInput).build();
    Response resp = Request.Get(uri).execute();
    String resultText = resp.returnContent().toString().trim();

    assertEquals(resultText, "SUCCESS\n" + unsanitizedInput);

}