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:cn.org.once.cstack.docker.core.SimpleDockerDriver.java

@Override
public DockerResponse find(DockerContainer container) throws FatalDockerJSONException {
    URI uri = null;//from   w  w  w  . j  a  v a2 s. com
    String body = new String();
    DockerResponse dockerResponse = null;
    try {
        uri = new URIBuilder().setScheme(NamingUtils.getProtocolSocket(isUnixSocket, mode)).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;
}

From source file:se.inera.certificate.proxy.mappings.remote.RemoteMappingTest.java

@Test
public void testMapToUrl2() throws URISyntaxException {
    RemoteMapping m = new RemoteMapping("/services", "http://www.google.com:80/test");
    URIBuilder builder = new URIBuilder();
    builder.setScheme(m.getMappedProtocol()).setHost(m.getMappedHost()).setPort(m.getMappedPort())
            .setPath("/some/new/uri").setQuery("some=1&less=34").setFragment("hello");

    assertEquals("http://www.google.com:80/some/new/uri?some=1&less=34#hello", builder.build().toString());
}

From source file:org.obm.service.solr.SolrClientFactoryImpl.java

public CommonsHttpSolrServer create(SolrService service, ObmDomain domain) {
    try {//ww w  .j a  va  2  s .c  o m
        URI uri = new URIBuilder().setScheme("http")
                .setHost(locatorService.getServiceLocation(service.getName(), domain.getName())).setPort(8080)
                .setPath('/' + service.getName()).build();
        return new CommonsHttpSolrServer(uri.toURL(), httpClient);
    } catch (MalformedURLException e) {
        throw new LocatorClientException(e);
    } catch (URISyntaxException e) {
        throw new LocatorClientException(e);
    }
}

From source file:com.autonomy.nonaci.indexing.impl.IndexingServiceImpl.java

private URI createIndexCommandURI(final ServerDetails serverDetails, final IndexCommand command)
        throws URISyntaxException {
    LOGGER.trace("createIndexCommandURI() called...");

    // Create the URI to use... We can't use URLEncodedUtils.parse() or setQuery() since they decode
    // command.getQueryString(), which we shouldn't do since both '+' and '%20' will be decoded-and-reencoded
    // to '+', which causes problems since IDOL treats these differently e.g. when listing DREREFERENCEs.
    final URI uri = new URIBuilder()
            .setScheme(serverDetails.getProtocol().toString().toLowerCase(Locale.ENGLISH))
            .setHost(serverDetails.getHost()).setPort(serverDetails.getPort())
            .setPath('/' + command.getCommand()).build();

    final String qs = command.getQueryString();

    return StringUtils.isBlank(qs) ? uri : new URI(uri + "?" + qs);
}

From source file:de.devbliss.apitester.dummyserver.DummyApiServer.java

public URI buildRequestUri(String pathOnServer) throws URISyntaxException {
    URIBuilder uriBuilder = new URIBuilder();
    uriBuilder.setScheme("http");
    uriBuilder.setHost("localhost");
    uriBuilder.setPort(port);//  w ww.j  a v  a 2 s  .com
    uriBuilder.setPath(pathOnServer);
    return uriBuilder.build();
}

From source file:org.jboss.quickstarts.wfk.travelagent.flight.FlightService.java

JSONObject findById(Long id) {

    try {//from  w  w w  . j av  a2 s .  c  o  m
        URI uri = new URIBuilder().setScheme("http").setHost("jbosscontactsangularjs-110336260.rhcloud.com")
                .setPath("/rest/flights/id/" + id.toString())
                //.setParameter("id", id.toString())
                .build();
        HttpGet req = new HttpGet(uri);
        CloseableHttpResponse response = httpClient.execute(req);
        String responseBody = EntityUtils.toString(response.getEntity());
        JSONObject responseJson = new JSONObject(responseBody);

        HttpClientUtils.closeQuietly(response);
        return responseJson;
    } catch (Exception e) {
        log.info(e.toString());
        return null;
    }

}

From source file:com.gogh.plugin.translator.YoudaoTranslator.java

@NotNull
@Override//  w  w  w  .  j  av  a2  s  .c o  m
public URI createUrl(String query) throws URISyntaxException {
    String[] apiKey = ApiConfig.getAPISet();
    URIBuilder builder = new URIBuilder();
    builder.setScheme("http").setHost("fanyi.youdao.com").setPath("/openapi.do")
            .addParameter("keyfrom", apiKey[0]).addParameter("key", apiKey[1]).addParameter("type", "data")
            .addParameter("version", "1.1").addParameter("doctype", "json").addParameter("q", query);
    return builder.build();
}

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

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

From source file:it.txt.ens.core.impl.test.BasicENSResourceTest.java

private void testURI(ENSResource resource) {
    URIBuilder uriBuilder = new URIBuilder();
    uriBuilder.addParameter(ENSResource.NAMESPACE_PARAMETER_NAME, resource.getNamespace());
    uriBuilder.addParameter(ENSResource.PATTERN_PARAMETER_NAME, resource.getPattern());
    uriBuilder.setHost(resource.getHost());
    uriBuilder.setPath(resource.getPath());
    uriBuilder.setScheme(ENSResource.URI_SCHEME);

    try {//from w  w w. j a  v  a2 s  . co m
        assertEquals("Unexpected resourceURI", uriBuilder.build(), resource.getURI());
    } catch (URISyntaxException e) {
        fail(e.getMessage());
        e.printStackTrace();
    }
}