解析CSV行后出现SSLProtocolException

时间:2013-10-01 12:34:46

标签: android ssl bufferedreader android-2.3-gingerbread

我通过SSL连接通过简单的HTTP/GET请求将一组CSV行下载到我的Android设备。在我们切换到新服务器(Debian 6 - > Debian 7)之前,这就像一个魅力,这可能是服务器证书的问题,但我不这么认为,因为下载开始并在此之前解析大约700篇文章异常抛出.readLine()

(请注意,下载已经在Android ICS(4. *)上测试过并且没有任何问题,似乎只影响Android< = 2.3。)

Read error: ssl=0x35e700: Failure in SSL library, usually a protocol error
javax.net.ssl.SSLProtocolException: Read error: ssl=0x35e700: Failure in SSL library, usually a protocol error
    at org.apache.harmony.xnet.provider.jsse.NativeCrypto.SSL_read(Native Method)
    at org.apache.harmony.xnet.provider.jsse.OpenSSLSocketImpl$SSLInputStream.read(OpenSSLSocketImpl.java:788)
    at org.apache.http.impl.io.AbstractSessionInputBuffer.fillBuffer(AbstractSessionInputBuffer.java:103)
    at org.apache.http.impl.io.AbstractSessionInputBuffer.read(AbstractSessionInputBuffer.java:134)
    at org.apache.http.impl.io.ChunkedInputStream.read(ChunkedInputStream.java:161)
    at org.apache.http.conn.EofSensorInputStream.read(EofSensorInputStream.java:159)
    at java.io.InputStreamReader.read(InputStreamReader.java:255)
    at java.io.BufferedReader.fillBuf(BufferedReader.java:128)
    at java.io.BufferedReader.readLine(BufferedReader.java:357)
    at xx.xxxxx.services.ArticlesSync.doInBackground(ArticlesSync.java:155)
    at xx.xxxxx.services.ArticlesSync.doInBackground(ArticlesSync.java:26)
    at android.os.AsyncTask$2.call(AsyncTask.java:185)
    at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:306)
    at java.util.concurrent.FutureTask.run(FutureTask.java:138)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1088)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:581)
    at java.lang.Thread.run(Thread.java:1019)

|

InputStream inputStream = response.getContent();
BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(inputStream));

String currentLine = null;
SQLArticleManager articles = SQLArticleManager.createArticles();
while ((currentLine = bufferedReader.readLine()) != null)
{
    if (!progressDialog.isShowing())
    {
        return ERROR_ABORTED;
    }

    String[] data = currentLine.split("`");

    if (data.length == 4)
    {
        articles.addArticle(data[0], data[1], data[2], Float.parseFloat(data[3]));
    }

    rowsRead++;
    publishProgress(createProgress((int) (rowsRead * 100 / rows), ""));
}

我在这里做错了吗?可能是因为某处的超时?

1 个答案:

答案 0 :(得分:1)

很抱歉成为坏消息的持有者,但这是一个已知的Android错误,影响版本2.2-2.3.3(API级别9和10)。 See this bug以及this bug了解更多详情。

有一个further discussion文件证明这可能是关于根CA的问题,但是那里的第二个链接与这些数据冲突,所以我不相信这种情况。

我认为有用(虽然我没有嘲笑快速验证样本)是明确使用4k缓冲区和getInputStream(),即

private static final int BUFFER_SIZE = 4096;

希望有所帮助。