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.loyalty.service.RemoteService.java

public CardDTO cardDetails(String cardNumber) throws IOException, KioskException {
    try (CloseableHttpResponse result = getHttpClient().post("/public-api/card",
            ContentType.APPLICATION_FORM_URLENCODED, new BasicNameValuePair("number", cardNumber))) {
        if (result.getStatusLine().getStatusCode() != HttpStatus.SC_OK) {
            throw new KioskException(result.getStatusLine().getStatusCode(),
                    "Can't find card by card number: " + cardNumber);
        }/*from  w  w w.j  a  va  2  s.c  om*/
        final CardDTO cardDTO = getMapper().readValue(EntityUtils.toString(result.getEntity()), CardDTO.class);
        return cardDTO;
    }
}

From source file:org.piraso.client.net.HttpPirasoStopHandler.java

@Override
public void execute() throws IOException {
    Validate.notNull(uri, "uri should not be null.");

    HttpPost post = new HttpPost(uri.getPath());

    List<NameValuePair> params = new ArrayList<NameValuePair>();
    params.add(new BasicNameValuePair(SERVICE_PARAMETER, SERVICE_STOP_PARAMETER_VALUE));
    params.add(new BasicNameValuePair(ACTIVITY_PARAMETER, id));

    post.setEntity(new UrlEncodedFormEntity(params, ENCODING_UTF_8));

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

    if (status.getStatusCode() != HttpStatus.SC_OK) {
        throw new HttpPirasoException(status.toString());
    }//from  w ww. j a  v a 2  s .c o  m
}

From source file:com.lexicalintelligence.admin.remove.RemoveRequest.java

public RemoveResponse execute() {
    List<BasicNameValuePair> params = Collections
            .singletonList(new BasicNameValuePair(getName(), StringUtils.join(items, ",")));
    RemoveResponse removeResponse;/*from  ww w . j a  v  a  2s.  c  o m*/
    Reader reader = null;
    try {
        HttpResponse response = client.getHttpClient().execute(new HttpGet(client.getUrl() + PATH + getPath()
                + "?" + URLEncodedUtils.format(params, StandardCharsets.UTF_8)));
        reader = new InputStreamReader(response.getEntity().getContent(), StandardCharsets.UTF_8);
        removeResponse = new RemoveResponse(Boolean.valueOf(IOUtils.toString(reader)));
    } catch (Exception e) {
        removeResponse = new RemoveResponse(false);
        log.error(e);
    } finally {
        try {
            reader.close();
        } catch (Exception e) {
            log.error(e);
        }
    }
    return removeResponse;
}

From source file:es.upm.oeg.examples.watson.service.LanguageIdentificationService.java

public String getLang(String text) throws IOException, URISyntaxException {

    List<NameValuePair> qparams = new ArrayList<NameValuePair>();
    qparams.add(new BasicNameValuePair("txt", text));
    qparams.add(new BasicNameValuePair("sid", "lid-generic"));
    qparams.add(new BasicNameValuePair("rt", "json"));

    Executor executor = Executor.newInstance().auth(username, password);

    URI serviceURI = new URI(baseURL).normalize();
    String auth = username + ":" + password;
    String resp = executor.execute(Request.Post(serviceURI)
            .addHeader("Authorization", "Basic " + Base64.encodeBase64String(auth.getBytes()))
            .bodyString(URLEncodedUtils.format(qparams, "utf-8"), ContentType.APPLICATION_FORM_URLENCODED))
            .returnContent().asString();

    JSONObject lang = JSONObject.parse(resp);

    return lang.get("lang").toString();

}

From source file:org.dataconservancy.ui.it.support.CollectionSplashPageRequest.java

public HttpPost asHttpPost() {

    HttpPost post = null;//from  www. jav a 2 s  .  c  om
    try {
        post = new HttpPost(urlConfig.getCollectionSplashUrl().toURI());
    } catch (URISyntaxException e) {
        throw new RuntimeException(e.getMessage(), e);
    }

    List<NameValuePair> params = new ArrayList<NameValuePair>();

    if (null != collectionId) {
        params.add(new BasicNameValuePair("collectionId", collectionId));
    }
    params.add(new BasicNameValuePair(STRIPES_EVENT, "View Collections Details"));

    HttpEntity entity = null;
    try {
        entity = new UrlEncodedFormEntity(params, "UTF-8");
    } catch (UnsupportedEncodingException e) {
        throw new RuntimeException(e.getMessage(), e);
    }

    post.setEntity(entity);

    return post;
}

From source file:com.mobile.godot.core.controller.CoreController.java

public synchronized void pop(String username) {

    String servlet = "PopMessage";
    List<BasicNameValuePair> params = new ArrayList<BasicNameValuePair>();
    params.add(new BasicNameValuePair("username", username));
    SparseIntArray mMessageMap = new SparseIntArray();
    mMessageMap.append(HttpURLConnection.HTTP_OK, GodotMessage.Core.MESSAGE_READ);

    GodotAction action = new GodotAction(servlet, params, mMessageMap, mHandler);
    Thread tAction = new Thread(action);
    tAction.start();/*  w  w  w.j  a  v  a  2s . com*/

}

From source file:org.lightcouch.Params.java

public Params addParam(String name, String value) {
    params.add(new BasicNameValuePair(name, value));
    return this;
}

From source file:com.testmax.uri.HttpRestWebservice.java

public String handleHTTPPostUnit() throws Exception {
    String resp = null;// w  w w  .j  a va  2s  .  c  o m

    String replacedParam = "";
    System.out.println(this.url);
    HttpPost httpost = new HttpPost(this.url);
    //System.out.println(this.url);
    List<NameValuePair> nvps = new ArrayList<NameValuePair>();
    URLConfig urlConf = this.page.getURLConfig();

    Set<String> s = urlConf.getUrlParamset();
    for (String param : s) {
        replacedParam = urlConf.getUrlParamValue(param);
        System.out.println(urlConf.getUrlParamValue(param));
        nvps.add(new BasicNameValuePair(param, urlConf.getUrlParamValue(param)));
    }

    httpost.setEntity(new UrlEncodedFormEntity(nvps, HTTP.UTF_8));
    //set the time for this HTTP resuest
    this.startRecording();
    long starttime = this.getCurrentTime();
    HttpResponse response = this.httpsclient.execute(httpost);
    HttpEntity entity = response.getEntity();
    // Measure the time passed between response
    long elaspedTime = this.getElaspedTime(starttime);
    this.stopRecording(response, elaspedTime);
    resp = this.getResponseBodyAsString(entity);
    System.out.println(resp);
    System.out.println("ElaspedTime: " + elaspedTime);
    WmLog.getCoreLogger().info("Response XML: " + resp);
    WmLog.getCoreLogger().info("ElaspedTime: " + elaspedTime);
    this.printRecording();
    this.printLog();
    if (this.getResponseStatus() == 200 && validateAssert(urlConf, resp)) {
        this.addThreadActionMonitor(this.action, true, elaspedTime);
    } else {
        this.addThreadActionMonitor(this.action, false, elaspedTime);
        WmLog.getCoreLogger().info("Input XML: " + replacedParam);
        WmLog.getCoreLogger().info("Response XML: " + resp);
    }
    this.closeEntity(entity);
    return (resp);

}

From source file:com.browsertophone.ShareLink.java

public void send(final String link) {
    new Thread(new Runnable() {
        public void run() {
            sendToast(mContext.getString(R.string.sending_link_toast));
            try {
                List<NameValuePair> params = new ArrayList<NameValuePair>();
                params.add(new BasicNameValuePair("url", URLEncoder.encode(link)));
                params.add(new BasicNameValuePair("deviceType", "chrome"));
                SharedPreferences settings = Prefs.get(mContext);
                final String accountName = settings.getString("accountName", null);

                AppEngineClient client = new AppEngineClient(mContext, accountName);
                HttpResponse res = client.makeRequest(SEND_PATH, params);
                if (res.getStatusLine().getStatusCode() == 200) {
                    sendToast(mContext.getString(R.string.link_sent_toast));
                } else {
                    sendToast(mContext.getString(R.string.link_not_sent_toast));
                }/*from ww w .  j  a v  a 2  s  .  c o m*/
            } catch (AppEngineClient.PendingAuthException e) {
                sendToast(mContext.getString(R.string.link_not_sent_auth_toast));
            } catch (Exception e) {
                sendToast(mContext.getString(R.string.link_not_sent_toast));
            }
        }
    }).start();
}

From source file:eu.over9000.cathode.data.parameters.OffsetPagination.java

@Override
public List<NameValuePair> buildParamPairs() {
    return Arrays.asList(new BasicNameValuePair("limit", String.valueOf(limit)),
            new BasicNameValuePair("offset", String.valueOf(offset)));
}