2015-09-26 46 views
2

我們的應用程序使用一個使用SSL證書進行保護的WebApi。大多時候一切正常,但是,有時,有以下錯誤應用程序崩潰:Android Spring和SSL的java.lang.StackOverflowError

java.lang.StackOverflowError 
at java.io.FilterInputStream.read(FilterInputStream.java:118) 
at com.android.org.bouncycastle.asn1.DefiniteLengthInputStream.read(DefiniteLengthInputStream.java:74) 
at java.io.FilterInputStream.read(FilterInputStream.java:118) 
at com.android.org.bouncycastle.asn1.DefiniteLengthInputStream.read(DefiniteLengthInputStream.java:74) 
at java.io.FilterInputStream.read(FilterInputStream.java:118) 
at com.android.org.bouncycastle.asn1.DefiniteLengthInputStream.read(DefiniteLengthInputStream.java:74) 
at java.io.FilterInputStream.read(FilterInputStream.java:118) 
at com.android.org.bouncycastle.asn1.DefiniteLengthInputStream.read(DefiniteLengthInputStream.java:74) 
at com.android.org.bouncycastle.util.io.Streams.readFully(Streams.java:49) 
at com.android.org.bouncycastle.util.io.Streams.readFully(Streams.java:40) 
at com.android.org.bouncycastle.asn1.ASN1InputStream.getBuffer(ASN1InputStream.java:384) 
at com.android.org.bouncycastle.asn1.ASN1InputStream.createPrimitiveDERObject(ASN1InputStream.java:447) 
at com.android.org.bouncycastle.asn1.ASN1InputStream.buildObject(ASN1InputStream.java:184) 
at com.android.org.bouncycastle.asn1.ASN1InputStream.readObject(ASN1InputStream.java:272) 
at com.android.org.bouncycastle.asn1.ASN1InputStream.buildEncodableVector(ASN1InputStream.java:193) 
at com.android.org.bouncycastle.asn1.ASN1InputStream.buildDEREncodableVector(ASN1InputStream.java:204) 
at com.android.org.bouncycastle.asn1.ASN1InputStream.buildObject(ASN1InputStream.java:173) 
at com.android.org.bouncycastle.asn1.ASN1InputStream.readObject(ASN1InputStream.java:272) 
at com.android.org.bouncycastle.asn1.ASN1InputStream.buildEncodableVector(ASN1InputStream.java:193) 
at com.android.org.bouncycastle.asn1.ASN1InputStream.buildDEREncodableVector(ASN1InputStream.java:204) 
at com.android.org.bouncycastle.asn1.ASN1InputStream.buildObject(ASN1InputStream.java:173) 
at com.android.org.bouncycastle.asn1.ASN1InputStream.readObject(ASN1InputStream.java:272) 
at com.android.org.bouncycastle.asn1.ASN1InputStream.buildEncodableVector(ASN1InputStream.java:193) 
at com.android.org.bouncycastle.asn1.ASN1InputStream.buildDEREncodableVector(ASN1InputStream.java:204) 
at com.android.org.bouncycastle.asn1.ASN1InputStream.buildObject(ASN1InputStream.java:173) 
at com.android.org.bouncycastle.asn1.ASN1InputStream.readObject(ASN1InputStream.java:272) 
at com.android.org.bouncycastle.asn1.ASN1InputStream.buildEncodableVector(ASN1InputStream.java:193) 
at com.android.org.bouncycastle.asn1.ASN1InputStream.buildDEREncodableVector(ASN1InputStream.java:204) 
at com.android.org.bouncycastle.asn1.ASN1InputStream.buildObject(ASN1InputStream.java:173) 
at com.android.org.bouncycastle.asn1.ASN1InputStream.readObject(ASN1InputStream.java:272) 
at com.android.org.bouncycastle.jce.provider.CertPathValidatorUtilities.getObject(CertPathValidatorUtilities.java:339) 
at com.android.org.bouncycastle.jce.provider.CertPathValidatorUtilities.getExtensionValue(CertPathValidatorUtilities.java:325) 
at com.android.org.bouncycastle.jce.provider.RFC3280CertPathUtilities.processCertD(RFC3280CertPathUtilities.java:1268) 
at com.android.org.bouncycastle.jce.provider.PKIXCertPathValidatorSpi.engineValidate(PKIXCertPathValidatorSpi.java:310) 
at com.sec.android.security.pkix.SecCertPathValidatorSpi.engineValidate(SecCertPathValidatorSpi.java:100) 
at java.security.cert.CertPathValidator.validate(CertPathValidator.java:190) 
at com.android.org.conscrypt.TrustManagerImpl.checkTrusted(TrustManagerImpl.java:295) 
at com.android.org.conscrypt.TrustManagerImpl.checkServerTrusted(TrustManagerImpl.java:202) 
at com.android.org.conscrypt.OpenSSLSocketImpl.verifyCertificateChain(OpenSSLSocketImpl.java:612) 
at com.android.org.conscrypt.NativeCrypto.SSL_do_handshake(Native Method) 
at com.android.org.conscrypt.OpenSSLSocketImpl.startHandshake(OpenSSLSocketImpl.java:406) 
at com.android.okhttp.Connection.upgradeToTls(Connection.java:146) 
at com.android.okhttp.Connection.connect(Connection.java:107) 
at com.android.okhttp.internal.http.HttpEngine.connect(HttpEngine.java:294) 
at com.android.okhttp.internal.http.HttpEngine.sendSocketRequest(HttpEngine.java:255) 
at com.android.okhttp.internal.http.HttpEngine.sendRequest(HttpEngine.java:206) 
at com.android.okhttp.internal.http.HttpURLConnectionImpl.execute(HttpURLConnectionImpl.java:345) 
at com.android.okhttp.internal.http.HttpURLConnectionImpl.connect(HttpURLConnectionImpl.java:89) 
at com.android.okhttp.internal.http.HttpsURLConnectionImpl.connect(HttpsURLConnectionImpl.java:161) 
at org.springframework.http.client.SimpleBufferingClientHttpRequest.org.springframework.http.client.ClientHttpResponse executeInternal(org.springframework.http.HttpHeaders,byte[])(SourceFile:76) 
at org.springframework.http.client.AbstractBufferingClientHttpRequest.org.springframework.http.client.ClientHttpResponse executeInternal(org.springframework.http.HttpHeaders)(SourceFile:48) 
at org.springframework.http.client.AbstractClientHttpRequest.org.springframework.http.client.ClientHttpResponse execute()(SourceFile:84) 
at org.springframework.http.client.InterceptingClientHttpRequest$RequestExecution.org.springframework.http.client.ClientHttpResponse execute(org.springframework.http.HttpRequest,byte[])(SourceFile:91) 
at com.myapplication.webapi.spring.interceptors.IonAuthenticationClientInterceptor.org.springframework.http.client.ClientHttpResponse intercept(org.springframework.http.HttpRequest,byte[],org.springframework.http.client.ClientHttpRequestExecution)(SourceFile:82) 
at org.springframework.http.client.InterceptingClientHttpRequest$RequestExecution.org.springframework.http.client.ClientHttpResponse execute(org.springframework.http.HttpRequest,byte[])(SourceFile:81) 
at org.springframework.http.client.InterceptingClientHttpRequest.org.springframework.http.client.ClientHttpResponse executeInternal(org.springframework.http.HttpHeaders,byte[])(SourceFile:67) 
at org.springframework.http.client.AbstractBufferingClientHttpRequest.org.springframework.http.client.ClientHttpResponse executeInternal(org.springframework.http.HttpHeaders)(SourceFile:48) 

//The stack below repeats about 100 times 
at org.springframework.http.client.AbstractClientHttpRequest.org.springframework.http.client.ClientHttpResponse execute()(SourceFile:84) 
at org.springframework.http.client.InterceptingClientHttpRequest$RequestExecution.org.springframework.http.client.ClientHttpResponse execute(org.springframework.http.HttpRequest,byte[])(SourceFile:91) 
at com.myapplication.webapi.spring.interceptors.IonAuthenticationClientInterceptor.org.springframework.http.client.ClientHttpResponse intercept(org.springframework.http.HttpRequest,byte[],org.springframework.http.client.ClientHttpRequestExecution)(SourceFile:82) 
at org.springframework.http.client.InterceptingClientHttpRequest$RequestExecution.org.springframework.http.client.ClientHttpResponse execute(org.springframework.http.HttpRequest,byte[])(SourceFile:81) 
at org.springframework.http.client.InterceptingClientHttpRequest.org.springframework.http.client.ClientHttpResponse executeInternal(org.springframework.http.HttpHeaders,byte[])(SourceFile:67) 
at org.springframework.http.client.AbstractBufferingClientHttpRequest.org.springframework.http.client.ClientHttpResponse executeInternal(org.springframework.http.HttpHeaders)(SourceFile:48) 
//End of stack that repeats 100 times 

at org.springframework.http.client.InterceptingClientHttpRequest$RequestExecution.org.springframework.http.client.ClientHttpResponse execute(org.springframework.http.HttpRequest,byte[])(SourceFile:91) 
at com.myapplication.webapi.spring.interceptors.IonAuthenticationClientInterceptor.org.springframework.http.client.ClientHttpResponse intercept(org.springframework.http.HttpRequest,byte[],org.springframework.http.client.ClientHttpRequestExecution)(SourceFile:82) 
at org.springframework.http.client.InterceptingClientHttpRequest$RequestExecution.org.springframework.http.client.ClientHttpResponse execute(org.springframework.http.HttpRequest,byte[])(SourceFile:81) 
at org.springframework.http.client.InterceptingClientHttpRequest.org.springframework.http.client.ClientHttpResponse executeInternal(org.springframework.http.HttpHeaders,byte[])(SourceFile:67) 
at org.springframework.http.client.AbstractBufferingClientHttpRequest.org.springframework.http.client.ClientHttpResponse executeInternal(org.springframework.http.HttpHeaders)(SourceFile:48) 
at org.springframework.http.client.AbstractClientHttpRequest.org.springframework.http.client.ClientHttpResponse execute()(SourceFile:84) 
at org.springframework.http.client.InterceptingClientHttpRequest$RequestExecution.org.springframework.http.client.ClientHttpResponse execute(org.springframework.http.HttpRequest,byte[])(SourceFile:91) 
at com.myapplication.webapi.spring.interceptors.IonAuthenticationClientInterceptor.org.springframework.http.client.ClientHttpResponse intercept(org.springframework.http.HttpRequest,byte[],org.springframework.http.client.ClientHttpRequestExecution)(SourceFile:82) 
at org.springframework.http.client.InterceptingClientHttpRequest$RequestExecution.org.springframework.http.client.ClientHttpResponse execute(org.springframework.http.HttpRequest,byte[])(SourceFile:81) 
at org.springframework.http.client.InterceptingClientHttpRequest.org.springframework.http.client.ClientHttpResponse executeInternal(org.springframework.http.HttpHeaders,byte[])(SourceFile:67) 
at org.springframework.http.client.AbstractBufferingClientHttpRequest.org.springframework.http.client.ClientHttpResponse executeInternal(org.springframework.http.HttpHeaders)(SourceFile:48) 
at org.springframework.http.client.AbstractClientHttpRequest.org.springframework.http.client.ClientHttpResponse execute()(SourceFile:84) 
at org.springframework.web.client.RestTemplate.java.lang.Object doExecute(java.net.URI,org.springframework.http.HttpMethod,org.springframework.web.client.RequestCallback,org.springframework.web.client.ResponseExtractor)(SourceFile:536) 
at org.springframework.web.client.RestTemplate.java.lang.Object execute(java.lang.String,org.springframework.http.HttpMethod,org.springframework.web.client.RequestCallback,org.springframework.web.client.ResponseExtractor,java.util.Map)(SourceFile:506) 
at org.springframework.web.client.RestTemplate.org.springframework.http.ResponseEntity exchange(java.lang.String,org.springframework.http.HttpMethod,org.springframework.http.HttpEntity,java.lang.Class,java.util.Map)(SourceFile:455) 
at com.myapplication.webapi.smartclients.SynchronizationClient_.org.springframework.http.ResponseEntity requestUpdateFile(long,long)(SourceFile:95) 
at com.myapplication.services.synchronization.SynchronizationTask$2$1.org.springframework.http.ResponseEntity call()(SourceFile:514) 
at com.myapplication.services.synchronization.SynchronizationTask$2$1.java.lang.Object call()(SourceFile:509) 
at com.myapplication.managers.rest.RestManager$RestRequest.java.lang.Object execute()(SourceFile:110) 
at com.myapplication.managers.rest.RestManager.java.lang.Object executeRequest(java.lang.String,int,com.myapplication.webapi.spring.RestErrorProcessor,java.util.concurrent.Callable)(SourceFile:67) 
at com.myapplication.services.synchronization.SynchronizationTask$2.void run()(SourceFile:506) 
at java.lang.Thread.run(Thread.java:841) 

有不是一個具體的WebAPI調用導致此問題......它已經幾乎所有的WebAPI方法報告可在我們的系統,但正如我之前所說的,在同一臺設備上,大多數情況下它工作得很好。

我也注意到,在我們的web服務服務器上啓用SSL後,發生了這種情況。

有沒有人知道發生了什麼,還有,我怎麼解決這個問題?

回答

0

您可以嘗試增加執行REST調用的線程的堆棧大小。 在Android的主UI線程堆棧大小是有限的,但理論上你可以開始與一個任意大小的新線程(在這種情況下1MB),如下

ThreadGroup group = new ThreadGroup("restAPIgroup"); 
new Thread(group, runnableObject, "YourThreadName", 1024*1024).start(); 
+0

你好卡捷琳娜!非常感謝!我會嘗試你的方法,但是我真的擔心同一段代碼被反覆調用,因爲堆棧跟蹤顯示...我認爲,增加堆棧大小隻會使系統重複這些調用,然後再次失敗... – regisxp

+0

原因可能是你有一個非常複雜的SSL證書,在這種情況下,具有適當大小的堆棧可以解決你的問題。 –

+0

我怎麼知道我的證書是否複雜?它有2048個密鑰長度和兩個中間證書以及根證書。非常感謝! – regisxp