akkasprayspray-dsl

java.lang.ClassCastException: Cannot cast akka.actor.Status$Success$ to akka.actor.Status$Success


I am facing a weird exception

java.lang.ClassCastException: Cannot cast akka.actor.Status$Success$ to akka.actor.Status$Success
    at java.lang.Class.cast(Class.java:3094) ~[na:1.7.0_45]
    at scala.concurrent.Future$$anonfun$mapTo$1.apply(Future.scala:405) ~[scala-library.jar:na]
    at scala.util.Success$$anonfun$map$1.apply(Try.scala:206) ~[scala-library.jar:na]
    at scala.util.Try$.apply(Try.scala:161) ~[scala-library.jar:na]
    at scala.util.Success.map(Try.scala:206) ~[scala-library.jar:na]

Where the problem is the trailing $ - something like inner class or so ..

My code follows:

  post {
    authenticate(BasicAuth(pifUserPasswordAuthenticator _, realm = "bd pif import api")) {
      user =>
        entity(as[Array[Byte]]) { e =>
          val resp = pifImportService.ask(PifTransactions("storeId","dob",e)).mapTo[akka.actor.Status.Success]
          complete {
            resp
          }
        }
    }
  }

Because of my actor is replying as follows:

  Try(kafkaProducer.send(payload)) match {
    case Success(_) =>
      log.debug(s"$storeId - $dob - sending payload sucessfully sended to kafka")
      sender() ! akka.actor.Status.Success
    case Failure(throwable) =>
      log.debug(s"$storeId - $dob - sending payload attempt failed $throwable")
      sender() ! akka.actor.Status.Failure(throwable)
  }

Am I missing any trick or am I using a wrong name here?

thx


Solution

  • sender() ! akka.actor.Status.Success

    akka.actor.status.Success is a case class requiring one argument. Looks like that you've replied not with a class instance, but with a partially-applied Success.apply(_) function, which is not you've planned to do, I believe:

    case Success(_) =>
      sender() ! akka.actor.Status.Success(storeId)