美文网首页
android使用appache httpclient混淆后错误

android使用appache httpclient混淆后错误

作者: iBoss | 来源:发表于2017-11-10 17:51 被阅读0次

    android使用appache httpclient混淆后错误排除总结

    引用出处:http://blog.csdn.net/chenrunhua/article/details/50054225

    android上使用appache httpclient上传文件时报一下错误:

    [html]view plaincopy

    11-20 12:49:59.572 7360-22466/com.cn21.ecloud D/d: org.apache.http.client.ClientProtocolException

    11-20 12:49:59.572 7360-22466/com.cn21.ecloud D/d:     at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:756)

    11-20 12:49:59.572 7360-22466/com.cn21.ecloud D/d:     at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:519)

    11-20 12:49:59.572 7360-22466/com.cn21.ecloud D/d:     at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:497)

    11-20 12:49:59.572 7360-22466/com.cn21.ecloud D/d:     at com.cloudapm.agent.android.instrumentation.HttpInstrumentation.execute(SourceFile:188)

    11-20 12:49:59.572 7360-22466/com.cn21.ecloud D/d:     at com.cn21.ecloud.netapi.a.m.a(SourceFile:130)

    11-20 12:49:59.572 7360-22466/com.cn21.ecloud D/d:     at com.cn21.ecloud.f.j.dY(SourceFile:160)

    11-20 12:49:59.572 7360-22466/com.cn21.ecloud D/d:     at com.cn21.android.b.e.dX(SourceFile:52)

    11-20 12:49:59.572 7360-22466/com.cn21.ecloud D/d:     at com.cn21.android.b.d.run(SourceFile:459)

    11-20 12:49:59.572 7360-22466/com.cn21.ecloud D/d:     at com.cn21.android.b.b.dS(SourceFile:316)

    11-20 12:49:59.572 7360-22466/com.cn21.ecloud D/d:     at com.cn21.android.b.b.a(SourceFile:14)

    11-20 12:49:59.572 7360-22466/com.cn21.ecloud D/d:     at com.cn21.android.b.c.run(SourceFile:62)

    11-20 12:49:59.572 7360-22466/com.cn21.ecloud D/d:     at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)

    11-20 12:49:59.572 7360-22466/com.cn21.ecloud D/d:     at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)

    11-20 12:49:59.572 7360-22466/com.cn21.ecloud D/d:     at java.lang.Thread.run(Thread.java:864)

    11-20 12:49:59.572 7360-22466/com.cn21.ecloud D/d:  Caused by: org.apache.http.client.NonRepeatableRequestException: Cannot retry request with a non-repeatable request entity

    11-20 12:49:59.572 7360-22466/com.cn21.ecloud D/d:     at org.apache.http.impl.client.DefaultRequestDirector.execute(DefaultRequestDirector.java:427)

    11-20 12:49:59.572 7360-22466/com.cn21.ecloud D/d:     at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:754)

    11-20 12:49:59.572 7360-22466/com.cn21.ecloud D/d:     at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:519)?

    11-20 12:49:59.572 7360-22466/com.cn21.ecloud D/d:     at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:497)?

    11-20 12:49:59.572 7360-22466/com.cn21.ecloud D/d:     at com.cloudapm.agent.android.instrumentation.HttpInstrumentation.execute(SourceFile:188)?

    11-20 12:49:59.572 7360-22466/com.cn21.ecloud D/d:     at com.cn21.ecloud.netapi.a.m.a(SourceFile:130)?

    11-20 12:49:59.572 7360-22466/com.cn21.ecloud D/d:     at com.cn21.ecloud.f.j.dY(SourceFile:160)?

    11-20 12:49:59.572 7360-22466/com.cn21.ecloud D/d:     at com.cn21.android.b.e.dX(SourceFile:52)?

    11-20 12:49:59.572 7360-22466/com.cn21.ecloud D/d:     at com.cn21.android.b.d.run(SourceFile:459)?

    11-20 12:49:59.572 7360-22466/com.cn21.ecloud D/d:     at com.cn21.android.b.b.dS(SourceFile:316)?

    11-20 12:49:59.572 7360-22466/com.cn21.ecloud D/d:     at com.cn21.android.b.b.a(SourceFile:14)?

    11-20 12:49:59.572 7360-22466/com.cn21.ecloud D/d:     at com.cn21.android.b.c.run(SourceFile:62)?

    代码如下

    [html]view plaincopy

    RandomAccessFilefile=newRandomAccessFile(localFile, "r");

    // 仅上传未完成的文件内容

    file.seek(status._size);

    InternalFileStreamfs=newInternalFileStream(new FileInputStream(

    file.getFD()), status._size, observer);

    InputStreamEntityentity=newInputStreamEntity(fs, fileLength

    - status._size);

    request.setEntity(entity);

    DLog.d(TAG,"entity is repeatable ? = " + entity.isRepeatable());

    DLog.write2File(TAG, "entity is repeatable ? = " + entity.isRepeatable(), DLog.LOG_PATH_TRANSFER);

    if(ConstantConfig.DEBUG){

    dumpRequest(request, null);

    }

    try {

    HttpResponseresponse=mHttpClient.execute(request);

    InternalFileStream是继承FilterInputStream类,实现进度得回调;

    问题的表现:在混淆中,上传文件时就会报这个问题;不混淆则一直没有没有问题;

    解决:

    1.一开始被这个问题领向错误的方向;因为是混淆出问题,不混淆则一直没问题,所以在查混淆是否导致问题这个方向上:到最后添加了所有的类都不混淆的也不能解决问题

    -keep class **{*;}

    2.查看错误的log:貌似是NonRepeatableRequestException是不可重读的问题,

    用filebody不好替换;

    3.用HttpURLConnection替换http client,最后报错如下:

    [html]view plaincopy

    11-25 18:17:41.783 26180-26378/com.cn21.ecloud D/e: Release UploadService:com.cn21.ecloud.netapi.a.m@24817145

    11-25 18:17:41.783 26180-26378/com.cn21.ecloud D/d: Transfer Ex

    java.io.IOException: File descriptor closed

    at libcore.io.Posix.readBytes(Native Method)

    at libcore.io.Posix.read(Posix.java:147)

    at libcore.io.BlockGuardOs.read(BlockGuardOs.java:230)

    at libcore.io.IoBridge.read(IoBridge.java:472)

    at java.io.FileInputStream.read(FileInputStream.java:177)

    at java.io.DataInputStream.read(DataInputStream.java:63)

    at java.io.InputStream.read(InputStream.java:162)

    at java.io.DataInputStream.read(DataInputStream.java:59)

    at com.cn21.ecloud.netapi.a.m.a(SourceFile:145)

    at com.cn21.ecloud.f.j.dY(SourceFile:160)

    at com.cn21.android.b.e.dX(SourceFile:52)

    at com.cn21.android.b.d.run(SourceFile:459)

    at com.cn21.android.b.b.dS(SourceFile:316)

    at com.cn21.android.b.b.a(SourceFile:14)

    at com.cn21.android.b.c.run(SourceFile:62)

    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)

    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)

    at java.lang.Thread.run(Thread.java:818)

    11-25 18:17:41.783 26180-26378/com.cn21.ecloud D/transferLoop: Transfer task:20151124_111841.mp4 stopped

    报文件无效问题;

    检查文件的读方面发现有个getFD(),获取文件的通道;进入FileInputStream这个类构造方法去发现这个stream流需要手动关闭:

    [html]view plaincopy

    /**

    * Constructs a new {@code FileInputStream} that reads from {@code fd}.

    *

    * @param fd

    *            the FileDescriptor from which this stream reads.

    * @throws NullPointerException

    *             if {@code fd} is {@code null}.

    */

    public FileInputStream(FileDescriptor fd) {

    if (fd== null) {

    throw new NullPointerException("fd== null");

    }

    this.fd=fd;

    this.shouldClose=false;

    // Note that we do not call guard.open here because the

    // FileDescriptor is not owned by the stream.

    }

    this.shouldClose = false;这个问题有点大,因此需要最后文件上传完再finally中关闭之前用RandomAccessFile打开的文件的句柄。

    但是这个问题有点怪异,为什么不混淆时就不会出问题?而在混淆过后才能爆出这个问题?

    总结:

    最终问题的表面现在也许不是问题发生的根本原因;因为最后表现出来的问题可能是上一个问题引发的;因此需要往前面走点查查。

    相关文章

      网友评论

          本文标题:android使用appache httpclient混淆后错误

          本文链接:https://www.haomeiwen.com/subject/petmhxtx.html