GitHub version

JPush API Java Library

Github 源码

概述

这是 JPush REST API 的 Java 版本封装开发包,是由极光推送官方提供的,一般支持最新的 API 功能。

对应的 REST API 文档:REST API - Push, REST API - Report.

本开发包 Javadoc:API Docs

版本更新:Release页面。下载更新请到这里。

非常欢迎各位开发者提交代码,贡献一份力量,review过有效的代码将会合入本项目。

安装

maven 方式

将下边的依赖条件放到你项目的 maven pom.xml 文件里。v3.3.10 为例,最新版本请看Release页面

  1. <dependency>
  2. <groupId>cn.jpush.api</groupId>
  3. <artifactId>jpush-client</artifactId>
  4. <version>3.3.10</version>
  5. </dependency>

jar 包方式

请到 Release页面下载相应版本的发布包。

依赖包

其中 slf4j 可以与 logback, log4j, commons-logging 等日志框架一起工作,可根据你的需要配置使用。

如果使用 Maven 构建项目,则需要在你的项目 pom.xml 里增加:

  1. <dependency>
  2. <groupId>cn.jpush.api</groupId>
  3. <artifactId>jiguang-common</artifactId>
  4. <version>1.1.4</version>
  5. </dependency>
  6. <dependency>
  7. <groupId>io.netty</groupId>
  8. <artifactId>netty-all</artifactId>
  9. <version>4.1.6.Final</version>
  10. <scope>compile</scope>
  11. </dependency>
  12. <dependency>
  13. <groupId>com.google.code.gson</groupId>
  14. <artifactId>gson</artifactId>
  15. <version>2.3</version>
  16. </dependency>
  17. <dependency>
  18. <groupId>org.slf4j</groupId>
  19. <artifactId>slf4j-api</artifactId>
  20. <version>1.7.7</version>
  21. </dependency>
  22. <!-- For log4j -->
  23. <dependency>
  24. <groupId>org.slf4j</groupId>
  25. <artifactId>slf4j-log4j12</artifactId>
  26. <version>1.7.7</version>
  27. </dependency>
  28. <dependency>
  29. <groupId>log4j</groupId>
  30. <artifactId>log4j</artifactId>
  31. <version>1.2.17</version>
  32. </dependency>

如果不使用 Maven 构建项目,则项目 libs/ 目录下有依赖的 jar 可复制到你的项目里去。

编译源码

如果开发者想基于本项目做一些扩展的开发,或者想了解本项目源码,可以参考此章,否则可略过此章。

导入本项目

  • 可以采用 git clone https://github.com/jpush/jpush-api-java-client.git jpush-api-src 命令下载源码
  • 如果不使用git,请到Release页面下载源码包并解压
  • 采用eclipse导入下载的源码工程,推荐采用maven的方式,方便依赖包的管理
  • 假如采用导入普通项目的方式,项目报错,检查Build Path,Libraries
  • 依赖jar包都在libs目录下可以找到,没有加入的请添加到Build Path,Libraries
  • 默认采用了log4j做日志框架,开发者可根据自己需求替换logback、commons-logging等日志框架
  • 极个别情况下,如果test目录报错,请手动添加test的依赖jar包mockwebserver-2.0.0.jar、okhttp-2.0.0.jar、okio-1.0.0.jar
  • 开发者需要注意,将本项目的编码格式设置为UTF-8

构建本项目

可以用 Eclipse 类 IDE 导出 jar 包。建议直接使用 maven,执行命令:

  1. mvn package

自动化测试

在项目目录下执行命令:

  1. mvn test

使用样例

如果使用 NettyHttpClient(v3.2.15 版本新增),需要在响应返回后手动调用一下 NettyHttpClient 中的 close 方法,否则进程不会退出。代码示例:

  1. ...
  2. try {
  3. PushResult result = jpushClient.sendPush(payload);
  4. LOG.info("Got result - " + result);
  5. Thread.sleep(5000);
  6. // 请求结束后,调用 NettyHttpClient 中的 close 方法,否则进程不会退出。
  7. jpushClient.close();
  8. } catch(InterruptedException e) {
  9. e.printStackTrace();
  10. }

3.2.17 版本后,在 PushClient 中添加了 setHttpClient(IHttpClient client) 方法,用户可以自由切换 ApacheHttpClient,NettyHttpClient 或是 NativeHttpClient。

推送样例

以下片断来自项目代码里的文件:example / cn.jpush.api.examples.PushExample
  1. JPushClient jpushClient = new JPushClient(MASTER_SECRET, APP_KEY, null, ClientConfig.getInstance());
  2. // For push, all you need do is to build PushPayload object.
  3. PushPayload payload = buildPushObject_all_all_alert();
  4. try {
  5. PushResult result = jpushClient.sendPush(payload);
  6. LOG.info("Got result - " + result);
  7. } catch (APIConnectionException e) {
  8. // Connection error, should retry later
  9. LOG.error("Connection error, should retry later", e);
  10. } catch (APIRequestException e) {
  11. // Should review the error, and fix the request
  12. LOG.error("Should review the error, and fix the request", e);
  13. LOG.info("HTTP Status: " + e.getStatus());
  14. LOG.info("Error Code: " + e.getErrorCode());
  15. LOG.info("Error Message: " + e.getErrorMessage());
  16. }

进行推送的关键在于构建一个 PushPayload 对象。以下示例一般的构建对象的用法。

  • 快捷地构建推送对象:所有平台,所有设备,内容为 ALERT 的通知。
  1. public static PushPayload buildPushObject_all_all_alert() {
  2. return PushPayload.alertAll(ALERT);
  3. }
  • 构建推送对象:所有平台,推送目标是别名为 "alias1",通知内容为 ALERT。
  1. public static PushPayload buildPushObject_all_alias_alert() {
  2. return PushPayload.newBuilder()
  3. .setPlatform(Platform.all())
  4. .setAudience(Audience.alias("alias1"))
  5. .setNotification(Notification.alert(ALERT))
  6. .build();
  7. }
  • 构建推送对象:平台是 Android,目标是 tag 为 "tag1" 的设备,内容是 Android 通知 ALERT,并且标题为 TITLE。
  1. public static PushPayload buildPushObject_android_tag_alertWithTitle() {
  2. return PushPayload.newBuilder()
  3. .setPlatform(Platform.android())
  4. .setAudience(Audience.tag("tag1"))
  5. .setNotification(Notification.android(ALERT, TITLE, null))
  6. .build();
  7. }
  • 构建推送对象:平台是 iOS,推送目标是 "tag1", "tag_all" 的交集,推送内容同时包括通知与消息 - 通知信息是 ALERT,角标数字为 5,通知声音为 "happy",并且附加字段 from = "JPush";消息内容是 MSG_CONTENT。通知是 APNs 推送通道的,消息是 JPush 应用内消息通道的。APNs 的推送环境是“生产”(如果不显式设置的话,Library 会默认指定为开发)
  1. public static PushPayload buildPushObject_ios_tagAnd_alertWithExtrasAndMessage() {
  2. return PushPayload.newBuilder()
  3. .setPlatform(Platform.ios())
  4. .setAudience(Audience.tag_and("tag1", "tag_all"))
  5. .setNotification(Notification.newBuilder()
  6. .addPlatformNotification(IosNotification.newBuilder()
  7. .setAlert(ALERT)
  8. .setBadge(5)
  9. .setSound("happy")
  10. .addExtra("from", "JPush")
  11. .build())
  12. .build())
  13. .setMessage(Message.content(MSG_CONTENT))
  14. .setOptions(Options.newBuilder()
  15. .setApnsProduction(true)
  16. .build())
  17. .build();
  18. }
  • 构建推送对象:平台是 Andorid 与 iOS,推送目标是 ("tag1" 与 "tag2" 的并集)交("alias1" 与 "alias2" 的并集),推送内容是 - 内容为 MSG_CONTENT 的消息,并且附加字段 from = JPush。
  1. public static PushPayload buildPushObject_ios_audienceMore_messageWithExtras() {
  2. return PushPayload.newBuilder()
  3. .setPlatform(Platform.android_ios())
  4. .setAudience(Audience.newBuilder()
  5. .addAudienceTarget(AudienceTarget.tag("tag1", "tag2"))
  6. .addAudienceTarget(AudienceTarget.alias("alias1", "alias2"))
  7. .build())
  8. .setMessage(Message.newBuilder()
  9. .setMsgContent(MSG_CONTENT)
  10. .addExtra("from", "JPush")
  11. .build())
  12. .build();
  13. }
  • 构建推送对象:推送内容包含SMS信息
  1. public static void testSendWithSMS() {
  2. JPushClient jpushClient = new JPushClient(masterSecret, appKey);
  3. try {
  4. SMS sms = SMS.newBuilder()
  5. .setDelayTime(1000)
  6. .setTempID(2000)
  7. .addPara("Test", 1)
  8. .build();
  9. PushResult result = jpushClient.sendAndroidMessageWithAlias("Test SMS", "test sms", sms, "alias1");
  10. LOG.info("Got result - " + result);
  11. } catch (APIConnectionException e) {
  12. LOG.error("Connection error. Should retry later. ", e);
  13. } catch (APIRequestException e) {
  14. LOG.error("Error response from JPush server. Should review and fix it. ", e);
  15. LOG.info("HTTP Status: " + e.getStatus());
  16. LOG.info("Error Code: " + e.getErrorCode());
  17. LOG.info("Error Message: " + e.getErrorMessage());
  18. }
  19. }

统计获取样例

以下片断来自项目代码里的文件:example / cn.jpush.api.examples.ReportsExample
  1. JPushClient jpushClient = new JPushClient(masterSecret, appKey);
  2. try {
  3. ReceivedsResult result = jpushClient.getReportReceiveds("1942377665");
  4. LOG.debug("Got result - " + result);
  5. } catch (APIConnectionException e) {
  6. // Connection error, should retry later
  7. LOG.error("Connection error, should retry later", e);
  8. } catch (APIRequestException e) {
  9. // Should review the error, and fix the request
  10. LOG.error("Should review the error, and fix the request", e);
  11. LOG.info("HTTP Status: " + e.getStatus());
  12. LOG.info("Error Code: " + e.getErrorCode());
  13. LOG.info("Error Message: " + e.getErrorMessage());
  14. }

Tag/Alias 样例

以下片断来自项目代码里的文件:example / cn.jpush.api.examples.DeviceExample
  • 获取Tag Alias
  1. try {
  2. TagAliasResult result = jpushClient.getDeviceTagAlias(REGISTRATION_ID1);
  3. LOG.info(result.alias);
  4. LOG.info(result.tags.toString());
  5. } catch (APIConnectionException e) {
  6. LOG.error("Connection error. Should retry later. ", e);
  7. } catch (APIRequestException e) {
  8. LOG.error("Error response from JPush server. Should review and fix it. ", e);
  9. LOG.info("HTTP Status: " + e.getStatus());
  10. LOG.info("Error Code: " + e.getErrorCode());
  11. LOG.info("Error Message: " + e.getErrorMessage());
  12. }
  • 绑定手机号
  1. try {
  2. DefaultResult result = jpushClient.bindMobile(REGISTRATION_ID1, "13000000000");
  3. LOG.info("Got result " + result);
  4. } catch (APIConnectionException e) {
  5. LOG.error("Connection error. Should retry later. ", e);
  6. } catch (APIRequestException e) {
  7. LOG.error("Error response from JPush server. Should review and fix it. ", e);
  8. LOG.info("HTTP Status: " + e.getStatus());
  9. LOG.info("Error Code: " + e.getErrorCode());
  10. LOG.info("Error Message: " + e.getErrorMessage());
  11. }

Schedule 样例

以下片断来自项目代码里的文件:example / cn.jpush.api.examples.ScheduleExample
  1. JPushClient jpushClient = new JPushClient(masterSecret, appKey);
  2. String name = "test_schedule_example";
  3. String time = "2016-07-30 12:30:25";
  4. PushPayload push = PushPayload.alertAll("test schedule example.");
  5. try {
  6. ScheduleResult result = jpushClient.createSingleSchedule(name, time, push);
  7. LOG.info("schedule result is " + result);
  8. } catch (APIConnectionException e) {
  9. LOG.error("Connection error. Should retry later. ", e);
  10. } catch (APIRequestException e) {
  11. LOG.error("Error response from JPush server. Should review and fix it. ", e);
  12. LOG.info("HTTP Status: " + e.getStatus());
  13. LOG.info("Error Code: " + e.getErrorCode());
  14. LOG.info("Error Message: " + e.getErrorMessage());
  15. }

Custom Client 样例

以下片断来自项目代码里面的文件:example / cn.jpush.api.examples.ClientExample
  • 配置的SSLVersion表示指定至少支持的协议版本,也可能支持其他多个协议版本,最终支持的协议版本列表取决于JRE和运行环境
  1. public static void testCustomClient() {
  2. ClientConfig config = ClientConfig.getInstance();
  3. config.setMaxRetryTimes(5);
  4. config.setConnectionTimeout(10 * 1000); // 10 seconds
  5. config.setSSLVersion("TLSv1.1"); // JPush server supports SSLv3, TLSv1, TLSv1.1, TLSv1.2
  6. JPushClient jPushClient = new JPushClient(masterSecret, appKey, null, config);
  7. }
  8. public static void testCustomPushClient() {
  9. ClientConfig config = ClientConfig.getInstance();
  10. config.setApnsProduction(false); // development env
  11. config.setTimeToLive(60 * 60 * 24); // one day
  12. // config.setGlobalPushSetting(false, 60 * 60 * 24); // development env, one day
  13. JPushClient jPushClient = new JPushClient(masterSecret, appKey, null, config); // JPush client
  14. // PushClient pushClient = new PushClient(masterSecret, appKey, null, config); // push client only
  15. }

Weblogic 使用Java SDK

Weblogic在使用jpush-api-java-client时需要注意的一些事项。

注意事项

本文档基于weblogic 10.3.6 版本,12版本请自己对应配置路径。

极个别时候,证书会有版本升级等情况,所以一定要验证当前使用的证书和官方证书的指纹是否一致。

Weblogic console 设置

  • 【主机名验证】设置为无,否则默认使用weblogic.security.SSL.HostnameVerifier进行主机名验证,导致Hostname验证失败
    • 配置路径 Weblogic Console > 服务器设置 > SSL > 高级 > 主机名验证
  • 选择【使用 JSSE SSL】,因为Weblogic默认的加密算法和Java标准的加密算法不一样

    • 配置路径 Weblogic Console > 服务器设置 > SSL > 高级 > 使用 JSSE SSL
      证书配置
  • 检查Weblogic使用的信任密钥库的位置

    • 默认使用的文件是 JRE目录下面的 jre\lib\security\cacerts 文件
    • 有些开发者可能会改为自定义的信任密钥库
  • 检查对应的信任库是否包含了Geo Trust的根证书或者Geo Trust SSL二级 证书
    • 举例:keytool -list -keystore cacerts
    • 此过程需要信任库的密码(默认changeit)
    • 如果包含这两个证书中任意一个,调用JPush接口都可以调用通过
  • 如果信任库不包含上述证书,需要导入公钥到对应的信任库

    • 打开jpush.cn,导出公钥(可以是Geo Trust根证书、Geo Trust SSL 或者 *.jpush.cn 三个任意一个,具体导出方法请百度)
    • 将导出的公钥证书导入到步骤1对应的信任库
    • 举例:keytool -import -alias geotrustssl -keystore cacerts -file GeoTrustSSL.cer
    • 此过程需要信任库的密码(默认changeit)
      证书对比方式
  • 执行 keytool -list -keystore mykey.jks 命令列出信任库里的所有公钥,观察对应证书的指纹

  • 检查官网证书,观察对应证书的指纹
  • 比较两个指纹是否一致,如下图所示jpush_weblogic

异常记录

证书错误异常

  1. Can not connect to JPush Server. Please ensure your internet connection is ok.
  2. If the problem persists, please let us know at support@jpush.cn.
  3. javax.net.ssl.SSLHandshakeException: General SSLEngine problem
  4. at com.sun.net.ssl.internal.ssl.Handshaker.checkThrown(Handshaker.java:1015)
  5. at com.sun.net.ssl.internal.ssl.SSLEngineImpl.checkTaskThrown(SSLEngineImpl.java:485)
  6. at com.sun.net.ssl.internal.ssl.SSLEngineImpl.writeAppRecord(SSLEngineImpl.java:1128)
  7. at com.sun.net.ssl.internal.ssl.SSLEngineImpl.wrap(SSLEngineImpl.java:1100)
  8. at javax.net.ssl.SSLEngine.wrap(SSLEngine.java:452)
  9. at weblogic.security.SSL.jsseadapter.JaSSLEngine$1.run(JaSSLEngine.java:68)
  10. at weblogic.security.SSL.jsseadapter.JaSSLEngine.doAction(JaSSLEngine.java:732)
  11. at weblogic.security.SSL.jsseadapter.JaSSLEngine.wrap(JaSSLEngine.java:66)
  12. at weblogic.socket.JSSEFilterImpl.wrapAndWrite(JSSEFilterImpl.java:619)
  13. at weblogic.socket.JSSEFilterImpl.doHandshake(JSSEFilterImpl.java:91)
  14. at weblogic.socket.JSSEFilterImpl.doHandshake(JSSEFilterImpl.java:64)
  15. at weblogic.socket.JSSEFilterImpl.doHandshake(JSSEFilterImpl.java:59)
  16. at weblogic.socket.JSSEFilterImpl.write(JSSEFilterImpl.java:390)
  17. at weblogic.socket.JSSESocket$JSSEOutputStream.write(JSSESocket.java:78)
  18. at java.io.BufferedOutputStream.flushBuffer(BufferedOutputStream.java:65)
  19. at java.io.BufferedOutputStream.flush(BufferedOutputStream.java:123)
  20. at java.io.FilterOutputStream.flush(FilterOutputStream.java:123)
  21. at weblogic.net.http.HttpURLConnection.writeRequests(HttpURLConnection.java:186)
  22. at weblogic.net.http.HttpURLConnection.getOutputStream(HttpURLConnection.java:280)
  23. at cn.jpush.api.common.connection.NativeHttpClient._doRequest(NativeHttpClient.java:153)
  24. at cn.jpush.api.common.connection.NativeHttpClient.doRequest(NativeHttpClient.java:93)
  25. at cn.jpush.api.common.connection.NativeHttpClient.sendPost(NativeHttpClient.java:80)
  26. at cn.jpush.api.push.PushClient.sendPush(PushClient.java:119)
  27. at cn.jpush.api.JPushClient.sendMessageAll(JPushClient.java:362)
  28. at cn.liucy.hello.HelloPush.doPost(HelloPush.java:40)
  29. at cn.liucy.hello.HelloPush.doGet(HelloPush.java:29)
  30. at javax.servlet.http.HttpServlet.service(HttpServlet.java:707)
  31. at javax.servlet.http.HttpServlet.service(HttpServlet.java:820)
  32. at weblogic.servlet.internal.StubSecurityHelper$ServletServiceAction.run(StubSecurityHelper.java:227)
  33. at weblogic.servlet.internal.StubSecurityHelper.invokeServlet(StubSecurityHelper.java:125)
  34. at weblogic.servlet.internal.ServletStubImpl.execute(ServletStubImpl.java:301)
  35. at weblogic.servlet.internal.ServletStubImpl.execute(ServletStubImpl.java:184)
  36. at weblogic.servlet.internal.WebAppServletContext$ServletInvocationAction.wrapRun(WebAppServletContext.java:3732)
  37. at weblogic.servlet.internal.WebAppServletContext$ServletInvocationAction.run(WebAppServletContext.java:3696)
  38. at weblogic.security.acl.internal.AuthenticatedSubject.doAs(AuthenticatedSubject.java:321)
  39. at weblogic.security.service.SecurityManager.runAs(SecurityManager.java:120)
  40. at weblogic.servlet.internal.WebAppServletContext.securedExecute(WebAppServletContext.java:2273)
  41. at weblogic.servlet.internal.WebAppServletContext.execute(WebAppServletContext.java:2179)
  42. at weblogic.servlet.internal.ServletRequestImpl.run(ServletRequestImpl.java:1490)
  43. at weblogic.work.ExecuteThread.execute(ExecuteThread.java:256)
  44. at weblogic.work.ExecuteThread.run(ExecuteThread.java:221)
  45. Caused by: javax.net.ssl.SSLHandshakeException: General SSLEngine problem
  46. at com.sun.net.ssl.internal.ssl.Alerts.getSSLException(Alerts.java:174)
  47. at com.sun.net.ssl.internal.ssl.SSLEngineImpl.fatal(SSLEngineImpl.java:1528)
  48. at com.sun.net.ssl.internal.ssl.Handshaker.fatalSE(Handshaker.java:243)
  49. at com.sun.net.ssl.internal.ssl.Handshaker.fatalSE(Handshaker.java:235)
  50. at com.sun.net.ssl.internal.ssl.ClientHandshaker.serverCertificate(ClientHandshaker.java:1206)
  51. at com.sun.net.ssl.internal.ssl.ClientHandshaker.processMessage(ClientHandshaker.java:136)
  52. at com.sun.net.ssl.internal.ssl.Handshaker.processLoop(Handshaker.java:593)
  53. at com.sun.net.ssl.internal.ssl.Handshaker$1.run(Handshaker.java:533)
  54. at java.security.AccessController.doPrivileged(Native Method)
  55. at com.sun.net.ssl.internal.ssl.Handshaker$DelegatedTask.run(Handshaker.java:952)
  56. at weblogic.socket.JSSEFilterImpl.doTasks(JSSEFilterImpl.java:186)
  57. at weblogic.socket.JSSEFilterImpl.doHandshake(JSSEFilterImpl.java:95)
  58. ... 31 more
  59. Caused by: sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target
  60. at sun.security.validator.PKIXValidator.doBuild(PKIXValidator.java:323)
  61. at sun.security.validator.PKIXValidator.engineValidate(PKIXValidator.java:217)
  62. at sun.security.validator.Validator.validate(Validator.java:218)
  63. at com.sun.net.ssl.internal.ssl.X509TrustManagerImpl.validate(X509TrustManagerImpl.java:126)
  64. at com.sun.net.ssl.internal.ssl.X509TrustManagerImpl.checkServerTrusted(X509TrustManagerImpl.java:209)
  65. at weblogic.security.SSL.jsseadapter.JaTrustManager.checkServerTrusted(JaTrustManager.java:125)
  66. at com.sun.net.ssl.internal.ssl.ClientHandshaker.serverCertificate(ClientHandshaker.java:1198)
  67. ... 38 more
  68. Caused by: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target
  69. at sun.security.provider.certpath.SunCertPathBuilder.engineBuild(SunCertPathBuilder.java:174)
  70. at java.security.cert.CertPathBuilder.build(CertPathBuilder.java:238)
  71. at sun.security.validator.PKIXValidator.doBuild(PKIXValidator.java:318)
  72. ... 44 more

未使用JSSE SSL异常

  1. Can not connect to JPush Server. Please ensure your internet connection is ok.
  2. If the problem persists, please let us know at support@jpush.cn.
  3. javax.net.ssl.SSLKeyException: FATAL Alert:BAD_CERTIFICATE - A corrupt or unuseable certificate was received.
  4. at com.certicom.tls.interfaceimpl.TLSConnectionImpl.fireException(Unknown Source)
  5. at com.certicom.tls.interfaceimpl.TLSConnectionImpl.fireAlertSent(Unknown Source)
  6. at com.certicom.tls.record.handshake.HandshakeHandler.fireAlert(Unknown Source)
  7. at com.certicom.tls.record.handshake.HandshakeHandler.handleHandshakeMessages(Unknown Source)
  8. at com.certicom.tls.record.MessageInterpreter.interpretContent(Unknown Source)
  9. at com.certicom.tls.record.MessageInterpreter.decryptMessage(Unknown Source)
  10. at com.certicom.tls.record.ReadHandler.processRecord(Unknown Source)
  11. at com.certicom.tls.record.ReadHandler.readRecord(Unknown Source)
  12. at com.certicom.tls.record.ReadHandler.readUntilHandshakeComplete(Unknown Source)
  13. at com.certicom.tls.interfaceimpl.TLSConnectionImpl.completeHandshake(Unknown Source)
  14. at com.certicom.tls.record.WriteHandler.write(Unknown Source)
  15. at com.certicom.io.OutputSSLIOStreamWrapper.write(Unknown Source)
  16. at java.io.BufferedOutputStream.flushBuffer(BufferedOutputStream.java:65)
  17. at java.io.BufferedOutputStream.flush(BufferedOutputStream.java:123)
  18. at java.io.FilterOutputStream.flush(FilterOutputStream.java:123)
  19. at weblogic.net.http.HttpURLConnection.writeRequests(HttpURLConnection.java:186)
  20. at weblogic.net.http.HttpURLConnection.getOutputStream(HttpURLConnection.java:280)
  21. at cn.jpush.api.common.connection.NativeHttpClient._doRequest(NativeHttpClient.java:153)
  22. at cn.jpush.api.common.connection.NativeHttpClient.doRequest(NativeHttpClient.java:93)
  23. at cn.jpush.api.common.connection.NativeHttpClient.sendPost(NativeHttpClient.java:80)
  24. at cn.jpush.api.push.PushClient.sendPush(PushClient.java:119)
  25. at cn.jpush.api.JPushClient.sendMessageAll(JPushClient.java:362)
  26. at cn.liucy.hello.HelloPush.doPost(HelloPush.java:40)
  27. at cn.liucy.hello.HelloPush.doGet(HelloPush.java:29)
  28. at javax.servlet.http.HttpServlet.service(HttpServlet.java:707)
  29. at javax.servlet.http.HttpServlet.service(HttpServlet.java:820)
  30. at weblogic.servlet.internal.StubSecurityHelper$ServletServiceAction.run(StubSecurityHelper.java:227)
  31. at weblogic.servlet.internal.StubSecurityHelper.invokeServlet(StubSecurityHelper.java:125)
  32. at weblogic.servlet.internal.ServletStubImpl.execute(ServletStubImpl.java:301)
  33. at weblogic.servlet.internal.ServletStubImpl.execute(ServletStubImpl.java:184)
  34. at weblogic.servlet.internal.WebAppServletContext$ServletInvocationAction.wrapRun(WebAppServletContext.java:3732)
  35. at weblogic.servlet.internal.WebAppServletContext$ServletInvocationAction.run(WebAppServletContext.java:3696)
  36. at weblogic.security.acl.internal.AuthenticatedSubject.doAs(AuthenticatedSubject.java:321)
  37. at weblogic.security.service.SecurityManager.runAs(SecurityManager.java:120)
  38. at weblogic.servlet.internal.WebAppServletContext.securedExecute(WebAppServletContext.java:2273)
  39. at weblogic.servlet.internal.WebAppServletContext.execute(WebAppServletContext.java:2179)
  40. at weblogic.servlet.internal.ServletRequestImpl.run(ServletRequestImpl.java:1490)
  41. at weblogic.work.ExecuteThread.execute(ExecuteThread.java:256)
  42. at weblogic.work.ExecuteThread.run(ExecuteThread.java:221)
  43. 15/12/09 13:52:03 ERROR hello.HelloPush: Failed to server.
  44. cn.jpush.api.common.resp.APIConnectionException: Connection IO error.
  45. Can not connect to JPush Server. Please ensure your internet connection is ok.
  46. If the problem persists, please let us know at support@jpush.cn.
  47. at cn.jpush.api.common.connection.NativeHttpClient._doRequest(NativeHttpClient.java:242)
  48. at cn.jpush.api.common.connection.NativeHttpClient.doRequest(NativeHttpClient.java:93)
  49. at cn.jpush.api.common.connection.NativeHttpClient.sendPost(NativeHttpClient.java:80)
  50. at cn.jpush.api.push.PushClient.sendPush(PushClient.java:119)
  51. at cn.jpush.api.JPushClient.sendMessageAll(JPushClient.java:362)
  52. at cn.liucy.hello.HelloPush.doPost(HelloPush.java:40)
  53. at cn.liucy.hello.HelloPush.doGet(HelloPush.java:29)
  54. at javax.servlet.http.HttpServlet.service(HttpServlet.java:707)
  55. at javax.servlet.http.HttpServlet.service(HttpServlet.java:820)
  56. at weblogic.servlet.internal.StubSecurityHelper$ServletServiceAction.run(StubSecurityHelper.java:227)
  57. at weblogic.servlet.internal.StubSecurityHelper.invokeServlet(StubSecurityHelper.java:125)
  58. at weblogic.servlet.internal.ServletStubImpl.execute(ServletStubImpl.java:301)
  59. at weblogic.servlet.internal.ServletStubImpl.execute(ServletStubImpl.java:184)
  60. at weblogic.servlet.internal.WebAppServletContext$ServletInvocationAction.wrapRun(WebAppServletContext.java:3732)
  61. at weblogic.servlet.internal.WebAppServletContext$ServletInvocationAction.run(WebAppServletContext.java:3696)
  62. at weblogic.security.acl.internal.AuthenticatedSubject.doAs(AuthenticatedSubject.java:321)
  63. at weblogic.security.service.SecurityManager.runAs(SecurityManager.java:120)
  64. at weblogic.servlet.internal.WebAppServletContext.securedExecute(WebAppServletContext.java:2273)
  65. at weblogic.servlet.internal.WebAppServletContext.execute(WebAppServletContext.java:2179)
  66. at weblogic.servlet.internal.ServletRequestImpl.run(ServletRequestImpl.java:1490)
  67. at weblogic.work.ExecuteThread.execute(ExecuteThread.java:256)
  68. at weblogic.work.ExecuteThread.run(ExecuteThread.java:221)
  69. Caused by: javax.net.ssl.SSLKeyException: FATAL Alert:BAD_CERTIFICATE - A corrupt or unuseable certificate was received.
  70. at com.certicom.tls.interfaceimpl.TLSConnectionImpl.fireException(Unknown Source)
  71. at com.certicom.tls.interfaceimpl.TLSConnectionImpl.fireAlertSent(Unknown Source)
  72. at com.certicom.tls.record.handshake.HandshakeHandler.fireAlert(Unknown Source)
  73. at com.certicom.tls.record.handshake.HandshakeHandler.handleHandshakeMessages(Unknown Source)
  74. at com.certicom.tls.record.MessageInterpreter.interpretContent(Unknown Source)
  75. at com.certicom.tls.record.MessageInterpreter.decryptMessage(Unknown Source)
  76. at com.certicom.tls.record.ReadHandler.processRecord(Unknown Source)
  77. at com.certicom.tls.record.ReadHandler.readRecord(Unknown Source)
  78. at com.certicom.tls.record.ReadHandler.readUntilHandshakeComplete(Unknown Source)
  79. at com.certicom.tls.interfaceimpl.TLSConnectionImpl.completeHandshake(Unknown Source)
  80. at com.certicom.tls.record.WriteHandler.write(Unknown Source)
  81. at com.certicom.io.OutputSSLIOStreamWrapper.write(Unknown Source)
  82. at java.io.BufferedOutputStream.flushBuffer(BufferedOutputStream.java:65)
  83. at java.io.BufferedOutputStream.flush(BufferedOutputStream.java:123)
  84. at java.io.FilterOutputStream.flush(FilterOutputStream.java:123)
  85. at weblogic.net.http.HttpURLConnection.writeRequests(HttpURLConnection.java:186)
  86. at weblogic.net.http.HttpURLConnection.getOutputStream(HttpURLConnection.java:280)
  87. at cn.jpush.api.common.connection.NativeHttpClient._doRequest(NativeHttpClient.java:153)
  88. ... 21 more

Hostname验证失败异常

  1. Can not connect to JPush Server. Please ensure your internet connection is ok.
  2. If the problem persists, please let us know at support@jpush.cn.
  3. javax.net.ssl.SSLKeyException: Hostname verification failed: HostnameVerifier=weblogic.security.utils.SSLWLSHostnameVerifier, hostname=api.jpush.cn.
  4. at weblogic.security.SSL.jsseadapter.JaSSLEngine.doPostHandshake(JaSSLEngine.java:675)
  5. at weblogic.security.SSL.jsseadapter.JaSSLEngine.doAction(JaSSLEngine.java:746)
  6. at weblogic.security.SSL.jsseadapter.JaSSLEngine.unwrap(JaSSLEngine.java:132)
  7. at weblogic.socket.JSSEFilterImpl.unwrap(JSSEFilterImpl.java:505)
  8. at weblogic.socket.JSSEFilterImpl.unwrapAndHandleResults(JSSEFilterImpl.java:448)
  9. at weblogic.socket.JSSEFilterImpl.doHandshake(JSSEFilterImpl.java:80)
  10. at weblogic.socket.JSSEFilterImpl.doHandshake(JSSEFilterImpl.java:64)
  11. at weblogic.socket.JSSEFilterImpl.doHandshake(JSSEFilterImpl.java:59)
  12. at weblogic.socket.JSSEFilterImpl.write(JSSEFilterImpl.java:390)
  13. at weblogic.socket.JSSESocket$JSSEOutputStream.write(JSSESocket.java:78)
  14. at java.io.BufferedOutputStream.flushBuffer(BufferedOutputStream.java:65)
  15. at java.io.BufferedOutputStream.flush(BufferedOutputStream.java:123)
  16. at java.io.FilterOutputStream.flush(FilterOutputStream.java:123)
  17. at weblogic.net.http.HttpURLConnection.writeRequests(HttpURLConnection.java:186)
  18. at weblogic.net.http.HttpURLConnection.getOutputStream(HttpURLConnection.java:280)
  19. at cn.jpush.api.common.connection.NativeHttpClient._doRequest(NativeHttpClient.java:153)
  20. at cn.jpush.api.common.connection.NativeHttpClient.doRequest(NativeHttpClient.java:93)
  21. at cn.jpush.api.common.connection.NativeHttpClient.sendPost(NativeHttpClient.java:80)
  22. at cn.jpush.api.push.PushClient.sendPush(PushClient.java:119)
  23. at cn.jpush.api.JPushClient.sendMessageAll(JPushClient.java:362)
  24. at cn.liucy.hello.HelloPush.doPost(HelloPush.java:40)
  25. at cn.liucy.hello.HelloPush.doGet(HelloPush.java:29)
  26. at javax.servlet.http.HttpServlet.service(HttpServlet.java:707)
  27. at javax.servlet.http.HttpServlet.service(HttpServlet.java:820)
  28. at weblogic.servlet.internal.StubSecurityHelper$ServletServiceAction.run(StubSecurityHelper.java:227)
  29. at weblogic.servlet.internal.StubSecurityHelper.invokeServlet(StubSecurityHelper.java:125)
  30. at weblogic.servlet.internal.ServletStubImpl.execute(ServletStubImpl.java:301)
  31. at weblogic.servlet.internal.ServletStubImpl.execute(ServletStubImpl.java:184)
  32. at weblogic.servlet.internal.WebAppServletContext$ServletInvocationAction.wrapRun(WebAppServletContext.java:3732)
  33. at weblogic.servlet.internal.WebAppServletContext$ServletInvocationAction.run(WebAppServletContext.java:3696)
  34. at weblogic.security.acl.internal.AuthenticatedSubject.doAs(AuthenticatedSubject.java:321)
  35. at weblogic.security.service.SecurityManager.runAs(SecurityManager.java:120)
  36. at weblogic.servlet.internal.WebAppServletContext.securedExecute(WebAppServletContext.java:2273)
  37. at weblogic.servlet.internal.WebAppServletContext.execute(WebAppServletContext.java:2179)
  38. at weblogic.servlet.internal.ServletRequestImpl.run(ServletRequestImpl.java:1490)
  39. at weblogic.work.ExecuteThread.execute(ExecuteThread.java:256)
  40. at weblogic.work.ExecuteThread.run(ExecuteThread.java:221)
  41. 15/12/09 14:27:17 ERROR hello.HelloPush: Failed to server.
  42. cn.jpush.api.common.resp.APIConnectionException: Connection IO error.
  43. Can not connect to JPush Server. Please ensure your internet connection is ok.
  44. If the problem persists, please let us know at support@jpush.cn.
  45. at cn.jpush.api.common.connection.NativeHttpClient._doRequest(NativeHttpClient.java:242)
  46. at cn.jpush.api.common.connection.NativeHttpClient.doRequest(NativeHttpClient.java:93)
  47. at cn.jpush.api.common.connection.NativeHttpClient.sendPost(NativeHttpClient.java:80)
  48. at cn.jpush.api.push.PushClient.sendPush(PushClient.java:119)
  49. at cn.jpush.api.JPushClient.sendMessageAll(JPushClient.java:362)
  50. at cn.liucy.hello.HelloPush.doPost(HelloPush.java:40)
  51. at cn.liucy.hello.HelloPush.doGet(HelloPush.java:29)
  52. at javax.servlet.http.HttpServlet.service(HttpServlet.java:707)
  53. at javax.servlet.http.HttpServlet.service(HttpServlet.java:820)
  54. at weblogic.servlet.internal.StubSecurityHelper$ServletServiceAction.run(StubSecurityHelper.java:227)
  55. at weblogic.servlet.internal.StubSecurityHelper.invokeServlet(StubSecurityHelper.java:125)
  56. at weblogic.servlet.internal.ServletStubImpl.execute(ServletStubImpl.java:301)
  57. at weblogic.servlet.internal.ServletStubImpl.execute(ServletStubImpl.java:184)
  58. at weblogic.servlet.internal.WebAppServletContext$ServletInvocationAction.wrapRun(WebAppServletContext.java:3732)
  59. at weblogic.servlet.internal.WebAppServletContext$ServletInvocationAction.run(WebAppServletContext.java:3696)
  60. at weblogic.security.acl.internal.AuthenticatedSubject.doAs(AuthenticatedSubject.java:321)
  61. at weblogic.security.service.SecurityManager.runAs(SecurityManager.java:120)
  62. at weblogic.servlet.internal.WebAppServletContext.securedExecute(WebAppServletContext.java:2273)
  63. at weblogic.servlet.internal.WebAppServletContext.execute(WebAppServletContext.java:2179)
  64. at weblogic.servlet.internal.ServletRequestImpl.run(ServletRequestImpl.java:1490)
  65. at weblogic.work.ExecuteThread.execute(ExecuteThread.java:256)
  66. at weblogic.work.ExecuteThread.run(ExecuteThread.java:221)
  67. Caused by: javax.net.ssl.SSLKeyException: Hostname verification failed: HostnameVerifier=weblogic.security.utils.SSLWLSHostnameVerifier, hostname=api.jpush.cn.
  68. at weblogic.security.SSL.jsseadapter.JaSSLEngine.doPostHandshake(JaSSLEngine.java:675)
  69. at weblogic.security.SSL.jsseadapter.JaSSLEngine.doAction(JaSSLEngine.java:746)
  70. at weblogic.security.SSL.jsseadapter.JaSSLEngine.unwrap(JaSSLEngine.java:132)
  71. at weblogic.socket.JSSEFilterImpl.unwrap(JSSEFilterImpl.java:505)
  72. at weblogic.socket.JSSEFilterImpl.unwrapAndHandleResults(JSSEFilterImpl.java:448)
  73. at weblogic.socket.JSSEFilterImpl.doHandshake(JSSEFilterImpl.java:80)
  74. at weblogic.socket.JSSEFilterImpl.doHandshake(JSSEFilterImpl.java:64)
  75. at weblogic.socket.JSSEFilterImpl.doHandshake(JSSEFilterImpl.java:59)
  76. at weblogic.socket.JSSEFilterImpl.write(JSSEFilterImpl.java:390)
  77. at weblogic.socket.JSSESocket$JSSEOutputStream.write(JSSESocket.java:78)
  78. at java.io.BufferedOutputStream.flushBuffer(BufferedOutputStream.java:65)
  79. at java.io.BufferedOutputStream.flush(BufferedOutputStream.java:123)
  80. at java.io.FilterOutputStream.flush(FilterOutputStream.java:123)
  81. at weblogic.net.http.HttpURLConnection.writeRequests(HttpURLConnection.java:186)
  82. at weblogic.net.http.HttpURLConnection.getOutputStream(HttpURLConnection.java:280)
  83. at cn.jpush.api.common.connection.NativeHttpClient._doRequest(NativeHttpClient.java:153)
  84. ... 21 more