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:hackathon.Hackathon.java

/**
 * @param args the command line arguments
 *//*from  www.  ja v a2 s. c o m*/
public static void main(String[] args) {
    // TODO code application logic here
    HttpClient httpclient = HttpClients.createDefault();

    try {
        URIBuilder builder = new URIBuilder(
                "https://westus.api.cognitive.microsoft.com/emotion/v1.0/recognize");

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

        // Request body
        String url = "https://s-media-cache-ak0.pinimg.com/564x/af/8b/47/af8b47d56ded6952fa8ebfdcf7e87f43.jpg";
        StringEntity reqEntity = new StringEntity(
                "{'url' : 'https://s-media-cache-ak0.pinimg.com/564x/af/8b/47/af8b47d56ded6952fa8ebfdcf7e87f43.jpg'}");
        request.setEntity(reqEntity);

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

        if (entity != null) {
            System.out.println(EntityUtils.toString(entity));
        }
    } catch (Exception e) {
        System.out.println(e.getMessage());
    }
}

From source file:com.kookoo.outbound.OutboundTest.java

public static void main(String a[]) {
    try {//from   www .  java 2  s  .  c  o m
        String server_ip = "http://XXXX:8080"; /*change to your web server*/
        String phone_no1 = "09985XXXXX";/*change number to your numbers*/
        String phone_no2 = "09985XXXXX";/*change number to your numbers*/
        String api_key = "KKXXXXX";/*kookoo api key*/
        String kookoo_number = "91xxxxx";/*kookoo assigned number*/

        Date d = new Date();
        String trackId = "" + d.getTime();
        String url = "http://kookoo.in/outbound/outbound.php";
        URIBuilder uribuilder = new URIBuilder(url);
        uribuilder.addParameter("api_key", api_key);
        uribuilder.addParameter("phone_no", phone_no1);
        uribuilder.addParameter("caller_id", kookoo_number);
        /*assigned kookoo number*/
        uribuilder.addParameter("url",
                server_ip + "/kookoocall/outboundcall?number2=" + phone_no2 + "&trackId=" + trackId);
        uribuilder.addParameter("callback_url",
                server_ip + "/kookoocall/outbound_callstatus?number2=" + phone_no2 + "&trackId=" + trackId);

        URI uri = uribuilder.build();
        System.out.println("Final Outboud API url " + uri);
        HttpGet request = new HttpGet(uri);
        HttpClient client = HttpClientBuilder.create().build();
        HttpResponse response = client.execute(request);

        String responseString = new BasicResponseHandler().handleResponse(response);
        System.out.println(responseString);

    } catch (Exception e) {
        e.printStackTrace();
    }

}

From source file:com.wudaosoft.net.httpclient.Test.java

public static void main(String[] args) throws Exception {

    Test test = new Test();
    test.test();/*from   w  w w  . j  a  v  a2  s. c om*/
    test.testSSL();
    test.testXml();

    System.out.println(new URIBuilder("https://www.baidu.com/?pp=").setCharset(Consts.UTF_8).build());
    System.out.println(new URIBuilder("https://www.baidu.com/?pp=jkdafow8ewqr").setCharset(Consts.UTF_8)
            .addParameter("ccs", "").addParameter("ooo", "").build());
}

From source file:com.github.autermann.wps.streaming.ExecuteBuilder.java

public static void main(String[] args) throws URISyntaxException, IOException, ExceptionReport, XmlException {
    OwsCodeType processId = new OwsCodeType(DelegatingStreamingAlgorithm.PROCESS_ID);

    ProcessInputs inputs = new ProcessInputs().addDataInput(INPUT_REMOTE_WPS_URL, LiteralData.of(WPS_URL))
            .addDataInput(INPUT_REMOTE_PROCESS_DESCRIPTION,
                    new ReferencedData(
                            new URIBuilder(WPS_URL).addParameter(PARAMETER_SERVICE, SERVICE_TYPE_WPS)
                                    .addParameter(PARAMETER_VERSION, SERVICE_VERSION_100)
                                    .addParameter(PARAMETER_REQUEST, OPERATION_DESCRIBE_PROCESS)
                                    .addParameter(PARAMETER_IDENTIFIER, AddAlgorithm.class.getName()).build(),
                            PROCESS_DESCRIPTION_FORMAT));

    //        StaticInputsDocument doc = StaticInputsDocument.Factory.newInstance();
    InputsDocument doc = InputsDocument.Factory.newInstance();
    InputsType d = doc.addNewInputs();//doc.addNewStaticInputs();

    CommonEncoding ce = new CommonEncoding();
    ce.encodeInput(d.addNewStreamingInput(), new DataProcessInput("intput1", LiteralData.of("input1")));
    ce.encodeInput(d.addNewStreamingInput(), new DataProcessInput("intput2",
            new ComplexData(new Format("application/xml", "UTF-8"), "<hello>world</hello>")));
    ce.encodeInput(d.addNewStreamingInput(),
            new DataProcessInput("intput3", new BoundingBoxData(BoundingBoxType.Factory.parse(
                    "<wps:BoundingBoxData xmlns:wps=\"http://www.opengis.net/wps/1.0.0\" xmlns:ows=\"http://www.opengis.net/ows/1.1\" crs=\"EPSG:4326\" dimensions=\"2\">\n"
                            + "        <ows:LowerCorner>52.2 7.0</ows:LowerCorner>\n"
                            + "        <ows:UpperCorner>55.2 15.0</ows:UpperCorner>\n"
                            + "      </wps:BoundingBoxData>"))));
    ce.encodeInput(d.addNewStreamingInput(), new DataProcessInput("input4", new ReferencedData(URI.create(
            "http://geoprocessing.demo.52north.org:8080/geoserver/wfs?service=WFS&version=1.0.0&request=GetFeature&typeName=topp:tasmania_roads&srs=EPSG:4326&outputFormat=GML3"),
            new Format("application/xml", "UTF-8", "http://schemas.opengis.net/gml/3.1.1/base/gml.xsd"))));

    System.out.println(doc.xmlText(SchemaConstants.XML_OPTIONS));
    //        try (CloseableHttpClient httpClient = HttpClients.createDefault();
    //             WPSClient client = new WPSClient(WPS_URL, httpClient)) {
    //            client.execute(processId, inputs,
    //                           Lists.newArrayList(OUTPUT_PROCESS_ID,
    //                                              OUTPUT_SOCKET_URI));
    //        }/*from w  ww .  ja  v a2  s .  co  m*/
}

From source file:manager.computerVisionManager.java

private static void getJson(String path) {
    System.out.println("Get Description from https://westus.api.cognitive.microsoft.com/vision/v1.0/describe");
    try {//from  www  . ja va  2  s.c  om
        URIBuilder builder = new URIBuilder("https://westus.api.cognitive.microsoft.com/vision/v1.0/describe");
        builder.setParameter("maxCandidates", "1");
        URI uri = builder.build();
        HttpPost request = new HttpPost(uri);
        request.setHeader("Content-Type", "application/json");
        request.setHeader("Ocp-Apim-Subscription-Key", "d7f6ef12e41c4f8c8e72d12a890fa703");
        // Request body
        StringEntity reqEntity = new StringEntity("{\"url\":\"" + path + "\"}");
        System.out.println("Request String: " + reqEntity.toString());
        request.setEntity(reqEntity);
        HttpResponse response = httpclient.execute(request);
        HttpEntity entity = response.getEntity();
        if (entity != null) {
            String respuesta = EntityUtils.toString(entity);
            JSONParser lector = new JSONParser();
            StringReader SR = new StringReader(respuesta);
            try {
                JSONObject temp = (JSONObject) lector.parse(SR);
                json = (JSONObject) temp.get("description");
            } catch (org.json.simple.parser.ParseException e) {
                System.err.println(e.getMessage());
            }
        }
    } catch (IOException | URISyntaxException | ParseException e) {
        System.err.println(e.getMessage());
    }
}

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

@Nonnull
public static String buildSignInUrl() throws InvalidUriException {
    String ret = null;//w  w  w .j  a va  2 s . c  om
    final String path = String.format(Locale.US, FORMAT_LOGIN_PATH,
            PluginModule.getDefault().getJenkinsDescriptor().getLoginURI());
    try {
        final URIBuilder builder = new URIBuilder(getRootURL());
        builder.setPath(path);
        final URI uri = builder.build();
        ret = uri.toURL().toExternalForm();
    } catch (URISyntaxException | MalformedURLException e) {
        onError(e.getLocalizedMessage());
    }
    return ret;
}

From source file:com.vmware.identity.openidconnect.common.CommonUtils.java

public static String appendQueryParameter(URI uri, String parameterName, String parameterValue) {
    Validate.notNull(uri, "uri");
    Validate.notEmpty(parameterName, "parameterName");
    Validate.notEmpty(parameterValue, "parameterValue");

    String result;/*w w w.j  a  v a2s  .  co m*/
    URIBuilder uriBuilder = new URIBuilder(uri);
    uriBuilder.addParameter(parameterName, parameterValue);
    try {
        result = uriBuilder.build().toString();
    } catch (URISyntaxException e) {
        String error = String.format("failed to add parameter [%s]=[%s] to uri [%s]", parameterName,
                parameterValue, uri);
        throw new IllegalArgumentException(error, e);
    }
    return result;
}

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

/**
 * Construct SSO URL to obtain token from username and password.
 *
 * @param url oVirt engine URL//from  w  ww .  j av a2 s  .  c o  m
 * @return URI to be used to obtain token
 */
public static URI buildSsoUrlBasic(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_TOKEN));
        return uriBuilder.build();
    } catch (URISyntaxException ex) {
        throw new Error("Failed to build SSO authentication URL", ex);
    }
}

From source file:com.ecofactor.qa.automation.util.HttpUtil.java

/**
 * Gets the./*  w w  w.j  a va2s  .  c  om*/
 * @param url the url
 * @return the http response
 */
public static String get(String url, Map<String, String> params, int expectedStatus) {

    String content = null;
    HttpClient httpClient = new DefaultHttpClient();
    HttpGet request = new HttpGet(url);
    URIBuilder builder = new URIBuilder(request.getURI());

    Set<String> keys = params.keySet();
    for (String key : keys) {
        builder.addParameter(key, params.get(key));
    }

    HttpResponse response = null;
    try {
        request.setURI(builder.build());
        DriverConfig.setLogString("URL " + request.getURI().toString(), true);
        response = httpClient.execute(request);
        content = IOUtils.toString(response.getEntity().getContent());
        DriverConfig.setLogString("Content " + content, true);
        Assert.assertEquals(response.getStatusLine().getStatusCode(), expectedStatus);
    } catch (Exception e) {
        LOGGER.error(e.getMessage());
    } finally {
        request.releaseConnection();
    }

    return content;
}

From source file:com.ecofactor.qa.automation.util.HttpsUtil.java

/**
 * Gets the.//from w  ww .ja  v  a  2  s. c om
 * @param url the url
 * @return the https response
 */
public static String get(String url, Map<String, String> params, int expectedStatus) {

    String content = null;
    HttpGet request = new HttpGet(url);
    URIBuilder builder = new URIBuilder(request.getURI());

    if (params != null) {
        Set<String> keys = params.keySet();
        for (String key : keys) {
            builder.addParameter(key, params.get(key));
        }
    }

    try {
        request.setURI(builder.build());
        DriverConfig.setLogString("URL " + request.getURI().toString(), true);
        driver.navigate().to(request.getURI().toString());
        tinyWait();
        content = driver.findElement(By.tagName("Body")).getText();
        DriverConfig.setLogString("Content: " + content, true);
    } catch (Exception e) {
        LOGGER.error(e.getMessage());
    } finally {
        request.releaseConnection();
    }

    return content;
}