Package org.apache.http.client.methods

Examples of org.apache.http.client.methods.HttpPost


    if (tags != null) {
      tree.mergeTree(tags);
    }

    URI url = metricBaseUrl.resolve("api/metric/").resolve(project);
    HttpPost request = new HttpPost(url);
    HttpResponse response = null;
    try {
      ByteArrayOutputStream baos = new ByteArrayOutputStream();
      metricTreeSerializer.serialize(tree, baos);
      baos.close();

      byte[] data = baos.toByteArray();

      log.debug("POSTing " + new String(data));

      // TODO: Stream body? We'd just need a custom ByteArrayEntity class
      request.setEntity(new ByteArrayEntity(data));

      response = httpClient.execute(request);

      StatusLine statusLine = response.getStatusLine();
      if (statusLine.getStatusCode() != 200) {
View Full Code Here


    * Helper methods
    */

   private String post(String path, HttpEntity entity) throws IOException
   {
      HttpPost post = new HttpPost(getBaseURL() + getContextPath() + path);
      post.setEntity(entity);
      HttpContext context = new BasicHttpContext();
      HttpResponse response = new DefaultHttpClient().execute(post, context);
      return Streams.toString(response.getEntity().getContent()).trim();
   }
View Full Code Here

          try {
            parser.parse(sql);
          HttpClient httpclient = new DefaultHttpClient();
          httpclient.getParams().setParameter(HttpMethodParams.SO_TIMEOUT, 60000*30);
           httpclient.getParams().setParameter(HttpMethodParams.HTTP_CONTENT_CHARSET, "UTF8");
          HttpPost httppost = new HttpPost("http://" + this.strurl+ "/higo/insert.jsp");
          List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(1);
          nameValuePairs.add(new BasicNameValuePair("project",parser.tablename));
          nameValuePairs.add(new BasicNameValuePair("json", parser.jsons));

          httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs,"UTF-8"));

          HttpResponse response = httpclient.execute(httppost);

          InputStream is = response.getEntity().getContent();
          BufferedInputStream bis = new BufferedInputStream(is);
View Full Code Here

//      }
    } else {
      HttpClient httpclient = new DefaultHttpClient();
      httpclient.getParams().setParameter(HttpMethodParams.SO_TIMEOUT, 60000*30);
       httpclient.getParams().setParameter(HttpMethodParams.HTTP_CONTENT_CHARSET, "UTF8");
      HttpPost httppost = new HttpPost("http://" + this.strurl
          + "/higo/result.jsp");
      List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(1);
      nameValuePairs.add(new BasicNameValuePair("project",parser.tablename));
      nameValuePairs.add(new BasicNameValuePair("start", parser.start));
      nameValuePairs.add(new BasicNameValuePair("rows", parser.rows));
      nameValuePairs.add(new BasicNameValuePair("fl", parser.fl));
      if (parser.queryStr != null) {
        nameValuePairs
            .add(new BasicNameValuePair("q", parser.queryStr));
      }
      if (parser.groupby != null) {
        nameValuePairs.add(new BasicNameValuePair("groupby",
            parser.groupby));
      }
      if (parser.sort != null) {
        nameValuePairs.add(new BasicNameValuePair("sort", parser.sort));
      }
      if (parser.order != null) {
        nameValuePairs
            .add(new BasicNameValuePair("order", parser.order));
      }

      httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs,"UTF-8"));

      HttpResponse response = httpclient.execute(httppost);

      InputStream is = response.getEntity().getContent();
      BufferedInputStream bis = new BufferedInputStream(is);
View Full Code Here

   * @param jsonPayload Serialized JSON payload.
   * @return Server's response body.
   */
  public String makePostRequest(String url, String jsonPayload) {
    try (CloseableHttpClient httpClient = HttpClientBuilder.create().build()) {
      HttpPost post = new HttpPost(url);
      post.setEntity(new StringEntity(jsonPayload, "utf-8"));
      post.addHeader("Content-Type", "application/json; charset=utf-8");

      return httpClient.execute(post, new BasicResponseHandler());
    } catch (IOException e) {
      throw new LogCommunicationException("Error making POST request to " + url, e);
    }
View Full Code Here

    /**
     * Executes POST request on given URL with {@link HttpEntity} typed POST
     * parameters and header parameters.
     */
    private HttpEntity executePost(String url, HttpEntity postData, String[][] headerParams) throws IOException {
  HttpPost httppost = new HttpPost(url);

  if (headerParams != null) {
      for (String[] param : headerParams) {
    if (param[0] != null && param[1] != null) {
        httppost.setHeader(param[0], param[1]);
    }
      }
  }

  httppost.setEntity(postData);

  return executeHttpRequest(httppost);
    }
View Full Code Here

    @Override
    public JobId register(JobScript script) throws IOException, InterruptedException {
        if (script == null) {
            throw new IllegalArgumentException("script must not be null"); //$NON-NLS-1$
        }
        HttpPost request = new HttpPost();
        URI uri = createUri("jobs");
        request.setURI(uri);
        request.setEntity(createEntity(script));

        if (LOG.isDebugEnabled()) {
            LOG.debug("Registering a job: method=post, uri={}, script={}", uri, script);
        }
        HttpResponse response = http.execute(request);
View Full Code Here

                is("org.apache.http.client.HttpClient.get-requests"));
    }

    @Test
    public void hostAndMethodWithName() {
        assertThat(HOST_AND_METHOD.getNameFor("some-service", new HttpPost("http://my.host.com/whatever")),
                   is("org.apache.http.client.HttpClient.some-service.my.host.com.post-requests"));
    }
View Full Code Here

                   is("org.apache.http.client.HttpClient.some-service.my.host.com.post-requests"));
    }

    @Test
    public void hostAndMethodWithoutName() {
        assertThat(HOST_AND_METHOD.getNameFor(null, new HttpPost("http://my.host.com/whatever")),
                is("org.apache.http.client.HttpClient.my.host.com.post-requests"));
    }
View Full Code Here

        return connect(endpoint, httpHeaders, true);
    }

    @Override
    public OutputStream connect(String endpoint, HashMap<String, String> httpHeaders, boolean enableCompression) throws IOException {
        post = new HttpPost(endpoint);
       
        for (String name : httpHeaders.keySet()) {
            post.addHeader(name, httpHeaders.get(name));
        }
       
View Full Code Here

TOP

Related Classes of org.apache.http.client.methods.HttpPost

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.