Package org.apache.http

Examples of org.apache.http.HttpEntity


     *
     * @see getHeaderParameters
     * */
    private ResponseWrapper executeGETRequest(String path, String[][] datapost) throws IOException {

  HttpEntity httpEntity = executeGet(path, datapost, getHeaderParameters(this.getToken(),null));
  return GooglePlay.ResponseWrapper.parseFrom(httpEntity.getContent());

    }
View Full Code Here


     *
     * @see getHeaderParameters
     * */
    private ResponseWrapper executePOSTRequest(String path, String[][] datapost) throws IOException {

  HttpEntity httpEntity = executePost(path, datapost, getHeaderParameters(this.getToken(), null));
  return GooglePlay.ResponseWrapper.parseFrom(httpEntity.getContent());

    }
View Full Code Here

     * Executes POST request and returns result as {@link ResponseWrapper}.
     * Content type can be specified for given byte array.
     */
    private ResponseWrapper executePOSTRequest(String url, byte[] datapost, String contentType) throws IOException {

  HttpEntity httpEntity = executePost(url, new ByteArrayEntity(datapost), getHeaderParameters(this.getToken(), contentType));
  return GooglePlay.ResponseWrapper.parseFrom(httpEntity.getContent());

    }
View Full Code Here

    }

    private <T> T extractContent(Class<T> type, HttpUriRequest request, HttpResponse response) throws IOException {
        assert request != null;
        assert response != null;
        HttpEntity entity = response.getEntity();
        if (entity == null) {
            throw new IOException(MessageFormat.format(
                    "Response message was invalid (empty): {0} ({1})",
                    request.getURI(),
                    response.getStatusLine()));
        }

        InputStream input = entity.getContent();
        try {
            Reader reader = new BufferedReader(new InputStreamReader(input, ENCODING));
            JsonParser parser = new JsonParser();
            JsonElement element = parser.parse(reader);
            if ((element instanceof JsonObject) == false) {
View Full Code Here

        public void handle(HttpRequest request, HttpResponse response, HttpContext context) throws HttpException, IOException {
            response.setStatusCode(200);
            response.setEntity(new StringEntity(
                    new Gson().toJson(responseElement).toString(), HttpJobClient.CONTENT_TYPE));
            if (request instanceof HttpEntityEnclosingRequest) {
                HttpEntity entity = ((HttpEntityEnclosingRequest) request).getEntity();
                String content = EntityUtils.toString(entity, "UTF-8");
                JsonElement element = parse(content);
                if (element instanceof JsonObject) {
                    requestElement = (JsonObject) element;
                }
View Full Code Here

                object.addProperty("error", code);
                object.addProperty("message", code);
                response.setEntity(new StringEntity(new Gson().toJson(object).toString(), HttpJobClient.CONTENT_TYPE));
            }
            if (request instanceof HttpEntityEnclosingRequest) {
                HttpEntity entity = ((HttpEntityEnclosingRequest) request).getEntity();
                String content = EntityUtils.toString(entity, "UTF-8");
                JsonElement element = parse(content);
                if (element instanceof JsonObject) {
                    requestElement = (JsonObject) element;
                }
View Full Code Here

           
            return null;
        } finally {
            try {
                if (response != null) {
                    HttpEntity entity = response.getEntity();
                    if (entity != null) {
                        entity.consumeContent();
                    }
                }
                //EntityUtils.consume(response.getEntity());
            } catch (IOException e) {
                // ignore
View Full Code Here

   
    private Long doAuthenticatedPost(String url, String body) throws Exception {
        HttpPost request = new HttpPost(url + "?oauth_token=" + oauthToken);
        HttpResponse response = null;
        try {
            HttpEntity entity = new StringEntity(body, HTTP.UTF_8);
            // set the content type to json
            request.setHeader("Content-Type", "application/json; charset=utf-8");
            request.setEntity(entity);
            // sign the request
            // send the request
            response = httpClient.execute(request);
            int statusCode = response.getStatusLine().getStatusCode();
            if (statusCode == 401) {
                throw new RuntimeException("unable to execute POST - url: "
                    + url
                    + " body: "
                    + body);
            }
           
            if (statusCode == 201) {
                Header loc = response.getFirstHeader("Location");
                if (loc != null) {
                    String locS = loc.getValue();
                    if (!StringUtils.isBlank(locS) && locS.matches(".*/[0-9]+$")) {
                        try {
                            return NumberUtils.createLong(
                                    locS.substring(locS.lastIndexOf("/") + 1));
                        } catch (NumberFormatException e) {
                            return null;
                        }
                    }
                }
            }
           
            return null;
        } finally {
            try {
                if (response != null) {
                    HttpEntity entity = response.getEntity();
                    if (entity != null) {
                        entity.consumeContent();
                    }
                }
                //EntityUtils.consume(response.getEntity());
            } catch (IOException e) {
                // ignore
View Full Code Here

                throw new RuntimeException("unable to execute DELETE - url: " + url);
            }
        } finally {
            try {
                if (response != null) {
                    HttpEntity entity = response.getEntity();
                    if (entity != null) {
                        entity.consumeContent();
                    }
                }
                //EntityUtils.consume(response.getEntity());
            } catch (IOException e) {
                // ignore
View Full Code Here

            if (statusCode != 200) {
                throw new RuntimeException("Unable to get resource: " + url);
            }

            // Get hold of the response entity
            HttpEntity entity = response.getEntity();
            return EntityUtils.toString(entity);

        } catch (Exception e) {
            throw new RuntimeException("Unable to get resource", e);
        }
View Full Code Here

TOP

Related Classes of org.apache.http.HttpEntity

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.