本文整理汇总了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());
}
}
示例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);
}
示例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);
});
}
示例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);
}
示例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;
}
示例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("");
}
}
示例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)))));
}
示例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)))));
}
示例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);
}
}
示例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();
}
示例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);
}
}
示例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);
}
}
示例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);
}
}
示例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);
}
}
});
}
示例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;
}