在使用httpcomponents-client-4.2.1时,任务运行一段时间就抛出以下一场

下面是异常的堆栈信息:

org.apache.http.TruncatedChunkException: Truncated chunk ( expected size: 47956; actual size: 35656) 
        at org.apache.http.impl.io.ChunkedInputStream.read(ChunkedInputStream.java:186) 
        at org.apache.http.conn.EofSensorInputStream.read(EofSensorInputStream.java:138) 
        at sun.nio.cs.StreamDecoder.readBytes(StreamDecoder.java:264) 
        at sun.nio.cs.StreamDecoder.implRead(StreamDecoder.java:306) 
        at sun.nio.cs.StreamDecoder.read(StreamDecoder.java:158) 
        at java.io.InputStreamReader.read(InputStreamReader.java:167) 
        at java.io.Reader.read(Reader.java:123) 
        at org.apache.http.util.EntityUtils.toString(EntityUtils.java:224) 
        at org.apache.http.util.EntityUtils.toString(EntityUtils.java:248) 
        at com.bw30.bjappmanage.common.service.impl.HttpClientServiceImpl$2.handleResponse(HttpClientServiceImpl.java:206)
        at com.bw30.bjappmanage.common.service.impl.HttpClientServiceImpl$2.handleResponse(HttpClientServiceImpl.java:1)
        at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:1070) 
        at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:1044) 
        at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:1035) 
        at com.bw30.bjappmanage.common.service.impl.HttpClientServiceImpl.getHttpEntityText(HttpClientServiceImpl.java:214)
        at com.bw30.bjappmanage.task.data.crawl.LiquGetThread.run(LiquGetThread.java:73) 
        at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886) 
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908) 
        at java.lang.Thread.run(Thread.java:662)

1、如果是一直报这个错 说明是服务端问题(如服务器故意给你返回错误的数据);

2、如果偶尔报这个错 说明是客户端网络(如丢包)等问题造成的,可以考虑失败重试两次,如果还失败 可以考虑记下日志,定期重试。

这个也是属于很正常的行为,就如网络问题,只要考虑好如失败重试 等策略解决这种问题就行了。

可以看下httpclient源码

你盼望1000字节 但实际获取了100  (这个服务器可以直接给你返回少于指定的数据, 网络问题也可能会遭遇这个问题)

 

org.apache.http.TruncatedChunkException: Truncated chunk ( expected size: 47956; actual size: 35656)的更多相关文章

  1. nginx的坑-org.apache.http.TruncatedChunkException: Truncated chunk( expected size: 7752; actual size: 4077)

    org.apache.http.TruncatedChunkException: Truncated chunk 项目中使用请求远程接口报错 ,项目是Spring-boot的,两个项目(A和B) , ...

  2. What does "size" in int(size) of MySQL mean?

    What does "size" in int(size) of MySQL mean? https://alexander.kirk.at/2007/08/24/what-doe ...

  3. Java对象大小:size和retained size

    最近看到网上很多文章讲如何计算java对象的大小(size),很多观点不敢苟同. 这是其中一篇比较靠前的文章,写的也比较全面: http://blog.csdn.net/iter_zc/article ...

  4. (python走过的坑)OpenCV中错误opencv-3.3.1\modules\highgui\src\window.cpp:339: error: (-215) size.width>0 && size.height>0 in function cv::imshow

    第一次在python中使用OpenCV(cv2),运行时报错opencv-3.3.1\modules\highgui\src\window.cpp:339: error: (-215) size.wi ...

  5. param size: The requested size, in points.

    param size: The requested size, in points. 字幕宽度的自适应 . fontScale c++ - OpenCV find the text Scale fro ...

  6. error: (-215:Assertion failed) size.width>0 && size.height>0 in function 'cv::imshow'

    用Python打开图像始终提示错误 error: OpenCV(4.1.1) C:\projects\opencv-python\opencv\modules\highgui\src\window.c ...

  7. line 352 Error: Assertion failed (size.width>0 && size.height>0) in cv::imshow

    OpenCV 使用 createtrackerbar()报错问题 Error Error: Assertion failed (size.width>0 && size.heig ...

  8. Shallow Size 和 Retained Size

    所有包含Heap Profling功能的工具(MAT, Yourkit, JProfiler, TPTP等)都会使用到两个名词,一个是Shallow Size,另一个是 Retained Size. ...

  9. 值得一提:关于 HDFS 的 file size 和 block size

    转 http://blog.csdn.net/samhacker/article/details/23089157?utm_source=tuicool&utm_medium=referral ...

随机推荐

  1. 排序遇到问题 JDK7的Comparison method violates its general contract

    图解JDK7的Comparison method violates its general contract异常 楼主分析的很详细,能力有限,我看得迷迷糊糊的,不过大致知道这个错误的起因了.学习了,谢 ...

  2. hihocoder 1496 寻找最大值(高维前缀最大次大值)

    [题目链接] https://hihocoder.com/problemset/problem/1496 [题目大意] 给定N个数A1, A2, A3, ... AN, 从中找到两个数Ai和Aj(i≠ ...

  3. BZOJ.3667.Rabin-Miller算法(MillerRabin PollardRho)

    题目链接 Pollard_Rho:http://blog.csdn.net/thy_asdf/article/details/51347390 #include<cstdio> #incl ...

  4. 学校的统一订书80%该烧掉——IT推荐书单

    学校的统一订书80%该烧掉——IT推荐书单 作者: 夏浅音.py 中文图书个人黑名单:清华大学出版社的国产作者,例如一段错n次的谭浩强.一页错n次的严蔚敏... 中文图书个人白名单:机械工业出版社.电 ...

  5. 使用Quartz搭建定时任务脚手架

    定时任务的实现有很多种,在Spring项目中使用一个注解 @Scheduled就可以很快搞定. 但是很难去管理项目中的定时任务,比如说:系统中有多少定时任务,每个定时任务执行规则,修改执行规则,暂停任 ...

  6. ios 类别(category)

    定义 类别(category)是Objective-C语言的新特性,为现有的类添加新方法的方式.局限性:1.无法添加新的实例变量.2.与类本身的方法名称冲突.当名称冲突时,类别具有更高的优先级.作用: ...

  7. XMPP接受发送消息

    在现阶段的通信服务中,各种标准都有,因此会出现无法实现相互连通,而XMPP(Extensible Message and presence Protocol)协议的出现,实现了整个及时通信服务协议的互 ...

  8. [猜你喜欢]冠军“yes,boy!”分享,含竞赛源代

    [猜你喜欢]冠军“yes,boy!”分享,含竞赛源代码  DataCastle运营 发表于 2016-7-20 17:31:52      844  3  5 我是Yes,boy! ,来自东北大学计算 ...

  9. linux 切分文件

    linux经常需要处理文件,如果文件比较大,那么需要切分成为若干的小文件再处理. 命令:split 比如有一个文件: ll -h 1431531915758 -rw-r--r-- 1 ticketde ...

  10. password、文件MD5加密,passwordsha256、sha384、sha512Hex等加密

    package encryption; import java.io.FileInputStream; import java.io.FileOutputStream; import java.io. ...