Example usage for org.apache.http.message BasicNameValuePair BasicNameValuePair

List of usage examples for org.apache.http.message BasicNameValuePair BasicNameValuePair

Introduction

In this page you can find the example usage for org.apache.http.message BasicNameValuePair BasicNameValuePair.

Prototype

public BasicNameValuePair(String str, String str2) 

Source Link

Usage

From source file:com.ibm.watson.developer_cloud.professor_languo.it.endpoints.IT_AskAQuestion.java

/**
 * Tests if the ask a question endpoint can be accessed and checks if the return is in JSON
 * format./*ww w.  j ava  2 s. c  om*/
 * 
 * @throws Exception
 */
@Test
public void askAQuestionTest() throws Exception {
    String postUrl = System.getProperty("app.url");
    postUrl = postUrl + "/api/ask_question";

    CloseableHttpClient httpClient = HttpClientBuilder.create().build();
    HttpPost postRequest = new HttpPost(postUrl);
    postRequest.addHeader("accept", "application/json");
    postRequest.addHeader("Content-Type", "application/x-www-form-urlencoded");

    List<NameValuePair> formParams = new ArrayList<NameValuePair>();
    formParams.add(new BasicNameValuePair("questionText", "question text"));

    postRequest.setEntity(new UrlEncodedFormEntity(formParams));

    HttpResponse response = httpClient.execute(postRequest);

    String jsonString = EntityUtils.toString(response.getEntity());

    Assert.assertEquals("response was: " + jsonString, 200, response.getStatusLine().getStatusCode());

    try {
        new JSONArray(jsonString);
    } catch (JSONException e) {
        Assert.fail("Response is not in JSON format: " + jsonString + e.getMessage());
    }
}

From source file:org.fcrepo.integration.api.FedoraFieldSearchIT.java

@Test
public void testSearchSubmitPaging() throws Exception {
    final HttpPost method = new HttpPost(serverAddress + "search");
    final List<BasicNameValuePair> list = new ArrayList<BasicNameValuePair>();

    list.add(new BasicNameValuePair("terms", ""));
    list.add(new BasicNameValuePair("offset", "1"));
    list.add(new BasicNameValuePair("maxResults", "1"));
    final UrlEncodedFormEntity formEntity = new UrlEncodedFormEntity(list);
    method.setEntity(formEntity);/* ww  w  . j  a v  a 2 s  . c  o m*/
    assertEquals(200, getStatus(method));

}

From source file:com.nexmo.security.RequestSigning.java

/**
 * sign a set of request parameters, generating additional parameters to represent the timestamp and generated signature
 * uses the supplied pre-shared secret key to generate the signature
 *
 * @param params List of NameValuePair instances containing the query parameters for the request that is to be signed
 * @param secretKey the pre-shared secret key held by the client
 *
 * @return String the fully constructed url complete with signature
 *//*w  w w. j  av  a  2 s .c  o m*/
public static void constructSignatureForRequestParameters(List<NameValuePair> params, String secretKey) {
    // First, inject a 'timestamp=' parameter containing the current time in seconds since Jan 1st 1970
    params.add(new BasicNameValuePair(PARAM_TIMESTAMP, "" + System.currentTimeMillis() / 1000));

    Map<String, String> sortedParams = new TreeMap<>();
    for (NameValuePair param : params) {
        String name = param.getName();
        String value = param.getValue();
        if (name.equals(PARAM_SIGNATURE))
            continue;
        if (value == null)
            value = "";
        if (!value.trim().equals(""))
            sortedParams.put(name, value);
    }

    // Now, walk through the sorted list of parameters and construct a string
    StringBuilder sb = new StringBuilder();
    for (Map.Entry<String, String> param : sortedParams.entrySet()) {
        String name = param.getKey();
        String value = param.getValue();
        sb.append("&").append(clean(name)).append("=").append(clean(value));
    }

    // Now, append the secret key, and calculate an MD5 signature of the resultant string
    sb.append(secretKey);

    String str = sb.toString();

    String md5 = "no signature";
    try {
        md5 = MD5Util.calculateMd5(str);
    } catch (Exception e) {
        log.error("error...", e);
    }

    log.debug("SECURITY-KEY-GENERATION -- String [ " + str + " ] Signature [ " + md5 + " ] ");

    params.add(new BasicNameValuePair(PARAM_SIGNATURE, md5));
}

From source file:com.dimasdanz.kendalipintu.usermodel.UserSendData.java

@Override
protected Boolean doInBackground(String... args) {
    JSONObject json = new JSONObject();
    List<NameValuePair> params = new ArrayList<NameValuePair>();
    if (args[0] != "delete") {
        if (args[0].isEmpty()) {
            params.add(new BasicNameValuePair("name", args[1]));
            params.add(new BasicNameValuePair("password", args[2]));
            json = jsonParser.makeHttpRequest(ServerUtilities.getInsertUserUrl(activity), "POST", params);
        } else {// ww w. j  a  va  2  s.c o m
            params.add(new BasicNameValuePair("id", args[0]));
            params.add(new BasicNameValuePair("name", args[1]));
            params.add(new BasicNameValuePair("password", args[2]));
            json = jsonParser.makeHttpRequest(ServerUtilities.getUpdateUserUrl(activity), "POST", params);
        }
    } else {
        params.add(new BasicNameValuePair("id", args[1]));
        json = jsonParser.makeHttpRequest(ServerUtilities.getDeleteUserUrl(activity), "POST", params);
    }

    if (json != null) {
        return true;
    } else {
        return false;
    }
}

From source file:com.foobnix.api.vkontakte.VkApi.java

@Override
public void setToken(String token) {

    if (StringUtils.isEmpty(token)) {
        throw new IllegalArgumentException("Empty token");
    }//from  ww  w . j av  a 2  s.com

    requestHelper.setDefaultParam(new BasicNameValuePair("access_token", token));
}

From source file:org.labkey.freezerpro.export.ExportSampleUserFieldsCommand.java

public FreezerProCommandResonse execute(HttpClient client, PipelineJob job) {
    HttpPost post = new HttpPost(_url);

    try {// w  ww .  jav a  2s  .  c o  m
        List<NameValuePair> params = new ArrayList<NameValuePair>();

        params.add(new BasicNameValuePair("method", "sample_userfields"));
        params.add(new BasicNameValuePair("username", _username));
        params.add(new BasicNameValuePair("password", _password));
        params.add(new BasicNameValuePair("id", _sampleId));

        post.setEntity(new UrlEncodedFormEntity(params));

        ResponseHandler<String> handler = new BasicResponseHandler();

        HttpResponse response = client.execute(post);
        StatusLine status = response.getStatusLine();

        if (response.getStatusLine().getStatusCode() == HttpStatus.SC_OK)
            return new ExportUserFieldsResponse(_export, handler.handleResponse(response),
                    status.getStatusCode(), job);
        else
            return new ExportUserFieldsResponse(_export, status.getReasonPhrase(), status.getStatusCode(), job);
    } catch (Exception e) {
        _export.getJob().error(
                "An error was encountered trying to get user defined fields for sample : " + _sampleId, e);
        return null;
    }
}

From source file:org.labkey.freezerpro.export.GetFreezerSamplesCommand.java

public FreezerProCommandResonse execute(HttpClient client, PipelineJob job) {
    HttpPost post = new HttpPost(_url);

    try {//from   w w w.  j a  va  2s. com
        List<NameValuePair> params = new ArrayList<NameValuePair>();

        params.add(new BasicNameValuePair("method", "freezer_samples"));
        params.add(new BasicNameValuePair("username", _username));
        params.add(new BasicNameValuePair("password", _password));
        params.add(new BasicNameValuePair("id", _typeId));
        params.add(new BasicNameValuePair("limit", "10000"));

        post.setEntity(new UrlEncodedFormEntity(params));

        ResponseHandler<String> handler = new BasicResponseHandler();

        HttpResponse response = client.execute(post);
        StatusLine status = response.getStatusLine();

        if (response.getStatusLine().getStatusCode() == HttpStatus.SC_OK)
            return new GetFreezerSamplesResponse(_export, handler.handleResponse(response),
                    status.getStatusCode(), job);
        else
            return new GetFreezerSamplesResponse(_export, status.getReasonPhrase(), status.getStatusCode(),
                    job);
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}

From source file:org.apache.clerezza.commons.rdf.impl.sparql.SparqlClient.java

public Object queryResult(final String query) throws IOException {
    CloseableHttpClient httpclient = HttpClients.createDefault();
    HttpPost httpPost = new HttpPost(endpoint);
    List<NameValuePair> nvps = new ArrayList<NameValuePair>();
    nvps.add(new BasicNameValuePair("query", query));
    httpPost.setEntity(new UrlEncodedFormEntity(nvps));
    CloseableHttpResponse response2 = httpclient.execute(httpPost);
    HttpEntity entity2 = response2.getEntity();
    try {//from  w ww. j a va  2s. co m
        InputStream in = entity2.getContent();
        final String mediaType = entity2.getContentType().getValue();
        if ("application/sparql-results+xml".equals(mediaType)) {
            return SparqlResultParser.parse(in);
        } else {
            //assuming RDF response
            //FIXME clerezza-core-rdf to clerezza dependency
            Parser parser = Parser.getInstance();
            return parser.parse(in, mediaType);
        }
    } finally {
        EntityUtils.consume(entity2);
        response2.close();
    }

}

From source file:com.dimasdanz.kendalipintu.logmodel.LogLoadDetail.java

@Override
protected List<LogModel> doInBackground(String... args) {
    List<NameValuePair> params = new ArrayList<NameValuePair>();
    params.add(new BasicNameValuePair("date", args[0]));
    JSONObject json = jsonParser.makeHttpRequest(ServerUtilities.getLogDetailUrl(activity), "POST", params);
    if (json != null) {
        try {/* w ww.j  a v  a 2s  .  c  o m*/
            JSONArray name = json.getJSONArray("name");
            JSONArray time = json.getJSONArray("time");
            JSONArray info = json.getJSONArray("info");
            for (int i = 0; i < name.length(); i++) {
                detail.add(new LogModel(name.get(i).toString(),
                        time.get(i).toString() + " - " + info.get(i).toString()));
            }
        } catch (JSONException e1) {
            e1.printStackTrace();
        }
        return detail;
    } else {
        return null;
    }
}

From source file:org.codeqinvest.web.IntegrationTestHelper.java

private static void addNewProject(Project project) throws IOException {
    List<NameValuePair> parameters = new ArrayList<NameValuePair>();
    parameters.add(new BasicNameValuePair("name", project.getName()));
    parameters.add(new BasicNameValuePair("profile.id", "1"));
    parameters.add(new BasicNameValuePair("cronExpression", project.getCronExpression()));
    parameters.add(new BasicNameValuePair("sonarConnectionSettings.url",
            project.getSonarConnectionSettings().getUrl()));
    parameters.add(new BasicNameValuePair("sonarConnectionSettings.project",
            project.getSonarConnectionSettings().getProject()));
    parameters.add(new BasicNameValuePair("scmSettings.type", "0"));
    parameters.add(new BasicNameValuePair("scmSettings.url", project.getScmSettings().getUrl()));
    parameters.add(new BasicNameValuePair("codeChangeSettings.method", "1"));
    parameters.add(new BasicNameValuePair("codeChangeSettings.days", "30"));
    doPostRequest(ADD_PROJECT_SITE, parameters);
}