Azure 通知中心 (1.1.0) Java 8 兼容性

问题描述 投票:0回答:1

我一直在尝试使用Azure通知中心的最新sdk。 (1.1.0) 在我的遗留 Spring 项目 (4.1.3) 中运行,在 Jboss 7.0 EPA 中,以便能够使用 FCMV1 模板注册设备(因为这是唯一支持 FCMV1 注册的版本)。但是,当我尝试使用 sdk 创建RegistrationId 或更新插入注册(通过 notificationHubClient)时,出现以下异常。该请求会无限循环而不执行此操作。以前有人遇到过这个吗?请提供您尝试解决此问题的任何建议。

public String[] registerAndroidAppToNotificationHub(String deviceId, String notificationHubName,
        String pushNotificationDeviceToken) {

    String[] regIds = "";
    
    try {

        NotificationHub notificationHubClient = new NotificationHub(
                "notHubConnString", notificationHubName);
        
        int i = 0;
        for (NotificationHubRegistrationTemplate androidTemplate : androidNotificationHubRegistrationTemplates) {
            
            String regId = notificationHubClient.createRegistrationId(); //Fails here
            
            Registration reg = new FcmV1TemplateRegistration(regId, pushNotificationDeviceToken,
                    androidTemplate.getTemplate());
            
            Registration registrationResult = notificationHubClient.upsertRegistration(reg);

            regId = registrationResult.getRegistrationId();
             regId[i++] = regId;
        
        }
    } catch (NotificationHubsException e) {
        log.info("Error: " + e);
    }
    

    return regIds;
}

这是异常消息:

09:42:48,486 ERROR [stderr] (httpclient-dispatch-1) Exception in thread "httpclient- 
dispatch-1" java.lang.NoSuchMethodError: 
javax.net.ssl.SSLParameters.setApplicationProtocols([Ljava/lang/String;)V
09:42:48,488 ERROR [stderr] (httpclient-dispatch-1) at  
org.apache.hc.client5.http.ssl.DefaultClientTlsStrategy.applyParameters 
 (DefaultClientTlsStrategy.java:108)
 09:42:48,488 ERROR [stderr] (httpclient-dispatch-1) at 
 org.apache.hc.client5.http.ssl.AbstractClientTlsStrategy.
lambda$upgrade$0(AbstractClientTlsStrategy.java:138)
09:42:48,488 ERROR [stderr] (httpclient-dispatch-1) at 
org.apache.hc.core5.reactor.ssl.SSLIOSession.initialize(SSLIOSession.java:293)
09:42:48,488 ERROR [stderr] (httpclient-dispatch-1) at org.apache.hc.core5.reactor.ssl.SSLIOSession.beginHandshake(SSLIOSession.java:268)
09:42:48,489 ERROR [stderr] (httpclient-dispatch-1) at org.apache.hc.core5.reactor.InternalDataChannel.startTls(InternalDataChannel.java:258)
09:42:48,489 ERROR [stderr] (httpclient-dispatch-1) at org.apache.hc.client5.http.ssl.AbstractClientTlsStrategy.upgrade(AbstractClientTlsStrategy.java:111)
09:42:48,489 ERROR [stderr] (httpclient-dispatch-1) at org.apache.hc.client5.http.ssl.DefaultClientTlsStrategy.upgrade(DefaultClientTlsStrategy.java:48)
09:42:48,489 ERROR [stderr] (httpclient-dispatch-1) at org.apache.hc.core5.http2.nio.pool.H2ConnPool$1.completed(H2ConnPool.java:117)
09:42:48,490 ERROR [stderr] (httpclient-dispatch-1) at org.apache.hc.core5.http2.nio.pool.H2ConnPool$1.completed(H2ConnPool.java:110)
09:42:48,490 ERROR [stderr] (httpclient-dispatch-1) at org.apache.hc.core5.concurrent.BasicFuture.completed(BasicFuture.java:123)
09:42:48,490 ERROR [stderr] (httpclient-dispatch-1) at org.apache.hc.core5.concurrent.ComplexFuture.completed(ComplexFuture.java:72)
09:42:48,490 ERROR [stderr] (httpclient-dispatch-1) at org.apache.hc.client5.http.impl.nio.MultihomeIOSessionRequester$2$1.completed(MultihomeIOSessionRequester.java:150)
09:42:48,490 ERROR [stderr] (httpclient-dispatch-1) at org.apache.hc.client5.http.impl.nio.MultihomeIOSessionRequester$2$1.completed(MultihomeIOSessionRequester.java:142)
09:42:48,490 ERROR [stderr] (httpclient-dispatch-1) at org.apache.hc.core5.concurrent.BasicFuture.completed(BasicFuture.java:123)
09:42:48,491 ERROR [stderr] (httpclient-dispatch-1) at org.apache.hc.core5.reactor.IOSessionRequest.completed(IOSessionRequest.java:73)
09:42:48,491 ERROR [stderr] (httpclient-dispatch-1) at org.apache.hc.core5.reactor.InternalConnectChannel.onIOEvent(InternalConnectChannel.java:75)
09:42:48,491 ERROR [stderr] (httpclient-dispatch-1) at org.apache.hc.core5.reactor.InternalChannel.handleIOEvent(InternalChannel.java:51)
09:42:48,492 ERROR [stderr] (httpclient-dispatch-1) at org.apache.hc.core5.reactor.SingleCoreIOReactor.processEvents(SingleCoreIOReactor.java:178)
09:42:48,492 ERROR [stderr] (httpclient-dispatch-1) at org.apache.hc.core5.reactor.SingleCoreIOReactor.doExecute(SingleCoreIOReactor.java:127)
09:42:48,494 ERROR [stderr] (httpclient-dispatch-1) at org.apache.hc.core5.reactor.AbstractSingleCoreIOReactor.execute(AbstractSingleCoreIOReactor.java:86)
09:42:48,494 ERROR [stderr] (httpclient-dispatch-1) at org.apache.hc.core5.reactor.IOReactorWorker.run(IOReactorWorker.java:44)
azure azure-notificationhub
1个回答
0
投票

NoSuchMethodError: javax.net.ssl.SSLParameters.setApplicationProtocols([Ljava/lang/String;)V
错误通常是由不兼容的
javax.net.ssl
API版本引起的。此方法
setApplicationProtocols
是在 Java 9 中引入的,表明 Azure 通知中心 SDK(或其依赖项之一)正在使用较新的 SSL/TLS 功能,而这些功能在 JBoss 7.0 EPA 环境中运行时不可用。 Java 8 或更早版本。

  • 您可以保留现有的Java版本(Java 8)和JBoss 7.0 EPA,而不必担心升级它们,这对于遗留系统很重要。

  • 通过将 HTTP 客户端降级到 4.x (与 Java 8 完全兼容),避免与当前 Java 版本中不可用的 SSL/TLS 方法相关的问题。

更新

pom.xml
以添加 Apache HTTP Client 4.x(与 Java 8 兼容)并排除 Apache HTTP Client 5.x(需要 Java 9 功能)。

<dependency>
    <groupId>org.apache.httpcomponents</groupId>
    <artifactId>httpclient</artifactId>
    <version>4.5.13</version> <!-- Compatible with Java 8 -->
</dependency>

<dependency>
    <groupId>com.azure</groupId>
    <artifactId>azure-notificationhubs</artifactId>
    <version>1.1.0</version>
    <exclusions>
        <exclusion>
            <groupId>org.apache.httpcomponents.client5</groupId>
            <artifactId>httpclient5</artifactId>
        </exclusion>
    </exclusions>
</dependency>

进行上述更改后,测试了注册和通知功能。解决了所有与 SSL 相关的错误和无限循环,并能够使用 FCMv1 注册设备。

enter image description here

© www.soinside.com 2019 - 2024. All rights reserved.