scala - Spray/Akka missing implicit -



scala - Spray/Akka missing implicit -

myservice.scala:33: not find implicit value parameter eh: spray.routing.exceptionhandler

i have run "missing implicit" compilation error using akka, in spray.io code makes http phone call separate back-end server, part of responding http get. code needs import quite lot of spray , akka libraries, it's bit hard figuring whether there may library conflicts causing this, , i'd rather figure how logically trace sort of problem , other cases.

the missing implicit encountered on calling runroute(myroute)

here's code:

import spray.routing._ import akka.actor.actor import akka.actor.actorsystem import spray.http._ import mediatypes._ import akka.io.io import spray.httpx.requestbuilding._ import scala.concurrent.future import spray.can.http import spray.http._ import akka.util.timeout import httpmethods._ import akka.pattern.ask import akka.event.logging import scala.concurrent.duration._ // don't implement our route construction straight in service actor because // want able test independently, without having spin actor class myserviceactor extends actor myservice akka.actor.actorlogging { log.info("starting") // httpservice trait defines 1 abstract member, // connects services environment enclosing actor or test def actorreffactory = context // actor runs our route, add together // other things here, request stream processing // or timeout handling def receive = runroute(myroute) } // trait defines our service behavior independently service actor trait myservice extends httpservice { implicit val system: actorsystem = actorsystem() implicit val timeout: timeout = timeout(15.seconds) import system.dispatcher // implicit execution context //val logger = context.actorselection("/user/logger") val logger = actorreffactory.actorselection("../logger") val myroute = { def forward(): string = { logger ! log("forwarding backend") val response: future[httpresponse] = (io(http) ? get("http:3080//localhost/backend")).mapto[httpresponse] "<html><body><h1>api response after backend processing</h1></body></html>" } path("") { { respondwithmediatype(`text/html`) { // xml marshalled `text/xml` default, override here complete(forward) } } } } }

i wondering what's best way solve this, providing insight how solve similar problems implicits beingness missing, somehow inherently not straightforward track down.

edit: when trying straight pass implicits in @christian's reply below, get:

myservice.scala:35: ambiguous implicit values: both value context in trait actor of type => akka.actor.actorcontext , value scheme in trait myservice of type => akka.actor.actorsystem match expected type akka.actor.actorreffactory routingsettings.default, loggingcontext.fromactorreffactory) ^

not quite sure why beingness specific in @christian's reply leaves room ambiguity compiler...

runroute expects few implicits. missing import:

import spray.routing.rejectionhandler.default

update: think did have problems runroute because supplying implicit parameters explicitly:

runroute(route)(exceptionhandler.default, rejectionhandler.default, context, routingsettings.default, loggingcontext.fromactorreffactory)

update2: prepare lastly error, remove creation of actorsystem (in myservice actor scheme myserviceactor - hence have utilize self type annotation). compiles:

import akka.actor.actor import akka.io.io import spray.httpx.requestbuilding._ import spray.http.mediatypes._ import spray.routing.{routingsettings, rejectionhandler, exceptionhandler, httpservice} import spray.util.loggingcontext import scala.concurrent.future import spray.can.http import spray.http._ import akka.util.timeout import httpmethods._ import akka.pattern.ask import akka.event.logging import scala.concurrent.duration._ // don't implement our route construction straight in service actor because // want able test independently, without having spin actor class myserviceactor extends actor myservice akka.actor.actorlogging { log.info("starting") // httpservice trait defines 1 abstract member, // connects services environment enclosing actor or test implicit def actorreffactory = context // actor runs our route, add together // other things here, request stream processing // or timeout handling def receive = runroute(myroute)(exceptionhandler.default, rejectionhandler.default, context, routingsettings.default, loggingcontext.fromactorreffactory) } // trait defines our service behavior independently service actor trait myservice extends httpservice { this: myserviceactor => implicit val timeout: timeout = timeout(15.seconds) implicit val scheme = context.system //val logger = context.actorselection("/user/logger") val logger = actorreffactory.actorselection("../logger") val myroute = { def forward(): string = { //logger ! log("forwarding backend") val response: future[httpresponse] = (io(http) ? get("http:3080//localhost/backend")).mapto[httpresponse] "<html><body><h1>api response after backend processing</h1></body></html>" } path("") { { respondwithmediatype(`text/html`) { // xml marshalled `text/xml` default, override here complete(forward) } } } } }

scala akka spray

Comments

Popular posts from this blog

php - Android app custom user registration and login with cookie using facebook sdk -

django - Access session in user model .save() -

php - .htaccess Multiple Rewrite Rules / Prioritizing -