Package org.apache.http

Examples of org.apache.http.HttpEntity


        url = truncData(url);
      long t1 = System.currentTimeMillis();
      HttpResponse response = client.execute(httpUriRequest);
      long t2 = System.currentTimeMillis();
      NewRelic.addCustomParameter(System.currentTimeMillis()+"--"+url, (t2 - t1) + " ms");
      HttpEntity resEntity = response.getEntity();
      String contentCharSet = EntityUtils.getContentCharSet(resEntity);
      map.put("status", response.getStatusLine().getStatusCode());
      map.put("response", contentCharSet != null ? new String(EntityUtils.toByteArray(resEntity), contentCharSet) : new String(EntityUtils.toByteArray(resEntity)));
    }
    catch (Exception e)
View Full Code Here


        url = truncData(url);
      long t1 = System.currentTimeMillis();
      HttpResponse response = client.execute(httpUriRequest);
      long t2 = System.currentTimeMillis();
      NewRelic.addCustomParameter(System.currentTimeMillis()+"--"+url, (t2 - t1) + " ms");
      HttpEntity resEntity = response.getEntity();
      String contentCharSet = EntityUtils.getContentCharSet(resEntity);
      map.put("status", response.getStatusLine().getStatusCode());
      map.put("response", contentCharSet != null ? new String(EntityUtils.toByteArray(resEntity), contentCharSet) : new String(EntityUtils.toByteArray(resEntity)));
    }
    catch (Exception e)
View Full Code Here

    httppost.setEntity(entity);
    long t1 = System.currentTimeMillis();
    HttpResponse response = client.execute(httppost);
    long t2 = System.currentTimeMillis();
    NewRelic.addCustomParameter(System.currentTimeMillis()+"--"+url, (t2 - t1) + " ms");
    HttpEntity resEntity = response.getEntity();
    String contentCharSet = EntityUtils.getContentCharSet(resEntity);
    HashMap<String, Object> map = new HashMap<String, Object>();
    map.put("status", response.getStatusLine().getStatusCode());
    map.put("response", contentCharSet != null ? new String(EntityUtils.toByteArray(resEntity), contentCharSet) : new String(EntityUtils.toByteArray(resEntity)));
    return map;
View Full Code Here

    HttpClient client = getHttpClient(url, connectionTimeout, soTimeout);
    HttpGet httpclient = new HttpGet(url);
    if (authMap != null)
      httpclient.addHeader(new BasicScheme().authenticate(new UsernamePasswordCredentials((String) authMap.get("user"), (String) authMap.get("password")), httpclient));
    HttpResponse response = client.execute(httpclient);
    HttpEntity resEntity = response.getEntity();
    String contentCharSet = EntityUtils.getContentCharSet(resEntity);
    HashMap<String, Object> map = new HashMap<String, Object>();
    map.put("status", response.getStatusLine().getStatusCode());
    map.put("response", contentCharSet != null ? new String(EntityUtils.toByteArray(resEntity), contentCharSet) : new String(EntityUtils.toByteArray(resEntity)));
    return map;
View Full Code Here

      long t1 = System.currentTimeMillis();
      HttpResponse response = client.execute(httpUriRequest);
      long t2 = System.currentTimeMillis();
      if (!url.contains("SensitiveController"))
        NewRelic.addCustomParameter(System.currentTimeMillis()+"--"+url, (t2 - t1) + " ms");
      HttpEntity resEntity = response.getEntity();
      String contentCharSet = EntityUtils.getContentCharSet(resEntity);
      map.put("status", response.getStatusLine().getStatusCode());
      map.put("response", contentCharSet != null ? new String(EntityUtils.toByteArray(resEntity), contentCharSet) : new String(EntityUtils.toByteArray(resEntity)));
    }
    catch (Exception e)
View Full Code Here

    private void executeHttpRequest() {
        ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
        try {
            response = httpClient.execute(request);
            HttpEntity entity = response.getEntity();
            if (entity != null) {
                entity.writeTo(outputStream);
            }
            responseBody = outputStream.toString("UTF-8");
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
View Full Code Here

            if (response.getStatusLine().getStatusCode() != 200) {
                LOG.error("Expected version check HTTP status code [200] but got [{}]", response.getStatusLine().getStatusCode());
                return;
            }

            HttpEntity entity = response.getEntity();

            StringWriter writer = new StringWriter();
            IOUtils.copy(entity.getContent(), writer, Charset.forName("UTF-8"));
            String body = writer.toString();

            VersionCheckResponse parsedResponse = parse(body);
            Version reportedVersion = new Version(parsedResponse.version.major, parsedResponse.version.minor, parsedResponse.version.patch);
View Full Code Here

    @Override
    public void doRun() {
        LOG.debug("Telemetry is activated: Transmitting metrics.");

        HttpEntity postBody;
        try {
            Map<String, Object> report = Maps.newHashMap();

            report.put("token", configuration.getTelemetryServiceToken());
            report.put("anon_id", DigestUtils.sha256Hex(serverStatus.getNodeId().toString()));
View Full Code Here

     * @param httpRequest the method that was executed
     * @return the response either as a stream, or as a deserialized java object
     * @throws IOException can be thrown
     */
    protected static Object extractResponseBody(HttpRequestBase httpRequest, HttpResponse httpResponse, Exchange exchange) throws IOException, ClassNotFoundException {
        HttpEntity entity = httpResponse.getEntity();
        if (entity == null) {
            return null;
        }

        InputStream is = entity.getContent();
        if (is == null) {
            return null;
        }

        Header header = httpResponse.getFirstHeader(Exchange.CONTENT_ENCODING);
View Full Code Here

            url = rewriteUrl;
            uri = new URI(url);
        }

        // create http holder objects for the request
        HttpEntity requestEntity = createRequestEntity(exchange);
        HttpMethods methodToUse = HttpHelper.createMethod(exchange, getEndpoint(), requestEntity != null);
        HttpRequestBase method = methodToUse.createMethod(url);

        LOG.trace("Using URL: {} with method: {}", url, method);

        if (methodToUse.isEntityEnclosing()) {
            ((HttpEntityEnclosingRequestBase) method).setEntity(requestEntity);
            if (requestEntity != null && requestEntity.getContentType() == null) {
                LOG.debug("No Content-Type provided for URL: {} with exchange: {}", url, exchange);
            }
        }

        // there must be a host on the method
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.