gpt4 book ai didi

java - Android 查询 - 随机 SSLExceptions

转载 作者:太空宇宙 更新时间:2023-11-03 10:52:18 26 4
gpt4 key购买 nike

我正在使用 Android-Query 进行 HTTP 调用,并且不断收到随机的 SSLExceptions,如下所示:

AQuery(7746): javax.net.ssl.SSLException: Read error: ssl=0x19d3c0: I/O error during system call, Connection reset by peer
AQuery(7746): at org.apache.harmony.xnet.provider.jsse.NativeCrypto.SSL_read(Native Method)
AQuery(7746): at org.apache.harmony.xnet.provider.jsse.OpenSSLSocketImpl$SSLInputStream.read(OpenSSLSocketImpl.java:801)
AQuery(7746): at org.apache.http.impl.io.AbstractSessionInputBuffer.fillBuffer(AbstractSessionInputBuffer.java:103)
AQuery(7746): at org.apache.http.impl.io.AbstractSessionInputBuffer.readLine(AbstractSessionInputBuffer.java:191)
AQuery(7746): at org.apache.http.impl.conn.DefaultResponseParser.parseHead(DefaultResponseParser.java:82)
AQuery(7746): at org.apache.http.impl.io.AbstractMessageParser.parse(AbstractMessageParser.java:174)
AQuery(7746): at org.apache.http.impl.AbstractHttpClientConnection.receiveResponseHeader(AbstractHttpClientConnection.java:180)
AQuery(7746): at org.apache.http.impl.conn.DefaultClientConnection.receiveResponseHeader(DefaultClientConnection.java:235)
AQuery(7746): at org.apache.http.impl.conn.AbstractClientConnAdapter.receiveResponseHeader(AbstractClientConnAdapter.java:259)
AQuery(7746): at org.apache.http.protocol.HttpRequestExecutor.doReceiveResponse(HttpRequestExecutor.java:279)
AQuery(7746): at org.apache.http.protocol.HttpRequestExecutor.execute(HttpRequestExecutor.java:121)
AQuery(7746): at org.apache.http.impl.client.DefaultRequestDirector.execute(DefaultRequestDirector.java:428)
AQuery(7746): at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:555)
AQuery(7746): at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:487)
AQuery(7746): at com.androidquery.callback.AbstractAjaxCallback.httpDo(AbstractAjaxCallback.java:1328)
AQuery(7746): at com.androidquery.callback.AbstractAjaxCallback.httpGet(AbstractAjaxCallback.java:1207)
AQuery(7746): at com.androidquery.callback.AbstractAjaxCallback.network(AbstractAjaxCallback.java:1133)
AQuery(7746): at com.androidquery.callback.AbstractAjaxCallback.networkWork(AbstractAjaxCallback.java:986)
AQuery(7746): at com.androidquery.callback.AbstractAjaxCallback.backgroundWork(AbstractAjaxCallback.java:933)
AQuery(7746): at com.androidquery.callback.AbstractAjaxCallback.run(AbstractAjaxCallback.java:894)
AQuery(7746): at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1081)
AQuery(7746): at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:574)
AQuery(7746): at java.lang.Thread.run(Thread.java:1020)

它们的出现似乎没有规律可循。它们可能占我打电话时间的 1/6。

下面是我使用 Android-Query ($) 的方式:

//应用创建:

public void onCreate()
{
AQUtility.setExceptionHandler( new UncaughtExceptionHandler() {
public void uncaughtException( Thread thread, Throwable ex )
{
ex.printStackTrace();
}
} );

AQUtility.setDebug( true );

AjaxCallback.setTransformer( new JsonTransformer() );

//set the max number of concurrent network connections, default is 4
AjaxCallback.setNetworkLimit( 8 );

//set the max number of icons (image width <= 50) to be cached in memory, default is 20
BitmapAjaxCallback.setIconCacheLimit( 20 );

//set the max number of images (image width > 50) to be cached in memory, default is 20
BitmapAjaxCallback.setCacheLimit( 40 );

//set the max size of an image to be cached in memory, default is 1600 pixels (ie. 400x400)
BitmapAjaxCallback.setPixelLimit( 480 * 480 );

//set the max size of the memory cache, default is 1M pixels (4MB) (2---)
BitmapAjaxCallback.setMaxPixelLimit( 4000000 );

super.onCreate();
}

//用法//注意:uri =//07-13 17:26:08.040: W/AQuery(7746): get: https://site.com/me/ticker/

$.auth( Security.getAuth( this ) ).ajax( uri, BaseModelListRequest.class, this, "loadAdapterObjectsCallback" );

public void loadAdapterObjectsCallback( String uri, BaseModelListRequest requestData, AjaxStatus status )
{
setProgressBarIndeterminateVisibility( false );
setSupportProgressBarIndeterminateVisibility( false );

if( requestData != null && status.getCode() == 200 )
{
// stuff
}
}

//这是 GETAUTH:

public static synchronized BasicHandle getAuth( Context context )
{
return new BasicHandle( "user", "pass" );
}

//和 JSONTRANSFORMER(使用 jaxson 来编码 json):

public class JsonTransformer implements Transformer
{
public < T > T transform( String url, Class< T > type, String encoding, byte[] data, AjaxStatus status )
{
ObjectMapper mapper = new ObjectMapper();

try
{
return mapper.readValue( new String( data ), type );
}
catch( Exception e )
{
return null;
}
}
}

编辑:这发生在 2.X 和 3.X 上,使用 SSL。禁用 SSL(https -> http)使其工作。

这是另一个异常(exception),使用 SSL:

07-13 22:03:41.454: W/AQuery(2517): javax.net.ssl.SSLException: Not trusted server certificate
07-13 22:03:41.454: W/AQuery(2517): at org.apache.harmony.xnet.provider.jsse.OpenSSLSocketImpl.startHandshake(OpenSSLSocketImpl.java:360)
07-13 22:03:41.454: W/AQuery(2517): at org.apache.http.conn.ssl.AbstractVerifier.verify(AbstractVerifier.java:92)
07-13 22:03:41.454: W/AQuery(2517): at org.apache.http.conn.ssl.SSLSocketFactory.connectSocket(SSLSocketFactory.java:321)
07-13 22:03:41.454: W/AQuery(2517): at org.apache.http.impl.conn.DefaultClientConnectionOperator.openConnection(DefaultClientConnectionOperator.java:140)
07-13 22:03:41.454: W/AQuery(2517): at org.apache.http.impl.conn.AbstractPoolEntry.open(AbstractPoolEntry.java:164)
07-13 22:03:41.454: W/AQuery(2517): at org.apache.http.impl.conn.AbstractPooledConnAdapter.open(AbstractPooledConnAdapter.java:119)
07-13 22:03:41.454: W/AQuery(2517): at org.apache.http.impl.client.DefaultRequestDirector.execute(DefaultRequestDirector.java:348)
07-13 22:03:41.454: W/AQuery(2517): at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:555)
07-13 22:03:41.454: W/AQuery(2517): at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:487)
07-13 22:03:41.454: W/AQuery(2517): at com.androidquery.callback.AbstractAjaxCallback.httpDo(AbstractAjaxCallback.java:1328)
07-13 22:03:41.454: W/AQuery(2517): at com.androidquery.callback.AbstractAjaxCallback.httpGet(AbstractAjaxCallback.java:1207)
07-13 22:03:41.454: W/AQuery(2517): at com.androidquery.callback.AbstractAjaxCallback.network(AbstractAjaxCallback.java:1133)
07-13 22:03:41.454: W/AQuery(2517): at com.androidquery.callback.AbstractAjaxCallback.networkWork(AbstractAjaxCallback.java:986)
07-13 22:03:41.454: W/AQuery(2517): at com.androidquery.callback.AbstractAjaxCallback.backgroundWork(AbstractAjaxCallback.java:933)
07-13 22:03:41.454: W/AQuery(2517): at com.androidquery.callback.AbstractAjaxCallback.run(AbstractAjaxCallback.java:894)
07-13 22:03:41.454: W/AQuery(2517): at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1068)
07-13 22:03:41.454: W/AQuery(2517): at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:561)
07-13 22:03:41.454: W/AQuery(2517): at java.lang.Thread.run(Thread.java:1096)
07-13 22:03:41.454: W/AQuery(2517): Caused by: java.security.cert.CertificateException: java.security.cert.CertPathValidatorException: TrustAnchor for CertPath not found.
07-13 22:03:41.454: W/AQuery(2517): at org.apache.harmony.xnet.provider.jsse.TrustManagerImpl.checkServerTrusted(TrustManagerImpl.java:168)
07-13 22:03:41.454: W/AQuery(2517): at org.apache.harmony.xnet.provider.jsse.OpenSSLSocketImpl.startHandshake(OpenSSLSocketImpl.java:355)
07-13 22:03:41.454: W/AQuery(2517): ... 17 more
07-13 22:03:41.454: W/AQuery(2517): Caused by: java.security.cert.CertPathValidatorException: TrustAnchor for CertPath not found.
07-13 22:03:41.454: W/AQuery(2517): at org.bouncycastle.jce.provider.PKIXCertPathValidatorSpi.engineValidate(PKIXCertPathValidatorSpi.java:149)
07-13 22:03:41.454: W/AQuery(2517): at java.security.cert.CertPathValidator.validate(CertPathValidator.java:211)
07-13 22:03:41.454: W/AQuery(2517): at org.apache.harmony.xnet.provider.jsse.TrustManagerImpl.checkServerTrusted(TrustManagerImpl.java:164)
07-13 22:03:41.454: W/AQuery(2517): ... 18 more

编辑 2:

进一步检查发现错误发生在 Android 2.3.x 设备上。删除协议(protocol)(即 SSL)中的“s”使一切正常。

我之前遇到过 RestTemplate (Spring-Android) 的这个问题,并按照这篇文章的建议修复了它:Self-signed SSL acceptance on Android

但是,我以同样的方式将源代码修改为Android-Query,并没有解决问题。

最佳答案

这个问题已经被问过几次了herehere .此异常似乎是服务器重置连接的结果。我认为除了优雅地处理异常并继续前进之外,您在应用程序代码中无能为力。如果服务器在您的控制之下,则值得检查日志和配置以查看导致连接重置的原因。您或许可以在此处最小化或解决问题。

关于java - Android 查询 - 随机 SSLExceptions,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11478814/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com