Java-httpClient警告: Going to buffer response body of large or unknown size. Using getResponseBodyAsStream instead is recommended.
使用HttpClient,总是报出“Going to buffer response body of large or unknown size. Using getResponseBodyAsStream instead is recommended.”的WARN日志,定位到HttpClient的源码如下:
public abstract class HttpMethodBase
implements HttpMethod
{
...
public byte[] getResponseBody() throws IOException {
if (responseBody == null) {
InputStream instream = getResponseBodyAsStream();
if (instream != null) {
long contentLength = getResponseContentLength();
if (contentLength > 2147483647L){
throw new IOException("Content too large to be buffered: " + contentLength + " bytes");
}
int limit = getParams().getIntParameter("http.method.response.buffer.warnlimit", 1048576);
if (contentLength == -1L || contentLength > (long) limit){
LOG.warn("Going to buffer response body of large or unknown size. Using getResponseBodyAsStream instead is recommended.");
}
LOG.debug("Buffering response body");
ByteArrayOutputStream outstream = new ByteArrayOutputStream(contentLength <= 0L ? 4096: (int) contentLength);
byte buffer[] = new byte[4096];
int len;
while ((len = instream.read(buffer)) > 0){
outstream.write(buffer, 0, len);
}
outstream.close();
setResponseStream(null);
responseBody = outstream.toByteArray();
}
}
return responseBody;
}
...
}
报WARN的条件是((contentLength == -1) || (contentLength > limit)),也就是说,或者是返回的HTTP头没有指定contentLength,或者是contentLength大于上限(默认是1M)。如果能确定返回结果的大小对程序没有显著影响,这个WARN就可以忽略,可以在日志的配置中把HttpClient的日志级别调到ERROR,不让它报出来。
当然,这个警告也是有意义的,HttpClient建议使用InputStream getResponseBodyAsStream()代替byte[] getResponseBody()。对于返回结果很大或无法预知的情况,就需要使用InputStreamgetResponseBodyAsStream(),避免byte[] getResponseBody()可能带来的内存的耗尽问题。
Java-httpClient警告: Going to buffer response body of large or unknown size. Using getResponseBodyAsStream instead is recommended.的更多相关文章
- WARN警告:Going to buffer response body of large or unknown size. Using getResponseBodyAsStream instead is recommended
使用Apache HttpClient发送请求,有大量WARN警告:Going to buffer response body of large or unknown size. Using getR ...
- 关于http客户端常见错误"警告:Going to buffer response body of large or unknown size. Using getResponseBodyAsStream instead is rec"
在开发过程中,经常得写http客户端测试接口服务,今天在使用过程中出现了这样的一个警告: 警告: Going to buffer response body of large or unknown s ...
- httpClient使用中报错org.apache.commons.httpclient.HttpMethodBase - Going to buffer response body of large or unknown size.
在使用HttpClient发送请求,使用httpMethod.getResponseBodyAsString();时当返回值过大时会报错: org.apache.commons.httpclient. ...
- java HttpClient操作工具类
maven: <dependency> <groupId>org.apache.httpcomponents</groupId> <artifactId> ...
- java.lang.IllegalStateException: Cannot forward after response has been committed的一个情况解决方法
java.lang.IllegalStateException: Cannot forward after response has been committed xxx.xxx.doPost(upd ...
- java.io.IOException: Server returned HTTP response code: 411 for URL
今日调用一post方式提交的http接口,此接口在测试环境ip调用时无问题,但在生产环境通过域名调用时一直报如下错误: java.io.IOException: Server returned HTT ...
- 通过设置代理,解决服务器禁止抓取,报“java.io.IOException: Server returned HTTP response code: 403 for URL”错误的方法
java.io.IOException: Server returned HTTP response code: 403 for URL: http:// 这个是什么异常呢? 当你使用java程序检索 ...
- nested exception is java.lang.IllegalStateException: Cannot forward after response has been committed
org.springframework.web.util.NestedServletException: Request processing failed; nested exception is ...
- Error:java: 发现警告, 但指定了 -Werror
最近在使用IntelliJ IDEA编译Apache Guacamole Web项目时,遇到了一个罕见的bug:"Error:java: 发现警告, 但指定了 -Werror",见 ...
随机推荐
- 搜索+剪枝 POJ 1416 Shredding Company
POJ 1416 Shredding Company Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 5231 Accep ...
- 手把手教你如何用ZBrush刻画脸部
今天的ZBrush教程我们将参照一张效果图对模型进行脸部刻画.在进入课堂之前我们有必要对Layers层概念和操作有所了解,然后结合之前学习的雕刻笔刷对模型的特征表情给予重点刻画. 详细的视频教程地址请 ...
- Cg关键字(keywords)
保留标识符 除了下面列出的,任何以两个的下划线作为前缀(例如,__ newType)的标识符被保留. 注意,矩阵(matrix)和向量类型(vector types)(如half2x3或float4) ...
- 关于软件测试人员能力模型的建立(from知乎)
转自: http://www.zhihu.com/question/20254092 测试思维方面:1.测试基础理论(测试流程.测试的基础知识)2.测试用例设计方法论(黑盒.白盒)3.软件质量体系(建 ...
- javascript中的hasOwnProperty和isPrototypeOf
hasOwnProperty:是用来判断一个对象是否有你给出名称的属性或对象.不过需要注意的是,此方法无法检查该对象的原型链中是否具有该属性,该属性必须是对象本身的一个成员.isPrototypeOf ...
- mac终端命令大全介绍
OSX 的文件系统 OSX 采用的Unix文件系统,所有文件都挂在跟目录 / 下面,所以不在要有Windows 下的盘符概念. 你在桌面上看到的硬盘都挂在 /Volumes 下. 比如接上个叫做 US ...
- 【WPF】无边框窗体
之前写了一个支持尺寸变换的无边框窗体的一个基窗体,代码如下: public class LBaseWindow : Window { /// <summary> /// 基窗体 /// & ...
- HTML语义化之常见模块
用合理的HTML标记以及特有的属性去格式化文档内容. 浏览器会根据标签的语义给定一个默认的样式. 判断网页标签语义是否良好的一个简单方法就是:去掉样式,看网页结构是否组织良好有序,是否仍然有很好的可读 ...
- php基础33:正则匹配-perl
<?php //1.搜索数组中的相匹配的字符串 //preg_grep() 返回一个数组 $language = array("php","asp",&q ...
- 反射中使用 BindingFlags.IgnoreCase
我们经常需要通过反射来调用目标对象的方法或获取/设置目标对象的属性,Type.InvokeMember 方法签名如下: public object InvokeMember(string name,B ...