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() 

Source Link

Document

Constructs an empty instance.

Usage

From source file:org.wuspba.ctams.ws.ITSoloResultController.java

@Test
public void testListAll() throws Exception {
    CloseableHttpClient httpclient = HttpClients.createDefault();

    URI uri = new URIBuilder().setScheme(PROTOCOL).setHost(HOST).setPort(PORT).setPath(PATH).build();

    LOG.info("Connecting to " + uri.toString());

    HttpGet httpGet = new HttpGet(uri);

    try (CloseableHttpResponse response = httpclient.execute(httpGet)) {
        assertEquals(response.getStatusLine().toString(), IntegrationTestUtils.OK_STRING);

        HttpEntity entity = response.getEntity();

        CTAMSDocument doc = IntegrationTestUtils.convertEntity(entity);

        assertEquals(doc.getSoloContestResults().size(), 1);
        testEquality(doc.getSoloContestResults().get(0), TestFixture.INSTANCE.soloResult);

        EntityUtils.consume(entity);/*from   w w  w.  j  ava 2s .co  m*/
    }
}

From source file:org.wuspba.ctams.ws.ITBandRegistrationController.java

@Test
public void testListAll() throws Exception {
    CloseableHttpClient httpclient = HttpClients.createDefault();

    URI uri = new URIBuilder().setScheme(PROTOCOL).setHost(HOST).setPort(PORT).setPath(PATH).build();

    LOG.info("Connecting to " + uri.toString());

    HttpGet httpGet = new HttpGet(uri);

    try (CloseableHttpResponse response = httpclient.execute(httpGet)) {
        assertEquals(response.getStatusLine().toString(), IntegrationTestUtils.OK_STRING);

        HttpEntity entity = response.getEntity();

        CTAMSDocument doc = IntegrationTestUtils.convertEntity(entity);

        assertEquals(doc.getBandRegistrations().size(), 1);
        testEquality(doc.getBandRegistrations().get(0), TestFixture.INSTANCE.bandRegistration);

        EntityUtils.consume(entity);/*from w  w w  .  j  ava 2 s  . c  o  m*/
    }
}

From source file:org.wuspba.ctams.ws.ITSoloRegistrationController.java

@Test
public void testListAll() throws Exception {
    CloseableHttpClient httpclient = HttpClients.createDefault();

    URI uri = new URIBuilder().setScheme(PROTOCOL).setHost(HOST).setPort(PORT).setPath(PATH).build();

    LOG.info("Connecting to " + uri.toString());

    HttpGet httpGet = new HttpGet(uri);

    try (CloseableHttpResponse response = httpclient.execute(httpGet)) {
        assertEquals(response.getStatusLine().toString(), IntegrationTestUtils.OK_STRING);

        HttpEntity entity = response.getEntity();

        CTAMSDocument doc = IntegrationTestUtils.convertEntity(entity);

        assertEquals(doc.getSoloRegistrations().size(), 1);
        testEquality(doc.getSoloRegistrations().get(0), TestFixture.INSTANCE.soloRegistration);

        EntityUtils.consume(entity);/*from   w  ww.  jav  a 2 s.  c  o m*/
    }
}

From source file:org.finra.herd.tools.uploader.UploaderWebClient.java

/**
 * Gets the business object data upload credentials.
 *
 * @param manifest the manifest/* w w w. j av  a  2s.  co m*/
 * @param storageName the storage name
 * @param businessObjectDataVersion the version of the business object data
 * @param createNewVersion specifies to provide credentials fof the next business object data version
 *
 * @return {@link BusinessObjectDataUploadCredential}
 * @throws URISyntaxException When error occurs while URI creation
 * @throws IOException When error occurs communicating with server
 * @throws JAXBException When error occurs parsing the XML
 */
public BusinessObjectDataUploadCredential getBusinessObjectDataUploadCredential(
        DataBridgeBaseManifestDto manifest, String storageName, Integer businessObjectDataVersion,
        Boolean createNewVersion) throws URISyntaxException, IOException, JAXBException {
    URIBuilder uriBuilder = new URIBuilder().setScheme(getUriScheme())
            .setHost(regServerAccessParamsDto.getRegServerHost())
            .setPort(regServerAccessParamsDto.getRegServerPort())
            .setPath(String.join("/", HERD_APP_REST_URI_PREFIX, "businessObjectData", "upload", "credential",
                    "namespaces", manifest.getNamespace(), "businessObjectDefinitionNames",
                    manifest.getBusinessObjectDefinitionName(), "businessObjectFormatUsages",
                    manifest.getBusinessObjectFormatUsage(), "businessObjectFormatFileTypes",
                    manifest.getBusinessObjectFormatFileType(), "businessObjectFormatVersions",
                    manifest.getBusinessObjectFormatVersion(), "partitionValues", manifest.getPartitionValue()))
            .setParameter("storageName", storageName);
    if (manifest.getSubPartitionValues() != null) {
        uriBuilder.setParameter("subPartitionValues",
                herdStringHelper.join(manifest.getSubPartitionValues(), "|", "\\"));
    }
    if (businessObjectDataVersion != null) {
        uriBuilder.setParameter("businessObjectDataVersion", businessObjectDataVersion.toString());
    }
    if (createNewVersion != null) {
        uriBuilder.setParameter("createNewVersion", createNewVersion.toString());
    }
    HttpGet httpGet = new HttpGet(uriBuilder.build());
    httpGet.addHeader("Accepts", DEFAULT_ACCEPT);
    if (regServerAccessParamsDto.isUseSsl()) {
        httpGet.addHeader(getAuthorizationHeader());
    }
    try (CloseableHttpClient httpClient = httpClientOperations.createHttpClient()) {
        LOGGER.info("Retrieving upload credentials from registration server...");
        return getBusinessObjectDataUploadCredential(httpClientOperations.execute(httpClient, httpGet));
    }
}

From source file:org.wuspba.ctams.ws.ITBandResultController.java

@Test
public void testListAll() throws Exception {
    CloseableHttpClient httpclient = HttpClients.createDefault();

    URI uri = new URIBuilder().setScheme(PROTOCOL).setHost(HOST).setPort(PORT).setPath(PATH).build();

    LOG.info("Connecting to " + uri.toString());

    HttpGet httpGet = new HttpGet(uri);

    try (CloseableHttpResponse response = httpclient.execute(httpGet)) {
        assertEquals(response.getStatusLine().toString(), IntegrationTestUtils.OK_STRING);

        HttpEntity entity = response.getEntity();

        CTAMSDocument doc = IntegrationTestUtils.convertEntity(entity);

        assertEquals(doc.getBandContestResults().size(), 1);
        testEquality(doc.getBandContestResults().get(0), TestFixture.INSTANCE.bandResult);

        EntityUtils.consume(entity);//from  w  ww .  j  a va2 s  .c o m
    }
}

From source file:eu.hansolo.accs.RestClient.java

public JSONObject getLocation(final String NAME) {
    URIBuilder builder = new URIBuilder();
    builder.setScheme("https").setHost("api.mlab.com").setPort(443).setPath(DbCollection.LOCATIONS.REST_URL)
            .setParameter("q", "{\"name\":\"" + NAME + "\"}").setParameter("apiKey", MLAB_API_KEY);
    return getSpecificObject(builder);
}

From source file:org.finra.msl.client.MockAPI.java

/**
 * Method to register mock response. Once you register, whenever
 * server receives a request matching the registered requestPath, it will
 * respond with a fake response using the provided JSONObject's information.
 * /*from w  ww.  j  a v  a2  s.co m*/
 * @param server
 *            => url of web-server.js running on node
 * @param port
 *            => port number of web-server.js running on node
 * @param configurations
 *            => the JSONObject that contains all of the options (content
 *            type, requestPath, etc)
 * @return
 * @throws Exception
 */
@SuppressWarnings("unchecked")
public static String setMockRespond(String server, int port, Map<String, Object> configurations)
        throws Exception {

    URIBuilder builder = new URIBuilder();
    builder.setScheme("http").setHost(server).setPort(port).setPath("/mock/fakerespond");

    if (configurations.keySet().contains("keyValues")) {
        if (configurations.get("keyValues") != null && configurations.get("keyValues") instanceof Map) {
            configurations.put("keyValues",
                    new JSONObject((Map<String, Object>) configurations.get("keyValues")));
        }
    }

    if (configurations.keySet().contains("header")) {
        if (configurations.get("header") != null && configurations.get("header") instanceof Map) {
            configurations.put("header", new JSONObject((Map<String, Object>) configurations.get("header")));
        }
    }

    JSONObject object = new JSONObject(configurations);
    HttpPost post = new HttpPost(builder.toString());

    post.setHeader("Content-Type", "application/json");
    post.setEntity(new StringEntity(object.toString()));

    HttpClient client = new DefaultHttpClient();
    HttpResponse resp = client.execute(post);

    if (resp.getStatusLine().getStatusCode() != 200) {
        throw new Exception("POST failed. Error code: " + resp.getStatusLine().getStatusCode());
    }
    return EntityUtils.toString(resp.getEntity());
}

From source file:org.wuspba.ctams.ws.ITBandController.java

@Test
public void testList() throws Exception {
    CloseableHttpClient httpclient = HttpClients.createDefault();

    URI uri = new URIBuilder().setScheme(PROTOCOL).setHost(HOST).setPort(PORT).setPath(PATH).build();

    LOG.info("Connecting to " + uri.toString());

    HttpGet httpGet = new HttpGet(uri);

    try (CloseableHttpResponse response = httpclient.execute(httpGet)) {
        assertEquals(response.getStatusLine().toString(), IntegrationTestUtils.OK_STRING);

        HttpEntity entity = response.getEntity();

        CTAMSDocument doc = IntegrationTestUtils.convertEntity(entity);

        assertEquals(doc.getBands().size(), 1);
        assertTrue(doc.getBands().get(0).getName().equals(SKYE.getName()));

        EntityUtils.consume(entity);//from w  w w .  j a  v a 2s.c  o  m
    }
}

From source file:org.wuspba.ctams.ws.ITJudgeQualificationController.java

@Test
public void testList() throws Exception {
    CloseableHttpClient httpclient = HttpClients.createDefault();

    URI uri = new URIBuilder().setScheme(PROTOCOL).setHost(HOST).setPort(PORT).setPath(PATH).build();

    LOG.info("Connecting to " + uri.toString());

    HttpGet httpGet = new HttpGet(uri);

    try (CloseableHttpResponse response = httpclient.execute(httpGet)) {
        assertEquals(response.getStatusLine().toString(), IntegrationTestUtils.OK_STRING);

        HttpEntity entity = response.getEntity();

        CTAMSDocument doc = IntegrationTestUtils.convertEntity(entity);

        assertEquals(doc.getJudgeQualifications().size(), 3);
        for (JudgeQualification q : doc.getJudgeQualifications()) {
            if (q.getType().equals(JudgeType.BAND_PIPING)) {
                testEquality(q, TestFixture.INSTANCE.pipingQual);
            } else if (q.getType().equals(JudgeType.BAND_DRUMMING)) {
                testEquality(q, TestFixture.INSTANCE.drummingQual);
            } else if (q.getType().equals(JudgeType.BAND_ENSEMBLE)) {
                testEquality(q, TestFixture.INSTANCE.ensembleQual);
            } else {
                fail();//from   ww w . j a  va2  s.  co  m
            }
        }

        EntityUtils.consume(entity);
    }
}

From source file:fr.treeptik.cloudunit.docker.core.SimpleDockerDriver.java

@Override
public DockerResponse find(DockerContainer container) throws FatalDockerJSONException {
    URI uri = null;/*  w  ww  .j a  v a 2  s  .  c o  m*/
    String body = new String();
    DockerResponse dockerResponse = null;
    try {
        uri = new URIBuilder().setScheme(protocol).setHost(host)
                .setPath("/containers/" + container.getName() + "/json").build();
        dockerResponse = client.sendGet(uri);
    } catch (URISyntaxException | JSONClientException e) {
        StringBuilder contextError = new StringBuilder(256);
        contextError.append("uri : " + uri + " - ");
        contextError.append("request body : " + body + " - ");
        contextError.append("server response : " + dockerResponse);
        logger.error(contextError.toString());
        throw new FatalDockerJSONException(
                "An error has occurred for find a container request due to " + e.getMessage(), e);
    }

    return dockerResponse;
}