Netty unable to process request after adding Firebase Admin 6.12.2

198 Views Asked by At

I'm having play framework 2.5.4 with scala version 2.11.7 and sbt 0.13, things stop working after adding "com.google.firebase" % "firebase-admin" % "6.12.2" to build.sbt file

getting following error on request

[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

There are 1 best solutions below

0
Rajat Verma On

If anyone facing the same issue, the following worked for me,

add firebase-admin-6.12.2.jar to external lib and add following dependencies to your 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"

and following code to send notification using 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;
}