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:net.fizzl.redditengine.impl.SearchApi.java

public LinkListing search(String subreddit, String query, boolean restrictToSubreddit, String before,
        String after, int count, int limit, String sort, String syntax, String timeScope, String show)
        throws RedditEngineException {
    //GET [/r/subreddit]/search[ .json | .xml ]
    // TODO make int types optional as well?
    StringBuilder sb = new StringBuilder();
    if (subreddit != null) {
        sb.append("/r/");
        sb.append(subreddit);//w  ww  . j a  v a2 s.c  om
    }
    sb.append("/search");
    String url = UrlUtils.getGetUrl(sb.toString());

    List<NameValuePair> params = new ArrayList<NameValuePair>();
    params.add(new BasicNameValuePair("q", query));
    params.add(new BasicNameValuePair("restrict_sr", String.valueOf(restrictToSubreddit)));
    if (after != null) {
        params.add(new BasicNameValuePair("after", after));
    }
    if (before != null) {
        params.add(new BasicNameValuePair("before", before));
    }
    params.add(new BasicNameValuePair("count", String.valueOf(count)));
    params.add(new BasicNameValuePair("limit", String.valueOf(limit)));
    if (sort != null) {
        params.add(new BasicNameValuePair("sort", sort));
    }
    if (syntax != null) {
        params.add(new BasicNameValuePair("syntax", syntax));
    }
    if (timeScope != null) {
        params.add(new BasicNameValuePair("t", timeScope));
    }
    if (show != null) {
        params.add(new BasicNameValuePair("show", show));
    }

    LinkListing retval = new LinkListing();
    try {
        SimpleHttpClient client = SimpleHttpClient.getInstance();
        InputStream is = client.get(url, params);
        retval = LinkListing.fromInputStream(is);
        is.close();
    } catch (ClientProtocolException e) {
        throw new RedditEngineException(e);
    } catch (IOException e) {
        throw new RedditEngineException(e);
    } catch (UnexpectedHttpResponseException e) {
        throw new RedditEngineException(e);
    }

    return retval;
}

From source file:uk.codingbadgers.SurvivalPlus.error.ReportExceptionRunnable.java

public boolean run() {
    try {/*from  w  ww  .  j  a  v  a  2  s . c  o m*/
        List<NameValuePair> data = new ArrayList<NameValuePair>();
        data.add(new BasicNameValuePair("password",
                DigestUtils.md5Hex(SurvivalPlus.getConfigurationManager().getCrashPassword())));
        data.add(new BasicNameValuePair("project", "bFundamentals"));
        data.add(new BasicNameValuePair("cause", getException(throwable)));
        data.add(new BasicNameValuePair("message", getMessage(throwable)));
        data.add(new BasicNameValuePair("st", buildStackTrace(throwable)));
        HttpPost post = new HttpPost("http://server.mcbadgercraft.com/crash/report.php");
        post.setEntity(new UrlEncodedFormEntity(data));

        DefaultHttpClient client = new DefaultHttpClient();
        HttpResponse responce = client.execute(post);
        String result = EntityUtils.toString(responce.getEntity());

        if (SurvivalPlus.getConfigurationManager().isDebugEnabled())
            System.out.println(result);

        JSONObject object = (JSONObject) new JSONParser().parse(result);
        boolean success = (Boolean) object.get("success");
        if (!success)
            System.err.println(object.get("error"));
        return success;
    } catch (ClientProtocolException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    } catch (ParseException e) {
        e.printStackTrace();
    }

    return false;
}

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

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

    try {/* w w w  . j av  a2s . com*/
        List<NameValuePair> params = new ArrayList<NameValuePair>();

        params.add(new BasicNameValuePair("method", "freezers"));
        params.add(new BasicNameValuePair("username", _username));
        params.add(new BasicNameValuePair("password", _password));

        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 GetFreezersResponse(_export, handler.handleResponse(response), status.getStatusCode(),
                    job);
        else
            return new GetFreezersResponse(_export, status.getReasonPhrase(), status.getStatusCode(), job);
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}

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

@Override
public List<NameValuePair> buildParamPairs() {
    if (emoteSets.isEmpty()) {
        return Collections.emptyList();
    }/*from w w  w  . j  a  v  a  2 s. com*/
    return Collections.singletonList(new BasicNameValuePair("emotesets", String.join(",", emoteSets)));
}

From source file:uk.submergedcode.SubmergedCore.error.ReportExceptionRunnable.java

public boolean run() {
    try {/*from  w  w  w  . j a v a  2 s. c  om*/
        List<NameValuePair> data = new ArrayList<NameValuePair>();
        data.add(new BasicNameValuePair("password",
                DigestUtils.md5Hex(SubmergedCore.getConfigurationManager().getCrashPassword())));
        data.add(new BasicNameValuePair("project", "SubmergedCore"));
        data.add(new BasicNameValuePair("cause", getException(throwable)));
        data.add(new BasicNameValuePair("message", getMessage(throwable)));
        data.add(new BasicNameValuePair("st", buildStackTrace(throwable)));
        HttpPost post = new HttpPost("http://server.mcbadgercraft.com/crash/report.php");
        post.setEntity(new UrlEncodedFormEntity(data));

        DefaultHttpClient client = new DefaultHttpClient();
        HttpResponse responce = client.execute(post);
        String result = EntityUtils.toString(responce.getEntity());

        if (SubmergedCore.getConfigurationManager().isDebugEnabled())
            System.out.println(result);

        JSONObject object = (JSONObject) new JSONParser().parse(result);
        boolean success = (Boolean) object.get("success");
        if (!success)
            System.err.println(object.get("error"));
        return success;
    } catch (ClientProtocolException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    } catch (ParseException e) {
        e.printStackTrace();
    }

    return false;
}

From source file:lh.api.showcase.server.api.lh.offers.OffersServiceImpl.java

@Override
public String getSeatMaps(String flightNumber, AirportCode origin, AirportCode destination,
        String departureDate, CabinClass cabinClass) throws HttpErrorResponseException {

    // e.g., https://api.lufthansa.com/v1/offers/seatmaps/LH741/KIX/FRA/2015-06-25/C
    OffersRequestFactoryImpl reqFact = new OffersRequestFactoryImpl();
    try {//  ww  w. j a  va  2  s  .  c  om
        URI uri = reqFact.getRequestUri((NameValuePair) new BasicNameValuePair("seatmaps", ""),
                (List<NameValuePair>) Arrays.asList((NameValuePair) new BasicNameValuePair(flightNumber, ""),
                        (NameValuePair) new BasicNameValuePair(origin.toString(), ""),
                        (NameValuePair) new BasicNameValuePair(destination.toString(), ""),
                        (NameValuePair) new BasicNameValuePair(departureDate, ""),
                        (NameValuePair) new BasicNameValuePair(cabinClass.toString(), "")),
                null);

        return HttpQueryUtils.executeQuery(uri);

    } catch (URISyntaxException e) {
        logger.log(Level.SEVERE, e.getMessage());
    }
    return null;
}

From source file:org.ambraproject.wombat.util.UrlParamBuilder.java

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

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

@Override
public RemoveResponse execute() {
    RemoveResponse removeResponse;/*ww w  .  j a  va 2  s. co  m*/

    List<BasicNameValuePair> params = new ArrayList<>();
    params.add(new BasicNameValuePair("name", entry.getName()));
    params.add(new BasicNameValuePair("synonym", entry.getSynonym()));

    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) {

        }
    }
    return removeResponse;
}

From source file:com.github.robozonky.integrations.zonkoid.UtilTest.java

@Test
void responseContent() {
    final Collection<NameValuePair> nvp = Collections.singletonList(new BasicNameValuePair("key", "value"));
    final HttpEntity e = new UrlEncodedFormEntity(nvp);
    assertThat(Util.readEntity(e)).isNotEmpty();
}

From source file:dk.i2m.drupal.field.wrapper.ImageWrapper.java

@Override
public Set<NameValuePair> setup(String language, Set<NameValuePair> nvps) {
    for (int i = 0; i < images.size(); i++) {
        Image image = images.get(i);

        if (image.getFid() == null) {
            throw new IllegalArgumentException("fid cannot be null");
        }// w  w  w  .j ava2 s .  c  om

        nvps.add(new BasicNameValuePair(name + "[" + language + "]" + "[" + i + "][fid]", image.getFid()));

        nvps.add(new BasicNameValuePair(name + "[" + language + "]" + "[" + i + "][display]", "1"));

        if (image.getAlt() != null) {
            nvps.add(new BasicNameValuePair(name + "[" + language + "]" + "[" + i + "][alt]", image.getAlt()));
        }

        if (image.getTitle() != null) {
            nvps.add(new BasicNameValuePair(name + "[" + language + "]" + "[" + i + "][title]",
                    image.getTitle()));
        }
    }

    return nvps;
}