當前位置: 首頁>>代碼示例>>Java>>正文


Java BufferedHttpEntity類代碼示例

本文整理匯總了Java中org.apache.http.entity.BufferedHttpEntity的典型用法代碼示例。如果您正苦於以下問題:Java BufferedHttpEntity類的具體用法?Java BufferedHttpEntity怎麽用?Java BufferedHttpEntity使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


BufferedHttpEntity類屬於org.apache.http.entity包,在下文中一共展示了BufferedHttpEntity類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: ResponseWrap

import org.apache.http.entity.BufferedHttpEntity; //導入依賴的package包/類
public ResponseWrap(CloseableHttpClient httpClient, HttpRequestBase request, CloseableHttpResponse response, HttpClientContext context,
		ObjectMapper _mapper) {
	this.response = response;
	this.httpClient = httpClient;
	this.request = request;
	this.context = context;
	mapper = _mapper;

	try {
		HttpEntity entity = response.getEntity();
		if (entity != null) {
			this.entity = new BufferedHttpEntity(entity);
		} else {
			this.entity = new BasicHttpEntity();
		}

		EntityUtils.consumeQuietly(entity);
		this.response.close();
	} catch (IOException e) {
		logger.warn(e.getMessage());
	}
}
 
開發者ID:swxiao,項目名稱:bubble2,代碼行數:23,代碼來源:ResponseWrap.java

示例2: sendApiMethod

import org.apache.http.entity.BufferedHttpEntity; //導入依賴的package包/類
private Serializable sendApiMethod(BotApiMethod method) throws TelegramApiException {
    String responseContent;
    try {
        CloseableHttpClient httpclient = HttpClientBuilder.create().setSSLHostnameVerifier(new NoopHostnameVerifier()).build();
        String url = getBaseUrl() + method.getPath();
        HttpPost httppost = new HttpPost(url);
        httppost.addHeader("charset", StandardCharsets.UTF_8.name());
        httppost.setEntity(new StringEntity(method.toJson().toString(), ContentType.APPLICATION_JSON));
        CloseableHttpResponse response = httpclient.execute(httppost);
        HttpEntity ht = response.getEntity();
        BufferedHttpEntity buf = new BufferedHttpEntity(ht);
        responseContent = EntityUtils.toString(buf, StandardCharsets.UTF_8);
    } catch (IOException e) {
        throw new TelegramApiException("Unable to execute " + method.getPath() + " method", e);
    }

    JSONObject jsonObject = new JSONObject(responseContent);
    if (!jsonObject.getBoolean(Constants.RESPONSEFIELDOK)) {
        throw new TelegramApiException("Error at " + method.getPath(), jsonObject.getString("description"));
    }

    return method.deserializeResponse(jsonObject);
}
 
開發者ID:gomgomdev,項目名稱:telegram-bot_misebot,代碼行數:24,代碼來源:AbsSender.java

示例3: download

import org.apache.http.entity.BufferedHttpEntity; //導入依賴的package包/類
private void download(String url, Handler<AsyncResult<Object>> handler) {
    vertx.executeBlocking(future -> {
        HttpGet httpGet = new HttpGet(rootOPDS + url);
        try {
            CloseableHttpResponse response = httpclient.execute(httpGet, context);
            if (response.getStatusLine().getStatusCode() == 200) {
                String fileName = fileNameParser.parse(url);
                HttpEntity ht = response.getEntity();
                BufferedHttpEntity buf = new BufferedHttpEntity(ht);
                File book = File.createTempFile("flibot_" + Long.toHexString(System.currentTimeMillis()), null);
                buf.writeTo(new FileOutputStream(book));
                final SendDocument sendDocument = new SendDocument();
                sendDocument.setNewDocument(fileName, new FileInputStream(book));
                sendDocument.setCaption("book");
                future.complete(sendDocument);
            }
        } catch (Exception e) {
            log.warn(e, e);
            future.fail(e);
        }
    }, res -> {
        handler.handle(res);
    });
}
 
開發者ID:flicus,項目名稱:flibot,代碼行數:25,代碼來源:FliBot.java

示例4: execute

import org.apache.http.entity.BufferedHttpEntity; //導入依賴的package包/類
@Override
public <T extends TelegraphObject> T execute(TelegraphMethod<T> method) throws TelegraphException {
    String responseContent;
    try {
        String url = TelegraphConstants.BASE_URL + method.getUrlPath();
        HttpPost httppost = new HttpPost(url);
        httppost.setConfig(requestConfig);
        httppost.addHeader("charset", StandardCharsets.UTF_8.name());
        httppost.addHeader("Content-Type", "application/json");
        httppost.setEntity(new StringEntity(objectMapper.writeValueAsString(method), ContentType.APPLICATION_JSON));
        try (CloseableHttpResponse response = httpclient.execute(httppost)) {
            HttpEntity ht = response.getEntity();
            BufferedHttpEntity buf = new BufferedHttpEntity(ht);
            responseContent = EntityUtils.toString(buf, StandardCharsets.UTF_8);
        }
    } catch (IOException e) {
        throw new TelegraphRequestException("Unable to execute " + method.getUrlPath() + " method", e);
    }

    return method.deserializeResponse(responseContent);
}
 
開發者ID:rubenlagus,項目名稱:Telegraph,代碼行數:22,代碼來源:DefaultTelegraphExecutor.java

示例5: HttpGet

import org.apache.http.entity.BufferedHttpEntity; //導入依賴的package包/類
public static ByteArrayBuffer ʻ(String paramString)
{
  HttpGet localHttpGet = new HttpGet(paramString);
  DefaultHttpClient localDefaultHttpClient = ˊ();
  BufferedHttpEntity localBufferedHttpEntity = new BufferedHttpEntity(localDefaultHttpClient.execute(localHttpGet).getEntity());
  BufferedInputStream localBufferedInputStream = new BufferedInputStream(localBufferedHttpEntity.getContent());
  ByteArrayBuffer localByteArrayBuffer = new ByteArrayBuffer(50);
  while (true)
  {
    int i = localBufferedInputStream.read();
    if (i == -1)
      break;
    localByteArrayBuffer.append((byte)i);
  }
  localBufferedInputStream.close();
  localBufferedHttpEntity.consumeContent();
  localDefaultHttpClient.getConnectionManager().shutdown();
  return localByteArrayBuffer;
}
 
開發者ID:mmmsplay10,項目名稱:QuizUpWinner,代碼行數:20,代碼來源:„Ä≥.java

示例6: log

import org.apache.http.entity.BufferedHttpEntity; //導入依賴的package包/類
public static void log(HttpRequest req, BufferedHttpEntity entity) {
    if (log_level > 1) {
        System.out.println("----------------------");
        System.out.println("     HTTP Request");
        System.out.println("----------------------");
        System.out.println(req.getRequestLine().toString());
        if (log_level > 2) {
            System.out.println("Headers:");
            System.out.println("--------");
            Header[] hdrs = req.getAllHeaders();
            for (int i = 0; i < hdrs.length; ++i) {
                System.out.println(hdrs[i].getName() + ": " + hdrs[i].getValue());
            }
            if (entity != null) {
                try {
                    System.out.println("Entity:");
                    System.out.println("-------");
                    System.out.println(EntityUtils.toString(entity));
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
        System.out.println("");
    }
}
 
開發者ID:dirkboye,項目名稱:GDriveUpload,代碼行數:27,代碼來源:ConsoleLog.java

示例7: testBufferedHttpEntity

import org.apache.http.entity.BufferedHttpEntity; //導入依賴的package包/類
/**
 * <p>Test for a {@link Request} with a <b>buffered</b> entity.</p>
 * 
 * @since 1.3.0
 */
@Test
public final void testBufferedHttpEntity() throws ParseException, IOException {
	
	String subpath = "/bufferedhttpentity";
	
	ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
	InputStream inputStream = classLoader.getResourceAsStream("LICENSE.txt");
	InputStream parallelInputStream = classLoader.getResourceAsStream("LICENSE.txt");
	BasicHttpEntity bhe = new BasicHttpEntity();
	bhe.setContent(parallelInputStream);
	
	stubFor(put(urlEqualTo(subpath))
			.willReturn(aResponse()
			.withStatus(200)));
	
	requestEndpoint.bufferedHttpEntity(inputStream);
	
	verify(putRequestedFor(urlEqualTo(subpath))
		   .withRequestBody(equalTo(EntityUtils.toString(new BufferedHttpEntity(bhe)))));
}
 
開發者ID:sahan,項目名稱:ZombieLink,代碼行數:26,代碼來源:RequestParamEndpointTest.java

示例8: testBufferedHttpEntity

import org.apache.http.entity.BufferedHttpEntity; //導入依賴的package包/類
/**
 * <p>Test for a {@link Request} with a <b>buffered</b> entity.</p>
 * 
 * @since 1.3.0
 */
@Test
public final void testBufferedHttpEntity() throws ParseException, IOException {
	
	Robolectric.getFakeHttpLayer().interceptHttpRequests(false);
	
	String subpath = "/bufferedhttpentity";
	
	ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
	InputStream inputStream = classLoader.getResourceAsStream("LICENSE.txt");
	InputStream parallelInputStream = classLoader.getResourceAsStream("LICENSE.txt");
	BasicHttpEntity bhe = new BasicHttpEntity();
	bhe.setContent(parallelInputStream);
	
	stubFor(put(urlEqualTo(subpath))
			.willReturn(aResponse()
			.withStatus(200)));
	
	requestEndpoint.bufferedHttpEntity(inputStream);
	
	verify(putRequestedFor(urlEqualTo(subpath))
		   .withRequestBody(equalTo(EntityUtils.toString(new BufferedHttpEntity(bhe)))));
}
 
開發者ID:sahan,項目名稱:RoboZombie,代碼行數:28,代碼來源:RequestParamEndpointTest.java

示例9: serializeContent

import org.apache.http.entity.BufferedHttpEntity; //導入依賴的package包/類
private byte[] serializeContent(HttpRequest request) {
    if (!(request instanceof HttpEntityEnclosingRequest)) {
        return new byte[]{};
    }

    final HttpEntityEnclosingRequest entityWithRequest = (HttpEntityEnclosingRequest) request;
    HttpEntity entity = entityWithRequest.getEntity();
    if (entity == null) {
        return new byte[]{};
    }

    try {
        // Buffer non-repeatable entities
        if (!entity.isRepeatable()) {
            entityWithRequest.setEntity(new BufferedHttpEntity(entity));
        }
        return EntityUtils.toByteArray(entityWithRequest.getEntity());
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
}
 
開發者ID:akamai,項目名稱:AkamaiOPEN-edgegrid-java,代碼行數:22,代碼來源:ApacheHttpClientEdgeGridRequestSigner.java

示例10: getStreamFromNetwork

import org.apache.http.entity.BufferedHttpEntity; //導入依賴的package包/類
@Override
protected InputStream getStreamFromNetwork(String imageUri, Object extra) throws IOException {
	HttpGet httpRequest = new HttpGet(imageUri);
	HttpResponse response = httpClient.execute(httpRequest);
	HttpEntity entity = response.getEntity();
	BufferedHttpEntity bufHttpEntity = new BufferedHttpEntity(entity);
	return bufHttpEntity.getContent();
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:9,代碼來源:HttpClientImageDownloader.java

示例11: sendResponseMessage

import org.apache.http.entity.BufferedHttpEntity; //導入依賴的package包/類
protected void sendResponseMessage(HttpResponse response) {
    Throwable e;
    StatusLine status = response.getStatusLine();
    String responseBody = null;
    try {
        HttpEntity temp = response.getEntity();
        if (temp != null) {
            HttpEntity entity = new BufferedHttpEntity(temp);
            try {
                responseBody = EntityUtils.toString(entity, "UTF-8");
            } catch (IOException e2) {
                e = e2;
                HttpEntity httpEntity = entity;
                sendFailureMessage(e, null);
                if (status.getStatusCode() >= 300) {
                    sendSuccessMessage(status.getStatusCode(), response.getAllHeaders(), responseBody);
                } else {
                    sendFailureMessage(new HttpResponseException(status.getStatusCode(), status.getReasonPhrase()), responseBody);
                }
            }
        }
    } catch (IOException e3) {
        e = e3;
        sendFailureMessage(e, null);
        if (status.getStatusCode() >= 300) {
            sendFailureMessage(new HttpResponseException(status.getStatusCode(), status.getReasonPhrase()), responseBody);
        } else {
            sendSuccessMessage(status.getStatusCode(), response.getAllHeaders(), responseBody);
        }
    }
    if (status.getStatusCode() >= 300) {
        sendFailureMessage(new HttpResponseException(status.getStatusCode(), status.getReasonPhrase()), responseBody);
    } else {
        sendSuccessMessage(status.getStatusCode(), response.getAllHeaders(), responseBody);
    }
}
 
開發者ID:JackChan1999,項目名稱:letv,代碼行數:37,代碼來源:AsyncHttpResponseHandler.java

示例12: newBufferedHttpEntity

import org.apache.http.entity.BufferedHttpEntity; //導入依賴的package包/類
/**
 * Utility function for creating a new BufferedEntity and wrapping any errors
 * as a SdkClientException.
 *
 * @param entity The HTTP entity to wrap with a buffered HTTP entity.
 * @return A new BufferedHttpEntity wrapping the specified entity.
 */
public static HttpEntity newBufferedHttpEntity(HttpEntity entity) {
    try {
        return new BufferedHttpEntity(entity);
    } catch (IOException e) {
        throw new UncheckedIOException("Unable to create HTTP entity: " + e.getMessage(), e);
    }
}
 
開發者ID:aws,項目名稱:aws-sdk-java-v2,代碼行數:15,代碼來源:ApacheUtils.java

示例13: afterDoCap

import org.apache.http.entity.BufferedHttpEntity; //導入依賴的package包/類
@Override
public void afterDoCap(InvokeChainContext context, Object[] args) {

    if (UAVServer.instance().isExistSupportor("com.creditease.uav.apm.supporters.SlowOperSupporter")) {
        Span span = (Span) context.get(InvokeChainConstants.PARAM_SPAN_KEY);
        SlowOperContext slowOperContext = new SlowOperContext();
        if (Throwable.class.isAssignableFrom(args[0].getClass())) {

            Throwable e = (Throwable) args[0];
            slowOperContext.put(SlowOperConstants.PROTOCOL_HTTP_EXCEPTION, e.toString());

        }
        else {
            HttpResponse response = (HttpResponse) args[0];

            slowOperContext.put(SlowOperConstants.PROTOCOL_HTTP_HEADER, getResponHeaders(response));
            HttpEntity entity = response.getEntity();
            // 由於存在讀取失敗和無法緩存的大entity會使套殼失敗,故此處添加如下判斷
            if (BufferedHttpEntity.class.isAssignableFrom(entity.getClass())) {
                Header header = entity.getContentEncoding();
                String encoding = header == null ? "utf-8" : header.getValue();
                slowOperContext.put(SlowOperConstants.PROTOCOL_HTTP_BODY, getHttpEntityContent(entity, encoding));
            }
            else {
                slowOperContext.put(SlowOperConstants.PROTOCOL_HTTP_BODY,
                        "HttpEntityWrapper failed! Maybe HTTP entity too large to be buffered in memory");
            }
        }

        Object params[] = { span, slowOperContext };
        UAVServer.instance().runSupporter("com.creditease.uav.apm.supporters.SlowOperSupporter", "runCap",
                span.getEndpointInfo().split(",")[0], InvokeChainConstants.CapturePhase.DOCAP, context, params);
    }

}
 
開發者ID:uavorg,項目名稱:uavstack,代碼行數:36,代碼來源:ApacheHttpClientAdapter.java

示例14: sendApiMethodAsync

import org.apache.http.entity.BufferedHttpEntity; //導入依賴的package包/類
private void sendApiMethodAsync(BotApiMethod method, SentCallback callback) {
    exe.submit(new Runnable() {
        @Override
        public void run() {
            try {
                CloseableHttpClient httpclient = HttpClientBuilder.create().setSSLHostnameVerifier(new NoopHostnameVerifier()).build();
                String url = getBaseUrl() + method.getPath();
                HttpPost httppost = new HttpPost(url);
                httppost.addHeader("charset", StandardCharsets.UTF_8.name());
                httppost.setEntity(new StringEntity(method.toJson().toString(), ContentType.APPLICATION_JSON));
                CloseableHttpResponse response = httpclient.execute(httppost);
                HttpEntity ht = response.getEntity();
                BufferedHttpEntity buf = new BufferedHttpEntity(ht);
                String responseContent = EntityUtils.toString(buf, StandardCharsets.UTF_8);

                JSONObject jsonObject = new JSONObject(responseContent);
                if (!jsonObject.getBoolean(Constants.RESPONSEFIELDOK)) {
                    callback.onError(method, jsonObject);
                }
                callback.onResult(method, jsonObject);
            } catch (IOException e) {
                callback.onException(method, e);
            }

        }
    });
}
 
開發者ID:gomgomdev,項目名稱:telegram-bot_misebot,代碼行數:28,代碼來源:AbsSender.java

示例15: execute

import org.apache.http.entity.BufferedHttpEntity; //導入依賴的package包/類
protected HttpResponse execute(final HttpClient client, final HttpRequestBase request) throws Exception {
	HttpContext context = new BasicHttpContext();
	HttpResponse response = requestChain.execute(request, context);

	if (context.getAttribute("Location")!=null)
		response.setHeader(MECHANIZE_LOCATION, (String) context.getAttribute("Location"));

	response.setEntity(new BufferedHttpEntity(response.getEntity()));

	return response;
}
 
開發者ID:Coffeeboys,項目名稱:RenewPass,代碼行數:12,代碼來源:MechanizeAgent.java


注:本文中的org.apache.http.entity.BufferedHttpEntity類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。