Example usage for org.apache.http.client.utils URIBuilder build

List of usage examples for org.apache.http.client.utils URIBuilder build

Introduction

In this page you can find the example usage for org.apache.http.client.utils URIBuilder build.

Prototype

public URI build() throws URISyntaxException 

Source Link

Document

Builds a URI instance.

Usage

From source file:com.opensearchserver.client.v1.WebCrawlerApi1.java

/**
 * Crawl an URL/* w w w . j  a va  2  s  .  c o  m*/
 * 
 * @param indexName
 *            The name of the index
 * @param url
 *            The URL to crawl
 * @param msTimeOut
 *            The timeout in milliseconds
 * @return the status of the crawl
 * @throws IOException
 *             if any IO error occurs
 * @throws URISyntaxException
 *             if the URI is not valid
 */
public CommonResult crawl(String indexName, String url, Integer msTimeOut)
        throws IOException, URISyntaxException {
    URIBuilder uriBuilder = client.getBaseUrl("index/", indexName, "/crawler/web/crawl")
            .addParameter("url", url).addParameter("returnData", "false");
    Request request = Request.Get(uriBuilder.build());
    return client.execute(request, null, msTimeOut, CommonResult.class, 200);
}

From source file:com.epam.ngb.cli.manager.command.handler.http.DatasetDeletionHandler.java

@Override
protected void runDeletion(Long id) {
    String url = String.format(getRequestUrl(), id);
    try {/*from  ww w.  jav  a2s . com*/
        URIBuilder requestBuilder = new URIBuilder(String.format(url, projectId));
        requestBuilder.setParameter("force", String.valueOf(force));
        HttpRequestBase request = getRequest(requestBuilder.build().toString());

        setDefaultHeader(request);
        if (isSecure()) {
            addAuthorizationToRequest(request);
        }

        String result = RequestManager.executeRequest(request);
        ResponseResult response = getMapper().readValue(result,
                getMapper().getTypeFactory().constructType(ResponseResult.class));
        LOGGER.info(response.getStatus() + "\t" + response.getMessage());
    } catch (IOException | URISyntaxException e) {
        throw new ApplicationException(e.getMessage(), e);
    }
}

From source file:org.sharetask.controller.WorkspaceControllerIT.java

@Test
public void testFindWorkspaceByOwner() throws IOException, URISyntaxException {
    final URIBuilder builder = new URIBuilder();
    builder.setScheme(SCHEMA).setHost(HOST).setPath(BASE_PATH + WORKSPACE_PATH).setParameter("type", "OWNER");
    final URI uri = builder.build();
    //given/*from   ww w  .  j  a  va 2 s .  c om*/
    final HttpGet httpGet = new HttpGet(uri);

    //when
    final HttpResponse response = getClient().execute(httpGet);

    //then
    Assert.assertEquals(HttpStatus.OK.value(), response.getStatusLine().getStatusCode());
    final String responseData = EntityUtils.toString(response.getEntity());
    Assert.assertTrue(responseData.contains("\"title\":\"ABX Agency\""));
}

From source file:de.ii.ldproxy.service.SparqlAdapter.java

private URI getRequestUri(String value, QUERY type) throws URISyntaxException {
    URIBuilder uri = new URIBuilder(SPARQL_ENDPOINT);
    uri.addParameter("format", "application/json");
    uri.addParameter("query", getQuery(value, type));

    return uri.build();
}

From source file:com.redhat.refarch.microservices.trigger.service.TriggerService.java

public JSONObject doPurchase() throws Exception {

    HttpClient client = new DefaultHttpClient();

    //get a customer
    JSONObject jsonObject = new JSONObject();
    jsonObject.put("username", "bobdole");
    jsonObject.put("password", "password");
    URIBuilder uriBuilder = getUriBuilder("customers", "authenticate");
    HttpPost post = new HttpPost(uriBuilder.build());
    post.setEntity(new StringEntity(jsonObject.toString(), ContentType.APPLICATION_JSON));
    logInfo("Executing " + post);
    HttpResponse response = client.execute(post);
    String responseString = EntityUtils.toString(response.getEntity());
    logInfo("Got login response " + responseString);
    JSONObject jsonResponse = new JSONObject(responseString);
    Customer customer = new Customer();
    customer.setId(jsonResponse.getLong("id"));
    customer.setAddress(jsonResponse.getString("address"));
    customer.setName(jsonResponse.getString("name"));

    //initialize an order
    jsonObject = new JSONObject().put("status", "Initial");
    uriBuilder = getUriBuilder("customers", customer.getId(), "orders");

    post = new HttpPost(uriBuilder.build());
    post.setEntity(new StringEntity(jsonObject.toString(), ContentType.APPLICATION_JSON));
    logInfo("Executing " + post);
    response = client.execute(post);//from   ww w. j a v a  2  s  .c o  m

    responseString = EntityUtils.toString(response.getEntity());
    logInfo("Got response " + responseString);
    jsonResponse = new JSONObject(responseString);
    Long orderId = jsonResponse.getLong("id");

    // get an item
    uriBuilder = getUriBuilder("products");
    uriBuilder.addParameter("featured", "");

    HttpGet get = new HttpGet(uriBuilder.build());
    logInfo("Executing " + get);
    response = client.execute(get);
    responseString = EntityUtils.toString(response.getEntity());
    logInfo("Got response " + responseString);
    JSONArray jsonArray = new JSONArray(responseString);
    List<Map<String, Object>> products = Utils.getList(jsonArray);
    logInfo("array info " + Arrays.toString(products.toArray()));
    Map<String, Object> item = products.get(0);

    // put item on order
    jsonObject = new JSONObject().put("sku", item.get("sku")).put("quantity", 1);
    uriBuilder = getUriBuilder("customers", customer.getId(), "orders", orderId, "orderItems");
    post = new HttpPost(uriBuilder.build());
    post.setEntity(new StringEntity(jsonObject.toString(), ContentType.APPLICATION_JSON));
    logInfo("Executing " + post);
    response = client.execute(post);
    responseString = EntityUtils.toString(response.getEntity());
    logInfo("Got response " + responseString);

    // billing/process
    jsonObject = new JSONObject().put("amount", item.get("price")).put("creditCardNumber", 1234567890123456L)
            .put("expMonth", 1).put("expYear", 2019).put("verificationCode", 123)
            .put("billingAddress", customer.getAddress()).put("customerName", customer.getName())
            .put("customerId", customer.getId()).put("orderNumber", orderId);

    logInfo(jsonObject.toString());

    uriBuilder = getUriBuilder("billing", "process");
    post = new HttpPost(uriBuilder.build());
    post.setEntity(new StringEntity(jsonObject.toString(), ContentType.APPLICATION_JSON));

    logInfo("Executing " + post);
    response = new DefaultHttpClient().execute(post);
    responseString = EntityUtils.toString(response.getEntity());

    logInfo("Transaction processed as: " + responseString);
    return new JSONObject(responseString);
}

From source file:org.apache.sling.tooling.lc.jira.IssueFinder.java

public List<Issue> findIssues(List<String> issueKeys) throws IOException {

    HttpClient client = new DefaultHttpClient();

    HttpGet get;//from   w ww  .j a va2s. co  m
    try {
        URIBuilder builder = new URIBuilder("https://issues.apache.org/jira/rest/api/2/search")
                .addParameter("jql", "key in (" + String.join(",", issueKeys) + ")")
                .addParameter("fields", "key,summary");

        get = new HttpGet(builder.build());
    } catch (URISyntaxException e) {
        // never happens
        throw new RuntimeException(e);
    }

    HttpResponse response = client.execute(get);
    try {
        if (response.getStatusLine().getStatusCode() != 200) {
            throw new IOException("Search call returned status " + response.getStatusLine().getStatusCode());
        }

        try (Reader reader = new InputStreamReader(response.getEntity().getContent(), "UTF-8")) {
            Response apiResponse = new Gson().fromJson(reader, Response.class);
            List<Issue> issues = apiResponse.getIssues();
            Collections.sort(issues);
            return issues;

        }
    } finally {
        HttpClientUtils.closeQuietly(client);
    }

}

From source file:org.talend.dataprep.api.service.command.dataset.CopyDataSet.java

/**
 * Private constructor./*from ww w  .ja  va 2  s  . c  o  m*/
 *
 * @param id the dataset id to copy.
 * @param name the copy name.
 */
private CopyDataSet(String id, String name) {
    super(GenericCommand.DATASET_GROUP);
    execute(() -> {
        try {
            URIBuilder uriBuilder = new URIBuilder(datasetServiceUrl + "/datasets/" + id + "/copy");
            if (StringUtils.isNotBlank(name)) {
                uriBuilder.addParameter("copyName", name);
            }
            return new HttpPost(uriBuilder.build());
        } catch (URISyntaxException e) {
            throw new TDPException(UNEXPECTED_EXCEPTION, e);
        }
    });
    on(HttpStatus.OK).then(asString());
}

From source file:ca.nrc.cadc.search.PackageServlet.java

/**
 * Handle a GET request with the given Registry client to perform the lookup.
 *
 * @param request        The HTTP Request.
 * @param response       The HTTP Response.
 * @param registryClient The RegistryClient to do lookups.
 * @throws IOException        Any request access problems.
 *///  www. jav a 2  s  .  c o  m
void get(final HttpServletRequest request, final HttpServletResponse response,
        final RegistryClient registryClient) throws IOException {

    // TODO: prior to version 2.5.0, this servlet supported multiple IDs.
    // TODO: Consider how this might be supported in future.
    final String[] idValues = request.getParameterValues("ID");
    if (idValues.length > 1) {
        throw new UnsupportedOperationException("Multiple IDs in package lookup.");
    } else {
        final String IDValue = idValues[0];
        if (IDValue.length() > 0) {
            try {
                final PublisherID publisherID = new PublisherID(URI.create(IDValue));

                final URL serviceURL = registryClient.getServiceURL(publisherID.getResourceID(),
                        Standards.PKG_10, AuthMethod.COOKIE);

                final URIBuilder builder = new URIBuilder(serviceURL.toURI());
                builder.addParameter("ID", IDValue);

                response.sendRedirect(builder.build().toURL().toExternalForm());
            } catch (URISyntaxException e) {
                throw new IOException(String.format("Service URL from %s is invalid.", IDValue), e);
            }
        } else {
            throw new UnsupportedOperationException("Invalid ID in package lookup.");
        }
    }
}

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 .  com*/
    URI fullUri = b.build();
    HttpGet getMethod = new HttpGet(fullUri);
    getMethod = (HttpGet) addHeadersToMethod(getMethod);

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

From source file:org.apache.streams.riak.http.RiakHttpClient.java

public void start() throws Exception {
    Objects.nonNull(config);/*w  w  w .  j a v  a  2s  . com*/
    assert (config.getScheme().startsWith("http"));
    URIBuilder uriBuilder = new URIBuilder();
    uriBuilder.setScheme(config.getScheme());
    uriBuilder.setHost(config.getHosts().get(0));
    uriBuilder.setPort(config.getPort().intValue());
    baseURI = uriBuilder.build();
    client = HttpClients.createDefault();
}