Netty не может обработать запрос после добавления Firebase Admin 6.12.2 - PullRequest
0 голосов
/ 27 февраля 2020

У меня есть Play Framework 2.5.4 с scala версия 2.11.7 и sbt 0.13, все перестает работать после добавления "com.google.firebase" % "firebase-admin" % "6.12.2" в build.sbt файл

, получая следующую ошибку по запросу

[error] p.c.s.n.PlayRequestHandler - Exception caught in Netty
java.lang.AbstractMethodError: null
    at io.netty.util.ReferenceCountUtil.touch(ReferenceCountUtil.java:77)
    at io.netty.channel.DefaultChannelPipeline.touch(DefaultChannelPipeline.java:116)
    at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:342)
    at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:337)
    at com.typesafe.netty.http.HttpStreamsHandler.channelRead(HttpStreamsHandler.java:129)
    at com.typesafe.netty.http.HttpStreamsServerHandler.channelRead(HttpStreamsServerHandler.java:96)
    at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:359)
    at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:345)
    at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:337)
    at io.netty.handler.codec.MessageToMessageDecoder.channelRead(MessageToMessageDecoder.java:102)

1 Ответ

0 голосов
/ 28 февраля 2020

Если у кого-то возникла такая же проблема, у меня сработало следующее:

добавьте firebase-admin-6.12.2.jar во внешнюю библиотеку и добавьте следующие зависимости в свой build.sbt

"com.google.guava" % "guava" % "28.2-jre",
"com.google.api" % "api-common" % "1.8.1",
"com.google.api-client" % "google-api-client" % "1.30.1",
"com.google.auth" % "google-auth-library-oauth2-http" % "0.20.0"

и следующий код для отправки уведомления с использованием firebase admin

String fcmToken = "";
Message message = Message.builder()
                            .setNotification(new Notification(
                                    title,
                                    context))
                            .setToken(fcmToken)
                            .build();
String response = null;
try {
         response = FirebaseMessaging.getInstance(FirebaseApp.initializeApp(getOptions()))
                                    .send(message);
     } catch (FirebaseMessagingException e) {
       e.printStackTrace();
     }
System.out.println("Successfully sent message: " + response);



FirebaseOptions getOptions() {
    FileInputStream serviceAccount = null;
    FirebaseOptions options =null;
    try {
             serviceAccount = new FileInputStream("conf/projectPrivateKey.json");
        } catch (FileNotFoundException e) {
                e.printStackTrace();
        }


        try {
                 options = new FirebaseOptions.Builder()

                 .setCredentials(GoogleCredentials.fromStream(serviceAccount))

                 .setDatabaseUrl("https://DATABASE_NAME.firebaseio.com")
                            .build();
             } catch (IOException e) {
                    e.printStackTrace();
             }

    return options;
}
...