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.apache.rya.indexing.smarturi.SmartUriAdapter.java

private static URI createTypePropertiesUri(
        final ImmutableMap<RyaURI, ImmutableMap<RyaURI, Property>> typeProperties) throws SmartUriException {
    final List<NameValuePair> nameValuePairs = new ArrayList<>();
    for (final Entry<RyaURI, ImmutableMap<RyaURI, Property>> typeProperty : typeProperties.entrySet()) {
        final RyaURI type = typeProperty.getKey();
        final Map<RyaURI, Property> propertyMap = typeProperty.getValue();
        final URI typeUri = createIndividualTypeWithPropertiesUri(type, propertyMap);
        final String keyString = type.getDataType().getLocalName();
        final String valueString = typeUri.getLocalName();
        nameValuePairs.add(new BasicNameValuePair(keyString, valueString));
    }//from   w w  w .  j  av a2s .c  o m

    final URIBuilder uriBuilder = new URIBuilder();
    uriBuilder.addParameters(nameValuePairs);

    String uriString;
    try {
        final java.net.URI uri = uriBuilder.build();
        final String queryString = uri.getRawSchemeSpecificPart();
        uriString = "urn:test" + queryString;
    } catch (final URISyntaxException e) {
        throw new SmartUriException("Unable to create type properties for the Smart URI", e);
    }

    return new URIImpl(uriString);
}

From source file:org.jboss.as.quickstarts.resteasyspring.test.ResteasySpringIT.java

@Test
public void testHelloSpringResource() throws Exception {
    try (CloseableHttpClient client = HttpClients.createDefault()) {
        {//from  w  w  w .j a  v a 2  s . com
            URI uri = new URIBuilder().setScheme("http").setHost(url.getHost()).setPort(url.getPort())
                    .setPath(url.getPath() + "hello").setParameter("name", "JBoss Developer").build();
            HttpGet method = new HttpGet(uri);
            try (CloseableHttpResponse response = client.execute(method)) {
                Assert.assertEquals(HttpResponseCodes.SC_OK, response.getStatusLine().getStatusCode());
                Assert.assertTrue(EntityUtils.toString(response.getEntity()).contains("JBoss Developer"));
            } finally {
                method.releaseConnection();
            }
        }
        {
            HttpGet method = new HttpGet(url.toString() + "basic");
            try (CloseableHttpResponse response = client.execute(method)) {
                Assert.assertEquals(HttpResponseCodes.SC_OK, response.getStatusLine().getStatusCode());
                Assert.assertTrue(EntityUtils.toString(response.getEntity()).contains("basic"));
            } finally {
                method.releaseConnection();
            }
        }
        {
            HttpPut method = new HttpPut(url.toString() + "basic");
            method.setEntity(new StringEntity("basic", ContentType.TEXT_PLAIN));
            try (CloseableHttpResponse response = client.execute(method)) {
                Assert.assertEquals(HttpResponseCodes.SC_NO_CONTENT, response.getStatusLine().getStatusCode());
            } finally {
                method.releaseConnection();
            }
        }
        {
            URI uri = new URIBuilder().setScheme("http").setHost(url.getHost()).setPort(url.getPort())
                    .setPath(url.getPath() + "queryParam").setParameter("param", "hello world").build();
            HttpGet method = new HttpGet(uri);
            try (CloseableHttpResponse response = client.execute(method)) {
                Assert.assertEquals(HttpResponseCodes.SC_OK, response.getStatusLine().getStatusCode());
                Assert.assertTrue(EntityUtils.toString(response.getEntity()).contains("hello world"));
            } finally {
                method.releaseConnection();
            }
        }
        {
            HttpGet method = new HttpGet(url.toString() + "matrixParam;param=matrix");
            try (CloseableHttpResponse response = client.execute(method)) {
                Assert.assertEquals(HttpResponseCodes.SC_OK, response.getStatusLine().getStatusCode());
                Assert.assertTrue(EntityUtils.toString(response.getEntity()).equals("matrix"));
            } finally {
                method.releaseConnection();
            }
        }
        {
            HttpGet method = new HttpGet("http://localhost:8080/spring-resteasy/uriParam/1234");
            try (CloseableHttpResponse response = client.execute(method)) {
                Assert.assertEquals(HttpResponseCodes.SC_OK, response.getStatusLine().getStatusCode());
                Assert.assertTrue(EntityUtils.toString(response.getEntity()).equals("1234"));
            } finally {
                method.releaseConnection();
            }
        }
    }
}

From source file:com.github.dziga.orest.client.HttpRestClient.java

int Get() throws IOException, URISyntaxException, NoSuchAlgorithmException, InvalidKeyException {
    URIBuilder b = new URIBuilder().setScheme(scheme).setHost(host).setPath(path);
    addQueryParams(b);//from  w  w w . j  a  va  2  s.  c o  m
    URI fullUri = b.build();
    HttpGet getMethod = new HttpGet(fullUri);
    getMethod = (HttpGet) addHeadersToMethod(getMethod);

    processResponse(httpClient.execute(getMethod));
    return getResponseCode();
}

From source file:org.wuspba.ctams.ws.ITBandContestController.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.getBandContests().size(), 1);
        testEquality(doc.getBandContests().get(0), TestFixture.INSTANCE.bandContest);

        EntityUtils.consume(entity);//from w ww  .j av a  2 s  .c om
    }
}

From source file:org.wso2.security.tools.dependencycheck.scanner.NotificationManager.java

public static void notifyScanStatus(String status) throws NotificationManagerException {
    int i = 0;// www.  ja va  2s.c  om
    while (i < 10) {
        try {
            URI uri = (new URIBuilder()).setHost(automationManagerHost).setPort(automationManagerPort)
                    .setScheme("http").setPath(ScannerProperties.getNotifyScanStatus())
                    .addParameter("containerId", myContainerId).addParameter("status", status).build();
            HttpClient httpClient = HttpClientBuilder.create().build();
            HttpGet get = new HttpGet(uri);
            HttpResponse response = httpClient.execute(get);
            if (response.getStatusLine().getStatusCode() == HttpStatus.SC_OK) {
                LOGGER.info("Notified successfully");
                return;
            } else {
                i++;
            }
            Thread.sleep(2000);
        } catch (URISyntaxException | InterruptedException | IOException e) {
            LOGGER.error("Error occurred while notifying the scan status to automation manager", e);
            i++;
        }
    }
    throw new NotificationManagerException("Error occurred while notifying status to Automation Manager");
}

From source file:org.wuspba.ctams.ws.ITPersonController.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.getPeople().size(), 5);
        for (Person p : doc.getPeople()) {
            if (p.getLastName().equals(TestFixture.INSTANCE.andy.getLastName())) {
                testEquality(p, TestFixture.INSTANCE.andy);
            } else if (p.getLastName().equals(TestFixture.INSTANCE.bob.getLastName())) {
                testEquality(p, TestFixture.INSTANCE.bob);
            } else if (p.getLastName().equals(TestFixture.INSTANCE.elaine.getLastName())) {
                testEquality(p, TestFixture.INSTANCE.elaine);
            } else if (p.getLastName().equals(TestFixture.INSTANCE.eoin.getLastName())) {
                testEquality(p, TestFixture.INSTANCE.eoin);
            } else if (p.getLastName().equals(TestFixture.INSTANCE.jamie.getLastName())) {
                testEquality(p, TestFixture.INSTANCE.jamie);
            } else {
                fail();/*from w w w  .j  ava2 s.  co  m*/
            }
        }

        EntityUtils.consume(entity);
    }
}

From source file:org.jwifisd.transcend.TranscendWiFiSD.java

/**
 * get the file contents of the specified file. No cache here so every call
 * will get the data from the card.//from   w ww. ja v a  2  s  . c o  m
 * 
 * @param wifiFile
 *            the file to get the contents of
 */
protected void downloadFile(final TranscendWifiSDFile wifiFile) {
    try {
        String fileName = wifiFile.name().substring(wifiFile.name().lastIndexOf('/') + 1);
        String fileDir = wifiFile.name().substring(0, wifiFile.name().lastIndexOf('/')).replace("/mnt/sd",
                "/www/sd");
        URI uri = new URIBuilder()//
                .setScheme("http")//
                .setHost(ipAddress().getHostAddress())//
                .setPath("/cgi-bin/wifi_download")//
                .setParameter("fn", fileName) // file name
                .setParameter("fd", fileDir) // file directory
                .build();
        HttpGet httpget = new HttpGet(uri);

        if (LOG.isInfoEnabled()) {
            LOG.info("Executing request " + httpget.getRequestLine());
        }

        byte[] responseBody = getHttpClient().execute(httpget, new ByteResponseHandler());
        wifiFile.setData(responseBody);
        // TODO: set timestamp?
    } catch (Exception e) {
        LOG.error("TranscendWiFiSD could not download file data!", e);
    }
}

From source file:fr.insalyon.creatis.vip.query.server.rpc.EndPointSparqlServiceImpl.java

public String getUrlResult(String param1, String param2) {
    String url = null;//from w  w w.  java  2s  . com
    String k = null;
    URIBuilder builder = new URIBuilder();
    builder.setHost("ginseng.unice.fr");
    builder.setPort(9000);
    builder.setPath("/sparql");

    builder.setParameter("query", param1);

    builder.setParameter("format", param2);
    try {
        url = builder.build().toString();

    } catch (URISyntaxException ex) {
        Logger.getLogger(EndPointSparqlServiceImpl.class.getName()).log(Level.SEVERE, null, ex);
    }

    return url;

}

From source file:org.wuspba.ctams.ws.ITSoloContestController.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.getSoloContests().size(), 1);
        testEquality(doc.getSoloContests().get(0), TestFixture.INSTANCE.soloContest);

        EntityUtils.consume(entity);//w  ww.j av  a2 s  . c o  m
    }
}

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

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

    URI uri = new URIBuilder().setScheme(PROTOCOL).setHost(HOST).setPort(PORT).setPath(PATH)
            .setParameter("season", Integer.toString(TestFixture.INSTANCE.roster1.getSeason())).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.getRosters().size(), 2);
        for (Roster r : doc.getRosters()) {
            if (r.getVersion() == TestFixture.INSTANCE.roster1.getVersion()) {
                testEquality(r, TestFixture.INSTANCE.roster1);
            } else if (r.getVersion() == TestFixture.INSTANCE.roster2.getVersion()) {
                testEquality(r, TestFixture.INSTANCE.roster2);
            } else {
                fail();//from ww w .  jav  a  2  s  .c o  m
            }
        }

        EntityUtils.consume(entity);
    }
}