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

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

Introduction

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

Prototype

public URIBuilder addParameter(final String param, final String value) 

Source Link

Document

Adds parameter to URI query.

Usage

From source file:org.talend.dataprep.api.service.command.preparation.PreparationCopyStepsFrom.java

private HttpRequestBase onExecute(final String to, final String from) {
    try {// w  ww . j  a  v a  2s . c  o  m
        URIBuilder builder = new URIBuilder(preparationServiceUrl + "/preparations/" + to + "/steps/copy");
        builder.addParameter("from", from);
        return new HttpPut(builder.build());
    } catch (URISyntaxException e) {
        throw new TDPException(UNEXPECTED_EXCEPTION, e);
    }
}

From source file:org.apache.hadoop.gateway.shell.AbstractRequest.java

protected void addQueryParam(URIBuilder uri, String name, Object value) {
    if (value != null) {
        uri.addParameter(name, value.toString());
    }
}

From source file:org.talend.dataprep.api.service.command.preparation.PreparationSearchByName.java

/**
 * Private constructor used to construct the generic command used to list of preparations matching name.
 *
 * @param name the specified name//from   w  w  w. j  a va  2 s . c  o m
 * @param exactMatch the specified boolean
 */
private PreparationSearchByName(String name, boolean exactMatch) {
    super(GenericCommand.PREPARATION_GROUP);
    execute(() -> {
        try {
            URIBuilder uriBuilder = new URIBuilder(preparationServiceUrl + "/preparations/search");
            uriBuilder.addParameter("name", name);
            uriBuilder.addParameter("exactMatch", String.valueOf(exactMatch));
            return new HttpGet(uriBuilder.build());
        } catch (URISyntaxException e) {
            throw new TDPException(CommonErrorCodes.UNEXPECTED_EXCEPTION, e);
        }
    });
    onError(e -> new TDPException(APIErrorCodes.UNABLE_TO_RETRIEVE_PREPARATION_LIST, e));
    on(HttpStatus.NO_CONTENT, HttpStatus.ACCEPTED).then(emptyStream());
    on(HttpStatus.OK).then(pipeStream());
}

From source file:com.google.appengine.tck.byteman.DiffEntityGroupTest.java

private void doTest(URI root, boolean xg) throws Exception {
    try (CloseableHttpClient client = HttpClients.createMinimal()) {

        List<Thread> threads = new ArrayList<>();

        Holder h1 = new Holder();
        URIBuilder builder = new URIBuilder(root + "/ctx");
        builder.addParameter("eg", "EG1");
        builder.addParameter("c", "1");
        builder.addParameter("p", "1");
        builder.addParameter("xg", String.valueOf(xg));
        threads.add(execute(client, new HttpPost(builder.build()), h1));

        Holder h2 = new Holder();
        builder = new URIBuilder(root + "/ctx");
        builder.addParameter("eg", "EG2");
        builder.addParameter("c", "2");
        builder.addParameter("p", "2");
        builder.addParameter("xg", String.valueOf(xg));
        threads.add(execute(client, new HttpPost(builder.build()), h2));

        join(threads);//  w  ww. j a v a2s . co m

        System.out.println("h1 = " + h1);
        System.out.println("h2 = " + h2);

        Assert.assertTrue("Expected ok: " + h1, h1.out.startsWith("OK1"));
        Assert.assertTrue("Expected ok: " + h2, h2.out.startsWith("OK2"));
    }
}

From source file:org.aesop.serializer.batch.reader.UserInfoServiceReader.java

/**
 * Returns a number of {@link UserInfo} instances looked up from a service end-point.
 * Note : The end-point and parameters used here are very specific to this sample. Also the code is mostly for testing and production 
 * ready (no Http connection pools etc.) 
 * @see org.trpr.platform.batch.spi.spring.reader.BatchItemStreamReader#batchRead(org.springframework.batch.item.ExecutionContext)
 *//*from   ww w .  ja  va 2 s.c om*/
public UserInfo[] batchRead(ExecutionContext context)
        throws Exception, UnexpectedInputException, ParseException {
    objectMapper.configure(DeserializationConfig.Feature.FAIL_ON_UNKNOWN_PROPERTIES, false);
    UserInfo[] results = new UserInfo[PHONE_NUMBERS.length];
    for (int i = 0; i < PHONE_NUMBERS.length; i++) {
        DefaultHttpClient httpclient = new DefaultHttpClient();
        HttpGet executionGet = new HttpGet(SERVICE_URL);
        URIBuilder uriBuilder = new URIBuilder(executionGet.getURI());
        uriBuilder.addParameter("primary_phone", PHONE_NUMBERS[i]);
        uriBuilder.addParameter("require", "{\"preferences\":true,\"addresses\":true}");
        ((HttpRequestBase) executionGet).setURI(uriBuilder.build());
        HttpResponse httpResponse = httpclient.execute(executionGet);
        String response = new String(EntityUtils.toByteArray(httpResponse.getEntity()));
        SearchResult searchResult = objectMapper.readValue(response, SearchResult.class);
        results[i] = searchResult.results[0]; // we take only the first result
    }
    return results;
}

From source file:org.talend.dataprep.api.service.command.preparation.PreparationListByFolder.java

/**
 * Private constructor used to construct the generic command used to list of preparations matching name.
 *
 * @param folderId the folder id where to look for preparations.
 * @param sort how to sort the preparations.
 * @param order the order to apply to the sort.
 *///from w ww  .j a  v a2s.  c om
private PreparationListByFolder(final String folderId, final Sort sort, final Order order) {
    super(GenericCommand.PREPARATION_GROUP);
    execute(() -> {
        try {
            final URIBuilder uriBuilder = new URIBuilder(preparationServiceUrl + "/preparations/search");
            uriBuilder.addParameter("folderId", folderId);
            uriBuilder.addParameter("sort", sort.camelName());
            uriBuilder.addParameter("order", order.camelName());
            return new HttpGet(uriBuilder.build());
        } catch (URISyntaxException e) {
            throw new TDPException(CommonErrorCodes.UNEXPECTED_EXCEPTION, e);
        }
    });
    onError(e -> new TDPException(UNABLE_TO_RETRIEVE_PREPARATION_LIST, e));
    on(NO_CONTENT, ACCEPTED).then(emptyStream());
    on(OK).then(pipeStream());
}

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

private HttpRequestBase onExecute(String dataSetId, boolean metadata, String sheetName) {
    try {/*w ww .j  a va 2  s .c  o m*/

        URIBuilder uriBuilder = new URIBuilder(datasetServiceUrl + "/datasets/" + dataSetId + "/preview/");
        uriBuilder.addParameter("metadata", Boolean.toString(metadata));
        if (StringUtils.isNotEmpty(sheetName)) {
            // yup this sheet name can contains weird characters space, great french accents or even chinese
            // characters
            uriBuilder.addParameter("sheetName", sheetName);
        }
        return new HttpGet(uriBuilder.build());
    } catch (URISyntaxException e) {
        throw new TDPException(CommonErrorCodes.UNEXPECTED_EXCEPTION, e);
    }
}

From source file:com.google.appengine.tck.byteman.SameEntityGroupTest.java

private void doTest(URI root, boolean xg) throws Exception {
    try (CloseableHttpClient client = HttpClients.createMinimal()) {

        List<Thread> threads = new ArrayList<>();

        Holder h1 = new Holder();
        URIBuilder builder = new URIBuilder(root + "/ctx");
        builder.addParameter("eg", "EG1");
        builder.addParameter("c", "1");
        builder.addParameter("xg", String.valueOf(xg));
        threads.add(execute(client, new HttpPost(builder.build()), h1));

        Holder h2 = new Holder();
        builder = new URIBuilder(root + "/ctx");
        builder.addParameter("eg", "EG1");
        builder.addParameter("c", "2");
        builder.addParameter("xg", String.valueOf(xg));
        threads.add(execute(client, new HttpPost(builder.build()), h2));

        join(threads);//from   ww w  . j a v  a  2  s.  c  om

        System.out.println("h1 = " + h1);
        System.out.println("h2 = " + h2);

        if (h1.out.startsWith("ERROR1")) {
            Assert.assertTrue("Expected ok: " + h2, h2.out.startsWith("OK2"));
            Assert.assertTrue("Expected CME: " + h2,
                    h1.out.contains(ConcurrentModificationException.class.getName()));
        } else {
            Assert.assertTrue("Expected ok: " + h1, h1.out.startsWith("OK1"));
            Assert.assertTrue("Expected error: " + h2, h2.out.startsWith("ERROR2"));
            Assert.assertTrue("Expected CME: " + h2,
                    h2.out.contains(ConcurrentModificationException.class.getName()));
        }
    }
}

From source file:com.stormpath.sdk.servlet.mvc.provider.DefaultAccountStoreModel.java

public DefaultAccountStoreModel(Directory directory, ProviderModel provider, String authorizeBaseUri) {
    this.directory = directory;
    this.providerModel = provider;
    if (providerModel instanceof OAuthProviderModel && authorizeBaseUri != null) {
        try {//w  ww  .jav a2s .c o  m
            URIBuilder builder = new URIBuilder(authorizeBaseUri);
            builder.setPath("/authorize");
            builder.addParameter("response_type", "stormpath_token");
            builder.addParameter("account_store_href", directory.getHref());
            authorizeUri = builder.build().toString();
        } catch (URISyntaxException e) {
            throw new IllegalArgumentException("authorizeBaseUri must be value URI", e);
        }
    } else {
        authorizeUri = null;
    }
}

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