创建 SSL 套接字时出现 NullPointerException

发布于 2024-11-15 19:07:58 字数 1741 浏览 5 评论 0原文

在我的应用程序中,我通过 SSL 与网络服务进行通信。因为我使用默认情况下 android 不支持的多部分实体,所以我包含了以下库:

  • httpclient-4.1.1.jar
  • httpcore-4.1.jar
  • httpmime-4.1.1.jar

服务器使用由支持的机构签名的证书安卓。但这适用于大多数设备。今天,我的一位用户(Android 2.2 Motorola Defy)向我发送了一份日志,其中包含以下内容:

W/System.err( 2328): Caused by: java.lang.NullPointerException
W/System.err( 2328): at org.apache.harmony.xnet.provider.jsse.OpenSSLSocketFactoryImpl.createSocket(OpenSSLSocketFactoryImpl.java:83)
W/System.err( 2328): at org.apache.http.conn.ssl.SSLSocketFactory.createSocket(SSLSocketFactory.java:375)
W/System.err( 2328): at org.apache.http.impl.conn.DefaultClientConnectionOperator.openConnection(DefaultClientConnectionOperator.java:168)
W/System.err( 2328): at org.apache.http.impl.conn.AbstractPoolEntry.open(AbstractPoolEntry.java:164)
W/System.err( 2328): at org.apache.http.impl.conn.AbstractPooledConnAdapter.open(AbstractPooledConnAdapter.java:119)
W/System.err( 2328): at org.apache.http.impl.client.DefaultRequestDirector.execute(DefaultRequestDirector.java:352)
W/System.err( 2328): at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:555)
W/System.err( 2328): at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:487)
W/System.err( 2328): at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:465)
W/System.err( 2328): at my.api.Client.sendRequest(Client.java)
...

我无法在我的设备上重现此情况,并且我不知道为什么会发生这种情况。我查看了 OpenSSLSocketFactoryImpl 的源代码,发现 NullPointerException 的唯一来源是因为 sslParametersnull。您知道我可以在代码中做什么来解决此异常吗?

如果您不知道如何解决问题,但知道该向向我发送日志的用户询问什么,也请给出答案。 我已经问过他,当他尝试通过 https 访问网站时,他的浏览器是否显示错误消息。我收到回复后会立即将其附在此处。

In my app I'm communicating with an webservice over SSL. Because I use a multipart entity which is not supported by android by default I included the following libraries:

  • httpclient-4.1.1.jar
  • httpcore-4.1.jar
  • httpmime-4.1.1.jar

The server uses a certificate signed by an authority supported by android. This works on most devices though. Today one of my users (Android 2.2 Motorola Defy) sent me a log which contains the following:

W/System.err( 2328): Caused by: java.lang.NullPointerException
W/System.err( 2328): at org.apache.harmony.xnet.provider.jsse.OpenSSLSocketFactoryImpl.createSocket(OpenSSLSocketFactoryImpl.java:83)
W/System.err( 2328): at org.apache.http.conn.ssl.SSLSocketFactory.createSocket(SSLSocketFactory.java:375)
W/System.err( 2328): at org.apache.http.impl.conn.DefaultClientConnectionOperator.openConnection(DefaultClientConnectionOperator.java:168)
W/System.err( 2328): at org.apache.http.impl.conn.AbstractPoolEntry.open(AbstractPoolEntry.java:164)
W/System.err( 2328): at org.apache.http.impl.conn.AbstractPooledConnAdapter.open(AbstractPooledConnAdapter.java:119)
W/System.err( 2328): at org.apache.http.impl.client.DefaultRequestDirector.execute(DefaultRequestDirector.java:352)
W/System.err( 2328): at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:555)
W/System.err( 2328): at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:487)
W/System.err( 2328): at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:465)
W/System.err( 2328): at my.api.Client.sendRequest(Client.java)
...

I can't reproduce this on my devices and I have no clue why this happens. I looked into the source code of OpenSSLSocketFactoryImpl and the only point where the NullPointerException can come from is because sslParameters is null. Do you have any idea what I can do in my code to work around this exception?

If you don't know how to solve the problem but have an idea what to ask the user who sent the log to me, please also place an answer.
I already asked him whether his browser shows error messages when he tries to access a website over https. I will append the reply here as soon as I received it.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

迷爱 2024-11-22 19:07:58

回溯并不完全匹配,但如果您的用户使用代理服务器,您可能想查看您的 HttpClient 版本是否修复了此错误:http://code.google.com/p/android/issues/detail?id=5255

The traceback isn't an exact match but if your user is using a proxy server you might want to see if your version of HttpClient has the fix for this bug: http://code.google.com/p/android/issues/detail?id=5255

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文